grsf-publisher-ws/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java

81 lines
2.5 KiB
Java
Raw Normal View History

package org.gcube.data_catalogue.grsf_publish_ws.services;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue;
import org.slf4j.LoggerFactory;
/**
* Stock web service methods
* @author Costantino Perciante at ISTI-CNR
*/
@Path("stock/")
public class GrsfPublisherStockService {
// Logger
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
@POST
@Path("publish-product")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response publishStock(StockRecord record){
// retrieve context and username
Caller caller = AuthorizationProvider.instance.get();
String username = caller.getClient().getId();
String context = ScopeProvider.instance.get();
logger.info("Incoming request for creating a stock record by user with id " + username);
ResponseCreationBean responseBean = new ResponseCreationBean();
Status status = Status.CREATED;
String id = "";
try{
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
// check the user has editor/admin role into the org TODO pending or accepted?
// check the record has a name, at least
// evaluate the tags of the product
// evaluate the resources
// evaluate tags and groups using reflection
List<String> tags = new ArrayList<String>();
List<String> groups = new ArrayList<String>();
// create the product
//catalogue.createCKanDataset(apiKey, title, organizationNameOrId, author, authorMail, maintainer, maintainerMail, version, description, licenseId, tags, customFields, resources, setPublic)
}catch(Exception e){
logger.error("Failed to create stock record", e);
status = Status.INTERNAL_SERVER_ERROR;
responseBean.setError(e.toString());
responseBean.setId(id);
}
return Response.status(status).entity(responseBean).build();
}
}