1 package org.apache.maven.archiva.web.action.admin.repositories;
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.Configuration;
24 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
25 import org.springframework.context.annotation.Scope;
26 import org.springframework.stereotype.Controller;
28 import java.util.List;
31 * SortRepositoriesAction
32 * FIXME remove access to archivaconfiguration
34 @Controller( "sortRepositoriesAction" )
36 public class SortRepositoriesAction
37 extends AbstractRepositoriesAdminAction
40 private String repoGroupId;
42 private String targetRepo;
44 public String sortDown()
46 Configuration config = archivaConfiguration.getConfiguration();
48 List<String> repositories = getRepositoriesFromGroup();
50 int idx = findTargetRepository( repositories, targetRepo );
52 if ( idx >= 0 && validIndex( repositories, idx + 1 ) )
54 repositories.remove( idx );
55 repositories.add( idx + 1, targetRepo );
58 return saveConfiguration( config );
61 public String sortUp()
63 Configuration config = archivaConfiguration.getConfiguration();
65 List<String> repositories = getRepositoriesFromGroup();
67 int idx = findTargetRepository( repositories, targetRepo );
69 if ( idx >= 0 && validIndex( repositories, idx - 1 ) )
71 repositories.remove( idx );
72 repositories.add( idx - 1, targetRepo );
75 return saveConfiguration( config );
78 public String getRepoGroupId()
83 public void setRepoGroupId( String repoGroupId )
85 this.repoGroupId = repoGroupId;
88 public String getTargetRepo()
93 public void setTargetRepo( String targetRepo )
95 this.targetRepo = targetRepo;
98 private int findTargetRepository( List<String> repositories, String targetRepository )
102 for ( int i = 0; i < repositories.size(); i++ )
104 if ( StringUtils.equals( targetRepository, repositories.get( i ) ) )
113 private List<String> getRepositoriesFromGroup()
115 Configuration config = archivaConfiguration.getConfiguration();
116 RepositoryGroupConfiguration repoGroup = config.findRepositoryGroupById( repoGroupId );
117 return repoGroup.getRepositories();
120 private boolean validIndex( List<String> repositories, int idx )
122 return ( idx >= 0 ) && ( idx < repositories.size() );