From: Olivier Lamy Date: Tue, 6 Sep 2011 21:32:13 +0000 (+0000) Subject: [MRM-1490] Expose Archiva services trough REST : repository group admin tru rest... X-Git-Tag: archiva-1.4-M1~371 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b11271fe494ce22fb01335b9f4b9a8be8870cd36;p=archiva.git [MRM-1490] Expose Archiva services trough REST : repository group admin tru rest service git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165865 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/RepositoryGroup.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/RepositoryGroup.java new file mode 100644 index 000000000..aaa908d5a --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/RepositoryGroup.java @@ -0,0 +1,136 @@ +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.ArrayList; +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@XmlRootElement( name = "repositoryGroup" ) +public class RepositoryGroup + implements Serializable +{ + /** + * repository group Id + */ + private String id; + + /** + * repositories ids + */ + private List repositories; + + public RepositoryGroup() + { + // no op + } + + public RepositoryGroup( String id, List repositories ) + { + this.id = id; + this.repositories = repositories; + } + + /** + * Get the id of the repository group. + * + * @return String + */ + public String getId() + { + return this.id; + } + + /** + * Method getRepositories. + * + * @return List + */ + public List getRepositories() + { + if ( this.repositories == null ) + { + this.repositories = new ArrayList(); + } + + return this.repositories; + } + + + /** + * Set the id of the repository group. + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } + + /** + * Set the list of repository ids under the group. + * + * @param repositories + */ + public void setRepositories( List repositories ) + { + this.repositories = repositories; + } + + public boolean equals( Object other ) + { + if ( this == other ) + { + return true; + } + + if ( !( other instanceof RepositoryGroup ) ) + { + return false; + } + + RepositoryGroup that = (RepositoryGroup) other; + boolean result = true; + result = result && ( getId() == null ? that.getId() == null : getId().equals( that.getId() ) ); + return result; + } + + public int hashCode() + { + int result = 17; + result = 37 * result + ( id != null ? id.hashCode() : 0 ); + return result; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(); + sb.append( "RepositoryGroup" ); + sb.append( "{id='" ).append( id ).append( '\'' ); + sb.append( ", repositories=" ).append( repositories ); + sb.append( '}' ); + return sb.toString(); + } +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoryGroupService.java new file mode 100644 index 000000000..fd26e24df --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoryGroupService.java @@ -0,0 +1,97 @@ +package org.apache.archiva.rest.api.services; +/* + * 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 org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.rest.api.model.RepositoryGroup; +import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.codehaus.plexus.redback.authorization.RedbackAuthorization; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@Path( "/repositoryGroupService/" ) +public interface RepositoryGroupService +{ + @Path( "getRepositoriesGroups" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + List getRepositoriesGroups() + throws RepositoryAdminException; + + @Path( "getRepositoryGroup/{repositoryGroupId}" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + RepositoryGroup getRepositoryGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId ) + throws RepositoryAdminException; + + @Path( "addRepositoryGroup" ) + @POST + @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean addRepositoryGroup( RepositoryGroup repositoryGroup ) + throws RepositoryAdminException; + + @Path( "updateRepositoryGroup" ) + @POST + @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean updateRepositoryGroup( RepositoryGroup repositoryGroup ) + throws RepositoryAdminException; + + @Path( "deleteRepositoryGroup/{repositoryGroupId}" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean deleteRepositoryGroup( @PathParam( "repositoryGroupId" ) String repositoryGroupId ) + throws RepositoryAdminException; + + @Path( "addRepositoryToGroup" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean addRepositoryToGroup( @QueryParam( "repositoryGroupId" ) String repositoryGroupId, + @QueryParam( "repositoryId" ) String repositoryId ) + throws RepositoryAdminException; + + @Path( "addRepositoryToGroup" ) + @GET + @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN } ) + @RedbackAuthorization( permission = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) + Boolean deleteRepositoryFromGroup( @QueryParam( "repositoryGroupId" ) String repositoryGroupId, + @QueryParam( "repositoryId" ) String repositoryId ) + throws RepositoryAdminException; + + +} diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java new file mode 100644 index 000000000..eb2767ac3 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java @@ -0,0 +1,100 @@ +package org.apache.archiva.rest.services; +/* + * 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 org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.group.RepositoryGroupAdmin; +import org.apache.archiva.rest.api.model.RepositoryGroup; +import org.apache.archiva.rest.api.services.RepositoryGroupService; +import org.apache.commons.lang.StringUtils; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Olivier Lamy + */ +public class DefaultRepositoryGroupService + extends AbstractRestService + implements RepositoryGroupService +{ + + @Inject + private RepositoryGroupAdmin repositoryGroupAdmin; + + public List getRepositoriesGroups() + throws RepositoryAdminException + { + List repositoriesGroups = new ArrayList(); + for ( org.apache.archiva.admin.repository.group.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() ) + { + repositoriesGroups.add( + new RepositoryGroup( repoGroup.getId(), new ArrayList( repoGroup.getRepositories() ) ) ); + } + return repositoriesGroups; + } + + public RepositoryGroup getRepositoryGroup( String repositoryGroupId ) + throws RepositoryAdminException + { + for ( RepositoryGroup repositoryGroup : getRepositoriesGroups() ) + { + if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) ) + { + return repositoryGroup; + } + } + return null; + } + + public Boolean addRepositoryGroup( RepositoryGroup repoGroup ) + throws RepositoryAdminException + { + return repositoryGroupAdmin.addRepositoryGroup( + new org.apache.archiva.admin.repository.group.RepositoryGroup( repoGroup.getId(), new ArrayList( + repoGroup.getRepositories() ) ), getAuditInformation() ); + } + + public Boolean updateRepositoryGroup( RepositoryGroup repoGroup ) + throws RepositoryAdminException + { + return repositoryGroupAdmin.updateRepositoryGroup( + new org.apache.archiva.admin.repository.group.RepositoryGroup( repoGroup.getId(), new ArrayList( + repoGroup.getRepositories() ) ), getAuditInformation() ); + } + + public Boolean deleteRepositoryGroup( String repositoryGroupId ) + throws RepositoryAdminException + { + return repositoryGroupAdmin.deleteRepositoryGroup( repositoryGroupId, getAuditInformation() ); + } + + public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId ) + throws RepositoryAdminException + { + return repositoryGroupAdmin.addRepositoryToGroup( repositoryGroupId, repositoryId, getAuditInformation() ); + } + + public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId ) + throws RepositoryAdminException + { + return repositoryGroupAdmin.deleteRepositoryFromGroup( repositoryGroupId, repositoryId, getAuditInformation() ); + } +}