1 package org.apache.maven.archiva.web.action.admin.legacy;
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.admin.ArchivaAdministration;
26 import org.apache.archiva.admin.repository.admin.LegacyArtifactPath;
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.maven.archiva.model.ArtifactReference;
29 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
30 import org.apache.maven.archiva.web.action.AbstractActionSupport;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Controller;
34 import javax.inject.Inject;
35 import javax.inject.Named;
38 * Add a LegacyArtifactPath to archiva configuration
42 @Controller( "addLegacyArtifactPathAction" )
44 public class AddLegacyArtifactPathAction
45 extends AbstractActionSupport
46 implements Preparable, Validateable
50 private ArchivaAdministration archivaAdministration;
53 @Named( value = "managedRepositoryContent#legacy" )
54 private ManagedRepositoryContent repositoryContent;
57 private LegacyArtifactPath legacyArtifactPath;
59 private String groupId;
61 private String artifactId;
63 private String version;
65 private String classifier;
72 this.legacyArtifactPath = new LegacyArtifactPath();
80 public String commit()
82 this.legacyArtifactPath.setArtifact(
83 this.groupId + ":" + this.artifactId + ":" + this.version + ":" + this.classifier + ":" + this.type );
85 // Check the proposed Artifact macthes the path
86 ArtifactReference artifact = new ArtifactReference();
88 artifact.setGroupId( this.groupId );
89 artifact.setArtifactId( this.artifactId );
90 artifact.setClassifier( this.classifier );
91 artifact.setVersion( this.version );
92 artifact.setType( this.type );
94 String path = repositoryContent.toPath( artifact );
95 if ( !path.equals( this.legacyArtifactPath.getPath() ) )
97 addActionError( "artifact reference does not match the initial path : " + path );
103 getArchivaAdministration().addLegacyArtifactPath( legacyArtifactPath );
105 catch ( RepositoryAdminException e )
107 log.error( e.getMessage(), e );
108 addActionError( "Error occured " + e.getMessage() );
114 public LegacyArtifactPath getLegacyArtifactPath()
116 return legacyArtifactPath;
119 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
121 this.legacyArtifactPath = legacyArtifactPath;
124 public void validate()
126 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
127 trimAllRequestParameterValues();
130 private void trimAllRequestParameterValues()
132 if ( StringUtils.isNotEmpty( legacyArtifactPath.getPath() ) )
134 legacyArtifactPath.setPath( legacyArtifactPath.getPath().trim() );
137 if ( StringUtils.isNotEmpty( groupId ) )
139 groupId = groupId.trim();
142 if ( StringUtils.isNotEmpty( artifactId ) )
144 artifactId = artifactId.trim();
147 if ( StringUtils.isNotEmpty( version ) )
149 version = version.trim();
152 if ( StringUtils.isNotEmpty( classifier ) )
154 classifier = classifier.trim();
157 if ( StringUtils.isNotEmpty( type ) )
163 public String getGroupId()
168 public void setGroupId( String groupId )
170 this.groupId = groupId;
173 public String getArtifactId()
178 public void setArtifactId( String artifactId )
180 this.artifactId = artifactId;
183 public String getVersion()
188 public void setVersion( String version )
190 this.version = version;
193 public String getClassifier()
198 public void setClassifier( String classifier )
200 this.classifier = classifier;
203 public String getType()
208 public void setType( String type )
213 public ArchivaAdministration getArchivaAdministration()
215 return archivaAdministration;
218 public void setArchivaAdministration( ArchivaAdministration archivaAdministration )
220 this.archivaAdministration = archivaAdministration;