mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
added GroupsResource
This commit is contained in:
@@ -16,16 +16,23 @@ import sonia.scm.util.Util;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlAccessType;
|
||||||
|
import javax.xml.bind.annotation.XmlAccessorType;
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.XmlType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@XmlRootElement
|
@XmlRootElement(name = "groups")
|
||||||
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
|
@XmlType(propOrder = { "name", "members" })
|
||||||
public class Group implements Serializable
|
public class Group implements Serializable
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -34,6 +41,12 @@ public class Group implements Serializable
|
|||||||
|
|
||||||
//~--- constructors ---------------------------------------------------------
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public Group() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -59,6 +72,24 @@ public class Group implements Serializable
|
|||||||
this.members = members;
|
this.members = members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param members
|
||||||
|
*/
|
||||||
|
public Group(String name, String... members)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.members = new ArrayList<String>();
|
||||||
|
|
||||||
|
if (Util.isNotEmpty(members))
|
||||||
|
{
|
||||||
|
this.members.addAll(Arrays.asList(members));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -154,6 +185,7 @@ public class Group implements Serializable
|
|||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
@XmlElement(name = "members")
|
||||||
private List<String> members;
|
private List<String> members;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ package sonia.scm.api.rest;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import sonia.scm.Group;
|
import sonia.scm.Group;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import com.sun.jersey.api.json.JSONConfiguration;
|
import com.sun.jersey.api.json.JSONConfiguration;
|
||||||
@@ -28,7 +27,6 @@ import javax.xml.bind.JAXBContext;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@Provider
|
|
||||||
public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -42,7 +40,7 @@ public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
|||||||
{
|
{
|
||||||
this.context = new JSONJAXBContext(
|
this.context = new JSONJAXBContext(
|
||||||
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
JSONConfiguration.mapped().rootUnwrapping(true).arrays(
|
||||||
"members").build(), types.toArray(new Class[0]));
|
"member", "groups").build(), types.toArray(new Class[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@@ -69,5 +67,6 @@ public class JsonJaxbContextResolver implements ContextResolver<JAXBContext>
|
|||||||
private JAXBContext context;
|
private JAXBContext context;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private List<Class> types = Arrays.asList(new Class[] { Group.class });
|
private List<Class> types = Arrays.asList(new Class[] {
|
||||||
|
Group.class });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ import javax.ws.rs.core.MediaType;
|
|||||||
public class UriExtensionsConfig extends PackagesResourceConfig
|
public class UriExtensionsConfig extends PackagesResourceConfig
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static final String EXTENSION_XML = "xml";
|
||||||
|
|
||||||
|
public static final String EXTENSION_JSON = "json";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs ...
|
* Constructs ...
|
||||||
*
|
*
|
||||||
@@ -68,8 +72,8 @@ public class UriExtensionsConfig extends PackagesResourceConfig
|
|||||||
if (mediaTypeMap == null)
|
if (mediaTypeMap == null)
|
||||||
{
|
{
|
||||||
mediaTypeMap = new HashMap<String, MediaType>();
|
mediaTypeMap = new HashMap<String, MediaType>();
|
||||||
mediaTypeMap.put("json", MediaType.APPLICATION_JSON_TYPE);
|
mediaTypeMap.put(EXTENSION_JSON, MediaType.APPLICATION_JSON_TYPE);
|
||||||
mediaTypeMap.put("xml", MediaType.APPLICATION_XML_TYPE);
|
mediaTypeMap.put(EXTENSION_XML, MediaType.APPLICATION_XML_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mediaTypeMap;
|
return mediaTypeMap;
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
package sonia.scm.api.rest.resources;
|
||||||
|
|
||||||
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import sonia.scm.Group;
|
||||||
|
|
||||||
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Sebastian Sdorra
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
@Path("groups")
|
||||||
|
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||||
|
public class GroupsResource
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public GroupsResource()
|
||||||
|
{
|
||||||
|
groupStore = new LinkedHashMap<String, Group>();
|
||||||
|
groupStore.put("csit",
|
||||||
|
new Group("csit", "th", "merlec", "hopper", "oelkersd",
|
||||||
|
"sdorra", "gollnict"));
|
||||||
|
groupStore.put("devel",
|
||||||
|
new Group("devel", "sdorra", "th", "merlec", "oelkersd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("{name}")
|
||||||
|
public Group get(@PathParam("name") String name)
|
||||||
|
{
|
||||||
|
Group group = groupStore.get(name);
|
||||||
|
|
||||||
|
if (group == null)
|
||||||
|
{
|
||||||
|
throw new WebApplicationException(Status.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println( group );
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
public Group[] getAll()
|
||||||
|
{
|
||||||
|
Collection<Group> groupCollection = groupStore.values();
|
||||||
|
|
||||||
|
return groupCollection.toArray(new Group[groupCollection.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private LinkedHashMap<String, Group> groupStore;
|
||||||
|
}
|
||||||
11
scm-webapp/src/main/webapp/WEB-INF/sun-web.xml
Normal file
11
scm-webapp/src/main/webapp/WEB-INF/sun-web.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
|
||||||
|
<sun-web-app error-url="">
|
||||||
|
<context-root>/scm-webapp</context-root>
|
||||||
|
<class-loader delegate="true"/>
|
||||||
|
<jsp-config>
|
||||||
|
<property name="keepgenerated" value="true">
|
||||||
|
<description>Keep a copy of the generated servlet class' java code.</description>
|
||||||
|
</property>
|
||||||
|
</jsp-config>
|
||||||
|
</sun-web-app>
|
||||||
@@ -7,8 +7,12 @@ and open the template in the editor.
|
|||||||
<head>
|
<head>
|
||||||
<title></title>
|
<title></title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
|
||||||
|
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
TODO write content
|
<h1>Content</h1>
|
||||||
|
<pre></pre>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user