From 6d762550711ec579d34b3d05dddc1acb1e5e6f5f Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Wed, 7 Jun 2017 09:04:44 +0000 Subject: [PATCH] further changes due to requests in ticket #8719 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/grsf-publisher-ws@149332 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 ++- .../grsf_publish_ws/json/input/Base.java | 3 +- .../services/CommonServiceUtils.java | 3 ++ .../services/GrsfPublisherFisheryService.java | 40 +++++++++++-------- .../services/GrsfPublisherStockService.java | 20 ++++++---- 5 files changed, 46 insertions(+), 26 deletions(-) diff --git a/.classpath b/.classpath index d6737f6..54fde77 100644 --- a/.classpath +++ b/.classpath @@ -19,6 +19,10 @@ - + + + + + diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Base.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Base.java index 61742aa..3edd60e 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Base.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/json/input/Base.java @@ -26,6 +26,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class Base { private static Logger logger = LoggerFactory.getLogger(Base.class); + public static final String UUID_KB_KEY = "UUID Knowledge Base"; @JsonProperty("description") private String description; @@ -57,7 +58,7 @@ public class Base { private List extrasResources = new ArrayList(); @JsonProperty("uuid_knowledge_base") - @CustomField(key="UUID Knowledge Base") + @CustomField(key=UUID_KB_KEY) @NotNull(message="uuid_knowledge_base cannot be null") @Size(min=1, message="uuid_knowledge_base cannot be empty") private String uuid; diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java index 58c4046..92fb894 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/CommonServiceUtils.java @@ -36,6 +36,9 @@ public class CommonServiceUtils { private static final int TIME_SERIES_TAKE_LAST_VALUES = 5; private static final String REGEX_TAGS = "[^\\s\\w-_.]"; public static final String SYSTEM_TYPE = "system:type"; + + // item url property + public static final String ITEM_URL_FIELD = "UUID"; /** * Retrieve the list of licenses for stocks and fisheries diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java index 53d3b72..4b6ef58 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherFisheryService.java @@ -29,6 +29,7 @@ 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.Base; import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common; import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean; import org.gcube.data_catalogue.grsf_publish_ws.json.input.FisheryRecord; @@ -59,9 +60,6 @@ public class GrsfPublisherFisheryService { // the default license for these records private static final String DEFAULT_FISHERY_LICENSE = "CC-BY-SA-4.0"; - // item url property - private static final String ITEM_URL_FIELD = "Item URL"; - // the context @Context ServletContext contextServlet; @@ -129,7 +127,7 @@ public class GrsfPublisherFisheryService { String role = catalogue.getRoleOfUserInOrganization(username, organization, apiKey); logger.info("Role of the user " + username + " is " + role); - + if(role == null || role.isEmpty()) throw new Exception("You are not authorized to create a product. Please check you have the Catalogue-Administrator role!"); @@ -229,16 +227,16 @@ public class GrsfPublisherFisheryService { // set the visibility of the datatest according the context boolean publicDataset = context.equals((String)contextServlet.getInitParameter(HelperMethods.PUBLIC_CONTEX_KEY)); - + // add the SYSTEM_TYPE customFields.put(CommonServiceUtils.SYSTEM_TYPE, Arrays.asList(sourceInPath.getOrigName())); - + // convert extras' keys to keys with namespace Map namespaces = HelperMethods.getFieldToFieldNameSpaceMapping(HelperMethods.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); logger.info("Invoking creation method.."); @@ -272,7 +270,7 @@ public class GrsfPublisherFisheryService { // add the "Product URL" to the field Map> addField = new HashMap>(); - addField.put(ITEM_URL_FIELD, Arrays.asList(itemUrl)); + addField.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl)); catalogue.patchProductCustomFields(id, apiKey, addField); if(!groups.isEmpty()){ @@ -365,18 +363,18 @@ public class GrsfPublisherFisheryService { // check it is in the right source and it is a fishery String grsfType = fisheryInCkan.getExtrasAsHashMap().get(Common.GRSF_TYPE_KEY); String groupToCheck = sourceInPath.equals(Sources.GRSF) ? "grsf-group" : sourceInPath.getOrigName().toLowerCase(); - + if(catalogue.isDatasetInGroup(groupToCheck, recordToDelete.getId()) && Product_Type.FISHERY.getOrigName().equals(grsfType)){ - + logger.warn("Ok, this is a fishery of the right source, removing it"); boolean deleted = catalogue.deleteProduct(fisheryInCkan.getId(), catalogue.getApiKeyFromUsername(username), true); - + if(deleted){ - + logger.info("Fishery DELETED AND PURGED!"); status = Status.OK; responseBean.setId(fisheryInCkan.getId()); - + } else{ @@ -499,9 +497,17 @@ public class GrsfPublisherFisheryService { // retrieve the product url Map customFields = dataset.getExtrasAsHashMap(); - if(customFields.containsKey(ITEM_URL_FIELD)) - result.put("url", customFields.get(ITEM_URL_FIELD)); - else + + boolean found = false; + Set KeySet = customFields.keySet(); + for (String key : KeySet) { + if(key.contains(CommonServiceUtils.ITEM_URL_FIELD) && !key.contains(Base.UUID_KB_KEY)){ + result.put("url", customFields.get(key)); + found = true; + break; + } + } + if(!found) result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId())); responseBean.setResult(result); diff --git a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java index 0be8268..725a875 100644 --- a/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java +++ b/src/main/java/org/gcube/data_catalogue/grsf_publish_ws/services/GrsfPublisherStockService.java @@ -29,6 +29,7 @@ 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.Base; import org.gcube.data_catalogue.grsf_publish_ws.json.input.Common; import org.gcube.data_catalogue.grsf_publish_ws.json.input.DeleteProductBean; import org.gcube.data_catalogue.grsf_publish_ws.json.input.RefersToBean; @@ -64,9 +65,6 @@ public class GrsfPublisherStockService { // Logger private static final org.slf4j.Logger logger = LoggerFactory.getLogger(GrsfPublisherStockService.class); - // item url property - private static final String ITEM_URL_FIELD = "Item URL"; - @GET @Path("hello") @Produces(MediaType.TEXT_PLAIN) @@ -265,7 +263,7 @@ public class GrsfPublisherStockService { // add the "Product URL" to the field Map> addField = new HashMap>(); - addField.put(ITEM_URL_FIELD, Arrays.asList(itemUrl)); + addField.put(CommonServiceUtils.ITEM_URL_FIELD, Arrays.asList(itemUrl)); catalogue.patchProductCustomFields(id, apiKey, addField); if(!groups.isEmpty()){ @@ -488,9 +486,17 @@ public class GrsfPublisherStockService { // retrieve the product url Map customFields = dataset.getExtrasAsHashMap(); - if(customFields.containsKey(ITEM_URL_FIELD)) - result.put("url", customFields.get(ITEM_URL_FIELD)); - else + + boolean found = false; + Set KeySet = customFields.keySet(); + for (String key : KeySet) { + if(key.contains(CommonServiceUtils.ITEM_URL_FIELD) && !key.contains(Base.UUID_KB_KEY)){ + result.put("url", customFields.get(key)); + found = true; + break; + } + } + if(!found) result.put("url", catalogue.getUnencryptedUrlFromDatasetIdOrName(dataset.getId())); responseBean.setResult(result);