mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
use repositorymanager in repositoryresource
This commit is contained in:
@@ -44,7 +44,8 @@ public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
|||||||
{
|
{
|
||||||
this.context = new JSONJAXBContext(
|
this.context = new JSONJAXBContext(
|
||||||
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
||||||
"member", "groups", "permissions", "repositoryTypes").nonStrings(
|
"member", "groups", "permissions", "repositories",
|
||||||
|
"repositoryTypes").nonStrings(
|
||||||
"readable", "writeable", "groupPermission").build(), types.toArray(
|
"readable", "writeable", "groupPermission").build(), types.toArray(
|
||||||
new Class[0]));
|
new Class[0]));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,16 +36,20 @@ public abstract class AbstractResource<T>
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected abstract void addItem(T item);
|
protected abstract void addItem(T item) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected abstract void removeItem(T item);
|
protected abstract void removeItem(T item) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -53,8 +57,10 @@ public abstract class AbstractResource<T>
|
|||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected abstract void updateItem(String name, T item);
|
protected abstract void updateItem(String name, T item) throws Exception;
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
@@ -109,8 +115,15 @@ public abstract class AbstractResource<T>
|
|||||||
@POST
|
@POST
|
||||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public Response add(@Context UriInfo uriInfo, T item)
|
public Response add(@Context UriInfo uriInfo, T item)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
addItem(item);
|
addItem(item);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
return Response.created(
|
return Response.created(
|
||||||
uriInfo.getAbsolutePath().resolve(
|
uriInfo.getAbsolutePath().resolve(
|
||||||
@@ -136,7 +149,14 @@ public abstract class AbstractResource<T>
|
|||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
removeItem(item);
|
removeItem(item);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
return Response.noContent().build();
|
return Response.noContent().build();
|
||||||
}
|
}
|
||||||
@@ -159,14 +179,14 @@ public abstract class AbstractResource<T>
|
|||||||
public Response update(@Context UriInfo uriInfo,
|
public Response update(@Context UriInfo uriInfo,
|
||||||
@PathParam("name") String name, T item)
|
@PathParam("name") String name, T item)
|
||||||
{
|
{
|
||||||
T updateItem = getItem(name);
|
try
|
||||||
|
|
||||||
if (updateItem == null)
|
|
||||||
{
|
{
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateItem(name, item);
|
updateItem(name, item);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
return Response.created(
|
return Response.created(
|
||||||
uriInfo.getAbsolutePath().resolve(getId(item))).build();
|
uriInfo.getAbsolutePath().resolve(getId(item))).build();
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ package sonia.scm.api.rest.resources;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import sonia.scm.SCMContext;
|
|
||||||
import sonia.scm.ScmState;
|
import sonia.scm.ScmState;
|
||||||
import sonia.scm.User;
|
import sonia.scm.User;
|
||||||
import sonia.scm.repository.RepositoryManager;
|
import sonia.scm.repository.RepositoryManager;
|
||||||
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Path("authentication")
|
@Path("authentication")
|
||||||
|
@Singleton
|
||||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class AuthenticationResource
|
public class AuthenticationResource
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ package sonia.scm.api.rest.resources;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import com.google.inject.Singleton;
|
||||||
|
|
||||||
import sonia.scm.group.Group;
|
import sonia.scm.group.Group;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -25,6 +27,7 @@ import javax.ws.rs.core.MediaType;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Path("groups")
|
@Path("groups")
|
||||||
|
@Singleton
|
||||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class GroupResource extends AbstractResource<Group>
|
public class GroupResource extends AbstractResource<Group>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,15 +9,18 @@ package sonia.scm.api.rest.resources;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- 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.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryException;
|
||||||
|
import sonia.scm.repository.RepositoryManager;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.Collection;
|
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.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
@@ -28,6 +31,7 @@ import javax.ws.rs.core.MediaType;
|
|||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Path("repositories")
|
@Path("repositories")
|
||||||
|
@Singleton
|
||||||
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
public class RepositoryResource extends AbstractResource<Repository>
|
public class RepositoryResource extends AbstractResource<Repository>
|
||||||
{
|
{
|
||||||
@@ -35,47 +39,6 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String PATH_PART = "repositories";
|
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 --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,11 +46,15 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void addItem(Repository item)
|
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
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void removeItem(Repository item)
|
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 name
|
||||||
* @param item
|
* @param item
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void updateItem(String name, Repository item)
|
protected void updateItem(String name, Repository item)
|
||||||
|
throws RepositoryException, IOException
|
||||||
{
|
{
|
||||||
Repository repository = repositoryStore.get(name);
|
repositoryManager.modify(item);
|
||||||
|
|
||||||
repository.setContact(item.getContact());
|
|
||||||
repository.setDescription(item.getDescription());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -129,7 +101,7 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
@Override
|
@Override
|
||||||
protected Repository[] getAllItems()
|
protected Repository[] getAllItems()
|
||||||
{
|
{
|
||||||
Collection<Repository> repositoryCollection = repositoryStore.values();
|
Collection<Repository> repositoryCollection = repositoryManager.getAll();
|
||||||
|
|
||||||
return repositoryCollection.toArray(
|
return repositoryCollection.toArray(
|
||||||
new Repository[repositoryCollection.size()]);
|
new Repository[repositoryCollection.size()]);
|
||||||
@@ -146,21 +118,22 @@ public class RepositoryResource extends AbstractResource<Repository>
|
|||||||
@Override
|
@Override
|
||||||
protected String getId(Repository item)
|
protected String getId(Repository item)
|
||||||
{
|
{
|
||||||
return item.getName();
|
return item.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param name
|
*
|
||||||
|
* @param id
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@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;
|
return PATH_PART;
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String createId()
|
|
||||||
{
|
|
||||||
return UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private HashMap<String, Repository> repositoryStore;
|
@Inject
|
||||||
|
private RepositoryManager repositoryManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
|||||||
var repositoryStore = new Sonia.rest.JsonStore({
|
var repositoryStore = new Sonia.rest.JsonStore({
|
||||||
url: restUrl + 'repositories.json',
|
url: restUrl + 'repositories.json',
|
||||||
root: 'repositories',
|
root: 'repositories',
|
||||||
fields: [ 'name', 'type', 'contact', 'description' ],
|
fields: [ 'id', 'name', 'type', 'contact', 'description' ],
|
||||||
sortInfo: {
|
sortInfo: {
|
||||||
field: 'name'
|
field: 'name'
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ Sonia.repository.Grid = Ext.extend(Sonia.rest.Grid, {
|
|||||||
var config = {
|
var config = {
|
||||||
store: repositoryStore,
|
store: repositoryStore,
|
||||||
colModel: repositoryColModel,
|
colModel: repositoryColModel,
|
||||||
idField: 'name',
|
idField: 'id',
|
||||||
searchField: 'name',
|
searchField: 'name',
|
||||||
editForm: 'repositoryEditForm',
|
editForm: 'repositoryEditForm',
|
||||||
restAddUrl: restUrl + 'repositories.json',
|
restAddUrl: restUrl + 'repositories.json',
|
||||||
|
|||||||
@@ -207,7 +207,8 @@ Sonia.rest.Grid = Ext.extend(Ext.grid.GridPanel, {
|
|||||||
fn: function(item){
|
fn: function(item){
|
||||||
|
|
||||||
var store = this.store;
|
var store = this.store;
|
||||||
var id = item[this.idField];
|
var id = data[this.idField];
|
||||||
|
item[this.idField] = id;
|
||||||
var url = String.format(this.restEditUrlPattern, id);
|
var url = String.format(this.restEditUrlPattern, id);
|
||||||
|
|
||||||
if ( debug ){
|
if ( debug ){
|
||||||
|
|||||||
Reference in New Issue
Block a user