Added Content-Location and fixed Location HTTP Headers
This commit is contained in:
parent
4a3dba0097
commit
6e64c40b4b
|
@ -86,6 +86,9 @@ public abstract class Record extends CKANPackage {
|
||||||
|
|
||||||
protected String grsfUUID;
|
protected String grsfUUID;
|
||||||
|
|
||||||
|
protected URIResolver uriResolver;
|
||||||
|
protected String recordURL;
|
||||||
|
|
||||||
protected ObjectMapper objectMapper;
|
protected ObjectMapper objectMapper;
|
||||||
protected JsonNode jsonNode;
|
protected JsonNode jsonNode;
|
||||||
|
|
||||||
|
@ -97,6 +100,7 @@ public abstract class Record extends CKANPackage {
|
||||||
super(GRSFCatalogueConfigurationFactory.getInstance());
|
super(GRSFCatalogueConfigurationFactory.getInstance());
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
this.patch = false;
|
this.patch = false;
|
||||||
|
this.uriResolver = URIResolver.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getType();
|
public abstract String getType();
|
||||||
|
@ -246,13 +250,18 @@ public abstract class Record extends CKANPackage {
|
||||||
return fileContainer;
|
return fileContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRecordURL() {
|
||||||
|
if(recordURL==null) {
|
||||||
|
recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
|
||||||
|
}
|
||||||
|
return recordURL;
|
||||||
|
}
|
||||||
|
|
||||||
protected Map<String, Object> getMapFromSourceJson(JsonNode jsonNode) throws Exception {
|
protected Map<String, Object> getMapFromSourceJson(JsonNode jsonNode) throws Exception {
|
||||||
Map<String, Object> map = objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>(){});
|
Map<String, Object> map = objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>(){});
|
||||||
grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
|
grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
|
||||||
|
|
||||||
URIResolver uriResolver = URIResolver.getInstance();
|
map.put(RECORD_URL_TEMPLATE_PROPERTY_KEY, getRecordURL());
|
||||||
String recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
|
|
||||||
map.put(RECORD_URL_TEMPLATE_PROPERTY_KEY, recordURL);
|
|
||||||
|
|
||||||
map.put(INCLUDE_SENSITIVE_TEMPLATE_PROPERTY_KEY, ((GRSFCatalogueConfiguration) configuration).isIncludeSensitive());
|
map.put(INCLUDE_SENSITIVE_TEMPLATE_PROPERTY_KEY, ((GRSFCatalogueConfiguration) configuration).isIncludeSensitive());
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class BaseREST {
|
||||||
|
|
||||||
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
|
||||||
return responseBuilder.header(LOCATION_HEADER,
|
return responseBuilder.header(LOCATION_HEADER,
|
||||||
String.format("%s/%s", uriInfo.getAbsolutePath().toString(), id));
|
String.format("%s%s", uriInfo.getAbsolutePath().toString(), id));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createCountJson(int count) {
|
protected String createCountJson(int count) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class BaseRESTAPIs<R extends Record> extends BaseREST {
|
||||||
@Context
|
@Context
|
||||||
protected UriInfo uriInfo;
|
protected UriInfo uriInfo;
|
||||||
|
|
||||||
protected static final String LOCATION_HEADER = "Location";
|
protected static final String CONTENT_LOCATION_HEADER = "Content-Location";
|
||||||
|
|
||||||
/* Used for accounting */
|
/* Used for accounting */
|
||||||
protected final String COLLECTION_PARAMETER;
|
protected final String COLLECTION_PARAMETER;
|
||||||
|
@ -96,6 +96,9 @@ public class BaseRESTAPIs<R extends Record> extends BaseREST {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected ResponseBuilder addContentLocation(ResponseBuilder responseBuilder, String url) {
|
||||||
|
return responseBuilder.header(CONTENT_LOCATION_HEADER, url);
|
||||||
|
}
|
||||||
|
|
||||||
public Response create(String json) {
|
public Response create(String json) {
|
||||||
setCalledMethod("POST /" + COLLECTION_PARAMETER);
|
setCalledMethod("POST /" + COLLECTION_PARAMETER);
|
||||||
|
@ -104,6 +107,7 @@ public class BaseRESTAPIs<R extends Record> extends BaseREST {
|
||||||
|
|
||||||
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret);
|
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret);
|
||||||
responseBuilder = addLocation(responseBuilder, record.getName());
|
responseBuilder = addLocation(responseBuilder, record.getName());
|
||||||
|
responseBuilder = addContentLocation(responseBuilder, record.getRecordURL());
|
||||||
return responseBuilder.type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8).build();
|
return responseBuilder.type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue