Added Content-Location and fixed Location HTTP Headers

This commit is contained in:
Luca Frosini 2024-08-01 15:14:07 +02:00
parent 4a3dba0097
commit 6e64c40b4b
3 changed files with 18 additions and 5 deletions

View File

@ -86,6 +86,9 @@ public abstract class Record extends CKANPackage {
protected String grsfUUID;
protected URIResolver uriResolver;
protected String recordURL;
protected ObjectMapper objectMapper;
protected JsonNode jsonNode;
@ -97,6 +100,7 @@ public abstract class Record extends CKANPackage {
super(GRSFCatalogueConfigurationFactory.getInstance());
this.objectMapper = new ObjectMapper();
this.patch = false;
this.uriResolver = URIResolver.getInstance();
}
public abstract String getType();
@ -246,13 +250,18 @@ public abstract class Record extends CKANPackage {
return fileContainer;
}
public String getRecordURL() {
if(recordURL==null) {
recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
}
return recordURL;
}
protected Map<String, Object> getMapFromSourceJson(JsonNode jsonNode) throws Exception {
Map<String, Object> map = objectMapper.convertValue(jsonNode, new TypeReference<Map<String, Object>>(){});
grsfUUID = map.get(Record.GRSF_UUID_PROPERTY).toString();
URIResolver uriResolver = URIResolver.getInstance();
String recordURL = uriResolver.getCatalogueItemURL(grsfUUID);
map.put(RECORD_URL_TEMPLATE_PROPERTY_KEY, recordURL);
map.put(RECORD_URL_TEMPLATE_PROPERTY_KEY, getRecordURL());
map.put(INCLUDE_SENSITIVE_TEMPLATE_PROPERTY_KEY, ((GRSFCatalogueConfiguration) configuration).isIncludeSensitive());

View File

@ -38,7 +38,7 @@ public class BaseREST {
protected ResponseBuilder addLocation(ResponseBuilder responseBuilder, String id) {
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) {

View File

@ -35,7 +35,7 @@ public class BaseRESTAPIs<R extends Record> extends BaseREST {
@Context
protected UriInfo uriInfo;
protected static final String LOCATION_HEADER = "Location";
protected static final String CONTENT_LOCATION_HEADER = "Content-Location";
/* Used for accounting */
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) {
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 = addLocation(responseBuilder, record.getName());
responseBuilder = addContentLocation(responseBuilder, record.getRecordURL());
return responseBuilder.type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8).build();
}