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 -
30 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
33 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="sortProxyConnectorsAction"
35 public class SortProxyConnectorsAction
36 extends AbstractProxyConnectorAction
38 private String source;
40 private String target;
42 public String getSource()
47 public String getTarget()
52 public void setSource( String id )
57 public void setTarget( String id )
62 public String sortDown()
64 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
66 int idx = findTargetConnector( connectors, target );
70 incrementConnectorOrder( connectors, idx );
71 decrementConnectorOrder( connectors, idx + 1 );
74 return saveConfiguration();
77 public String sortUp()
79 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
81 int idx = findTargetConnector( connectors, target );
85 decrementConnectorOrder( connectors, idx );
86 incrementConnectorOrder( connectors, idx - 1 );
89 return saveConfiguration();
92 private void decrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
94 if ( !validIndex( connectors, idx ) )
100 int order = connectors.get( idx ).getOrder();
101 connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) );
104 private int findTargetConnector( List<ProxyConnectorConfiguration> connectors, String targetRepoId )
108 for ( int i = 0; i < connectors.size(); i++ )
110 if ( StringUtils.equals( targetRepoId, connectors.get( i ).getTargetRepoId() ) )
120 private void incrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
122 if ( !validIndex( connectors, idx ) )
128 int order = connectors.get( idx ).getOrder();
129 connectors.get( idx ).setOrder( order + 1 );
132 private boolean validIndex( List<ProxyConnectorConfiguration> connectors, int idx )
134 return ( idx >= 0 ) && ( idx < connectors.size() );