2016-10-08 20:46:17 +02:00
|
|
|
package org.gcube.data_catalogue.grsf_publish_ws.services;
|
|
|
|
|
2016-10-08 23:10:25 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-10-08 20:46:17 +02:00
|
|
|
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;
|
2016-10-08 23:10:25 +02:00
|
|
|
import javax.ws.rs.core.Response.Status;
|
2016-10-08 20:46:17 +02:00
|
|
|
|
2016-10-08 23:10:25 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
|
|
import org.gcube.common.authorization.library.utils.Caller;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2016-10-08 20:46:17 +02:00
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.StockRecord;
|
2016-10-08 23:10:25 +02:00
|
|
|
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;
|
2016-10-08 20:46:17 +02:00
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stock web service methods
|
|
|
|
* @author Costantino Perciante at ISTI-CNR
|
|
|
|
*/
|
|
|
|
@Path("stock/")
|
|
|
|
public class GrsfPublisherStockService {
|
2016-10-08 23:10:25 +02:00
|
|
|
|
2016-10-08 20:46:17 +02:00
|
|
|
// Logger
|
|
|
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
2016-10-08 23:10:25 +02:00
|
|
|
|
2016-10-08 20:46:17 +02:00
|
|
|
@POST
|
|
|
|
@Path("publish-product")
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Response publishStock(StockRecord record){
|
2016-10-08 23:10:25 +02:00
|
|
|
|
|
|
|
// 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);
|
2016-10-08 20:46:17 +02:00
|
|
|
|
2016-10-08 23:10:25 +02:00
|
|
|
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)
|
|
|
|
|
2016-10-08 20:46:17 +02:00
|
|
|
|
2016-10-08 23:10:25 +02:00
|
|
|
}catch(Exception e){
|
|
|
|
logger.error("Failed to create stock record", e);
|
|
|
|
status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
responseBean.setError(e.toString());
|
|
|
|
responseBean.setId(id);
|
|
|
|
}
|
2016-10-08 20:46:17 +02:00
|
|
|
|
2016-10-08 23:10:25 +02:00
|
|
|
return Response.status(status).entity(responseBean).build();
|
2016-10-08 20:46:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|