1 package org.apache.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.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ProxyConnector;
24 import org.apache.commons.lang.StringUtils;
25 import org.springframework.context.annotation.Scope;
26 import org.springframework.stereotype.Controller;
28 import java.util.List;
31 * SortProxyConnectorsAction -
35 @Controller( "sortProxyConnectorsAction" )
37 public class SortProxyConnectorsAction
38 extends AbstractProxyConnectorAction
40 private String source;
42 private String target;
44 public String getSource()
49 public String getTarget()
54 public void setSource( String id )
59 public void setTarget( String id )
64 public String sortDown()
65 throws RepositoryAdminException
67 List<ProxyConnector> connectors = createProxyConnectorMap().get( source );
69 int idx = findTargetConnector( connectors, target );
73 incrementConnectorOrder( connectors, idx );
74 decrementConnectorOrder( connectors, idx + 1 );
77 for ( ProxyConnector proxyConnector : connectors )
79 getProxyConnectorAdmin().updateProxyConnector( proxyConnector, getAuditInformation() );
84 public String sortUp()
85 throws RepositoryAdminException
87 List<ProxyConnector> connectors = createProxyConnectorMap().get( source );
89 int idx = findTargetConnector( connectors, target );
93 decrementConnectorOrder( connectors, idx );
94 incrementConnectorOrder( connectors, idx - 1 );
97 for ( ProxyConnector proxyConnector : connectors )
99 getProxyConnectorAdmin().updateProxyConnector( proxyConnector, getAuditInformation() );
104 private void decrementConnectorOrder( List<ProxyConnector> connectors, int idx )
106 if ( !validIndex( connectors, idx ) )
112 int order = connectors.get( idx ).getOrder();
113 connectors.get( idx ).setOrder( Math.max( 1, order - 1 ) );
116 private int findTargetConnector( List<ProxyConnector> connectors, String targetRepoId )
120 for ( int i = 0; i < connectors.size(); i++ )
122 if ( StringUtils.equals( targetRepoId, connectors.get( i ).getTargetRepoId() ) )
132 private void incrementConnectorOrder( List<ProxyConnector> connectors, int idx )
134 if ( !validIndex( connectors, idx ) )
140 int order = connectors.get( idx ).getOrder();
141 connectors.get( idx ).setOrder( order + 1 );
144 private boolean validIndex( List<ProxyConnector> connectors, int idx )
146 return ( idx >= 0 ) && ( idx < connectors.size() );