]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1490] Expose Archiva services trough REST : repository group admin tru rest...
authorOlivier Lamy <olamy@apache.org>
Tue, 6 Sep 2011 21:32:13 +0000 (21:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 6 Sep 2011 21:32:13 +0000 (21:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165865 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/model/RepositoryGroup.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/RepositoryGroupService.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoryGroupService.java [new file with mode: 0644]

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 (file)
index 0000000..aaa908d
--- /dev/null
@@ -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<String> repositories;
+
+    public RepositoryGroup()
+    {
+        // no op
+    }
+
+    public RepositoryGroup( String id, List<String> 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<String> getRepositories()
+    {
+        if ( this.repositories == null )
+        {
+            this.repositories = new ArrayList<String>();
+        }
+
+        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<String> 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 (file)
index 0000000..fd26e24
--- /dev/null
@@ -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<RepositoryGroup> 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 (file)
index 0000000..eb2767a
--- /dev/null
@@ -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<RepositoryGroup> getRepositoriesGroups()
+        throws RepositoryAdminException
+    {
+        List<RepositoryGroup> repositoriesGroups = new ArrayList<RepositoryGroup>();
+        for ( org.apache.archiva.admin.repository.group.RepositoryGroup repoGroup : repositoryGroupAdmin.getRepositoriesGroups() )
+        {
+            repositoriesGroups.add(
+                new RepositoryGroup( repoGroup.getId(), new ArrayList<String>( 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<String>(
+                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<String>(
+                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() );
+    }
+}