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 @Controller( "sortProxyConnectorsAction" )
36 public class SortProxyConnectorsAction
37 extends AbstractProxyConnectorAction
39 private String source;
41 private String target;
43 public String getSource()
48 public String getTarget()
53 public void setSource( String id )
58 public void setTarget( String id )
63 public String sortDown()
65 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
67 int idx = findTargetConnector( connectors, target );
71 incrementConnectorOrder( connectors, idx );
72 decrementConnectorOrder( connectors, idx + 1 );
75 return saveConfiguration();
78 public String sortUp()
80 List<ProxyConnectorConfiguration> connectors = createProxyConnectorMap().get( source );
82 int idx = findTargetConnector( connectors, target );
86 decrementConnectorOrder( connectors, idx );
87 incrementConnectorOrder( connectors, idx - 1 );
90 return saveConfiguration();
93 private void decrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
95 if ( !validIndex( connectors, idx ) )
101 int order = connectors.get( idx ).getOrder();
102 connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) );
105 private int findTargetConnector( List<ProxyConnectorConfiguration> connectors, String targetRepoId )
109 for ( int i = 0; i < connectors.size(); i++ )
111 if ( StringUtils.equals( targetRepoId, connectors.get( i ).getTargetRepoId() ) )
121 private void incrementConnectorOrder( List<ProxyConnectorConfiguration> connectors, int idx )
123 if ( !validIndex( connectors, idx ) )
129 int order = connectors.get( idx ).getOrder();
130 connectors.get( idx ).setOrder( order + 1 );
133 private boolean validIndex( List<ProxyConnectorConfiguration> connectors, int idx )
135 return ( idx >= 0 ) && ( idx < connectors.size() );