Cleanup and documentation

This commit is contained in:
René Pfeuffer
2018-06-06 16:24:59 +02:00
parent ff8c6ea014
commit a8c61a9bfd
20 changed files with 244 additions and 64 deletions

View File

@@ -3,6 +3,10 @@ package sonia.scm;
import java.util.Collection;
import java.util.Collections;
/**
* This represents the result of a page request. Contains the results for
* the page and a flag whether there are more pages or not.
*/
public class PageResult<T extends ModelObject> {
private final Collection<T> entities;
@@ -13,10 +17,16 @@ public class PageResult<T extends ModelObject> {
this.hasMore = hasMore;
}
/**
* The entities for the current page.
*/
public Collection<T> getEntities() {
return Collections.unmodifiableCollection(entities);
}
/**
* If this is <code>true</code>, there are more pages (that is, mor entities).
*/
public boolean hasMore() {
return hasMore;
}

View File

@@ -2,6 +2,11 @@ package sonia.scm.web;
import sonia.scm.plugin.ExtensionPoint;
/**
* Implementing this extension point you can post process json response objects.
* To do so, you get a {@link JsonEnricherContext} with the complete json tree,
* that can be modified.
*/
@ExtensionPoint
public interface JsonEnricher {

View File

@@ -5,6 +5,10 @@ import com.fasterxml.jackson.databind.JsonNode;
import javax.ws.rs.core.MediaType;
import java.net.URI;
/**
* Process data for the {@link JsonEnricher} extension point giving context for
* post processing json results.
*/
public class JsonEnricherContext {
private URI requestUri;
@@ -17,14 +21,24 @@ public class JsonEnricherContext {
this.responseEntity = responseEntity;
}
/**
* The URI of the originating request.
*/
public URI getRequestUri() {
return requestUri;
}
/**
* The media type of the response. Using this you can determine the content of the result.
* @see VndMediaType
*/
public MediaType getResponseMediaType() {
return responseMediaType;
}
/**
* The json result represented by nodes, that can be modified.
*/
public JsonNode getResponseEntity() {
return responseEntity;
}

View File

@@ -2,6 +2,9 @@ package sonia.scm.web;
import javax.ws.rs.core.MediaType;
/**
* Vendor media types used by SCMM.
*/
public class VndMediaType {
private static final String VERSION = "2";
private static final String TYPE = "application";
@@ -10,18 +13,14 @@ public class VndMediaType {
private static final String SUFFIX = "+json;v=" + VERSION;
public static final String USER = PREFIX + "user" + SUFFIX;
public static final String USER_COLLECTION = PREFIX + "userCollection" + SUFFIX;
private VndMediaType() {
}
public static MediaType jsonType(String resource) {
return MediaType.valueOf(json(resource));
}
public static String json(String resource) {
return PREFIX + resource + SUFFIX;// ".v2+json";
}
/**
* Checks whether the given media type is a media type used by SCMM.
*/
public static boolean isVndType(MediaType type) {
return type.getType().equals(TYPE) && type.getSubtype().startsWith(SUBTYPE_PREFIX);
}