[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
This commit is contained in:
Olivier Lamy 2011-09-06 21:32:13 +00:00
parent fcaaaa56a5
commit b11271fe49
3 changed files with 333 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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;
}

View File

@ -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() );
}
}