improve rest api documentation of Authentication, ChangePassword, Cipher, Group, Key and Plugin resource

This commit is contained in:
Sebastian Sdorra
2017-05-09 16:06:08 +02:00
parent 9ffb07acee
commit 42f412faa4
6 changed files with 159 additions and 228 deletions

View File

@@ -41,6 +41,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder; import com.google.common.collect.ImmutableList.Builder;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint; import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@@ -78,11 +80,9 @@ import sonia.scm.util.HttpUtil;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.DefaultValue; import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam; import javax.ws.rs.FormParam;
@@ -100,7 +100,8 @@ import javax.xml.bind.annotation.XmlRootElement;
import sonia.scm.security.XsrfCookies; import sonia.scm.security.XsrfCookies;
/** /**
* * Authentication related RESTful Web Service endpoint.
*
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Singleton @Singleton
@@ -152,15 +153,8 @@ public class AuthenticationResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Authenticate a user and return the state of the application.<br /> * Authenticate a user and return the state of the application.
* <br /> *
* <ul>
* <li>200 success</li>
* <li>400 bad request, required parameter is missing.</li>
* <li>401 unauthorized, the specified username or password is wrong</li>
* <li>500 internal server error</li>
* </ul>
*
* @param request the current http request * @param request the current http request
* @param username the username for the authentication * @param username the username for the authentication
* @param password the password for the authentication * @param password the password for the authentication
@@ -171,6 +165,12 @@ public class AuthenticationResource
@POST @POST
@Path("login") @Path("login")
@TypeHint(ScmState.class) @TypeHint(ScmState.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 400, condition = "bad request, required parameter is missing"),
@ResponseCode(code = 401, condition = "unauthorized, the specified username or password is wrong"),
@ResponseCode(code = 500, condition = "internal server error")
})
public Response authenticate(@Context HttpServletRequest request, public Response authenticate(@Context HttpServletRequest request,
@FormParam("username") String username, @FormParam("username") String username,
@FormParam("password") String password, @FormParam("rememberMe") @FormParam("password") String password, @FormParam("rememberMe")
@@ -243,13 +243,7 @@ public class AuthenticationResource
} }
/** /**
* Logout the current user. Returns the current state of the application, * Logout the current user. Returns the current state of the application, if public access is enabled.
* if public access is enabled.<br />
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param request the current http request * @param request the current http request
* @param response the current http response * @param response the current http response
@@ -259,6 +253,10 @@ public class AuthenticationResource
@GET @GET
@Path("logout") @Path("logout")
@TypeHint(ScmState.class) @TypeHint(ScmState.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
public Response logout(@Context HttpServletRequest request, public Response logout(@Context HttpServletRequest request,
@Context HttpServletResponse response) @Context HttpServletResponse response)
{ {
@@ -287,16 +285,8 @@ public class AuthenticationResource
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
* This method is an alias of the * This method is an alias of the {@link #getState(HttpServletRequest)} method.
* {@link #getState(javax.servlet.http.HttpServletRequest)} method. * The only difference between the methods, is that this one could not be used with basic authentication.
* The only difference between the methods,
* is that this one could not be used with basic authentication.<br />
* <br />
* <ul>
* <li>200 success</li>
* <li>401 unauthorized, user is not authenticated and public access is disabled.</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param request the current http request * @param request the current http request
* *
@@ -305,19 +295,18 @@ public class AuthenticationResource
@GET @GET
@Path("state") @Path("state")
@TypeHint(ScmState.class) @TypeHint(ScmState.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 401, condition = "unauthorized, user is not authenticated and public access is disabled"),
@ResponseCode(code = 500, condition = "internal server error")
})
public Response getCurrentState(@Context HttpServletRequest request) public Response getCurrentState(@Context HttpServletRequest request)
{ {
return getState(request); return getState(request);
} }
/** /**
* Returns the current state of the application.<br /> * Returns the current state of the application.
* <br />
* <ul>
* <li>200 success</li>
* <li>401 unauthorized, user is not authenticated and public access is disabled.</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param request the current http request * @param request the current http request
* *
@@ -325,6 +314,11 @@ public class AuthenticationResource
*/ */
@GET @GET
@TypeHint(ScmState.class) @TypeHint(ScmState.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 401, condition = "unauthorized, user is not authenticated and public access is disabled"),
@ResponseCode(code = 500, condition = "internal server error")
})
public Response getState(@Context HttpServletRequest request) public Response getState(@Context HttpServletRequest request)
{ {
Response response; Response response;
@@ -361,28 +355,12 @@ public class AuthenticationResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @return
*/
private ScmState createAnonymousState() private ScmState createAnonymousState()
{ {
return createState(SCMContext.ANONYMOUS, Collections.EMPTY_LIST, return createState(SCMContext.ANONYMOUS, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST); Collections.EMPTY_LIST, Collections.EMPTY_LIST);
} }
/**
* Method description
*
*
* @param securityContext
*
* @param subject
*
* @return
*/
private ScmState createState(Subject subject) private ScmState createState(Subject subject)
{ {
PrincipalCollection collection = subject.getPrincipals(); PrincipalCollection collection = subject.getPrincipals();
@@ -410,17 +388,6 @@ public class AuthenticationResource
return createState(user, groups.getCollection(), builder.build(), ap); return createState(user, groups.getCollection(), builder.build(), ap);
} }
/**
* Method description
*
*
* @param user
* @param groups
* @param assignedPermissions
* @param availablePermissions
*
* @return
*/
private ScmState createState(User user, Collection<String> groups, private ScmState createState(User user, Collection<String> groups,
List<String> assignedPermissions, List<String> assignedPermissions,
List<PermissionDescriptor> availablePermissions) List<PermissionDescriptor> availablePermissions)
@@ -431,17 +398,6 @@ public class AuthenticationResource
availablePermissions); availablePermissions);
} }
/**
* Method description
*
*
* @param request
* @param ex
* @param status
* @param failure
*
* @return
*/
private Response handleFailedAuthentication(HttpServletRequest request, private Response handleFailedAuthentication(HttpServletRequest request,
AuthenticationException ex, Response.Status status, AuthenticationException ex, Response.Status status,
WUIAuthenticationFailure failure) WUIAuthenticationFailure failure)

View File

@@ -36,6 +36,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.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint; import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@@ -66,7 +68,8 @@ import javax.ws.rs.core.Response;
import sonia.scm.security.Role; import sonia.scm.security.Role;
/** /**
* * Resource to change the password of the authenticated user.
*
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Path("action/change-password") @Path("action/change-password")
@@ -98,14 +101,7 @@ public class ChangePasswordResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Changes the password of the current user.<br /> * Changes the password of the current user.
* <br />
* Status codes:
* <ul>
* <li>200 success</li>
* <li>400 bad request, the old password is not correct</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param oldPassword old password of the current user * @param oldPassword old password of the current user
* @param newPassword new password for the current user * @param newPassword new password for the current user
@@ -117,6 +113,11 @@ public class ChangePasswordResource
*/ */
@POST @POST
@TypeHint(RestActionResult.class) @TypeHint(RestActionResult.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 400, condition = "bad request, the old password is not correct"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response changePassword(@FormParam("old-password") String oldPassword, public Response changePassword(@FormParam("old-password") String oldPassword,
@FormParam("new-password") String newPassword) @FormParam("new-password") String newPassword)

View File

@@ -35,6 +35,8 @@ package sonia.scm.api.rest.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@@ -60,12 +62,7 @@ public class CipherResource
/** /**
* Encrypts the request body and returns an encrypted string. This method can * Encrypts the request body and returns an encrypted string. This method can
* only executed with administration privileges.<br /> * only executed with administration privileges.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param value value to encrypt * @param value value to encrypt
* *
@@ -73,6 +70,10 @@ public class CipherResource
*/ */
@POST @POST
@Path("encrypt") @Path("encrypt")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public String encrypt(String value) public String encrypt(String value)
{ {

View File

@@ -37,6 +37,9 @@ package sonia.scm.api.rest.resources;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.ResponseHeader;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint; import com.webcohesion.enunciate.metadata.rs.TypeHint;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@@ -68,7 +71,8 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo; import javax.ws.rs.core.UriInfo;
/** /**
* * RESTful Web Service Resource to manage groups and their members.
*
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Path("groups") @Path("groups")
@@ -99,15 +103,7 @@ public class GroupResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Creates a new group.<br /> * Creates a new group. <strong>Note:</strong> This method requires admin privileges.
* This method requires admin privileges.<br />
* <br />
* Status codes:
* <ul>
* <li>201 create success</li>
* <li>403 forbidden, the current user has no admin privileges</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param uriInfo current uri informations * @param uriInfo current uri informations
* @param group the group to be created * @param group the group to be created
@@ -115,6 +111,14 @@ public class GroupResource
* @return * @return
*/ */
@POST @POST
@StatusCodes({
@ResponseCode(code = 201, condition = "create success", additionalHeaders = {
@ResponseHeader(name = "Location", description = "uri to the created group")
}),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Override @Override
public Response create(@Context UriInfo uriInfo, Group group) public Response create(@Context UriInfo uriInfo, Group group)
@@ -123,15 +127,7 @@ public class GroupResource
} }
/** /**
* Deletes a group.<br /> * Deletes a group. <strong>Note:</strong> This method requires admin privileges.
* This method requires admin privileges.<br />
* <br />
* Status codes:
* <ul>
* <li>201 delete success</li>
* <li>403 forbidden, the current user has no admin privileges</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param name the name of the group to delete. * @param name the name of the group to delete.
* *
@@ -139,6 +135,12 @@ public class GroupResource
*/ */
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@StatusCodes({
@ResponseCode(code = 204, condition = "delete success"),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Override @Override
public Response delete(@PathParam("id") String name) public Response delete(@PathParam("id") String name)
{ {
@@ -146,15 +148,7 @@ public class GroupResource
} }
/** /**
* Modifies the given group.<br /> * Modifies the given group. <strong>Note:</strong> This method requires admin privileges.
* This method requires admin privileges.<br />
* <br />
* Status codes:
* <ul>
* <li>201 update successful</li>
* <li>403 forbidden, the current user has no admin privileges</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param uriInfo current uri informations * @param uriInfo current uri informations
* @param name name of the group to be modified * @param name name of the group to be modified
@@ -164,6 +158,12 @@ public class GroupResource
*/ */
@PUT @PUT
@Path("{id}") @Path("{id}")
@StatusCodes({
@ResponseCode(code = 204, condition = "update success"),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Override @Override
public Response update(@Context UriInfo uriInfo, public Response update(@Context UriInfo uriInfo,
@@ -175,16 +175,7 @@ public class GroupResource
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
* Returns a group.<br /> * Fetches a group by its name or id. <strong>Note:</strong> This method requires admin privileges.
* This method requires admin privileges.<br />
* <br />
* Status codes:
* <ul>
* <li>200 get successful</li>
* <li>403 forbidden, the current user has no admin privileges</li>
* <li>404 not found, no group with the specified id/name available</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param request the current request * @param request the current request
* @param id the id/name of the group * @param id the id/name of the group
@@ -194,6 +185,12 @@ public class GroupResource
@GET @GET
@Path("{id}") @Path("{id}")
@TypeHint(Group.class) @TypeHint(Group.class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 404, condition = "not found, no group with the specified id/name available"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Override @Override
public Response get(@Context Request request, @PathParam("id") String id) public Response get(@Context Request request, @PathParam("id") String id)
@@ -213,15 +210,7 @@ public class GroupResource
} }
/** /**
* Returns all groups.<br /> * Returns all groups. <strong>Note:</strong> This method requires admin privileges.
* This method requires admin privileges.<br />
* <br />
* Status codes:
* <ul>
* <li>200 get successful</li>
* <li>403 forbidden, the current user has no admin privileges</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param request the current request * @param request the current request
* @param start the start value for paging * @param start the start value for paging
@@ -234,6 +223,11 @@ public class GroupResource
@GET @GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@TypeHint(Group[].class) @TypeHint(Group[].class)
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 403, condition = "forbidden, the current user has no admin privileges"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Override @Override
public Response getAll(@Context Request request, @DefaultValue("0") public Response getAll(@Context Request request, @DefaultValue("0")
@QueryParam("start") int start, @DefaultValue("-1") @QueryParam("start") int start, @DefaultValue("-1")
@@ -246,14 +240,6 @@ public class GroupResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param items
*
* @return
*/
@Override @Override
protected GenericEntity<Collection<Group>> createGenericEntity( protected GenericEntity<Collection<Group>> createGenericEntity(
Collection<Group> items) Collection<Group> items)
@@ -264,26 +250,12 @@ public class GroupResource
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param group
*
* @return
*/
@Override @Override
protected String getId(Group group) protected String getId(Group group)
{ {
return group.getName(); return group.getName();
} }
/**
* Method description
*
*
* @return
*/
@Override @Override
protected String getPathPart() protected String getPathPart()
{ {

View File

@@ -34,6 +34,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.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
@@ -72,17 +74,15 @@ public class KeyResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Generates a unique key. This method can only executed with administration * Generates a unique key. <strong>Note:</strong> This method can only executed with administration privileges.
* privileges.<br />
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return unique key * @return unique key
*/ */
@GET @GET
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN)
public String generateKey() public String generateKey()
{ {

View File

@@ -53,6 +53,9 @@ import sonia.scm.plugin.PluginInformationComparator;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import com.sun.jersey.multipart.FormDataParam; import com.sun.jersey.multipart.FormDataParam;
import com.webcohesion.enunciate.metadata.rs.ResponseCode;
import com.webcohesion.enunciate.metadata.rs.StatusCodes;
import com.webcohesion.enunciate.metadata.rs.TypeHint;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -73,7 +76,8 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
/** /**
* * RESTful Web Service Endpoint to manage plugins.
*
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
@Singleton @Singleton
@@ -104,13 +108,7 @@ public class PluginResource
//~--- methods -------------------------------------------------------------- //~--- methods --------------------------------------------------------------
/** /**
* Installs a plugin from a package.<br /> * Installs a plugin from a package.
* <br />
* <ul>
* <li>200 success</li>
* <li>412 precondition failed</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param uploadedInputStream * @param uploadedInputStream
* @return * @return
@@ -119,6 +117,11 @@ public class PluginResource
*/ */
@POST @POST
@Path("install-package") @Path("install-package")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 412, condition = "precondition failed"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response install( public Response install(
@@ -150,35 +153,30 @@ public class PluginResource
} }
/** /**
* Installs a plugin.<br /> * Installs a plugin.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param id id of the plugin to be installed * @param id id of the plugin to be installed
* *
* @return * @return
*/ */
@POST @POST
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@TypeHint(TypeHint.NO_CONTENT.class)
@Path("install/{id}") @Path("install/{id}")
public Response install(@PathParam("id") String id) public Response install(@PathParam("id") String id)
{ {
pluginManager.install(id); pluginManager.install(id);
// TODO should return 204 no content
return Response.ok().build(); return Response.ok().build();
} }
/** /**
* Installs a plugin from a package. This method is a workaround for ExtJS * Installs a plugin from a package. This method is a workaround for ExtJS
* file upload, which requires text/html as content-type.<br /> * file upload, which requires text/html as content-type.
* <br />
* <ul>
* <li>200 success</li>
* <li>412 precondition failed</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param uploadedInputStream * @param uploadedInputStream
* @return * @return
@@ -187,6 +185,11 @@ public class PluginResource
*/ */
@POST @POST
@Path("install-package.html") @Path("install-package.html")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 412, condition = "precondition failed"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Consumes(MediaType.MULTIPART_FORM_DATA) @Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML) @Produces(MediaType.TEXT_HTML)
public Response installFromUI( public Response installFromUI(
@@ -197,60 +200,62 @@ public class PluginResource
} }
/** /**
* Uninstalls a plugin.<br /> * Uninstalls a plugin.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param id id of the plugin to be uninstalled * @param id id of the plugin to be uninstalled
* *
* @return * @return
*/ */
@POST @POST
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Path("uninstall/{id}") @Path("uninstall/{id}")
public Response uninstall(@PathParam("id") String id) public Response uninstall(@PathParam("id") String id)
{ {
pluginManager.uninstall(id); pluginManager.uninstall(id);
// TODO should return 204 content
// consider to do a uninstall with a delete
return Response.ok().build(); return Response.ok().build();
} }
/** /**
* Updates a plugin.<br /> * Updates a plugin.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @param id id of the plugin to be updated * @param id id of the plugin to be updated
* *
* @return * @return
*/ */
@POST @POST
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Path("update/{id}") @Path("update/{id}")
public Response update(@PathParam("id") String id) public Response update(@PathParam("id") String id)
{ {
pluginManager.update(id); pluginManager.update(id);
// TODO should return 204 content
// consider to do an update with a put
return Response.ok().build(); return Response.ok().build();
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
/** /**
* Returns all plugins.<br /> * Returns all plugins.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return all plugins * @return all plugins
*/ */
@GET @GET
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Collection<PluginInformation> getAll() public Collection<PluginInformation> getAll()
{ {
@@ -258,17 +263,16 @@ public class PluginResource
} }
/** /**
* Returns all available plugins.<br /> * Returns all available plugins.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return all available plugins * @return all available plugins
*/ */
@GET @GET
@Path("available") @Path("available")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Collection<PluginInformation> getAvailable() public Collection<PluginInformation> getAvailable()
{ {
@@ -276,17 +280,16 @@ public class PluginResource
} }
/** /**
* Returns all plugins which are available for update.<br /> * Returns all plugins which are available for update.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return all plugins which are available for update * @return all plugins which are available for update
*/ */
@GET @GET
@Path("updates") @Path("updates")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Collection<PluginInformation> getAvailableUpdates() public Collection<PluginInformation> getAvailableUpdates()
{ {
@@ -294,17 +297,16 @@ public class PluginResource
} }
/** /**
* Returns all installed plugins.<br /> * Returns all installed plugins.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return all installed plugins * @return all installed plugins
*/ */
@GET @GET
@Path("installed") @Path("installed")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Collection<PluginInformation> getInstalled() public Collection<PluginInformation> getInstalled()
{ {
@@ -312,17 +314,16 @@ public class PluginResource
} }
/** /**
* Returns all plugins for the overview.<br /> * Returns all plugins for the overview.
* <br />
* <ul>
* <li>200 success</li>
* <li>500 internal server error</li>
* </ul>
* *
* @return all plugins for the overview * @return all plugins for the overview
*/ */
@GET @GET
@Path("overview") @Path("overview")
@StatusCodes({
@ResponseCode(code = 200, condition = "success"),
@ResponseCode(code = 500, condition = "internal server error")
})
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Collection<PluginInformation> getOverview() public Collection<PluginInformation> getOverview()
{ {