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
34 @Controller( "sortRepositoriesAction" )
36 public class SortRepositoriesAction
37 extends AbstractRepositoriesAdminAction
39 private String repoGroupId;
41 private String targetRepo;
43 public String sortDown()
45 Configuration config = archivaConfiguration.getConfiguration();
47 List<String> repositories = getRepositoriesFromGroup();
49 int idx = findTargetRepository( repositories, targetRepo );
51 if ( idx >= 0 && validIndex( repositories, idx + 1 ) )
53 repositories.remove( idx );
54 repositories.add( idx + 1, targetRepo );
57 return saveConfiguration( config );
60 public String sortUp()
62 Configuration config = archivaConfiguration.getConfiguration();
64 List<String> repositories = getRepositoriesFromGroup();
66 int idx = findTargetRepository( repositories, targetRepo );
68 if ( idx >= 0 && validIndex( repositories, idx - 1 ) )
70 repositories.remove( idx );
71 repositories.add( idx - 1, targetRepo );
74 return saveConfiguration( config );
77 public String getRepoGroupId()
82 public void setRepoGroupId( String repoGroupId )
84 this.repoGroupId = repoGroupId;
87 public String getTargetRepo()
92 public void setTargetRepo( String targetRepo )
94 this.targetRepo = targetRepo;
97 private int findTargetRepository( List<String> repositories, String targetRepository )
101 for ( int i = 0; i < repositories.size(); i++ )
103 if ( StringUtils.equals( targetRepository, repositories.get( i ) ) )
112 private List<String> getRepositoriesFromGroup()
114 Configuration config = archivaConfiguration.getConfiguration();
115 RepositoryGroupConfiguration repoGroup = config.findRepositoryGroupById( repoGroupId );
116 return repoGroup.getRepositories();
119 private boolean validIndex( List<String> repositories, int idx )
121 return ( idx >= 0 ) && ( idx < repositories.size() );