mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
improve RepositoryResource
This commit is contained in:
@@ -19,13 +19,20 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.PUT;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
import javax.ws.rs.core.Response.Status;
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -62,6 +69,86 @@ public class RepositoryResource
|
|||||||
"SONIA WebApplications"));
|
"SONIA WebApplications"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param uriInfo
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
|
public Response add(@Context UriInfo uriInfo, Repository repository)
|
||||||
|
{
|
||||||
|
repositoryStore.put(repository.getName(), repository);
|
||||||
|
|
||||||
|
return Response.created(
|
||||||
|
uriInfo.getAbsolutePath().resolve(
|
||||||
|
"repositories/".concat(repository.getName()))).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DELETE
|
||||||
|
@Path("{name}")
|
||||||
|
public Response delete(@PathParam("name") String name)
|
||||||
|
{
|
||||||
|
Repository repository = repositoryStore.get(name);
|
||||||
|
|
||||||
|
if (repository == null)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
repositoryStore.remove(name);
|
||||||
|
|
||||||
|
return Response.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param uriInfo
|
||||||
|
* @param name
|
||||||
|
* @param repository
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PUT
|
||||||
|
@Path("{name}")
|
||||||
|
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
|
public Response update(@Context UriInfo uriInfo,
|
||||||
|
@PathParam("name") String name, Repository repository)
|
||||||
|
{
|
||||||
|
Repository updateRepository = repositoryStore.get(name);
|
||||||
|
|
||||||
|
if (updateRepository == null)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateRepository.setName(name);
|
||||||
|
updateRepository.setDescription(repository.getDescription());
|
||||||
|
updateRepository.setContact(repository.getContact());
|
||||||
|
|
||||||
|
return Response.created(
|
||||||
|
uriInfo.getAbsolutePath().resolve(repository.getName())).build();
|
||||||
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user