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.repository.RepositoryAdminException;
25 import org.apache.archiva.admin.repository.managed.ManagedRepository;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.configuration.Configuration;
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( "addManagedRepositoryAction" )
41 public class AddManagedRepositoryAction
42 extends AbstractManagedRepositoriesAction
43 implements Preparable, Validateable
46 private ManagedRepository repository;
48 private boolean stageNeeded;
50 private String action = "addRepository";
54 this.repository = new ManagedRepository();
55 this.repository.setReleases( false );
56 this.repository.setScanned( false );
57 this.repository.setBlockRedeployments( false );
62 this.repository.setReleases( true );
63 this.repository.setScanned( true );
64 this.repository.setBlockRedeployments( true );
69 public String confirmAdd()
74 public String commit()
76 repository.setLocation( getRepositoryCommonValidator().removeExpressions( repository.getLocation() ) );
78 File location = new File( repository.getLocation() );
79 if ( location.exists() )
89 String result = SUCCESS;
92 getManagedRepositoryAdmin().addManagedRepository( repository, stageNeeded, getAuditInformation() );
94 catch ( RepositoryAdminException e )
96 log.error( e.getMessage(), e );
97 addActionError( "Check your server logs, Repository Administration Exception: " + e.getMessage() );
104 // FIXME olamy dupe with admin repo component
106 public void validate()
108 Configuration config = archivaConfiguration.getConfiguration();
110 CronExpressionValidator validator = new CronExpressionValidator();
111 String repoId = repository.getId();
113 if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
115 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
116 + "], that id already exists as a managed repository." );
118 else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
120 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
121 + "], that id already exists as a remote repository." );
123 else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
125 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
126 + "], that id already exists as a repository group." );
128 else if ( repoId.toLowerCase().contains( "stage" ) )
130 addFieldError( "repository.id", "Unable to add new repository with id [" + repoId
131 + "], repository id cannot contains word stage" );
134 if ( !validator.validate( repository.getCronExpression() ) )
136 addFieldError( "repository.refreshCronExpression", "Invalid cron expression." );
139 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
140 trimAllRequestParameterValues();
143 private void trimAllRequestParameterValues()
145 if ( StringUtils.isNotEmpty( repository.getId() ) )
147 repository.setId( repository.getId().trim() );
150 if ( StringUtils.isNotEmpty( repository.getName() ) )
152 repository.setName( repository.getName().trim() );
155 if ( StringUtils.isNotEmpty( repository.getLocation() ) )
157 repository.setLocation( repository.getLocation().trim() );
160 if ( StringUtils.isNotEmpty( repository.getIndexDirectory() ) )
162 repository.setIndexDirectory( repository.getIndexDirectory().trim() );
166 public ManagedRepository getRepository()
171 public void setRepository( ManagedRepository repository )
173 this.repository = repository;
177 public void setStageNeeded( boolean stageNeeded )
179 this.stageNeeded = stageNeeded;
182 public String getAction()