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;
25 import java.util.List;
28 * SortProxyConnectorsAction -
32 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="sortProxyConnectorsAction"
34 public class SortProxyConnectorsAction
35 extends AbstractProxyConnectorAction
37 private String source;
39 private String target;
41 public String getSource()
46 public String getTarget()
51 public void setSource( String id )
56 public void setTarget( String id )
61 public String sortDown()
63 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
65 int idx = findTargetConnector( connectors, target );
69 incrementConnectorOrder( connectors, idx );
70 decrementConnectorOrder( connectors, idx + 1 );
73 return saveConfiguration();
76 public String sortUp()
78 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
80 int idx = findTargetConnector( connectors, target );
84 decrementConnectorOrder( connectors, idx );
85 incrementConnectorOrder( connectors, idx - 1 );
88 return saveConfiguration();
91 private void decrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
93 if ( !validIndex( connectors, idx ) )
99 int order = connectors.get( idx ).getOrder();
100 connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) );
103 private int findTargetConnector( List<ProxyConnectorConfiguration> connectors, String targetRepoId )
107 for ( int i = 0; i < connectors.size(); i++ )
109 if ( StringUtils.equals( targetRepoId, connectors.get( i ).getTargetRepoId() ) )
119 private void incrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
121 if ( !validIndex( connectors, idx ) )
127 int order = connectors.get( idx ).getOrder();
128 connectors.get( idx ).setOrder( order + 1 );
131 private boolean validIndex( List<ProxyConnectorConfiguration> connectors, int idx )
133 return ( idx >= 0 ) && ( idx < connectors.size() );