mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
use repositorymanager in repositoryresource
This commit is contained in:
@@ -44,9 +44,10 @@ public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
||||
{
|
||||
this.context = new JSONJAXBContext(
|
||||
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
||||
"member", "groups", "permissions", "repositoryTypes").nonStrings(
|
||||
"readable", "writeable", "groupPermission").build(), types.toArray(
|
||||
new Class[0]));
|
||||
"member", "groups", "permissions", "repositories",
|
||||
"repositoryTypes").nonStrings(
|
||||
"readable", "writeable", "groupPermission").build(), types.toArray(
|
||||
new Class[0]));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@@ -36,16 +36,20 @@ public abstract class AbstractResource<T>
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected abstract void addItem(T item);
|
||||
protected abstract void addItem(T item) throws Exception;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected abstract void removeItem(T item);
|
||||
protected abstract void removeItem(T item) throws Exception;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -53,8 +57,10 @@ public abstract class AbstractResource<T>
|
||||
*
|
||||
* @param name
|
||||
* @param item
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected abstract void updateItem(String name, T item);
|
||||
protected abstract void updateItem(String name, T item) throws Exception;
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
@@ -110,7 +116,14 @@ public abstract class AbstractResource<T>
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response add(@Context UriInfo uriInfo, T item)
|
||||
{
|
||||
addItem(item);
|
||||
try
|
||||
{
|
||||
addItem(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WebApplicationException(ex);
|
||||
}
|
||||
|
||||
return Response.created(
|
||||
uriInfo.getAbsolutePath().resolve(
|
||||
@@ -136,7 +149,14 @@ public abstract class AbstractResource<T>
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
}
|
||||
|
||||
removeItem(item);
|
||||
try
|
||||
{
|
||||
removeItem(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WebApplicationException(ex);
|
||||
}
|
||||
|
||||
return Response.noContent().build();
|
||||
}
|
||||
@@ -159,14 +179,14 @@ public abstract class AbstractResource<T>
|
||||
public Response update(@Context UriInfo uriInfo,
|
||||
@PathParam("name") String name, T item)
|
||||
{
|
||||
T updateItem = getItem(name);
|
||||
|
||||
if (updateItem == null)
|
||||
try
|
||||
{
|
||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||
updateItem(name, item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WebApplicationException(ex);
|
||||
}
|
||||
|
||||
updateItem(name, item);
|
||||
|
||||
return Response.created(
|
||||
uriInfo.getAbsolutePath().resolve(getId(item))).build();
|
||||
|
||||
@@ -10,8 +10,8 @@ package sonia.scm.api.rest.resources;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.ScmState;
|
||||
import sonia.scm.User;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Path("authentication")
|
||||
@Singleton
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class AuthenticationResource
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@ package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.group.Group;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -25,6 +27,7 @@ import javax.ws.rs.core.MediaType;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Path("groups")
|
||||
@Singleton
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class GroupResource extends AbstractResource<Group>
|
||||
{
|
||||
|
||||
@@ -9,15 +9,18 @@ package sonia.scm.api.rest.resources;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.repository.Permission;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
@@ -28,6 +31,7 @@ import javax.ws.rs.core.MediaType;
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@Path("repositories")
|
||||
@Singleton
|
||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public class RepositoryResource extends AbstractResource<Repository>
|
||||
{
|
||||
@@ -35,47 +39,6 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
/** Field description */
|
||||
public static final String PATH_PART = "repositories";
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public RepositoryResource()
|
||||
{
|
||||
repositoryStore = new LinkedHashMap<String, Repository>();
|
||||
repositoryStore.put("sonia.lib",
|
||||
new Repository(createId(), "hg", "sonia.lib",
|
||||
"csit@ostfalia.de", "SONIA Library",
|
||||
new Permission("csit", true, true,
|
||||
true)));
|
||||
repositoryStore.put("sonia.misc",
|
||||
new Repository(createId(), "hg", "sonia.misc",
|
||||
"csit@ostfalia.de",
|
||||
"SONIA Miscelanious",
|
||||
new Permission("csit", true, true,
|
||||
true)));
|
||||
repositoryStore.put("PWA",
|
||||
new Repository(createId(), "svn", "PWA",
|
||||
"csit@fh-wolfenbuettel.de", "PWA",
|
||||
new Permission("th", true, true),
|
||||
new Permission("sdorra", true, true),
|
||||
new Permission("oelkersd", true,
|
||||
false)));
|
||||
repositoryStore.put("sonia.app",
|
||||
new Repository(createId(), "hg", "sonia.app",
|
||||
"csit@ostfalia.de",
|
||||
"SONIA Applications",
|
||||
new Permission("csit", true, true,
|
||||
true)));
|
||||
repositoryStore.put("sonia.webapps",
|
||||
new Repository(createId(), "hg", "sonia.webapps",
|
||||
"csit@ostfalia.de",
|
||||
"SONIA WebApplications",
|
||||
new Permission("csit", true, true,
|
||||
true)));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -83,11 +46,15 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void addItem(Repository item)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
repositoryStore.put(item.getName(), item);
|
||||
repositoryManager.create(item);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,11 +62,15 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
*
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void removeItem(Repository item)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
repositoryStore.remove(item.getName());
|
||||
repositoryManager.delete(item);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,14 +79,15 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
*
|
||||
* @param name
|
||||
* @param item
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
protected void updateItem(String name, Repository item)
|
||||
throws RepositoryException, IOException
|
||||
{
|
||||
Repository repository = repositoryStore.get(name);
|
||||
|
||||
repository.setContact(item.getContact());
|
||||
repository.setDescription(item.getDescription());
|
||||
repositoryManager.modify(item);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@@ -129,7 +101,7 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
@Override
|
||||
protected Repository[] getAllItems()
|
||||
{
|
||||
Collection<Repository> repositoryCollection = repositoryStore.values();
|
||||
Collection<Repository> repositoryCollection = repositoryManager.getAll();
|
||||
|
||||
return repositoryCollection.toArray(
|
||||
new Repository[repositoryCollection.size()]);
|
||||
@@ -146,21 +118,22 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
@Override
|
||||
protected String getId(Repository item)
|
||||
{
|
||||
return item.getName();
|
||||
return item.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
*
|
||||
* @param id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Repository getItem(String name)
|
||||
protected Repository getItem(String id)
|
||||
{
|
||||
return repositoryStore.get(name);
|
||||
return repositoryManager.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,21 +148,9 @@ public class RepositoryResource extends AbstractResource<Repository>
|
||||
return PATH_PART;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String createId()
|
||||
{
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HashMap<String, Repository> repositoryStore;
|
||||
@Inject
|
||||
private RepositoryManager repositoryManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user