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.xwork.Preparable;
23 import com.opensymphony.xwork.Validateable;
25 import org.apache.commons.lang.StringUtils;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.codehaus.plexus.redback.role.RoleManagerException;
29 import org.codehaus.plexus.scheduler.CronExpressionValidator;
31 import java.io.IOException;
34 * AddManagedRepositoryAction
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="editManagedRepositoryAction"
41 public class EditManagedRepositoryAction
42 extends AbstractManagedRepositoriesAction
43 implements Preparable, Validateable
46 * The model for this action.
48 private ManagedRepositoryConfiguration repository;
50 private String repoid;
54 if ( StringUtils.isNotBlank( repoid ) )
56 repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid );
58 else if ( repository != null )
60 repository.setReleases( false );
61 repository.setScanned( false );
67 if ( repository == null )
69 addActionError( "Edit failure, unable to edit a repository with a blank repository id." );
76 public String commit()
78 // Ensure that the fields are valid.
79 Configuration configuration = archivaConfiguration.getConfiguration();
81 // We are in edit mode, remove the old repository configuration.
82 removeRepository( repository.getId(), configuration );
84 // Save the repository configuration.
88 addRepository( repository, configuration );
89 addRepositoryRoles( repository );
90 result = saveConfiguration( configuration );
92 catch ( IOException e )
94 addActionError( "I/O Exception: " + e.getMessage() );
97 catch ( RoleManagerException e )
99 addActionError( "Role Manager Exception: " + e.getMessage() );
107 public void validate()
109 CronExpressionValidator validator = new CronExpressionValidator();
111 if ( !validator.validate( repository.getRefreshCronExpression() ) )
113 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
117 public String getRepoid()
122 public void setRepoid( String repoid )
124 this.repoid = repoid;
127 public ManagedRepositoryConfiguration getRepository()
132 public void setRepository( ManagedRepositoryConfiguration repository )
134 this.repository = repository;