mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-27 22:40:19 +01:00
Add json enricher and json field filter
This commit is contained in:
10
scm-core/src/main/java/sonia/scm/web/JsonEnricher.java
Normal file
10
scm-core/src/main/java/sonia/scm/web/JsonEnricher.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import sonia.scm.plugin.ExtensionPoint;
|
||||
|
||||
@ExtensionPoint
|
||||
public interface JsonEnricher {
|
||||
|
||||
void enrich(JsonEnricherContext context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.net.URI;
|
||||
|
||||
public class JsonEnricherContext {
|
||||
|
||||
private URI requestUri;
|
||||
private MediaType responseMediaType;
|
||||
private JsonNode responseEntity;
|
||||
|
||||
public JsonEnricherContext(URI requestUri, MediaType responseMediaType, JsonNode responseEntity) {
|
||||
this.requestUri = requestUri;
|
||||
this.responseMediaType = responseMediaType;
|
||||
this.responseEntity = responseEntity;
|
||||
}
|
||||
|
||||
public URI getRequestUri() {
|
||||
return requestUri;
|
||||
}
|
||||
|
||||
public MediaType getResponseMediaType() {
|
||||
return responseMediaType;
|
||||
}
|
||||
|
||||
public JsonNode getResponseEntity() {
|
||||
return responseEntity;
|
||||
}
|
||||
}
|
||||
28
scm-core/src/main/java/sonia/scm/web/VndMediaType.java
Normal file
28
scm-core/src/main/java/sonia/scm/web/VndMediaType.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package sonia.scm.web;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
public class VndMediaType {
|
||||
private static final String VERSION = "2";
|
||||
private static final String TYPE = "application";
|
||||
private static final String SUBTYPE_PREFIX = "vnd.scmm-";
|
||||
private static final String PREFIX = TYPE + "/" + SUBTYPE_PREFIX;
|
||||
private static final String SUFFIX = "+json;v=" + VERSION;
|
||||
|
||||
public static final String USER = PREFIX + "user" + 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";
|
||||
}
|
||||
|
||||
public static boolean isVndType(MediaType type) {
|
||||
return type.getType().equals(TYPE) && type.getSubtype().startsWith(SUBTYPE_PREFIX);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user