mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Cleanup and documentation
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user