* under the License.
*/
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
*/
private String artifact;
+ private String groupId;
+
+ private String artifactId;
+
+ private String version;
+
+ private String classifier;
+
+ private String type;
+
public LegacyArtifactPath()
{
// no op
public LegacyArtifactPath( String path, String artifact )
{
this.path = path;
+
this.artifact = artifact;
+ initValues( this.artifact );
+ }
+
+ private void initValues( String artifact )
+ {
+ String[] splitted = artifact.split( ":" );
+ if ( splitted.length < 4 )
+ {
+ throw new IllegalArgumentException( "artifact value '" + artifact + "' is not correct" );
+ }
+ this.groupId = splitted[0];// artifact.split( ":" )[0];
+ this.artifactId = splitted[1];// artifact.split( ":" )[1];
+ this.version = splitted[2];// artifact.split( ":" )[2];
+ String classifier = splitted.length >= 4 ? splitted[3] : null;// artifact.split( ":" )[3];
+ this.classifier = classifier.length() > 0 ? classifier : null;
+ String type = splitted.length >= 5 ? splitted[4] : null;
+ this.type = type.length() > 0 ? artifact.split( ":" )[4] : null;
}
public String getPath()
public void setArtifact( String artifact )
{
this.artifact = artifact;
+ initValues( this.artifact );
}
public boolean match( String path )
return path.equals( this.path );
}
- @JsonIgnore
+ public void setGroupId( String groupId )
+ {
+ this.groupId = groupId;
+ }
+
public String getGroupId()
{
- return artifact.split( ":" )[0];
+ return this.groupId;// artifact.split( ":" )[0];
}
- @JsonIgnore
+
public String getArtifactId()
{
- return artifact.split( ":" )[1];
+ return this.artifactId;// artifact.split( ":" )[1];
+ }
+
+ public void setArtifactId( String artifactId )
+ {
+ this.artifactId = artifactId;
}
- @JsonIgnore
public String getVersion()
{
- return artifact.split( ":" )[2];
+ return this.version;// artifact.split( ":" )[2];
}
- @JsonIgnore
public String getClassifier()
{
- String classifier = artifact.split( ":" )[3];
- return classifier.length() > 0 ? classifier : null;
+ //String classifier = artifact.split( ":" )[3];
+ //return classifier.length() > 0 ? classifier : null;
+ return this.classifier;
}
- @JsonIgnore
public String getType()
{
- return artifact.split( ":" )[4];
+ return this.type;// artifact.split( ":" )[4];
}
@Override
sb.append( "LegacyArtifactPath" );
sb.append( "{path='" ).append( path ).append( '\'' );
sb.append( ", artifact='" ).append( artifact ).append( '\'' );
+ sb.append( ", groupId='" ).append( groupId ).append( '\'' );
+ sb.append( ", artifactId='" ).append( artifactId ).append( '\'' );
+ sb.append( ", version='" ).append( version ).append( '\'' );
+ sb.append( ", classifier='" ).append( classifier ).append( '\'' );
+ sb.append( ", type='" ).append( type ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
import org.apache.archiva.admin.model.beans.NetworkConfiguration;
import org.apache.archiva.admin.model.beans.OrganisationInformation;
import org.apache.archiva.admin.model.beans.UiConfiguration;
+import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.rest.api.services.ArchivaAdministrationService;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
+import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
+import javax.inject.Named;
+import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Inject
private ArchivaAdministration archivaAdministration;
+ @Inject
+ @Named( value = "managedRepositoryContent#legacy" )
+ private ManagedRepositoryContent repositoryContent;
+
public List<LegacyArtifactPath> getLegacyArtifactPaths()
throws ArchivaRestServiceException
{
public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
throws ArchivaRestServiceException
{
+
+ // Check the proposed Artifact macthes the path
+ ArtifactReference artifact = new ArtifactReference();
+
+ artifact.setGroupId( legacyArtifactPath.getGroupId() );
+ artifact.setArtifactId( legacyArtifactPath.getArtifactId() );
+ artifact.setClassifier( legacyArtifactPath.getClassifier() );
+ artifact.setVersion( legacyArtifactPath.getVersion() );
+ artifact.setType( legacyArtifactPath.getType() );
+ String path = repositoryContent.toPath( artifact );
+ if ( !StringUtils.equals( path, legacyArtifactPath.getPath() ) )
+ {
+ throw new ArchivaRestServiceException(
+ "artifact path reference '" + legacyArtifactPath.getPath() + "' does not match the initial path: '"
+ + path + "'", Response.Status.BAD_REQUEST.getStatusCode() );
+ }
+
try
{
+
archivaAdministration.addLegacyArtifactPath( legacyArtifactPath, getAuditInformation() );
}
catch ( RepositoryAdminException e )
public void addAndDeleteLegacyPath()
throws Exception
{
+ //Path jaxen/jars/jaxen-1.0-FCS-full.jar
+ //Artifact jaxen:jaxen:1.0-FCS:full:jar
int initialSize = getArchivaAdministrationService().getLegacyArtifactPaths().size();
LegacyArtifactPath legacyArtifactPath = new LegacyArtifactPath();
- legacyArtifactPath.setArtifact( "foo" );
- legacyArtifactPath.setPath( "bar" );
+ legacyArtifactPath.setArtifact( "wine:bordeaux:2006:GREAT:jar" );
+ legacyArtifactPath.setPath( "wine/jars/bordeaux-2006-GREAT.jar" );
getArchivaAdministrationService().addLegacyArtifactPath( legacyArtifactPath );
assertEquals( initialSize + 1, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
- getArchivaAdministrationService().deleteLegacyArtifactPath( "bar" );
+ getArchivaAdministrationService().deleteLegacyArtifactPath( "wine/jars/bordeaux-2006-GREAT.jar" );
assertEquals( initialSize, getArchivaAdministrationService().getLegacyArtifactPaths().size() );
}