diff options
4 files changed, 151 insertions, 3 deletions
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/MetadataAddRequest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/MetadataAddRequest.java new file mode 100644 index 000000000..b024fefae --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/MetadataAddRequest.java @@ -0,0 +1,85 @@ +package org.apache.archiva.rest.api.model; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlRootElement; +import java.io.Serializable; +import java.util.Map; + +/** + * @author Adrien Lecharpentier <alecharp@apache.org> + * @since 1.4-M4 + */ +@XmlRootElement( name = "metadataAddRequest" ) +public class MetadataAddRequest + implements Serializable +{ + private String groupId; + + private String artifactId; + + private String version; + + private Map<String, String> metadatas; + + public MetadataAddRequest() + { + // no op + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public Map<String, String> getMetadatas() + { + return metadatas; + } + + public void setMetadatas( Map<String, String> metadatas ) + { + this.metadatas = metadatas; + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java index 735ea9279..fc65767d7 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/BrowseService.java @@ -21,17 +21,18 @@ package org.apache.archiva.rest.api.services; import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.maven2.model.TreeEntry; -import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.rest.api.model.ArtifactContent; import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.Entry; +import org.apache.archiva.rest.api.model.MetadataAddRequest; import org.apache.archiva.rest.api.model.VersionsList; import javax.ws.rs.DELETE; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -151,6 +152,12 @@ public interface BrowseService @QueryParam ("repositoryId") String repositoryId ) throws ArchivaRestServiceException; + @Path( "importMetadata" ) + @POST + @RedbackAuthorization( noPermission = false, noRestriction = false, permissions = "archiva-add-metadata") + Boolean importMetadata( MetadataAddRequest metadataAddRequest, @QueryParam ("repository") String repository ) + throws ArchivaRestServiceException; + @Path ("artifactContentEntries/{g}/{a}/{v}") @GET @Produces ({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java index 891c250e2..c16288040 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultBrowseService.java @@ -48,6 +48,7 @@ import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; import org.apache.archiva.rest.api.model.Entry; +import org.apache.archiva.rest.api.model.MetadataAddRequest; import org.apache.archiva.rest.api.model.VersionsList; import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.BrowseService; @@ -82,7 +83,7 @@ import java.util.zip.ZipEntry; * @author Olivier Lamy * @since 1.4-M3 */ -@Service ( "browseService#rest" ) +@Service( "browseService#rest" ) public class DefaultBrowseService extends AbstractRestService implements BrowseService @@ -95,7 +96,7 @@ public class DefaultBrowseService private RepositoryContentFactory repositoryContentFactory; @Inject - @Named ( value = "repositoryProxyConnectors#default" ) + @Named( value = "repositoryProxyConnectors#default" ) private RepositoryProxyConnectors connectors; public BrowseResult getRootGroups( String repositoryId ) @@ -849,6 +850,23 @@ public class DefaultBrowseService } } + public Boolean importMetadata( MetadataAddRequest metadataAddRequest, String repositoryId ) + throws ArchivaRestServiceException + { + boolean result = true; + for ( Map.Entry<String, String> metadata : metadataAddRequest.getMetadatas().entrySet() ) + { + result = addMetadata( metadataAddRequest.getGroupId(), metadataAddRequest.getArtifactId(), + metadataAddRequest.getVersion(), metadata.getKey(), metadata.getValue(), + repositoryId ); + if ( !result ) + { + break; + } + } + return result; + } + //--------------------------- // internals //--------------------------- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java index 05796a7d6..b565539d3 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/BrowseServiceTest.java @@ -24,6 +24,7 @@ import org.apache.archiva.rest.api.model.ArtifactContentEntry; import org.apache.archiva.rest.api.model.BrowseResult; import org.apache.archiva.rest.api.model.BrowseResultEntry; import org.apache.archiva.rest.api.model.Entry; +import org.apache.archiva.rest.api.model.MetadataAddRequest; import org.apache.archiva.rest.api.model.VersionsList; import org.apache.archiva.rest.api.services.BrowseService; import org.apache.cxf.jaxrs.client.WebClient; @@ -460,4 +461,41 @@ public class BrowseServiceTest } } + @Test + public void metadatainbatchmode() + throws Exception + { + + String testRepoId = "test-repo"; + // force guest user creation if not exists + if ( getUserService( authorizationHeader ).getGuestUser() == null ) + { + assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); + } + + createAndIndexRepo( testRepoId, new File( getBasedir(), "src/test/repo-with-osgi" ).getAbsolutePath() ); + + BrowseService browseService = getBrowseService( authorizationHeader, false ); + + Map<String, String> inputMetadata = new HashMap<String, String>( 3 ); + inputMetadata.put( "buildNumber", "1" ); + inputMetadata.put( "author", "alecharp" ); + inputMetadata.put( "jenkins_version", "1.486" ); + + MetadataAddRequest metadataAddRequest = new MetadataAddRequest(); + metadataAddRequest.setGroupId( "commons-cli" ); + metadataAddRequest.setArtifactId( "commons-cli" ); + metadataAddRequest.setVersion( "1.0" ); + metadataAddRequest.setMetadatas( inputMetadata ); + browseService.importMetadata( metadataAddRequest, testRepoId ); + + Map<String, String> metadatas = + toMap( browseService.getMetadatas( "commons-cli", "commons-cli", "1.0", testRepoId ) ); + + assertThat( metadatas ).isNotNull().isNotEmpty().contains( MapEntry.entry( "buildNumber", "1" ) ).contains( + MapEntry.entry( "author", "alecharp" ) ).contains( MapEntry.entry( "jenkins_version", "1.486" ) ); + + deleteTestRepo( testRepoId ); + } + } |