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 java.util.List;
24 import org.apache.commons.lang.StringUtils;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
29 * SortRepositoriesAction
32 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="sortRepositoriesAction"
34 public class SortRepositoriesAction
35 extends AbstractRepositoriesAdminAction
37 private String repoGroupId;
39 private String targetRepo;
41 public String sortDown()
43 Configuration config = archivaConfiguration.getConfiguration();
45 List<String> repositories = getRepositoriesFromGroup();
47 int idx = findTargetRepository( repositories, targetRepo );
49 if ( idx >= 0 && validIndex( repositories, idx + 1 ) )
51 repositories.remove( idx );
52 repositories.add( idx + 1, targetRepo );
55 return saveConfiguration( config );
58 public String sortUp()
60 Configuration config = archivaConfiguration.getConfiguration();
62 List<String> repositories = getRepositoriesFromGroup();
64 int idx = findTargetRepository( repositories, targetRepo );
66 if ( idx >= 0 && validIndex( repositories, idx - 1 ) )
68 repositories.remove( idx );
69 repositories.add( idx - 1, targetRepo );
72 return saveConfiguration( config );
75 public String getRepoGroupId()
80 public void setRepoGroupId( String repoGroupId )
82 this.repoGroupId = repoGroupId;
85 public String getTargetRepo()
90 public void setTargetRepo( String targetRepo )
92 this.targetRepo = targetRepo;
95 private int findTargetRepository( List<String> repositories, String targetRepository )
99 for ( int i = 0; i < repositories.size(); i++ )
101 if ( StringUtils.equals( targetRepository, repositories.get(i) ) )
110 private List<String> getRepositoriesFromGroup()
112 Configuration config = archivaConfiguration.getConfiguration();
113 RepositoryGroupConfiguration repoGroup = config.findRepositoryGroupById( repoGroupId );
114 return repoGroup.getRepositories();
117 private boolean validIndex( List<String> repositories, int idx )
119 return ( idx >= 0 ) && ( idx < repositories.size() );