|
|
|
@ -29,19 +29,19 @@ import org.gcube.common.authorization.library.provider.AuthorizationProvider;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
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.others.DeleteRecord;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.others.UpdateRecordStatus;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.input.record.FisheryRecord;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseBean;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.json.output.ResponseCreationBean;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_PORTED.FisheryRecord;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED.DeleteRecord;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED.ResponseBean;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED.ResponseCreationBean;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED.UpdateRecordStatus;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.CommonServiceUtils;
|
|
|
|
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.HelperMethods;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
|
|
|
|
import org.gcube.datacatalogue.common.Constants;
|
|
|
|
|
import org.gcube.datacatalogue.common.enums.Product_Type;
|
|
|
|
|
import org.gcube.datacatalogue.common.enums.Sources;
|
|
|
|
|
import org.gcube.datacatalogue.common.AAA_PORTED.Constants;
|
|
|
|
|
import org.gcube.datacatalogue.common.AAA_PORTED.Product_Type;
|
|
|
|
|
import org.gcube.datacatalogue.common.AAA_PORTED.Sources;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
|
|
|
@ -61,33 +61,33 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
// Logger
|
|
|
|
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("hello")
|
|
|
|
|
@Produces(MediaType.TEXT_PLAIN)
|
|
|
|
|
public Response hello() {
|
|
|
|
|
return Response.ok("Hello.. Fishery service is here").build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("get-licenses")
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public Response getLicenses() {
|
|
|
|
|
Status status = Status.OK;
|
|
|
|
|
String context = ScopeProvider.instance.get();
|
|
|
|
|
DataCatalogue catalogue;
|
|
|
|
|
try {
|
|
|
|
|
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
|
|
|
|
if(licenses == null)
|
|
|
|
|
status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
return Response.status(status).entity(licenses).build();
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
return Response.status(status)
|
|
|
|
|
.entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// @GET
|
|
|
|
|
// @Path("hello")
|
|
|
|
|
// @Produces(MediaType.TEXT_PLAIN)
|
|
|
|
|
// public Response hello() {
|
|
|
|
|
// return Response.ok("Hello.. Fishery service is here").build();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @GET
|
|
|
|
|
// @Path("get-licenses")
|
|
|
|
|
// @Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
// public Response getLicenses() {
|
|
|
|
|
// Status status = Status.OK;
|
|
|
|
|
// String context = ScopeProvider.instance.get();
|
|
|
|
|
// DataCatalogue catalogue;
|
|
|
|
|
// try {
|
|
|
|
|
//// catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
// Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
|
|
|
|
// if(licenses == null)
|
|
|
|
|
// status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
// return Response.status(status).entity(licenses).build();
|
|
|
|
|
// } catch(Exception e) {
|
|
|
|
|
// status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
// return Response.status(status)
|
|
|
|
|
// .entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
|
|
|
|
// .build();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
@Path("publish-product")
|
|
|
|
@ -113,34 +113,43 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
// Cast the source to the accepted ones
|
|
|
|
|
Sources sourceInPath = Sources.onDeserialize(source);
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
if(catalogue == null) {
|
|
|
|
|
throw new Exception("There was a problem while serving your request. No catalogue instance was found!");
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
|
|
|
|
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
|
|
|
|
|
|
|
|
|
// extend this role to the other organizations in this context
|
|
|
|
|
CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization,
|
|
|
|
|
RolesCkanGroupOrOrg.ADMIN);
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = null;
|
|
|
|
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
// if(catalogue == null) {
|
|
|
|
|
// throw new Exception("There was a problem while serving your request. No catalogue instance was found!");
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
|
|
String apiKey = "";
|
|
|
|
|
String organization = "";
|
|
|
|
|
|
|
|
|
|
// String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
// String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
|
|
|
|
// CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
|
|
|
|
//
|
|
|
|
|
// // extend this role to the other organizations in this context
|
|
|
|
|
// CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization,
|
|
|
|
|
// RolesCkanGroupOrOrg.ADMIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String authorMail = "";
|
|
|
|
|
String authorFullname = "";
|
|
|
|
|
// retrieve the user's email and fullname
|
|
|
|
|
String authorMail = HelperMethods.getUserEmail(context, token);
|
|
|
|
|
String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
|
|
|
|
|
|
|
|
if(authorMail == null || authorFullname == null) {
|
|
|
|
|
throw new Exception("Sorry but it was not possible to retrieve your fullname/email!");
|
|
|
|
|
}
|
|
|
|
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
|
|
|
|
// String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
|
|
|
//
|
|
|
|
|
// if(authorMail == null || authorFullname == null) {
|
|
|
|
|
// throw new Exception("Sorry but it was not possible to retrieve your fullname/email!");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// The name of the product will be the uuid of the kb. The title will be the fishery's fishery_name. Fishery has also the constraint that
|
|
|
|
|
// fishing area and jurisdiction area cannot be empty at the same time
|
|
|
|
|
String futureName = record.getUuid();
|
|
|
|
|
String futureTitle = record.getFisheryName();
|
|
|
|
|
String futureName = "";
|
|
|
|
|
String futureTitle = "";
|
|
|
|
|
// String futureName = record.getUuid();
|
|
|
|
|
// String futureTitle = record.getFisheryName();
|
|
|
|
|
|
|
|
|
|
// check name
|
|
|
|
|
CommonServiceUtils.checkName(futureName, catalogue);
|
|
|
|
|
// CommonServiceUtils.checkName(futureName, catalogue);
|
|
|
|
|
|
|
|
|
|
Map<String,List<String>> customFields = record.getExtrasFields();
|
|
|
|
|
Set<String> tags = new HashSet<String>();
|
|
|
|
@ -152,26 +161,31 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
Product_Type.FISHERY, tags, customFields, groups, resources, username, futureTitle);
|
|
|
|
|
|
|
|
|
|
// check the license id
|
|
|
|
|
String license = null;
|
|
|
|
|
if(record.getLicense() == null || record.getLicense().isEmpty())
|
|
|
|
|
license = Constants.DEFAULT_LICENSE;
|
|
|
|
|
else if(HelperMethods.existsLicenseId(record.getLicense(), catalogue))
|
|
|
|
|
license = record.getLicense();
|
|
|
|
|
else
|
|
|
|
|
throw new Exception("Please check the license id!");
|
|
|
|
|
|
|
|
|
|
String license = "";
|
|
|
|
|
// String license = null;
|
|
|
|
|
// if(record.getLicense() == null || record.getLicense().isEmpty())
|
|
|
|
|
// license = Constants.DEFAULT_LICENSE;
|
|
|
|
|
// else if(HelperMethods.existsLicenseId(record.getLicense(), catalogue))
|
|
|
|
|
// license = record.getLicense();
|
|
|
|
|
// else
|
|
|
|
|
// throw new Exception("Please check the license id!");
|
|
|
|
|
//
|
|
|
|
|
long version = record.getVersion() == null ? 1 : record.getVersion();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set the visibility of the datatest according the context
|
|
|
|
|
boolean publicDataset = context
|
|
|
|
|
.equals((String) contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// convert extras' keys to keys with namespace
|
|
|
|
|
Map<String,String> namespaces = HelperMethods
|
|
|
|
|
.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
|
|
|
|
Map<String,String> namespaces = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
if(namespaces == null)
|
|
|
|
|
throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
|
|
|
|
// Map<String,String> namespaces = HelperMethods
|
|
|
|
|
// .getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
|
|
|
|
// if(namespaces == null)
|
|
|
|
|
// throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
|
|
|
|
|
|
|
|
|
customFields = HelperMethods.replaceFieldsKey(customFields, namespaces,
|
|
|
|
|
!sourceInPath.equals(Sources.GRSF));
|
|
|
|
@ -180,6 +194,7 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
|
|
|
|
|
logger.info("Invoking create method..");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create the product
|
|
|
|
|
id = catalogue.createCKanDatasetMultipleCustomFields(apiKey, futureTitle, futureName,
|
|
|
|
|
publishInOrganization, authorFullname, authorMail,
|
|
|
|
@ -188,7 +203,7 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
null, license, new ArrayList<String>(tags), customFields, resources, publicDataset);
|
|
|
|
|
|
|
|
|
|
// post actions
|
|
|
|
|
if(id != null) {
|
|
|
|
|
// if(id != null) {
|
|
|
|
|
|
|
|
|
|
logger.info("Created record with identifier " + id);
|
|
|
|
|
String description = Constants.SHORT_NAME_CUSTOM_KEY + ": " + record.getShortName() + "\n";
|
|
|
|
@ -203,10 +218,10 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
|
|
|
|
|
status = Status.CREATED;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("There was an error during the record generation, sorry");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// } else {
|
|
|
|
|
// throw new Exception("There was an error during the record generation, sorry");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
logger.error("Failed to create fishery record" + e);
|
|
|
|
|
status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
@ -216,68 +231,69 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
return Response.status(status).entity(responseBean).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
|
@Path("delete-product")
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
public Response deleteFishery(@NotNull(message = "input value is missing") @Valid DeleteRecord recordToDelete,
|
|
|
|
|
@PathParam("source") String source) throws ValidationException {
|
|
|
|
|
|
|
|
|
|
// retrieve context and username
|
|
|
|
|
Caller caller = AuthorizationProvider.instance.get();
|
|
|
|
|
String username = caller.getClient().getId();
|
|
|
|
|
String context = ScopeProvider.instance.get();
|
|
|
|
|
|
|
|
|
|
ResponseCreationBean responseBean = new ResponseCreationBean();
|
|
|
|
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
|
|
|
|
|
// check it is a fishery ...
|
|
|
|
|
logger.info(
|
|
|
|
|
"Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a fishery");
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
|
|
|
|
|
// Cast the source to the accepted ones
|
|
|
|
|
Sources sourceInPath = Sources.onDeserialize(source);
|
|
|
|
|
logger.debug("The request is to delete a fishery object of source " + sourceInPath);
|
|
|
|
|
|
|
|
|
|
// retrieve the catalogue instance
|
|
|
|
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
CkanDataset fisheryInCkan = catalogue.getDataset(recordToDelete.getId(), apiKey);
|
|
|
|
|
|
|
|
|
|
if(fisheryInCkan == null) {
|
|
|
|
|
status = Status.NOT_FOUND;
|
|
|
|
|
throw new Exception("There was a problem while serving your request. This item was not found");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check it is in the right source and it is a fishery
|
|
|
|
|
String type = fisheryInCkan.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
|
|
|
|
|
|
|
|
|
|
if((fisheryInCkan.getOrganization().getName().equalsIgnoreCase(source)
|
|
|
|
|
|| fisheryInCkan.getOrganization().getName().toLowerCase().contains(source))
|
|
|
|
|
&& Product_Type.FISHERY.getOrigName().equals(type)) {
|
|
|
|
|
|
|
|
|
|
logger.debug("Ok, this is a fishery of the right source, removing it");
|
|
|
|
|
boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), apiKey, true);
|
|
|
|
|
|
|
|
|
|
if(deleted) {
|
|
|
|
|
logger.info("Fishery DELETED AND PURGED!");
|
|
|
|
|
status = Status.OK;
|
|
|
|
|
responseBean.setId(fisheryInCkan.getId());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
status = Status.BAD_REQUEST;
|
|
|
|
|
throw new Exception(
|
|
|
|
|
"The id you are using doesn't belong to a Fishery item having source " + source + "!");
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
logger.error("Failed to delete this", e);
|
|
|
|
|
responseBean.setError(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Response.status(status).entity(responseBean).build();
|
|
|
|
|
}
|
|
|
|
|
// @DELETE
|
|
|
|
|
// @Path("delete-product")
|
|
|
|
|
// @Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
// @Produces(MediaType.APPLICATION_JSON)
|
|
|
|
|
// public Response deleteFishery(@NotNull(message = "input value is missing") @Valid DeleteRecord recordToDelete,
|
|
|
|
|
// @PathParam("source") String source) throws ValidationException {
|
|
|
|
|
//
|
|
|
|
|
// // retrieve context and username
|
|
|
|
|
// Caller caller = AuthorizationProvider.instance.get();
|
|
|
|
|
// String username = caller.getClient().getId();
|
|
|
|
|
// String context = ScopeProvider.instance.get();
|
|
|
|
|
//
|
|
|
|
|
// ResponseCreationBean responseBean = new ResponseCreationBean();
|
|
|
|
|
// Status status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
//
|
|
|
|
|
// // check it is a fishery ...
|
|
|
|
|
// logger.info(
|
|
|
|
|
// "Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a fishery");
|
|
|
|
|
// try {
|
|
|
|
|
//
|
|
|
|
|
// DataCatalogue catalogue = null;
|
|
|
|
|
//// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
//
|
|
|
|
|
// // Cast the source to the accepted ones
|
|
|
|
|
// Sources sourceInPath = Sources.onDeserialize(source);
|
|
|
|
|
// logger.debug("The request is to delete a fishery object of source " + sourceInPath);
|
|
|
|
|
//
|
|
|
|
|
// // retrieve the catalogue instance
|
|
|
|
|
// String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
// CkanDataset fisheryInCkan = catalogue.getDataset(recordToDelete.getId(), apiKey);
|
|
|
|
|
//
|
|
|
|
|
// if(fisheryInCkan == null) {
|
|
|
|
|
// status = Status.NOT_FOUND;
|
|
|
|
|
// throw new Exception("There was a problem while serving your request. This item was not found");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // check it is in the right source and it is a fishery
|
|
|
|
|
// String type = fisheryInCkan.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY);
|
|
|
|
|
//
|
|
|
|
|
// if((fisheryInCkan.getOrganization().getName().equalsIgnoreCase(source)
|
|
|
|
|
// || fisheryInCkan.getOrganization().getName().toLowerCase().contains(source))
|
|
|
|
|
// && Product_Type.FISHERY.getOrigName().equals(type)) {
|
|
|
|
|
//
|
|
|
|
|
// logger.debug("Ok, this is a fishery of the right source, removing it");
|
|
|
|
|
// boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), apiKey, true);
|
|
|
|
|
//
|
|
|
|
|
// if(deleted) {
|
|
|
|
|
// logger.info("Fishery DELETED AND PURGED!");
|
|
|
|
|
// status = Status.OK;
|
|
|
|
|
// responseBean.setId(fisheryInCkan.getId());
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// status = Status.BAD_REQUEST;
|
|
|
|
|
// throw new Exception(
|
|
|
|
|
// "The id you are using doesn't belong to a Fishery item having source " + source + "!");
|
|
|
|
|
// }
|
|
|
|
|
// } catch(Exception e) {
|
|
|
|
|
// logger.error("Failed to delete this", e);
|
|
|
|
|
// responseBean.setError(e.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return Response.status(status).entity(responseBean).build();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("get-fisheries-ids")
|
|
|
|
@ -298,11 +314,12 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
// Cast the source to the accepted ones
|
|
|
|
|
Sources sourceInPath = Sources.onDeserialize(source);
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
if(catalogue == null) {
|
|
|
|
|
throw new Exception("There was a problem while serving your request");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = null;
|
|
|
|
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
// if(catalogue == null) {
|
|
|
|
|
// throw new Exception("There was a problem while serving your request");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if it is a request for GRSF records, we have Fishery - Stock groups, so it is easy.
|
|
|
|
|
// For other cases, records needs to be parsed
|
|
|
|
|
if(sourceInPath.equals(Sources.GRSF))
|
|
|
|
@ -345,10 +362,13 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
if(catalogue == null) {
|
|
|
|
|
throw new Exception("There was a problem while serving your request");
|
|
|
|
|
}
|
|
|
|
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
// if(catalogue == null) {
|
|
|
|
|
// throw new Exception("There was a problem while serving your request");
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
DataCatalogue catalogue = null;
|
|
|
|
|
|
|
|
|
|
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
|
|
|
|
if(dataset != null) {
|
|
|
|
|
Map<String,String> result = new HashMap<String,String>();
|
|
|
|
@ -395,33 +415,40 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
throw new Exception("Please specify the '" + Constants.CATALOG_ID + "' property");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
|
|
|
|
|
if(catalogue == null) {
|
|
|
|
|
throw new Exception(
|
|
|
|
|
"There was a problem while serving your request. No catalogue instance was found in this context!");
|
|
|
|
|
} else {
|
|
|
|
|
DataCatalogue catalogue = null;
|
|
|
|
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
|
|
|
|
|
// if(catalogue == null) {
|
|
|
|
|
// throw new Exception(
|
|
|
|
|
// "There was a problem while serving your request. No catalogue instance was found in this context!");
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
|
|
// get already published record and modify it
|
|
|
|
|
String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
String apiKey = "";
|
|
|
|
|
// String apiKey = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
CkanDataset recordPublished = catalogue.getDataset(catalogId, apiKey);
|
|
|
|
|
|
|
|
|
|
if(recordPublished == null)
|
|
|
|
|
throw new Exception("A record with catalogue id " + catalogId + " does not exist!");
|
|
|
|
|
|
|
|
|
|
// retrieve the user's email and fullname
|
|
|
|
|
String authorMail = HelperMethods.getUserEmail(context, token);
|
|
|
|
|
String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
|
|
|
String authorMail = "";
|
|
|
|
|
String authorFullname = "";
|
|
|
|
|
|
|
|
|
|
if(authorMail == null || authorFullname == null) {
|
|
|
|
|
logger.debug("Author fullname or mail missing, cannot continue");
|
|
|
|
|
throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
|
|
|
|
}
|
|
|
|
|
// // retrieve the user's email and fullname
|
|
|
|
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
|
|
|
|
// String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
|
|
|
//
|
|
|
|
|
// if(authorMail == null || authorFullname == null) {
|
|
|
|
|
// logger.debug("Author fullname or mail missing, cannot continue");
|
|
|
|
|
// throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
|
|
|
|
String organization = "";
|
|
|
|
|
// String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
|
|
|
|
|
|
|
|
|
// check he/she has admin role
|
|
|
|
|
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
|
|
|
|
// CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
|
|
|
|
|
|
|
|
|
// name, product url and are going to remain unchanged (so we keep them from the already published record);
|
|
|
|
|
String name = recordPublished.getName();
|
|
|
|
@ -459,11 +486,12 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
.equals((String) contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY));
|
|
|
|
|
|
|
|
|
|
// convert extras' keys to keys with namespace
|
|
|
|
|
Map<String,String> namespaces = HelperMethods
|
|
|
|
|
.getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
|
|
|
|
|
|
|
|
|
if(namespaces == null)
|
|
|
|
|
throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
|
|
|
|
Map<String,String> namespaces = new HashMap<>();
|
|
|
|
|
// Map<String,String> namespaces = HelperMethods
|
|
|
|
|
// .getFieldToFieldNameSpaceMapping(Constants.GENERIC_RESOURCE_NAME_MAP_KEY_NAMESPACES_FISHERY);
|
|
|
|
|
//
|
|
|
|
|
// if(namespaces == null)
|
|
|
|
|
// throw new Exception("Failed to retrieve the namespaces for the key fields!");
|
|
|
|
|
|
|
|
|
|
// retrieve the already generated url
|
|
|
|
|
String modifiedUUIDKey = namespaces.containsKey(Constants.ITEM_URL_FIELD)
|
|
|
|
@ -502,7 +530,7 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
} else {
|
|
|
|
|
throw new Exception("There was an error during the item updated, sorry");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
logger.error("Failed to update fishery record" + e);
|
|
|
|
|
responseBean.setError(e.getMessage());
|
|
|
|
@ -527,14 +555,15 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
ResponseCreationBean responseBean = new ResponseCreationBean();
|
|
|
|
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// try {
|
|
|
|
|
DataCatalogue catalogue = null;
|
|
|
|
|
|
|
|
|
|
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
|
|
|
|
|
|
|
|
if(catalogue == null) {
|
|
|
|
|
throw new Exception(
|
|
|
|
|
"There was a problem while serving your request. No catalogue instance was found in this context!");
|
|
|
|
|
} else {
|
|
|
|
|
// if(catalogue == null) {
|
|
|
|
|
// throw new Exception(
|
|
|
|
|
// "There was a problem while serving your request. No catalogue instance was found in this context!");
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
|
|
// catalog id must be reported
|
|
|
|
|
String uuid = bean.getUuid();
|
|
|
|
@ -544,21 +573,24 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
String apiKeyUser = catalogue.getApiKeyFromUsername(username);
|
|
|
|
|
CkanDataset record = catalogue.getDataset(uuid, apiKeyUser);
|
|
|
|
|
|
|
|
|
|
if(record == null)
|
|
|
|
|
throw new Exception("A record with knowledge_base_id id " + uuid + " does not exist!");
|
|
|
|
|
if(record == null){
|
|
|
|
|
// throw new Exception("A record with knowledge_base_id id " + uuid + " does not exist!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check system type
|
|
|
|
|
boolean isGRSF = !record.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY)
|
|
|
|
|
.equals(Constants.SYSTEM_TYPE_FOR_SOURCES_VALUE);
|
|
|
|
|
|
|
|
|
|
if(!isGRSF)
|
|
|
|
|
throw new Exception("You are trying to modify a Legacy record!");
|
|
|
|
|
if(!isGRSF) {
|
|
|
|
|
// throw new Exception("You are trying to modify a Legacy record!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean rightDomain = record.getExtrasAsHashMap().get(Constants.DOMAIN_CUSTOM_KEY)
|
|
|
|
|
.equalsIgnoreCase(Product_Type.FISHERY.getOrigName());
|
|
|
|
|
|
|
|
|
|
if(!rightDomain)
|
|
|
|
|
throw new Exception("This is not a Fishery record!");
|
|
|
|
|
if(!rightDomain) {
|
|
|
|
|
// throw new Exception("This is not a Fishery record!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update it
|
|
|
|
|
Map<String,List<String>> updateStatus = new HashMap<String,List<String>>(1);
|
|
|
|
@ -570,11 +602,11 @@ public class GrsfPublisherFisheryService {
|
|
|
|
|
responseBean.setId(record.getId());
|
|
|
|
|
responseBean.setItemUrl(record.getExtrasAsHashMap().get(Constants.ITEM_URL_FIELD));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
logger.error("Failed to update fishery record's status", e);
|
|
|
|
|
responseBean.setError(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
// }
|
|
|
|
|
// } catch(Exception e) {
|
|
|
|
|
// logger.error("Failed to update fishery record's status", e);
|
|
|
|
|
// responseBean.setError(e.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
return Response.status(status).entity(responseBean).build();
|
|
|
|
|
|
|
|
|
|