Added Content-Location for CkanPackage

This commit is contained in:
Luca Frosini 2024-08-02 13:38:37 +02:00
parent 47caed1e16
commit e3dcaae93a
1 changed files with 10 additions and 0 deletions

View File

@ -9,12 +9,15 @@ import javax.ws.rs.core.Response.Status;
import org.gcube.gcat.api.GCatConstants; import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.api.interfaces.CRUD; import org.gcube.gcat.api.interfaces.CRUD;
import org.gcube.gcat.persistence.ckan.CKAN; import org.gcube.gcat.persistence.ckan.CKAN;
import org.gcube.gcat.persistence.ckan.CKANPackage;
/** /**
* @author Luca Frosini (ISTI - CNR) * @author Luca Frosini (ISTI - CNR)
*/ */
public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Response> { public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Response> {
protected static final String CONTENT_LOCATION_HEADER = "Content-Location";
protected final String COLLECTION_PARAMETER; protected final String COLLECTION_PARAMETER;
protected final String ID_PARAMETER; protected final String ID_PARAMETER;
protected final Class<C> reference; protected final Class<C> reference;
@ -43,6 +46,10 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Resp
return ckan.list(limit, offset); return ckan.list(limit, offset);
} }
protected ResponseBuilder addContentLocation(ResponseBuilder responseBuilder, String url) {
return responseBuilder.header(CONTENT_LOCATION_HEADER, url);
}
@Override @Override
public Response create(String json) { public Response create(String json) {
setCalledMethod("POST /" + COLLECTION_PARAMETER); setCalledMethod("POST /" + COLLECTION_PARAMETER);
@ -51,6 +58,9 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Resp
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret); ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret);
responseBuilder = addLocation(responseBuilder, ckan.getName()); responseBuilder = addLocation(responseBuilder, ckan.getName());
if(ckan instanceof CKANPackage) {
addContentLocation(responseBuilder, ((CKANPackage) ckan).getRecordURL());
}
return responseBuilder.type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8).build(); return responseBuilder.type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8).build();
} }