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 com.opensymphony.xwork2.Preparable;
23 import com.opensymphony.xwork2.Validateable;
24 import org.apache.archiva.admin.model.RepositoryAdminException;
25 import org.apache.archiva.admin.model.managed.ManagedRepository;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.codehaus.redback.components.scheduler.CronExpressionValidator;
29 import org.springframework.context.annotation.Scope;
30 import org.springframework.stereotype.Controller;
35 * AddManagedRepositoryAction
39 @Controller( "editManagedRepositoryAction" )
41 public class EditManagedRepositoryAction
42 extends AbstractManagedRepositoriesAction
43 implements Preparable, Validateable
46 private ManagedRepository repository;
48 private ManagedRepository stagingRepository;
50 private String repoid;
52 private final String action = "editRepository";
54 private boolean stageNeeded;
57 // FIXME better error message
59 throws RepositoryAdminException
61 if ( StringUtils.isNotBlank( repoid ) )
63 repository = getManagedRepositoryAdmin().getManagedRepository( repoid );
64 stagingRepository = getManagedRepositoryAdmin().getManagedRepository( repoid + "-stage" );
66 else if ( repository != null )
68 repository.setReleases( false );
69 repository.setScanned( false );
75 if ( repository == null )
77 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
84 public String confirmUpdate()
86 // location was changed
90 // FIXME olamy use ManagedRepositoryAdmin rather tha, directly archivaConfiguration
91 public String commit()
93 ManagedRepositoryConfiguration existingConfig =
94 archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
95 boolean resetStats = false;
97 // check if the location was changed
98 repository.setLocation( getRepositoryCommonValidator().removeExpressions( repository.getLocation() ) );
100 if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
104 File dir = new File( repository.getLocation() );
111 return save( resetStats );
114 private String save( boolean resetStats )
117 String result = SUCCESS;
120 getManagedRepositoryAdmin().updateManagedRepository( repository, stageNeeded, getAuditInformation(),
123 catch ( RepositoryAdminException e )
125 addActionError( "Repository Administration Exception: " + e.getMessage() );
134 public void validate()
136 CronExpressionValidator validator = new CronExpressionValidator();
138 if ( !validator.validate( repository.getCronExpression() ) )
140 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
143 trimAllRequestParameterValues();
146 private void trimAllRequestParameterValues()
148 if ( StringUtils.isNotEmpty( repository.getId() ) )
150 repository.setId( repository.getId().trim() );
153 if ( StringUtils.isNotEmpty( repository.getName() ) )
155 repository.setName( repository.getName().trim() );
158 if ( StringUtils.isNotEmpty( repository.getLocation() ) )
160 repository.setLocation( repository.getLocation().trim() );
163 if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
165 repository.setIndexDirectory( repository.getIndexDirectory().trim() );
169 public String getRepoid()
174 public void setRepoid( String repoid )
176 this.repoid = repoid;
180 public boolean isStageNeeded()
185 public void setStageNeeded( boolean stageNeeded )
188 this.stageNeeded = stageNeeded;
191 public String getAction()
196 public ManagedRepository getRepository()
201 public void setRepository( ManagedRepository repository )
203 this.repository = repository;
206 public ManagedRepository getStagingRepository()
208 return stagingRepository;
211 public void setStagingRepository( ManagedRepository stagingRepository )
213 this.stagingRepository = stagingRepository;