1 package org.apache.maven.archiva.web.action.admin.connectors.proxy;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.lang.StringUtils;
23 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
24 import org.springframework.context.annotation.Scope;
25 import org.springframework.stereotype.Controller;
27 import java.util.List;
30 * SortProxyConnectorsAction -
34 * plexus.component role="com.opensymphony.xwork2.Action" role-hint="sortProxyConnectorsAction" instantiation-strategy="per-lookup"
36 @Controller( "sortProxyConnectorsAction" )
38 public class SortProxyConnectorsAction
39 extends AbstractProxyConnectorAction
41 private String source;
43 private String target;
45 public String getSource()
50 public String getTarget()
55 public void setSource( String id )
60 public void setTarget( String id )
65 public String sortDown()
67 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
69 int idx = findTargetConnector( connectors, target );
73 incrementConnectorOrder( connectors, idx );
74 decrementConnectorOrder( connectors, idx + 1 );
77 return saveConfiguration();
80 public String sortUp()
82 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
84 int idx = findTargetConnector( connectors, target );
88 decrementConnectorOrder( connectors, idx );
89 incrementConnectorOrder( connectors, idx - 1 );
92 return saveConfiguration();
95 private void decrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
97 if ( !validIndex( connectors, idx ) )
103 int order = connectors.get( idx ).getOrder();
104 connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) );
107 private int findTargetConnector( List<ProxyConnectorConfiguration> connectors, String targetRepoId )
111 for ( int i = 0; i < connectors.size(); i++ )
113 if ( StringUtils.equals( targetRepoId, connectors.get( i ).getTargetRepoId() ) )
123 private void incrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
125 if ( !validIndex( connectors, idx ) )
131 int order = connectors.get( idx ).getOrder();
132 connectors.get( idx ).setOrder( order + 1 );
135 private boolean validIndex( List<ProxyConnectorConfiguration> connectors, int idx )
137 return ( idx >= 0 ) && ( idx < connectors.size() );