1 package org.apache.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.beans.ManagedRepository;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.archiva.redback.components.scheduler.CronExpressionValidator;
28 import org.springframework.context.annotation.Scope;
29 import org.springframework.stereotype.Controller;
34 * AddManagedRepositoryAction
38 @Controller( "editManagedRepositoryAction" )
40 public class EditManagedRepositoryAction
41 extends AbstractManagedRepositoriesAction
42 implements Preparable, Validateable
45 private ManagedRepository repository;
47 private ManagedRepository stagingRepository;
49 private String repoid;
51 private final String action = "editRepository";
53 private boolean stageNeeded;
56 // FIXME better error message
58 throws RepositoryAdminException
60 if ( StringUtils.isNotBlank( repoid ) )
62 repository = getManagedRepositoryAdmin().getManagedRepository( repoid );
63 stagingRepository = getManagedRepositoryAdmin().getManagedRepository( repoid + "-stage" );
65 else if ( repository != null )
67 repository.setReleases( false );
68 repository.setScanned( false );
74 if ( repository == null )
76 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
83 public String confirmUpdate()
85 // location was changed
89 public String commit()
90 throws RepositoryAdminException
92 ManagedRepository existingConfig = getManagedRepositoryAdmin().getManagedRepository( repository.getId() );
93 boolean resetStats = false;
95 // check if the location was changed
96 repository.setLocation( getRepositoryCommonValidator().removeExpressions( repository.getLocation() ) );
98 if ( !StringUtils.equalsIgnoreCase( existingConfig.getLocation().trim(), repository.getLocation().trim() ) )
102 File dir = new File( repository.getLocation() );
109 return save( resetStats );
112 private String save( boolean resetStats )
115 String result = SUCCESS;
118 getManagedRepositoryAdmin().updateManagedRepository( repository, stageNeeded, getAuditInformation(),
121 catch ( RepositoryAdminException e )
123 addActionError( "Repository Administration Exception: " + e.getMessage() );
132 public void validate()
134 CronExpressionValidator validator = new CronExpressionValidator();
136 if ( !validator.validate( repository.getCronExpression() ) )
138 addFieldError( "repository.cronExpression", "Invalid cron expression." );
141 trimAllRequestParameterValues();
144 private void trimAllRequestParameterValues()
146 if ( StringUtils.isNotEmpty( repository.getId() ) )
148 repository.setId( repository.getId().trim() );
151 if ( StringUtils.isNotEmpty( repository.getName() ) )
153 repository.setName( repository.getName().trim() );
156 if ( StringUtils.isNotEmpty( repository.getLocation() ) )
158 repository.setLocation( repository.getLocation().trim() );
161 if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
163 repository.setIndexDirectory( repository.getIndexDirectory().trim() );
167 public String getRepoid()
172 public void setRepoid( String repoid )
174 this.repoid = repoid;
178 public boolean isStageNeeded()
183 public void setStageNeeded( boolean stageNeeded )
186 this.stageNeeded = stageNeeded;
189 public String getAction()
194 public ManagedRepository getRepository()
199 public void setRepository( ManagedRepository repository )
201 this.repository = repository;
204 public ManagedRepository getStagingRepository()
206 return stagingRepository;
209 public void setStagingRepository( ManagedRepository stagingRepository )
211 this.stagingRepository = stagingRepository;