Commenting code which is related to action already covered by gCat
This commit is contained in:
parent
f1a81e071e
commit
013e54c070
|
@ -1,4 +1,4 @@
|
||||||
package org.gcube.data_catalogue.grsf_publish_ws.utils;
|
package org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED;
|
||||||
|
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
@ -61,33 +61,33 @@ public class GrsfPublisherFisheryService {
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherFisheryService.class);
|
||||||
|
|
||||||
@GET
|
// @GET
|
||||||
@Path("hello")
|
// @Path("hello")
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
// @Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response hello() {
|
// public Response hello() {
|
||||||
return Response.ok("Hello.. Fishery service is here").build();
|
// return Response.ok("Hello.. Fishery service is here").build();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GET
|
// @GET
|
||||||
@Path("get-licenses")
|
// @Path("get-licenses")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getLicenses() {
|
// public Response getLicenses() {
|
||||||
Status status = Status.OK;
|
// Status status = Status.OK;
|
||||||
String context = ScopeProvider.instance.get();
|
// String context = ScopeProvider.instance.get();
|
||||||
DataCatalogue catalogue;
|
// DataCatalogue catalogue;
|
||||||
try {
|
// try {
|
||||||
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
//// catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
// Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||||
if(licenses == null)
|
// if(licenses == null)
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(licenses).build();
|
// return Response.status(status).entity(licenses).build();
|
||||||
} catch(Exception e) {
|
// } catch(Exception e) {
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status)
|
// return Response.status(status)
|
||||||
.entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
// .entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
||||||
.build();
|
// .build();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("publish-product")
|
@Path("publish-product")
|
||||||
|
@ -113,26 +113,33 @@ public class GrsfPublisherFisheryService {
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
Sources sourceInPath = Sources.onDeserialize(source);
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
if(catalogue == null) {
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
throw new Exception("There was a problem while serving your request. No catalogue instance was found!");
|
// if(catalogue == null) {
|
||||||
} else {
|
// throw new Exception("There was a problem while serving your request. No catalogue instance was found!");
|
||||||
|
// } else {
|
||||||
|
|
||||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
String apiKey = "";
|
||||||
String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
String organization = "";
|
||||||
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
|
||||||
|
|
||||||
// extend this role to the other organizations in this context
|
// String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||||
CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization,
|
// String organization = HelperMethods.retrieveOrgNameFromScope(context);
|
||||||
RolesCkanGroupOrOrg.ADMIN);
|
// 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
|
// retrieve the user's email and fullname
|
||||||
String authorMail = HelperMethods.getUserEmail(context, token);
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
||||||
String authorFullname = HelperMethods.getUserFullname(context, token);
|
// String authorFullname = HelperMethods.getUserFullname(context, token);
|
||||||
|
//
|
||||||
if(authorMail == null || authorFullname == null) {
|
// if(authorMail == null || authorFullname == null) {
|
||||||
throw new Exception("Sorry but it was not possible to retrieve your fullname/email!");
|
// 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
|
// 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
|
// fishing area and jurisdiction area cannot be empty at the same time
|
||||||
|
@ -140,7 +147,7 @@ public class GrsfPublisherFisheryService {
|
||||||
String futureTitle = record.getFisheryName();
|
String futureTitle = record.getFisheryName();
|
||||||
|
|
||||||
// check name
|
// check name
|
||||||
CommonServiceUtils.checkName(futureName, catalogue);
|
// CommonServiceUtils.checkName(futureName, catalogue);
|
||||||
|
|
||||||
Map<String,List<String>> customFields = record.getExtrasFields();
|
Map<String,List<String>> customFields = record.getExtrasFields();
|
||||||
Set<String> tags = new HashSet<String>();
|
Set<String> tags = new HashSet<String>();
|
||||||
|
@ -206,7 +213,7 @@ public class GrsfPublisherFisheryService {
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("There was an error during the record generation, sorry");
|
throw new Exception("There was an error during the record generation, sorry");
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Failed to create fishery record" + e);
|
logger.error("Failed to create fishery record" + e);
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
@ -236,7 +243,8 @@ public class GrsfPublisherFisheryService {
|
||||||
"Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a fishery");
|
"Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a fishery");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
Sources sourceInPath = Sources.onDeserialize(source);
|
||||||
|
@ -298,11 +306,12 @@ public class GrsfPublisherFisheryService {
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
Sources sourceInPath = Sources.onDeserialize(source);
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
if(catalogue == null) {
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
throw new Exception("There was a problem while serving your request");
|
// 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.
|
// 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
|
// For other cases, records needs to be parsed
|
||||||
if(sourceInPath.equals(Sources.GRSF))
|
if(sourceInPath.equals(Sources.GRSF))
|
||||||
|
@ -345,10 +354,13 @@ public class GrsfPublisherFisheryService {
|
||||||
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
if(catalogue == null) {
|
// if(catalogue == null) {
|
||||||
throw new Exception("There was a problem while serving your request");
|
// throw new Exception("There was a problem while serving your request");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
DataCatalogue catalogue = null;
|
||||||
|
|
||||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||||
if(dataset != null) {
|
if(dataset != null) {
|
||||||
Map<String,String> result = new HashMap<String,String>();
|
Map<String,String> result = new HashMap<String,String>();
|
||||||
|
@ -395,33 +407,40 @@ public class GrsfPublisherFisheryService {
|
||||||
throw new Exception("Please specify the '" + Constants.CATALOG_ID + "' property");
|
throw new Exception("Please specify the '" + Constants.CATALOG_ID + "' property");
|
||||||
}
|
}
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
||||||
|
|
||||||
if(catalogue == null) {
|
DataCatalogue catalogue = null;
|
||||||
throw new Exception(
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
"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 {
|
||||||
|
|
||||||
// get already published record and modify it
|
// 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);
|
CkanDataset recordPublished = catalogue.getDataset(catalogId, apiKey);
|
||||||
|
|
||||||
if(recordPublished == null)
|
if(recordPublished == null)
|
||||||
throw new Exception("A record with catalogue id " + catalogId + " does not exist!");
|
throw new Exception("A record with catalogue id " + catalogId + " does not exist!");
|
||||||
|
|
||||||
// retrieve the user's email and fullname
|
String authorMail = "";
|
||||||
String authorMail = HelperMethods.getUserEmail(context, token);
|
String authorFullname = "";
|
||||||
String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
||||||
|
|
||||||
if(authorMail == null || authorFullname == null) {
|
// // retrieve the user's email and fullname
|
||||||
logger.debug("Author fullname or mail missing, cannot continue");
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
||||||
throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
// 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
|
// 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);
|
// name, product url and are going to remain unchanged (so we keep them from the already published record);
|
||||||
String name = recordPublished.getName();
|
String name = recordPublished.getName();
|
||||||
|
@ -502,7 +521,7 @@ public class GrsfPublisherFisheryService {
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("There was an error during the item updated, sorry");
|
throw new Exception("There was an error during the item updated, sorry");
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Failed to update fishery record" + e);
|
logger.error("Failed to update fishery record" + e);
|
||||||
responseBean.setError(e.getMessage());
|
responseBean.setError(e.getMessage());
|
||||||
|
@ -528,8 +547,9 @@ public class GrsfPublisherFisheryService {
|
||||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
DataCatalogue catalogue = null;
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
|
||||||
if(catalogue == null) {
|
if(catalogue == null) {
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
|
|
@ -61,33 +61,33 @@ public class GrsfPublisherStockService {
|
||||||
// Logger
|
// Logger
|
||||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class);
|
||||||
|
|
||||||
@GET
|
// @GET
|
||||||
@Path("hello")
|
// @Path("hello")
|
||||||
@Produces(MediaType.TEXT_PLAIN)
|
// @Produces(MediaType.TEXT_PLAIN)
|
||||||
public Response hello() {
|
// public Response hello() {
|
||||||
return Response.ok("Hello.. Stock service is here").build();
|
// return Response.ok("Hello.. Stock service is here").build();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GET
|
// @GET
|
||||||
@Path("get-licenses")
|
// @Path("get-licenses")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
// @Produces(MediaType.APPLICATION_JSON)
|
||||||
public Response getLicenses() {
|
// public Response getLicenses() {
|
||||||
Status status = Status.OK;
|
// Status status = Status.OK;
|
||||||
String context = ScopeProvider.instance.get();
|
// String context = ScopeProvider.instance.get();
|
||||||
DataCatalogue catalogue;
|
// DataCatalogue catalogue;
|
||||||
try {
|
// try {
|
||||||
catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
// catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
// Map<String,String> licenses = CommonServiceUtils.getLicenses(catalogue);
|
||||||
if(licenses == null)
|
// if(licenses == null)
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status).entity(licenses).build();
|
// return Response.status(status).entity(licenses).build();
|
||||||
} catch(Exception e) {
|
// } catch(Exception e) {
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
return Response.status(status)
|
// return Response.status(status)
|
||||||
.entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
// .entity(new ResponseBean(false, "Unable to retrieve license list " + e.getLocalizedMessage(), null))
|
||||||
.build();
|
// .build();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@Path("publish-product")
|
@Path("publish-product")
|
||||||
|
@ -113,35 +113,46 @@ public class GrsfPublisherStockService {
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
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);
|
DataCatalogue catalogue = null;
|
||||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
// 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); //"grsf_admin";
|
||||||
|
|
||||||
// check it has admin role or throw exception
|
// check it has admin role or throw exception
|
||||||
CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
// CommonServiceUtils.hasAdminRole(username, catalogue, apiKey, organization);
|
||||||
|
|
||||||
// extend this role to the other organizations in this context
|
// extend this role to the other organizations in this context
|
||||||
CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization,
|
// To support this gCat must be modified according to the following ticket
|
||||||
RolesCkanGroupOrOrg.ADMIN);
|
// https://support.d4science.org/issues/19365
|
||||||
|
// CommonServiceUtils.extendRoleToOtherOrganizations(username, catalogue, organization,
|
||||||
|
// RolesCkanGroupOrOrg.ADMIN);
|
||||||
|
|
||||||
|
String authorMail = "";
|
||||||
|
String authorFullname = "";
|
||||||
|
|
||||||
// retrieve the user's email and fullname
|
// retrieve the user's email and fullname
|
||||||
String authorMail = HelperMethods.getUserEmail(context, token);
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
||||||
String authorFullname = HelperMethods.getUserFullname(context, token);
|
// String authorFullname = HelperMethods.getUserFullname(context, token);
|
||||||
|
//
|
||||||
if(authorMail == null || authorFullname == null) {
|
// if(authorMail == null || authorFullname == null) {
|
||||||
throw new Exception("Sorry but it was not possible to retrieve your fullname/email!");
|
// throw new Exception("Sorry but it was not possible to retrieve your fullname/email!");
|
||||||
}
|
// }
|
||||||
|
|
||||||
// check the record has a name, at least
|
// check the record has a name, at least
|
||||||
String futureName = record.getUuid();
|
String futureName = record.getUuid();
|
||||||
String futureTitle = record.getStockName();
|
String futureTitle = record.getStockName();
|
||||||
|
|
||||||
// check name and throws exception
|
// check name and throws exception
|
||||||
CommonServiceUtils.checkName(futureName, catalogue);
|
// CommonServiceUtils.checkName(futureName, catalogue);
|
||||||
|
|
||||||
// load other information
|
// load other information
|
||||||
Map<String,List<String>> customFields = record.getExtrasFields();
|
Map<String,List<String>> customFields = record.getExtrasFields();
|
||||||
|
@ -209,7 +220,7 @@ public class GrsfPublisherStockService {
|
||||||
} else
|
} else
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
"There was an error during the product generation, sorry! Unable to create the dataset");
|
"There was an error during the product generation, sorry! Unable to create the dataset");
|
||||||
}
|
// }
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Failed to create stock record", e);
|
logger.error("Failed to create stock record", e);
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
@ -238,11 +249,13 @@ public class GrsfPublisherStockService {
|
||||||
"Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a stock");
|
"Received call to delete product with id " + recordToDelete.getId() + ", checking if it is a stock");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
if(catalogue == null) {
|
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
throw new Exception("There was a problem while serving your request");
|
// if(catalogue == null) {
|
||||||
}
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
// throw new Exception("There was a problem while serving your request");
|
||||||
|
// }
|
||||||
|
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
Sources sourceInPath = Sources.onDeserialize(source);
|
||||||
|
@ -304,11 +317,13 @@ public class GrsfPublisherStockService {
|
||||||
|
|
||||||
// Cast the source to the accepted ones
|
// Cast the source to the accepted ones
|
||||||
Sources sourceInPath = Sources.onDeserialize(source);
|
Sources sourceInPath = Sources.onDeserialize(source);
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
||||||
if(catalogue == null) {
|
DataCatalogue catalogue = null;
|
||||||
status = Status.INTERNAL_SERVER_ERROR;
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
throw new Exception("There was a problem while serving your request");
|
// if(catalogue == null) {
|
||||||
}
|
// status = Status.INTERNAL_SERVER_ERROR;
|
||||||
|
// 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.
|
// 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
|
// For other cases, records needs to be parsed
|
||||||
|
@ -348,10 +363,13 @@ public class GrsfPublisherStockService {
|
||||||
Status status = Status.INTERNAL_SERVER_ERROR;
|
Status status = Status.INTERNAL_SERVER_ERROR;
|
||||||
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
logger.info("Received call to get the catalogue identifier for the product with name " + name);
|
||||||
try {
|
try {
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
|
||||||
if(catalogue == null) {
|
DataCatalogue 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");
|
||||||
|
// }
|
||||||
|
|
||||||
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
CkanDataset dataset = catalogue.getDataset(name, catalogue.getApiKeyFromUsername(username));
|
||||||
if(dataset != null) {
|
if(dataset != null) {
|
||||||
Map<String,String> result = new HashMap<String,String>();
|
Map<String,String> result = new HashMap<String,String>();
|
||||||
|
@ -398,32 +416,40 @@ public class GrsfPublisherStockService {
|
||||||
throw new Exception("Please specify the 'catalog_id' property");
|
throw new Exception("Please specify the 'catalog_id' property");
|
||||||
}
|
}
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
|
|
||||||
if(catalogue == null) {
|
// if(catalogue == null) {
|
||||||
throw new Exception(
|
// throw new Exception(
|
||||||
"There was a problem while serving your request. No catalogue instance was found in this context!");
|
// "There was a problem while serving your request. No catalogue instance was found in this context!");
|
||||||
} else {
|
// } else {
|
||||||
|
|
||||||
// get already published record and modify it
|
// 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);
|
CkanDataset recordPublished = catalogue.getDataset(catalogId, apiKey);
|
||||||
|
|
||||||
if(recordPublished == null)
|
if(recordPublished == null)
|
||||||
throw new Exception("A record with id " + catalogId + " does not exist!");
|
throw new Exception("A record with id " + catalogId + " does not exist!");
|
||||||
|
|
||||||
// retrieve the user's email and fullname
|
String authorMail = "";
|
||||||
String authorMail = HelperMethods.getUserEmail(context, token);
|
String authorFullname = "";
|
||||||
String authorFullname = HelperMethods.getUserFullname(context, token);
|
|
||||||
|
|
||||||
if(authorMail == null || authorFullname == null) {
|
// retrieve the user's email and fullname
|
||||||
logger.debug("Author fullname or mail missing, cannot continue");
|
// String authorMail = HelperMethods.getUserEmail(context, token);
|
||||||
throw new Exception("Sorry but there was not possible to retrieve your fullname/email!");
|
// String authorFullname = HelperMethods.getUserFullname(context, token);
|
||||||
}
|
//
|
||||||
String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
// 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 = "";
|
||||||
|
|
||||||
|
// String organization = HelperMethods.retrieveOrgNameFromScope(context); //"grsf_admin";
|
||||||
|
|
||||||
// check he/she has admin role
|
// 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 publisher record);
|
// name, product url and are going to remain unchanged (so we keep them from the publisher record);
|
||||||
String name = recordPublished.getName();
|
String name = recordPublished.getName();
|
||||||
|
@ -506,7 +532,7 @@ public class GrsfPublisherStockService {
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("There was an error during the item updated, sorry");
|
throw new Exception("There was an error during the item updated, sorry");
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Failed to update stock record", e);
|
logger.error("Failed to update stock record", e);
|
||||||
responseBean.setError(e.getMessage());
|
responseBean.setError(e.getMessage());
|
||||||
|
@ -534,12 +560,13 @@ public class GrsfPublisherStockService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
DataCatalogue catalogue = null;
|
||||||
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
if(catalogue == null) {
|
//
|
||||||
throw new Exception(
|
// if(catalogue == null) {
|
||||||
"There was a problem while serving your request. No catalogue instance was found in this context!");
|
// throw new Exception(
|
||||||
} else {
|
// "There was a problem while serving your request. No catalogue instance was found in this context!");
|
||||||
|
// } else {
|
||||||
|
|
||||||
// catalog id must be reported
|
// catalog id must be reported
|
||||||
String uuid = bean.getUuid();
|
String uuid = bean.getUuid();
|
||||||
|
@ -574,7 +601,7 @@ public class GrsfPublisherStockService {
|
||||||
responseBean.setKbUuid(uuid);
|
responseBean.setKbUuid(uuid);
|
||||||
responseBean.setId(record.getId());
|
responseBean.setId(record.getId());
|
||||||
responseBean.setItemUrl(record.getExtrasAsHashMap().get(Constants.ITEM_URL_FIELD));
|
responseBean.setItemUrl(record.getExtrasAsHashMap().get(Constants.ITEM_URL_FIELD));
|
||||||
}
|
// }
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
logger.error("Failed to update stock record's status", e);
|
logger.error("Failed to update stock record's status", e);
|
||||||
responseBean.setError(e.getMessage());
|
responseBean.setError(e.getMessage());
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.gcube.data_catalogue.grsf_publish_ws.utils.csv.ManageTimeSeriesThread
|
||||||
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
import org.gcube.data_catalogue.grsf_publish_ws.utils.threads.AssociationToGroupThread;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
import org.gcube.datacatalogue.ckanutillibrary.shared.ResourceBean;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
|
||||||
import org.gcube.datacatalogue.common.AAA_PORTED.Constants;
|
import org.gcube.datacatalogue.common.AAA_PORTED.Constants;
|
||||||
import org.gcube.datacatalogue.common.AAA_PORTED.Product_Type;
|
import org.gcube.datacatalogue.common.AAA_PORTED.Product_Type;
|
||||||
import org.gcube.datacatalogue.common.AAA_PORTED.Sources;
|
import org.gcube.datacatalogue.common.AAA_PORTED.Sources;
|
||||||
|
@ -40,9 +39,6 @@ import org.gcube.datacatalogue.common.AAA_PORTED.Stock_Type;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanDataset;
|
|
||||||
import eu.trentorise.opendata.jackan.model.CkanLicense;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Services common utils.
|
* Services common utils.
|
||||||
* @author Costantino Perciante (ISTI - CNR)
|
* @author Costantino Perciante (ISTI - CNR)
|
||||||
|
@ -55,20 +51,20 @@ public class CommonServiceUtils {
|
||||||
private static final int TAG_MAX_SIZE = 100;
|
private static final int TAG_MAX_SIZE = 100;
|
||||||
private static Map<String,Boolean> extensionsCheck = new ConcurrentHashMap<>();
|
private static Map<String,Boolean> extensionsCheck = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Retrieve the list of licenses for stocks and fisheries
|
// * Retrieve the list of licenses for stocks and fisheries
|
||||||
* @return
|
// * @return
|
||||||
*/
|
// */
|
||||||
public static Map<String,String> getLicenses(DataCatalogue catalogue) {
|
// public static Map<String,String> getLicenses(DataCatalogue catalogue) {
|
||||||
logger.info("Requested licenses...");
|
// logger.info("Requested licenses...");
|
||||||
Map<String,String> toReturn = new HashMap<String,String>();
|
// Map<String,String> toReturn = new HashMap<String,String>();
|
||||||
List<CkanLicense> licenses = catalogue.getLicenses();
|
// List<CkanLicense> licenses = catalogue.getLicenses();
|
||||||
|
//
|
||||||
for(CkanLicense ckanLicense : licenses) {
|
// for(CkanLicense ckanLicense : licenses) {
|
||||||
toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
// toReturn.put(ckanLicense.getId(), ckanLicense.getTitle());
|
||||||
}
|
// }
|
||||||
return toReturn;
|
// return toReturn;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate an aggregated GRSF record. TODO use @Valid tags
|
* Validate an aggregated GRSF record. TODO use @Valid tags
|
||||||
|
@ -421,45 +417,46 @@ public class CommonServiceUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate if the user has the admin role
|
|
||||||
* Throws exception if he/she doesn't
|
|
||||||
*/
|
|
||||||
public static void hasAdminRole(String username, DataCatalogue catalogue, String apiKey, String organization)
|
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
// /**
|
||||||
logger.info("Role of the user " + username + " is " + role + " in " + organization);
|
// * Evaluate if the user has the admin role
|
||||||
|
// * Throws exception if he/she doesn't
|
||||||
|
// */
|
||||||
|
// public static void hasAdminRole(String username, DataCatalogue catalogue, String apiKey, String organization)
|
||||||
|
// throws Exception {
|
||||||
|
//
|
||||||
|
// String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey);
|
||||||
|
// logger.info("Role of the user " + username + " is " + role + " in " + organization);
|
||||||
|
//
|
||||||
|
// if(role == null || role.isEmpty() || !role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString()))
|
||||||
|
// throw new Exception(
|
||||||
|
// "You are not authorized to create a product. Please check you have the Catalogue-Administrator role!");
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
if(role == null || role.isEmpty() || !role.equalsIgnoreCase(RolesCkanGroupOrOrg.ADMIN.toString()))
|
// /**
|
||||||
throw new Exception(
|
// * Check this record's name
|
||||||
"You are not authorized to create a product. Please check you have the Catalogue-Administrator role!");
|
// * @param futureName
|
||||||
|
// * @param catalogue
|
||||||
}
|
// * @throws Exception on name check
|
||||||
|
// */
|
||||||
/**
|
// public static void checkName(String futureName, DataCatalogue catalogue) throws Exception {
|
||||||
* Check this record's name
|
//
|
||||||
* @param futureName
|
// if(!HelperMethods.isNameValid(futureName)) {
|
||||||
* @param catalogue
|
// throw new Exception(
|
||||||
* @throws Exception on name check
|
// "The 'uuid_knowledge_base' must contain only alphanumeric characters, and symbols like '.' or '_', '-'");
|
||||||
*/
|
// } else {
|
||||||
public static void checkName(String futureName, DataCatalogue catalogue) throws Exception {
|
//
|
||||||
|
// logger.debug("Checking if such name [" + futureName + "] doesn't exist ...");
|
||||||
if(!HelperMethods.isNameValid(futureName)) {
|
// boolean alreadyExists = catalogue.existProductWithNameOrId(futureName);
|
||||||
throw new Exception(
|
//
|
||||||
"The 'uuid_knowledge_base' must contain only alphanumeric characters, and symbols like '.' or '_', '-'");
|
// if(alreadyExists) {
|
||||||
} else {
|
// logger.debug("A product with 'uuid_knowledge_base' " + futureName + " already exists");
|
||||||
|
// throw new Exception("A product with 'uuid_knowledge_base' " + futureName + " already exists");
|
||||||
logger.debug("Checking if such name [" + futureName + "] doesn't exist ...");
|
//
|
||||||
boolean alreadyExists = catalogue.existProductWithNameOrId(futureName);
|
// }
|
||||||
|
// }
|
||||||
if(alreadyExists) {
|
// }
|
||||||
logger.debug("A product with 'uuid_knowledge_base' " + futureName + " already exists");
|
|
||||||
throw new Exception("A product with 'uuid_knowledge_base' " + futureName + " already exists");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and check sources
|
* Validate and check sources
|
||||||
|
@ -495,7 +492,11 @@ public class CommonServiceUtils {
|
||||||
String databaseSource = "";
|
String databaseSource = "";
|
||||||
// we have the id within the catalog of this record. This means that we can retrieve the record and its system:type
|
// we have the id within the catalog of this record. This means that we can retrieve the record and its system:type
|
||||||
for(RefersToBean refersToBean : refersTo) {
|
for(RefersToBean refersToBean : refersTo) {
|
||||||
String sourceOrganization = getRecordOrganization(refersToBean.getId(), apiKey, context);
|
|
||||||
|
String sourceOrganization = "";
|
||||||
|
// String sourceOrganization = getRecordOrganization(refersToBean.getId(), apiKey, context);
|
||||||
|
|
||||||
|
|
||||||
resources.add(new ResourceBean(refersToBean.getUrl(), sourceOrganization, "", null, username, null,
|
resources.add(new ResourceBean(refersToBean.getUrl(), sourceOrganization, "", null, username, null,
|
||||||
null));
|
null));
|
||||||
sourcesList.add(sourceOrganization.toLowerCase());
|
sourcesList.add(sourceOrganization.toLowerCase());
|
||||||
|
@ -563,35 +564,35 @@ public class CommonServiceUtils {
|
||||||
groups.add(groupName);
|
groups.add(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Fetch the system:type property from a record
|
// * Fetch the system:type property from a record
|
||||||
* @param itemIdOrName
|
// * @param itemIdOrName
|
||||||
* @param apiKey
|
// * @param apiKey
|
||||||
* @return null on error
|
// * @return null on error
|
||||||
* @throws Exception
|
// * @throws Exception
|
||||||
*/
|
// */
|
||||||
public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
|
// public static String getSystemTypeValue(String itemIdOrName, String apiKey, String context) throws Exception {
|
||||||
|
//
|
||||||
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
|
// DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
|
// CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
|
||||||
if(dataset == null)
|
// if(dataset == null)
|
||||||
throw new Exception("Unable to find record with id or name " + itemIdOrName);
|
// throw new Exception("Unable to find record with id or name " + itemIdOrName);
|
||||||
String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
|
// String systemTypeValue = dataset.getExtrasAsHashMap().get(Constants.SYSTEM_TYPE_CUSTOM_KEY);
|
||||||
if(systemTypeValue == null || systemTypeValue.isEmpty())
|
// if(systemTypeValue == null || systemTypeValue.isEmpty())
|
||||||
throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
|
// throw new Exception(Constants.SYSTEM_TYPE_CUSTOM_KEY + " property not set in record " + itemIdOrName);
|
||||||
else
|
// else
|
||||||
return systemTypeValue;
|
// return systemTypeValue;
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception {
|
// public static String getRecordOrganization(String itemIdOrName, String apiKey, String context) throws Exception {
|
||||||
DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
|
// DataCatalogue catalog = HelperMethods.getDataCatalogueRunningInstance(context);
|
||||||
CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
|
// CkanDataset dataset = catalog.getDataset(itemIdOrName, apiKey);
|
||||||
if(dataset == null)
|
// if(dataset == null)
|
||||||
throw new Exception("Unable to find record with id or name " + itemIdOrName);
|
// throw new Exception("Unable to find record with id or name " + itemIdOrName);
|
||||||
else
|
// else
|
||||||
return dataset.getOrganization().getTitle();
|
// return dataset.getOrganization().getTitle();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Actions to execute once the dataset has been updated or created.
|
* Actions to execute once the dataset has been updated or created.
|
||||||
|
@ -670,25 +671,25 @@ public class CommonServiceUtils {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Extend roles to other organization
|
// * Extend roles to other organization
|
||||||
* @param username
|
// * @param username
|
||||||
* @param catalogue
|
// * @param catalogue
|
||||||
* @param organization
|
// * @param organization
|
||||||
* @param admin
|
// * @param admin
|
||||||
*/
|
// */
|
||||||
public static void extendRoleToOtherOrganizations(String username, DataCatalogue catalogue, String organization,
|
// public static void extendRoleToOtherOrganizations(String username, DataCatalogue catalogue, String organization,
|
||||||
RolesCkanGroupOrOrg admin) {
|
// RolesCkanGroupOrOrg admin) {
|
||||||
|
//
|
||||||
logger.debug("Checking if role extension is needed here");
|
// logger.debug("Checking if role extension is needed here");
|
||||||
if(extensionsCheck.containsKey(username) && extensionsCheck.get(username))
|
// if(extensionsCheck.containsKey(username) && extensionsCheck.get(username))
|
||||||
return;
|
// return;
|
||||||
else {
|
// else {
|
||||||
catalogue.assignRolesOtherOrganization(username, organization, admin);
|
// catalogue.assignRolesOtherOrganization(username, organization, admin);
|
||||||
extensionsCheck.put(username, true);
|
// extensionsCheck.put(username, true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluate in which organization a record has to be published. The only exception is when grsf_admin is involved.
|
* Evaluate in which organization a record has to be published. The only exception is when grsf_admin is involved.
|
||||||
|
|
|
@ -29,6 +29,7 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundExcept
|
||||||
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
|
||||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.data_catalogue.grsf_publish_ws.AAA_UNNEEDED.GcoreEndPointReaderSocial;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||||
import org.gcube.datacatalogue.common.AAA_UNNEEDED.CacheImpl;
|
import org.gcube.datacatalogue.common.AAA_UNNEEDED.CacheImpl;
|
||||||
|
@ -103,38 +104,38 @@ public abstract class HelperMethods {
|
||||||
return modified;
|
return modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Retrieve the running instance of the data catalogue for this scope
|
// * Retrieve the running instance of the data catalogue for this scope
|
||||||
* @return
|
// * @return
|
||||||
* @throws Exception
|
// * @throws Exception
|
||||||
*/
|
// */
|
||||||
public static DataCatalogue getDataCatalogueRunningInstance(String scope) throws Exception{
|
// public static DataCatalogue getDataCatalogueRunningInstance(String scope) throws Exception{
|
||||||
|
//
|
||||||
|
// if(catalogueCache.get(scope) != null)
|
||||||
|
// return catalogueCache.get(scope);
|
||||||
|
// else{
|
||||||
|
// try{
|
||||||
|
// DataCatalogue instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scope);
|
||||||
|
// catalogueCache.insert(scope, instance);
|
||||||
|
// return instance;
|
||||||
|
// }catch(Exception e){
|
||||||
|
// logger.error("Failed to instantiate data catalogue lib", e);
|
||||||
|
// throw new Exception("Failed to retrieve catalogue information");
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if(catalogueCache.get(scope) != null)
|
// /**
|
||||||
return catalogueCache.get(scope);
|
// * Retrieve the organization name in which the user wants to publish starting from the scope
|
||||||
else{
|
// * @param contextInWhichPublish
|
||||||
try{
|
// * @return
|
||||||
DataCatalogue instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scope);
|
// */
|
||||||
catalogueCache.insert(scope, instance);
|
// public static String retrieveOrgNameFromScope(String scope) {
|
||||||
return instance;
|
//
|
||||||
}catch(Exception e){
|
// String[] splittedScope = scope.split("/");
|
||||||
logger.error("Failed to instantiate data catalogue lib", e);
|
// return splittedScope[splittedScope.length - 1].toLowerCase();
|
||||||
throw new Exception("Failed to retrieve catalogue information");
|
//
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the organization name in which the user wants to publish starting from the scope
|
|
||||||
* @param contextInWhichPublish
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static String retrieveOrgNameFromScope(String scope) {
|
|
||||||
|
|
||||||
String[] splittedScope = scope.split("/");
|
|
||||||
return splittedScope[splittedScope.length - 1].toLowerCase();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the name the product will have
|
* Validate the name the product will have
|
||||||
|
@ -150,13 +151,14 @@ public abstract class HelperMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
|
/* *//**
|
||||||
* Retrieve the user's email given his/her username
|
* Retrieve the user's email given his/her username
|
||||||
* @param context
|
* @param context
|
||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*//*
|
||||||
public static String getUserEmail(String context, String token){
|
public static String getUserEmail(String context, String token){
|
||||||
|
|
||||||
// check in cache
|
// check in cache
|
||||||
|
@ -174,13 +176,13 @@ public abstract class HelperMethods {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
*//**
|
||||||
* Retrieve the user's fullname given his/her username
|
* Retrieve the user's fullname given his/her username
|
||||||
* @param context
|
* @param context
|
||||||
* @param token
|
* @param token
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*//*
|
||||||
public static String getUserFullname(String context, String token){
|
public static String getUserFullname(String context, String token){
|
||||||
|
|
||||||
// check in cache
|
// check in cache
|
||||||
|
@ -198,10 +200,10 @@ public abstract class HelperMethods {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
*//**
|
||||||
* Execute the GET http request at this url, and return the result as string
|
* Execute the GET http request at this url, and return the result as string
|
||||||
* @return
|
* @return
|
||||||
*/
|
*//*
|
||||||
private static String executGETHttpRequest(String url, int expectedCodeOnSuccess){
|
private static String executGETHttpRequest(String url, int expectedCodeOnSuccess){
|
||||||
|
|
||||||
try(CloseableHttpClient client = HttpClientBuilder.create().build();){
|
try(CloseableHttpClient client = HttpClientBuilder.create().build();){
|
||||||
|
@ -231,7 +233,7 @@ public abstract class HelperMethods {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check that the given license id is in CKAN
|
* Check that the given license id is in CKAN
|
||||||
|
|
|
@ -378,39 +378,39 @@ public class JTests {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Test
|
// //@Test
|
||||||
public void testHierarchy() throws Exception{
|
// public void testHierarchy() throws Exception{
|
||||||
String name = "low-abundance";
|
// String name = "low-abundance";
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
|
||||||
List<String> uniqueGroups = new ArrayList<String>();
|
// List<String> uniqueGroups = new ArrayList<String>();
|
||||||
uniqueGroups.add(name);
|
// uniqueGroups.add(name);
|
||||||
uniqueGroups.add(name);
|
// uniqueGroups.add(name);
|
||||||
AssociationToGroupThread.findHierarchy(uniqueGroups, catalogue, catalogue.getApiKeyFromUsername("costantino_perciante"));
|
// AssociationToGroupThread.findHierarchy(uniqueGroups, catalogue, catalogue.getApiKeyFromUsername("costantino_perciante"));
|
||||||
logger.debug("Hierarchy is " + uniqueGroups);
|
// logger.debug("Hierarchy is " + uniqueGroups);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//@Test
|
// //@Test
|
||||||
public void testAssociationThread() throws Exception{
|
// public void testAssociationThread() throws Exception{
|
||||||
String name = "low-abundance";
|
// String name = "low-abundance";
|
||||||
DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
|
// DataCatalogue catalogue = HelperMethods.getDataCatalogueRunningInstance("/gcube/devNext/NextNext");
|
||||||
AssociationToGroupThread threadGroups = new AssociationToGroupThread(Arrays.asList(name), "another-test-test-please-ignore", "grsf", "costantino_perciante", catalogue, "apiKey");
|
// AssociationToGroupThread threadGroups = new AssociationToGroupThread(Arrays.asList(name), "another-test-test-please-ignore", "grsf", "costantino_perciante", catalogue, "apiKey");
|
||||||
threadGroups.start();
|
// threadGroups.start();
|
||||||
threadGroups.join();
|
// threadGroups.join();
|
||||||
logger.info("Thread stopped!");
|
// logger.info("Thread stopped!");
|
||||||
|
//
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//@Test
|
// //@Test
|
||||||
public void testCaches(){
|
// public void testCaches(){
|
||||||
|
//
|
||||||
String context = "/gcube/devNext/NextNext";
|
// String context = "/gcube/devNext/NextNext";
|
||||||
String token = "";
|
// String token = "";
|
||||||
for (int i = 0; i < 1000; i++) {
|
// for (int i = 0; i < 1000; i++) {
|
||||||
logger.debug(HelperMethods.getUserEmail(context, token));
|
// logger.debug(HelperMethods.getUserEmail(context, token));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
public void testMatch(){
|
public void testMatch(){
|
||||||
|
|
Loading…
Reference in New Issue