From 275880c428ee4515b898708703a43b06d3de9538 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 9 Dec 2020 15:33:28 +0100 Subject: [PATCH 01/25] Adding Configuration read/create to switch to the new IS --- pom.xml | 22 ++++++ .../org/gcube/gcat/profile/ISProfile.java | 73 ++++++++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4851920..dcbef86 100644 --- a/pom.xml +++ b/pom.xml @@ -63,6 +63,28 @@ + + org.gcube.information-system + information-system-model + provided + + + org.gcube.resource-management + gcube-model + provided + + + org.gcube.information-system + resource-registry-client + provided + + + org.gcube.information-system + resource-registry-publisher + provided + + + org.gcube.data-catalogue gcubedatacatalogue-metadata-discovery diff --git a/src/main/java/org/gcube/gcat/profile/ISProfile.java b/src/main/java/org/gcube/gcat/profile/ISProfile.java index 8b35609..c5fb919 100644 --- a/src/main/java/org/gcube/gcat/profile/ISProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ISProfile.java @@ -1,7 +1,11 @@ package org.gcube.gcat.profile; import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import javax.ws.rs.InternalServerErrorException; @@ -9,8 +13,11 @@ import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; +import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.Resources; +import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery; import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil; import org.gcube.gcat.persistence.ckan.CKANUser; @@ -19,6 +26,20 @@ import org.gcube.gcat.persistence.ckan.CKANUserCache; import org.gcube.gcat.utils.Constants; import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; +import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.XSDSchemaFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; +import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; +import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.XSDSchemaFacet; +import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; +import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.impl.QueryBox; @@ -29,13 +50,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; - public class ISProfile { public static int PRETTY_PRINT_INDENT_FACTOR = 4; + public static final String PROFILE = "profile"; + public static final String PROFILE_SCHEMA = "profileSchema"; + + public static final String SCHEMA_URL_ADDRESS = "https://wiki.gcube-system.org/images_gcube/e/e8/Gcdcmetadataprofilev3.xsd"; + public static final URL SCHEMA_URL; + + static { + try { + SCHEMA_URL = new URL(SCHEMA_URL_ADDRESS); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + private static Logger logger = LoggerFactory.getLogger(ISProfile.class); protected ObjectMapper mapper; @@ -62,6 +94,41 @@ public class ISProfile { } } + /* + * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Configuration + */ + protected Configuration instantiateConfiguration(String name, String xml) throws Exception { + Configuration configuration = new ConfigurationImpl(); + + IdentifierFacet identifierFacet = new IdentifierFacetImpl(); + identifierFacet.setValue(name); + identifierFacet.setType(IdentificationType.STRING); + IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); + configuration.addFacet(isIdentifiedBy); + + SimpleFacet profile = new SimpleFacetImpl(); + profile.setAdditionalProperty(PROFILE, xml); + configuration.addFacet(profile); + + XSDSchemaFacet xsdSchemaFacet = new XSDSchemaFacetImpl(); + xsdSchemaFacet.setName("gCube Item Profile"); + xsdSchemaFacet.setSchemaURL(SCHEMA_URL); + xsdSchemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); + xsdSchemaFacet.setContent(DataCalogueMetadataFormatReader.getProfileSchemaString()); + configuration.addFacet(xsdSchemaFacet); + + return configuration; + } + + + protected Configuration getConfiguration(String name) throws ResourceRegistryException { + ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); + Map map = new HashMap<>(); + map.put(IdentifierFacet.VALUE_PROPERTY, name); + List configurations = resourceRegistryClient.getFilteredResources(Configuration.class, IsIdentifiedBy.class, IdentifierFacet.class, false, map); + return configurations.get(0); + } + /* * TODO Check the Queries because the name in the Profile differs from the name in * From 9436e96d90050337813e39fdc4dd09d93bbea9dc Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 11 Jan 2021 13:17:53 +0100 Subject: [PATCH 02/25] Fixed profile according to latest version of IS Model and gCube Model --- .../org/gcube/gcat/profile/ISProfile.java | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/gcat/profile/ISProfile.java b/src/main/java/org/gcube/gcat/profile/ISProfile.java index c5fb919..a710f1b 100644 --- a/src/main/java/org/gcube/gcat/profile/ISProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ISProfile.java @@ -30,15 +30,17 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SchemaFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.XSDSchemaFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; +import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; +import org.gcube.resourcemanagement.model.reference.entities.facets.SchemaFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.XSDSchemaFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; +import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; @@ -57,7 +59,7 @@ public class ISProfile { public static final String PROFILE = "profile"; public static final String PROFILE_SCHEMA = "profileSchema"; - public static final String SCHEMA_URL_ADDRESS = "https://wiki.gcube-system.org/images_gcube/e/e8/Gcdcmetadataprofilev3.xsd"; + public static final String SCHEMA_URL_ADDRESS = "https://code-repo.d4science.org/gCubeSystem/gcubedatacatalogue-metadata-discovery/raw/branch/master/src/main/resources/org/gcube/datacatalogue/metadatadiscovery/Gdcmetadataprofilev3.xsd"; public static final URL SCHEMA_URL; static { @@ -110,12 +112,17 @@ public class ISProfile { profile.setAdditionalProperty(PROFILE, xml); configuration.addFacet(profile); - XSDSchemaFacet xsdSchemaFacet = new XSDSchemaFacetImpl(); - xsdSchemaFacet.setName("gCube Item Profile"); - xsdSchemaFacet.setSchemaURL(SCHEMA_URL); - xsdSchemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); - xsdSchemaFacet.setContent(DataCalogueMetadataFormatReader.getProfileSchemaString()); - configuration.addFacet(xsdSchemaFacet); + ValueSchema schema = new ValueSchemaImpl(); + schema.setValue(DataCalogueMetadataFormatReader.getProfileSchemaString()); + schema.setSchema(SCHEMA_URL.toURI()); + + + SchemaFacet schemaFacet = new SchemaFacetImpl(); + schemaFacet.setName("gCube Item Profile"); + schemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); + schemaFacet.setSchema(schema); + + configuration.addFacet(schemaFacet); return configuration; } From 6b011e4e093055021431b3c1d5a36678a9b0c1ef Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Sun, 24 Jan 2021 23:31:33 +0100 Subject: [PATCH 03/25] Fixed publishing on new Is due to change in gcube model --- .../org/gcube/gcat/profile/ISProfile.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/gcat/profile/ISProfile.java b/src/main/java/org/gcube/gcat/profile/ISProfile.java index c5fb919..f941ae5 100644 --- a/src/main/java/org/gcube/gcat/profile/ISProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ISProfile.java @@ -30,15 +30,17 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SchemaFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.XSDSchemaFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; +import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; +import org.gcube.resourcemanagement.model.reference.entities.facets.SchemaFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.XSDSchemaFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; +import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; @@ -110,12 +112,16 @@ public class ISProfile { profile.setAdditionalProperty(PROFILE, xml); configuration.addFacet(profile); - XSDSchemaFacet xsdSchemaFacet = new XSDSchemaFacetImpl(); - xsdSchemaFacet.setName("gCube Item Profile"); - xsdSchemaFacet.setSchemaURL(SCHEMA_URL); - xsdSchemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); - xsdSchemaFacet.setContent(DataCalogueMetadataFormatReader.getProfileSchemaString()); - configuration.addFacet(xsdSchemaFacet); + SchemaFacet schemaFacet = new SchemaFacetImpl(); + schemaFacet.setName("gCube Item Profile"); + schemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); + + ValueSchema valueSchema = new ValueSchemaImpl(); + valueSchema.setSchema(SCHEMA_URL.toURI()); + valueSchema.setValue(DataCalogueMetadataFormatReader.getProfileSchemaString()); + schemaFacet.setSchema(valueSchema); + + configuration.addFacet(schemaFacet); return configuration; } From 1d33bfefcb6f531b11ad00c050935e2b6357eb78 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Sun, 24 Jan 2021 23:32:19 +0100 Subject: [PATCH 04/25] Added test --- .../gcat/persistence/ckan/CKANGroupTest.java | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java index a6001f5..0ce4152 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java @@ -1,15 +1,23 @@ package org.gcube.gcat.persistence.ckan; +import java.io.IOException; import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; +import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; +import org.gcube.com.fasterxml.jackson.databind.JsonNode; +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; +import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; +import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.gcat.ContextTest; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; - public class CKANGroupTest extends ContextTest { private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class); @@ -69,4 +77,51 @@ public class CKANGroupTest extends ContextTest { ckanGroup.delete(true); } } + + private void create(Set createdGroup, Map groups, String name) throws JsonProcessingException, IOException { + if(createdGroup.contains(name)) { + return; + } + String sysAdminAPI = "522557b4-f709-4935-be81-947e13afa2a7"; // CKANUtility.getSysAdminAPI(); + CKANGroup ckanGroupToCreate = new CKANGroup(); + ckanGroupToCreate.setApiKey(sysAdminAPI); + ckanGroupToCreate.setName(name); + // ckanGroupToCreate.purge(); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(groups.get(name)); + ArrayNode array = (ArrayNode) jsonNode.get("groups"); + for(JsonNode node : array) { + String parentName = node.get("name").asText(); + if(!createdGroup.contains(parentName)) { + create(createdGroup, groups, parentName); + } + } + ckanGroupToCreate.create(groups.get(name)); + createdGroup.add(name); + } + + // @Test + public void createGRSFGroups() throws ObjectNotFound, Exception { + // Setting GRSF ADMIN token of grsf.publisher user to read groups + ContextTest.setContext("5213d3d8-6ea3-4d55-bf1c-da25ed3aba43-843339462"); + String key = CKANUtility.getSysAdminAPI(); + List groupNames = listGroup(); + Map groups = new HashMap<>(); + for(String name : groupNames) { + CKANGroup ckanGroup = new CKANGroup(); + ckanGroup.setApiKey(key); + ckanGroup.setName(name); + String read = ckanGroup.read(); + groups.put(name, read); + } + + Set createdGroup = new HashSet<>(); + + // Setting GRSF_PRE token of grsf.publisher user to create groups + ContextTest.setContext("17f72d12-5fe0-48a4-90d3-c398c41aedfe-843339462"); + for(String name : groupNames) { + create(createdGroup, groups, name); + } + + } } From 09ae3573f85b7fa4cbc5f97ee960f0300d0a77de Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 3 Feb 2021 16:28:17 +0100 Subject: [PATCH 05/25] Added support to get only the number of total items refs #20627 --- .../gcat/persistence/ckan/CKANPackage.java | 30 ++++++++++++++++++ src/main/java/org/gcube/gcat/rest/Item.java | 31 +++++++++++++++++++ src/test/java/org/gcube/gcat/ContextTest.java | 19 +++++++++--- .../persistence/ckan/CKANPackageTest.java | 7 +++++ 4 files changed, 82 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index fbfba87..8f91e24 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -100,6 +100,8 @@ public class CKANPackage extends CKAN { // The 'results' array is included in the 'result' object for package_search private static final String RESULTS_KEY = "results"; + private static final String COUNT_KEY = "count"; + protected static final String PRIVATE_KEY = "private"; protected static final String SEARCHABLE_KEY = "searchable"; protected static final String CAPACITY_KEY = "capacity"; @@ -326,6 +328,29 @@ public class CKANPackage extends CKAN { } } + public int count() { + Map parameters = new HashMap<>(); + if(uriInfo != null) { + MultivaluedMap queryParameters = uriInfo.getQueryParameters(); + parameters = checkListParameters(queryParameters, parameters); + } + + int limit = 1; + parameters.put(ROWS_KEY, String.valueOf(limit)); + int offset = 0; + parameters.put(START_KEY, String.valueOf(offset * limit)); + + if(!parameters.containsKey(GCatConstants.Q_KEY)) { + String filter = getFilterForOrganizations(); + parameters.put(GCatConstants.Q_KEY, filter); + } + + sendGetRequest(LIST, parameters); + + int count = result.get(COUNT_KEY).asInt(); + return count; + } + @Override public String list(int limit, int offset) { Map parameters = new HashMap<>(); @@ -347,6 +372,11 @@ public class CKANPackage extends CKAN { parameters = checkListParameters(queryParameters, parameters); } + if(!parameters.containsKey(GCatConstants.Q_KEY)) { + String filter = getFilterForOrganizations(); + parameters.put(GCatConstants.Q_KEY, filter); + } + return list(parameters); } diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index eea6314..f6182e5 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -33,6 +33,15 @@ public class Item extends REST implements org.gcube.gcat.api.interf super(ITEMS, ITEM_ID_PARAMETER, CKANPackage.class); } + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ + @Override + public int count() throws WebServiceException { + CKANPackage ckan = getInstance(); + return ckan.count(); + } + /* * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface */ @@ -44,6 +53,28 @@ public class Item extends REST implements org.gcube.gcat.api.interf @GET @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) + public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, + @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset, + @QueryParam(GCatConstants.COUNT_ONLY_PARAMETER) @DefaultValue("false") Boolean countOnly) { + String ret = null; + if(countOnly) { + int count = count(); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{\""); + stringBuilder.append(Item.COUNT_KEY); + stringBuilder.append("\":"); + stringBuilder.append(count); + stringBuilder.append("}"); + ret = stringBuilder.toString(); + }else { + ret = list(limit, offset); + } + return ret; + } + + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ @Override public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) { diff --git a/src/test/java/org/gcube/gcat/ContextTest.java b/src/test/java/org/gcube/gcat/ContextTest.java index 9d66a0b..b146499 100644 --- a/src/test/java/org/gcube/gcat/ContextTest.java +++ b/src/test/java/org/gcube/gcat/ContextTest.java @@ -48,11 +48,20 @@ public class ContextTest { DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE"; } - public static String getCurrentScope(String token) throws ObjectNotFound, Exception { + public static String getCurrentContextFullName() { + String token = SecurityTokenProvider.instance.get(); + AuthorizationEntry authorizationEntry = null; + try { + authorizationEntry = Constants.authorizationService().get(token); + } catch(Exception e) { + return ScopeProvider.instance.get(); + } + return authorizationEntry.getContext(); + } + + public static String getContextFullName(String token) throws ObjectNotFound, Exception { AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token); - String context = authorizationEntry.getContext(); - logger.info("Context of token {} is {}", token, context); - return context; + return authorizationEntry.getContext(); } public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception { @@ -68,7 +77,7 @@ public class ContextTest { String qualifier = authorizationEntry.getQualifier(); Caller caller = new Caller(clientInfo, qualifier); AuthorizationProvider.instance.set(caller); - ScopeProvider.instance.set(getCurrentScope(token)); + ScopeProvider.instance.set(getContextFullName(token)); } @BeforeClass diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java index 9d8c570..9578ba8 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java @@ -45,6 +45,13 @@ public class CKANPackageTest extends ContextTest { private static final String LICENSE_VALUE = "CC-BY-SA-4.0"; private static final String EXTRAS_TYPE_VALUE_VALUE = "TestEmptyProfile"; + @Test + public void count() throws Exception { + CKANPackage ckanPackage = new CKANPackage(); + int count = ckanPackage.count(); + logger.debug("Number of items in {} is {}", ContextTest.getCurrentContextFullName(), count); + } + @Test public void list() throws Exception { CKANPackage ckanPackage = new CKANPackage(); From f258ff80a28765840d135af83a769ba5ed1af3d8 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 3 Feb 2021 16:44:28 +0100 Subject: [PATCH 06/25] Fixed constant usage --- src/main/java/org/gcube/gcat/rest/Item.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index f6182e5..d22c981 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -61,7 +61,7 @@ public class Item extends REST implements org.gcube.gcat.api.interf int count = count(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("{\""); - stringBuilder.append(Item.COUNT_KEY); + stringBuilder.append(GCatConstants.COUNT_KEY); stringBuilder.append("\":"); stringBuilder.append(count); stringBuilder.append("}"); From 786bbc337fbf7aedae1b841ded3838bee4a81e72 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 3 Feb 2021 16:50:23 +0100 Subject: [PATCH 07/25] Fixed GCat constant --- .../java/org/gcube/gcat/persistence/ckan/CKANPackage.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 8f91e24..2d36947 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -100,8 +100,6 @@ public class CKANPackage extends CKAN { // The 'results' array is included in the 'result' object for package_search private static final String RESULTS_KEY = "results"; - private static final String COUNT_KEY = "count"; - protected static final String PRIVATE_KEY = "private"; protected static final String SEARCHABLE_KEY = "searchable"; protected static final String CAPACITY_KEY = "capacity"; @@ -347,7 +345,7 @@ public class CKANPackage extends CKAN { sendGetRequest(LIST, parameters); - int count = result.get(COUNT_KEY).asInt(); + int count = result.get(GCatConstants.COUNT_KEY).asInt(); return count; } From 826a990b42e64e0761846514a2d06554d291f60d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 9 Feb 2021 15:44:15 +0100 Subject: [PATCH 08/25] Ported count method from version 1.4.4 to 2.0.0-SNAPSHOT --- CHANGELOG.md | 10 +- .../gcat/persistence/ckan/CKANGroup.java | 7 + .../persistence/ckan/CKANOrganization.java | 11 +- .../org/gcube/gcat/profile/ISProfile.java | 87 +----- .../gcat/profile/ResourceRegistryProfile.java | 284 ++++++++++++++++++ .../java/org/gcube/gcat/rest/BaseREST.java | 11 + src/main/java/org/gcube/gcat/rest/Group.java | 24 ++ src/main/java/org/gcube/gcat/rest/Item.java | 14 +- .../org/gcube/gcat/rest/Organization.java | 24 ++ .../java/org/gcube/gcat/rest/Profile.java | 42 ++- .../gcat/persistence/ckan/CKANGroupTest.java | 15 +- .../ckan/CKANOrganizationTest.java | 10 +- .../org/gcube/gcat/profile/ProfileTest.java | 7 + 13 files changed, 448 insertions(+), 98 deletions(-) create mode 100644 src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c8acf..6f01f59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for gCube Catalogue (gCat) Service -## [v2.0.0-SNAPSHOT] [r5.0.0] - +## [v2.0.0-SNAPSHOT] -- Switched JSON management to gcube-jackson [#19735] - Added support to publish an item organizations not matching the current context [#19365] +## [v1.4.4] + +- Added count method for Item collection [#20627] +- Added count method for Organization, Group and Profile collection [#20629] +- Switched JSON management to gcube-jackson [#19735] + + ## [v1.4.3] [r4.23.0] - 2020-06-19 - Social Post is disabled if not explicitly enabled by the client [#19295] diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java index ae2f50a..9144968 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java @@ -98,4 +98,11 @@ public class CKANGroup extends CKAN { } return groups; } + + public int count() { + list(100000, 0); + ArrayNode arrayNode = (ArrayNode) result; + return arrayNode.size(); + } + } diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java index 5b7fa58..dd1907f 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java @@ -1,12 +1,12 @@ package org.gcube.gcat.persistence.ckan; +import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; +import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.common.scope.impl.ScopeBean; import org.gcube.gcat.utils.ContextUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; - /** * @author Luca Frosini (ISTI - CNR) */ @@ -76,4 +76,11 @@ public class CKANOrganization extends CKAN { ScopeBean scopeBean = new ScopeBean(context); return scopeBean.name().toLowerCase(); } + + public int count() { + list(100000, 0); + ArrayNode arrayNode = (ArrayNode) result; + return arrayNode.size(); + } + } diff --git a/src/main/java/org/gcube/gcat/profile/ISProfile.java b/src/main/java/org/gcube/gcat/profile/ISProfile.java index c3415a6..591544b 100644 --- a/src/main/java/org/gcube/gcat/profile/ISProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ISProfile.java @@ -1,11 +1,7 @@ package org.gcube.gcat.profile; import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Set; import javax.ws.rs.InternalServerErrorException; @@ -13,11 +9,8 @@ import javax.ws.rs.NotAuthorizedException; import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; -import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; -import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.Resources; -import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery; import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil; import org.gcube.gcat.persistence.ckan.CKANUser; @@ -26,22 +19,6 @@ import org.gcube.gcat.persistence.ckan.CKANUserCache; import org.gcube.gcat.utils.Constants; import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; -import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; -import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; -import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; -import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SchemaFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; -import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; -import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; -import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; -import org.gcube.resourcemanagement.model.reference.entities.facets.SchemaFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; -import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; -import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; -import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query; import org.gcube.resources.discovery.client.queries.impl.QueryBox; @@ -52,24 +29,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xml.sax.SAXException; +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; +import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; + public class ISProfile { public static int PRETTY_PRINT_INDENT_FACTOR = 4; - public static final String PROFILE = "profile"; - public static final String PROFILE_SCHEMA = "profileSchema"; - - public static final String SCHEMA_URL_ADDRESS = "https://code-repo.d4science.org/gCubeSystem/gcubedatacatalogue-metadata-discovery/raw/branch/master/src/main/resources/org/gcube/datacatalogue/metadatadiscovery/Gdcmetadataprofilev3.xsd"; - public static final URL SCHEMA_URL; - - static { - try { - SCHEMA_URL = new URL(SCHEMA_URL_ADDRESS); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - private static Logger logger = LoggerFactory.getLogger(ISProfile.class); protected ObjectMapper mapper; @@ -82,6 +48,14 @@ public class ISProfile { return mapper; } + public int count() { + try { + return (new MetadataUtility()).getProfilesNames().size(); + }catch(Exception e) { + throw new InternalServerErrorException(e); + } + } + public ArrayNode list() { ArrayNode arrayNode = mapper.createArrayNode(); @@ -96,45 +70,6 @@ public class ISProfile { } } - /* - * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Configuration - */ - protected Configuration instantiateConfiguration(String name, String xml) throws Exception { - Configuration configuration = new ConfigurationImpl(); - - IdentifierFacet identifierFacet = new IdentifierFacetImpl(); - identifierFacet.setValue(name); - identifierFacet.setType(IdentificationType.STRING); - IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); - configuration.addFacet(isIdentifiedBy); - - SimpleFacet profile = new SimpleFacetImpl(); - profile.setAdditionalProperty(PROFILE, xml); - configuration.addFacet(profile); - - SchemaFacet schemaFacet = new SchemaFacetImpl(); - schemaFacet.setName("gCube Item Profile"); - schemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); - - ValueSchema valueSchema = new ValueSchemaImpl(); - valueSchema.setSchema(SCHEMA_URL.toURI()); - valueSchema.setValue(DataCalogueMetadataFormatReader.getProfileSchemaString()); - schemaFacet.setSchema(valueSchema); - - configuration.addFacet(schemaFacet); - - return configuration; - } - - - protected Configuration getConfiguration(String name) throws ResourceRegistryException { - ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); - Map map = new HashMap<>(); - map.put(IdentifierFacet.VALUE_PROPERTY, name); - List configurations = resourceRegistryClient.getFilteredResources(Configuration.class, IsIdentifiedBy.class, IdentifierFacet.class, false, map); - return configurations.get(0); - } - /* * TODO Check the Queries because the name in the Profile differs from the name in * diff --git a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java new file mode 100644 index 0000000..6ae9826 --- /dev/null +++ b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java @@ -0,0 +1,284 @@ +package org.gcube.gcat.profile; + +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.NotAuthorizedException; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.WebApplicationException; + +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; +import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; +import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery; +import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil; +import org.gcube.gcat.persistence.ckan.CKANUser; +import org.gcube.gcat.persistence.ckan.CKANUser.Role; +import org.gcube.gcat.persistence.ckan.CKANUserCache; +import org.gcube.gcat.utils.Constants; +import org.gcube.informationsystem.publisher.RegistryPublisher; +import org.gcube.informationsystem.publisher.RegistryPublisherFactory; +import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; +import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; +import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SchemaFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; +import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; +import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; +import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; +import org.gcube.resourcemanagement.model.reference.entities.facets.SchemaFacet; +import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; +import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; +import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; +import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.Query; +import org.gcube.resources.discovery.client.queries.impl.QueryBox; +import org.gcube.resources.discovery.icclient.ICFactory; +import org.json.JSONObject; +import org.json.XML; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.xml.sax.SAXException; + +public class ResourceRegistryProfile { + + public static int PRETTY_PRINT_INDENT_FACTOR = 4; + + public static final String PROFILE = "profile"; + public static final String PROFILE_SCHEMA = "profileSchema"; + + public static final String SCHEMA_URL_ADDRESS = "https://code-repo.d4science.org/gCubeSystem/gcubedatacatalogue-metadata-discovery/raw/branch/master/src/main/resources/org/gcube/datacatalogue/metadatadiscovery/Gdcmetadataprofilev3.xsd"; + public static final URL SCHEMA_URL; + + static { + try { + SCHEMA_URL = new URL(SCHEMA_URL_ADDRESS); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + + private static Logger logger = LoggerFactory.getLogger(ResourceRegistryProfile.class); + + protected ObjectMapper mapper; + + public ResourceRegistryProfile() { + mapper = new ObjectMapper(); + } + + public ObjectMapper getMapper() { + return mapper; + } + + public ArrayNode list() { + ArrayNode arrayNode = mapper.createArrayNode(); + + try { + Set names = (new MetadataUtility()).getProfilesNames(); + for(String name : names) { + arrayNode.add(name); + } + return arrayNode; + } catch(Exception e) { + throw new InternalServerErrorException(e); + } + } + + /* + * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Configuration + */ + protected Configuration instantiateConfiguration(String name, String xml) throws Exception { + Configuration configuration = new ConfigurationImpl(); + + IdentifierFacet identifierFacet = new IdentifierFacetImpl(); + identifierFacet.setValue(name); + identifierFacet.setType(IdentificationType.STRING); + IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); + configuration.addFacet(isIdentifiedBy); + + SimpleFacet profile = new SimpleFacetImpl(); + profile.setAdditionalProperty(PROFILE, xml); + configuration.addFacet(profile); + + SchemaFacet schemaFacet = new SchemaFacetImpl(); + schemaFacet.setName("gCube Item Profile"); + schemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); + + ValueSchema valueSchema = new ValueSchemaImpl(); + valueSchema.setSchema(SCHEMA_URL.toURI()); + valueSchema.setValue(DataCalogueMetadataFormatReader.getProfileSchemaString()); + schemaFacet.setSchema(valueSchema); + + configuration.addFacet(schemaFacet); + + return configuration; + } + + + protected Configuration getConfiguration(String name) throws ResourceRegistryException { + ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create(); + Map map = new HashMap<>(); + map.put(IdentifierFacet.VALUE_PROPERTY, name); + List configurations = resourceRegistryClient.getFilteredResources(Configuration.class, IsIdentifiedBy.class, IdentifierFacet.class, false, map); + return configurations.get(0); + } + + /* + * TODO Check the Queries because the name in the Profile differs from the name in + * + * + */ + protected GenericResource instantiateGenericResource(String name, String xml) throws Exception { + GenericResource genericResource = new GenericResource(); + org.gcube.common.resources.gcore.GenericResource.Profile profile = genericResource.newProfile(); + profile.type(MetadataFormatDiscovery.DATA_CATALOGUE_METADATA_SECONDARY_TYPE); + profile.name(name); + profile.description("Profile create using " + Constants.CATALOGUE_NAME); + // appendXmlFragment(profile, xml); + profile.newBody(xml); + StringWriter stringWriter = new StringWriter(); + Resources.marshal(genericResource, stringWriter); + logger.debug("The generated {} is\n{}", GenericResource.class.getSimpleName(), stringWriter.toString()); + return genericResource; + } + + protected void createGenericResource(String name, String xml) throws Exception { + GenericResource genericResource = instantiateGenericResource(name, xml); + RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); + genericResource = registryPublisher.create(genericResource); + StringWriter stringWriter = new StringWriter(); + Resources.marshal(genericResource, stringWriter); + logger.trace("The {} with ID {} has been created \n{}", GenericResource.class.getSimpleName(), + genericResource.id(), stringWriter.toString()); + } + + protected GenericResource getGenericResource(String name) { + String query = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryTypeAndName(name, + MetadataFormatDiscovery.DATA_CATALOGUE_METADATA_SECONDARY_TYPE); + Query q = new QueryBox(query); + DiscoveryClient client = ICFactory.clientFor(GenericResource.class); + List resources = client.submit(q); + + if(resources == null || resources.size() == 0) { + throw new InternalServerErrorException( + "No Resources with secondaryType '" + MetadataFormatDiscovery.DATA_CATALOGUE_METADATA_SECONDARY_TYPE + + "' and name '" + name + "' exists in the current context"); + } else { + if(resources.size() == 1) { + GenericResource genericResource = resources.get(0); + return genericResource; + } else { + throw new InternalServerErrorException("More than one Resource with secondaryType '" + + MetadataFormatDiscovery.DATA_CATALOGUE_METADATA_SECONDARY_TYPE + "' and name '" + name + + "' exists in the current context"); + } + } + } + + protected void updateGenericResource(String name, String xml) { + + GenericResource genericResource = getGenericResource(name); + logger.info("The {} with ID {} is going to be updated", GenericResource.class.getSimpleName(), + genericResource.id()); + + genericResource.profile().newBody(xml); + RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); + registryPublisher.update(genericResource); + + StringWriter stringWriter = new StringWriter(); + Resources.marshal(genericResource, stringWriter); + logger.trace("The {} with ID {} has been updated to \n{}", GenericResource.class.getSimpleName(), + genericResource.id(), stringWriter.toString()); + + } + + protected void removeGenericResource(String name) { + GenericResource genericResource = getGenericResource(name); + RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); + registryPublisher.remove(genericResource); + } + + public String read(String name, boolean xml) { + try { + String profile = (new MetadataUtility()).getMetadataFormat(name).getMetadataSource(); + if(profile != null) { + if(xml) { + return profile; + } else { + JSONObject xmlJSONObj = XML.toJSONObject(profile); + String jsonString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR); + return jsonString; + } + } else { + throw new NotFoundException("Profile with name " + name + " not found"); + } + } catch(WebApplicationException e) { + throw e; + } catch(Exception e) { + throw new InternalServerErrorException(e.getMessage()); + } + } + + public boolean createOrUpdate(String name, String xml) throws SAXException { + try { + CKANUser ckanUser = CKANUserCache.getCurrrentCKANUser(); + if(ckanUser.getRole().ordinal() implements org.gcube.gcat.api.interfa super(GROUPS, GROUP_ID_PARAMETER, CKANGroup.class); } + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ + @Override + public int count() throws WebServiceException { + CKANGroup ckan = getInstance(); + return ckan.count(); + } + @GET @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) + public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, + @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset, + @QueryParam(GCatConstants.COUNT_PARAMETER) @DefaultValue("false") Boolean countOnly) { + if(countOnly) { + int count = count(); + return createCountJson(count); + }else { + return list(limit, offset); + } + } + + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ @Override public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) { diff --git a/src/main/java/org/gcube/gcat/rest/Item.java b/src/main/java/org/gcube/gcat/rest/Item.java index d22c981..6503d4b 100644 --- a/src/main/java/org/gcube/gcat/rest/Item.java +++ b/src/main/java/org/gcube/gcat/rest/Item.java @@ -55,21 +55,13 @@ public class Item extends REST implements org.gcube.gcat.api.interf @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset, - @QueryParam(GCatConstants.COUNT_ONLY_PARAMETER) @DefaultValue("false") Boolean countOnly) { - String ret = null; + @QueryParam(GCatConstants.COUNT_PARAMETER) @DefaultValue("false") Boolean countOnly) { if(countOnly) { int count = count(); - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("{\""); - stringBuilder.append(GCatConstants.COUNT_KEY); - stringBuilder.append("\":"); - stringBuilder.append(count); - stringBuilder.append("}"); - ret = stringBuilder.toString(); + return createCountJson(count); }else { - ret = list(limit, offset); + return list(limit, offset); } - return ret; } /* diff --git a/src/main/java/org/gcube/gcat/rest/Organization.java b/src/main/java/org/gcube/gcat/rest/Organization.java index d1acc3c..11b0d53 100644 --- a/src/main/java/org/gcube/gcat/rest/Organization.java +++ b/src/main/java/org/gcube/gcat/rest/Organization.java @@ -11,6 +11,7 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +import javax.xml.ws.WebServiceException; import org.gcube.gcat.ResourceInitializer; import org.gcube.gcat.annotation.PATCH; @@ -31,8 +32,31 @@ public class Organization extends REST super(ORGANIZATIONS, ORGANIZATION_ID_PARAMETER, CKANOrganization.class); } + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ + @Override + public int count() throws WebServiceException { + CKANOrganization ckan = getInstance(); + return ckan.count(); + } + @GET @Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8) + public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, + @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset, + @QueryParam(GCatConstants.COUNT_PARAMETER) @DefaultValue("false") Boolean countOnly) { + if(countOnly) { + int count = count(); + return createCountJson(count); + }else { + return list(limit, offset); + } + } + + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ @Override public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit, @QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) { diff --git a/src/main/java/org/gcube/gcat/rest/Profile.java b/src/main/java/org/gcube/gcat/rest/Profile.java index 68ce3c2..4b115a8 100644 --- a/src/main/java/org/gcube/gcat/rest/Profile.java +++ b/src/main/java/org/gcube/gcat/rest/Profile.java @@ -13,6 +13,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; @@ -23,6 +24,7 @@ import javax.ws.rs.core.UriInfo; import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.gcat.ResourceInitializer; +import org.gcube.gcat.api.GCatConstants; import org.gcube.gcat.profile.ISProfile; import org.xml.sax.SAXException; @@ -53,10 +55,46 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P @Context private UriInfo uriInfo; + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ + @Override + public int count() { + setCalledMethod("GET /" + PROFILES); + try { + ISProfile isProfile = new ISProfile(); + return isProfile.count(); + } catch(WebApplicationException e) { + throw e; + } catch(Exception e) { + throw new InternalServerErrorException(e); + } + } + @GET @Produces(MediaType.APPLICATION_JSON) - public String list() { + public String listOrCount(@QueryParam(GCatConstants.COUNT_PARAMETER) @DefaultValue("false") Boolean countOnly) { setCalledMethod("GET /" + PROFILES); + try { + ISProfile isProfile = new ISProfile(); + if(countOnly) { + return createCountJson(isProfile.count()); + }else{ + ArrayNode arrayNode = isProfile.list(); + return isProfile.getMapper().writeValueAsString(arrayNode); + } + } catch(WebApplicationException e) { + throw e; + } catch(Exception e) { + throw new InternalServerErrorException(e); + } + } + + /* + * Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface + */ + @Override + public String list() { try { ISProfile isProfile = new ISProfile(); ArrayNode arrayNode = isProfile.list(); @@ -161,5 +199,5 @@ public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.P public String update(String name, String xml) { return createOrUpdate(name, xml).getEntity().toString(); } - + } diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java index 0ce4152..a80a206 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANGroupTest.java @@ -22,10 +22,17 @@ public class CKANGroupTest extends ContextTest { private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class); + @Test + public void count() throws Exception { + CKANGroup ckanGroup = new CKANGroup(); + int count = ckanGroup.count(); + logger.debug("The groups are {}", count); + } + @Test public void list() throws Exception { CKANGroup ckanGroup = new CKANGroup(); - String ret = ckanGroup.list(10, 0); + String ret = ckanGroup.list(10000, 0); logger.debug("{}", ret); } @@ -82,7 +89,7 @@ public class CKANGroupTest extends ContextTest { if(createdGroup.contains(name)) { return; } - String sysAdminAPI = "522557b4-f709-4935-be81-947e13afa2a7"; // CKANUtility.getSysAdminAPI(); + String sysAdminAPI = ""; // CKANUtility.getSysAdminAPI(); CKANGroup ckanGroupToCreate = new CKANGroup(); ckanGroupToCreate.setApiKey(sysAdminAPI); ckanGroupToCreate.setName(name); @@ -103,7 +110,7 @@ public class CKANGroupTest extends ContextTest { // @Test public void createGRSFGroups() throws ObjectNotFound, Exception { // Setting GRSF ADMIN token of grsf.publisher user to read groups - ContextTest.setContext("5213d3d8-6ea3-4d55-bf1c-da25ed3aba43-843339462"); + ContextTest.setContext(""); String key = CKANUtility.getSysAdminAPI(); List groupNames = listGroup(); Map groups = new HashMap<>(); @@ -118,7 +125,7 @@ public class CKANGroupTest extends ContextTest { Set createdGroup = new HashSet<>(); // Setting GRSF_PRE token of grsf.publisher user to create groups - ContextTest.setContext("17f72d12-5fe0-48a4-90d3-c398c41aedfe-843339462"); + ContextTest.setContext(""); for(String name : groupNames) { create(createdGroup, groups, name); } diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java index cb25939..d76a8bf 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANOrganizationTest.java @@ -21,7 +21,15 @@ public class CKANOrganizationTest extends ContextTest { */ @Test - public void listOrganization() throws Exception { + public void countOrganizations() throws Exception { + ContextTest.setContextByName("/gcube"); + CKANOrganization ckanOrganization = new CKANOrganization(); + int count = ckanOrganization.count(); + logger.debug("The organizations are {}", count); + } + + @Test + public void listOrganizations() throws Exception { ContextTest.setContextByName("/gcube"); CKANOrganization ckanOrganization = new CKANOrganization(); String ret = ckanOrganization.list(1000, 0); diff --git a/src/test/java/org/gcube/gcat/profile/ProfileTest.java b/src/test/java/org/gcube/gcat/profile/ProfileTest.java index 24f1064..d3a2314 100644 --- a/src/test/java/org/gcube/gcat/profile/ProfileTest.java +++ b/src/test/java/org/gcube/gcat/profile/ProfileTest.java @@ -18,6 +18,13 @@ public class ProfileTest extends ContextTest { private static Logger logger = LoggerFactory.getLogger(ProfileTest.class); + @Test + public void count() throws Exception { + ISProfile profile = new ISProfile(); + int count = profile.count(); + logger.debug("We have {} types", count); + } + @Test public void list() throws Exception { ISProfile profile = new ISProfile(); From 51b76c89e675581d2d129f83d7e7ae9cbdb01708 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 9 Feb 2021 17:12:42 +0100 Subject: [PATCH 09/25] commented code which does not compile due to new gcube-model --- .../java/org/gcube/gcat/profile/ResourceRegistryProfile.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java index 6ae9826..297397e 100644 --- a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java @@ -102,11 +102,13 @@ public class ResourceRegistryProfile { protected Configuration instantiateConfiguration(String name, String xml) throws Exception { Configuration configuration = new ConfigurationImpl(); + /* IdentifierFacet identifierFacet = new IdentifierFacetImpl(); identifierFacet.setValue(name); identifierFacet.setType(IdentificationType.STRING); IsIdentifiedBy isIdentifiedBy = new IsIdentifiedByImpl(configuration, identifierFacet); configuration.addFacet(isIdentifiedBy); + */ SimpleFacet profile = new SimpleFacetImpl(); profile.setAdditionalProperty(PROFILE, xml); @@ -116,10 +118,12 @@ public class ResourceRegistryProfile { schemaFacet.setName("gCube Item Profile"); schemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields."); + /* ValueSchema valueSchema = new ValueSchemaImpl(); valueSchema.setSchema(SCHEMA_URL.toURI()); valueSchema.setValue(DataCalogueMetadataFormatReader.getProfileSchemaString()); schemaFacet.setSchema(valueSchema); + */ configuration.addFacet(schemaFacet); From eb8e0b7bea38e7cd01bc67a2b40e732eb78c0440 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 10 Feb 2021 12:26:12 +0100 Subject: [PATCH 10/25] Commented code which add non mandatory field as empty field if there are no mandatory fields --- src/main/java/org/gcube/gcat/oldutils/Validator.java | 2 ++ .../java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index e8fc751..020750d 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -337,9 +337,11 @@ public class Validator { // if there was no field with this key and it was not mandatory, just add an entry of the kind {"key": "key-value", "value" : ""}. // Sometimes it is important to view the field as empty. + /* if(fieldsFoundWithThisKey == 0 && !metadataField.getMandatory()) { toReturn.add(new CustomField(metadataFieldName, "", -1, -1)); } + */ return toReturn; diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java index 9578ba8..6b5dd32 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java @@ -307,10 +307,12 @@ public class CKANPackageTest extends ContextTest { typeNode.put(CKANPackage.EXTRAS_VALUE_KEY, EXTRAS_TYPE_VALUE_VALUE); extraArrayNode.add(typeNode); + /* ObjectNode modelNode = mapper.createObjectNode(); modelNode.put(CKANPackage.EXTRAS_KEY_KEY, "test"); modelNode.put(CKANPackage.EXTRAS_VALUE_KEY, "test 2.9°"); extraArrayNode.add(modelNode); + */ ObjectNode populationNode = mapper.createObjectNode(); populationNode.put(CKANPackage.EXTRAS_KEY_KEY, "Population"); From 878b5cfae960f3fb407082f2b31780914a490d81 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 10 Feb 2021 14:18:38 +0100 Subject: [PATCH 11/25] Removed owner_org from created/updated/read item --- .../gcube/gcat/persistence/ckan/CKANPackage.java | 13 +++++++++++++ .../gcat/persistence/ckan/CKANPackageTest.java | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 2d36947..464269d 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -237,6 +237,14 @@ public class CKANPackage extends CKAN { return checkBaseInformation(json, false); } + public JsonNode cleanResult(JsonNode jsonNode) { + if(jsonNode.has(OWNER_ORG_KEY)) { + ((ObjectNode) jsonNode).remove(OWNER_ORG_KEY); + } + return jsonNode; + } + + /** * @param json The json to check * @param allowPartialInfo used for patch method which provide only partial information (i.e. the info to patch) @@ -596,6 +604,8 @@ public class CKANPackage extends CKAN { sendSocialPost(title, catalogueItemURL); } + result = cleanResult(result); + return getAsString(result); } catch(WebApplicationException e) { rollbackManagedResources(); @@ -667,6 +677,7 @@ public class CKANPackage extends CKAN { String catalogueItemURL = uriResolver.getCatalogueItemURL(name); ((ObjectNode) result).put(ITEM_URL_KEY, catalogueItemURL); */ + result = cleanResult(result); return getAsString(result); } catch(WebApplicationException e) { @@ -742,6 +753,8 @@ public class CKANPackage extends CKAN { ((ObjectNode) result).put(ITEM_URL_KEY, catalogueItemURL); */ + result = cleanResult(result); + return getAsString(result); } catch(WebApplicationException e) { rollbackManagedResources(); diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java index 6b5dd32..d5068af 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java @@ -43,7 +43,7 @@ public class CKANPackageTest extends ContextTest { private static final String ITEM_NAME_VALUE = "restful_transaction_model"; private static final String LICENSE_VALUE = "CC-BY-SA-4.0"; - private static final String EXTRAS_TYPE_VALUE_VALUE = "TestEmptyProfile"; + private static final String EXTRAS_TYPE_VALUE_VALUE = "EmptyProfile"; @Test public void count() throws Exception { @@ -330,7 +330,7 @@ public class CKANPackageTest extends ContextTest { @Test public void create() throws Exception { - ContextTest.setContextByName("/gcube/devNext/NextNext"); + ContextTest.setContextByName("/gcube/devsec/devVRE"); ObjectMapper mapper = new ObjectMapper(); createPackage(mapper); } @@ -346,7 +346,7 @@ public class CKANPackageTest extends ContextTest { @Test public void createReadUpdateUpdatePurge() throws Exception { - ContextTest.setContextByName("/gcube/devNext/NextNext"); + ContextTest.setContextByName("/gcube/devsec/devVRE"); ObjectMapper mapper = new ObjectMapper(); createPackage(mapper); From 243cae757fb0ab698ca05c4a1d7e8a610f6c4b9d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 17 Feb 2021 17:30:25 +0100 Subject: [PATCH 12/25] Fixed check on controlled vocabulary --- src/main/java/org/gcube/gcat/oldutils/Validator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index 020750d..4d16ed2 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -23,6 +23,7 @@ import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataGrouping; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataTagging; +import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary; import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory; import org.gcube.gcat.persistence.ckan.CKANGroup; import org.gcube.gcat.persistence.ckan.CKANPackage; @@ -465,7 +466,14 @@ public class Validator { DataType dataType = metadataField.getDataType(); String regex = metadataField.getValidator() != null ? metadataField.getValidator().getRegularExpression() : null; - boolean hasControlledVocabulary = metadataField.getVocabulary() != null; + boolean hasControlledVocabulary = false; + MetadataVocabulary metadataVocabulary = metadataField.getVocabulary(); + if(metadataVocabulary!=null) { + List vocabularyFields = metadataVocabulary.getVocabularyFields(); + if(vocabularyFields!=null && vocabularyFields.size()>0) { + hasControlledVocabulary = true; + } + } String value = fieldToValidate.getValue(); String key = fieldToValidate.getKey(); String defaultValue = metadataField.getDefaultValue(); From 2b3c39d9bbbd3f8ead2e763ba0868ce088d5d085 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 17 Feb 2021 17:39:27 +0100 Subject: [PATCH 13/25] Fixed CHANGELOG --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f01f59..c7c592f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v2.0.0-SNAPSHOT] +- Improved check on controlled vocabulary to match corner cases [#20742] +- Added PATCH method on Item collection [#19768] +- Switched JSON management to gcube-jackson [#19735] - Added support to publish an item organizations not matching the current context [#19365] @@ -12,7 +15,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added count method for Item collection [#20627] - Added count method for Organization, Group and Profile collection [#20629] -- Switched JSON management to gcube-jackson [#19735] ## [v1.4.3] [r4.23.0] - 2020-06-19 From 501b65c92d2ea9170374fc7bf9375590bdc4b00c Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 22 Feb 2021 09:29:52 +0100 Subject: [PATCH 14/25] Moved links from http to https refs #20778 --- .../gcube/gcat/persistence/ckan/CKANGroup.java | 14 +++++++------- .../gcat/persistence/ckan/CKANLicense.java | 2 +- .../persistence/ckan/CKANOrganization.java | 14 +++++++------- .../gcat/persistence/ckan/CKANPackage.java | 18 +++++++++--------- .../gcat/persistence/ckan/CKANResource.java | 10 +++++----- .../gcube/gcat/persistence/ckan/CKANUser.java | 8 ++++---- .../gcat/persistence/ckan/CKANPackageTest.java | 6 +++--- .../org/gcube/gcat/social/SocialPostTest.java | 2 +- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java index 9144968..08891c7 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANGroup.java @@ -16,19 +16,19 @@ import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; */ public class CKANGroup extends CKAN { - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.group_list + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.group_list public static final String GROUP_LIST = CKAN.CKAN_API_PATH + "group_list"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.group_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.group_create public static final String GROUP_CREATE = CKAN.CKAN_API_PATH + "group_create"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.group_show + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.group_show public static final String GROUP_SHOW = CKAN.CKAN_API_PATH + "group_show"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.group_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.group_update public static final String GROUP_UPDATE = CKAN.CKAN_API_PATH + "group_update"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.group_patch + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.group_patch public static final String GROUP_PATCH = CKAN.CKAN_API_PATH + "group_patch"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.group_delete + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.group_delete public static final String GROUP_DELETE = CKAN.CKAN_API_PATH + "group_delete"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.group_purge + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.group_purge public static final String GROUP_PURGE = CKAN.CKAN_API_PATH + "group_purge"; public static final String GROUPS_KEY = "groups"; diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java index f474d90..baffab7 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANLicense.java @@ -8,7 +8,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; */ public class CKANLicense extends CKAN { - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.license_list + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.license_list public static final String LICENSES_LIST = CKAN.CKAN_API_PATH + "license_list"; public CKANLicense() { diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java index dd1907f..d206d39 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANOrganization.java @@ -17,19 +17,19 @@ public class CKANOrganization extends CKAN { // CKAN Connector sanitize the Organization name as following //organizationName.replaceAll(" ", "_").replace(".", "_").toLowerCase() - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.organization_list + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.organization_list public static final String ORGANIZATION_LIST = CKAN.CKAN_API_PATH + "organization_list"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.organization_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.organization_create public static final String ORGANIZATION_CREATE = CKAN.CKAN_API_PATH + "organization_create"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.organization_show + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.organization_show public static final String ORGANIZATION_SHOW = CKAN.CKAN_API_PATH + "organization_show"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.organization_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.organization_update public static final String ORGANIZATION_UPDATE = CKAN.CKAN_API_PATH + "organization_update"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.organization_patch + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.organization_patch public static final String ORGANIZATION_PATCH = CKAN.CKAN_API_PATH + "organization_patch"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.organization_delete + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.organization_delete public static final String ORGANIZATION_DELETE = CKAN.CKAN_API_PATH + "organization_delete"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.organization_purge + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.organization_purge public static final String ORGANIZATION_PURGE = CKAN.CKAN_API_PATH + "organization_purge"; // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.organization_member_create diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 464269d..92625ac 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -49,17 +49,17 @@ public class CKANPackage extends CKAN { */ // see https://docs.ckan.org/en/latest/api/index.html#ckan.logic.action.get.package_search public static final String ITEM_LIST = CKAN.CKAN_API_PATH + "package_search"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.package_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.package_create public static final String ITEM_CREATE = CKAN.CKAN_API_PATH + "package_create"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.package_show + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.package_show public static final String ITEM_SHOW = CKAN.CKAN_API_PATH + "package_show"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.package_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.package_update public static final String ITEM_UPDATE = CKAN.CKAN_API_PATH + "package_update"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.package_patch + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.package_patch public static final String ITEM_PATCH = CKAN.CKAN_API_PATH + "package_patch"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.package_delete + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.package_delete public static final String ITEM_DELETE = CKAN.CKAN_API_PATH + "package_delete"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.dataset_purge + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.dataset_purge public static final String ITEM_PURGE = CKAN.CKAN_API_PATH + "dataset_purge"; // limit in https://docs.ckan.org/en/latest/api/index.html#ckan.logic.action.get.package_search @@ -569,7 +569,7 @@ public class CKANPackage extends CKAN { } } - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.package_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.package_create @Override public String create(String json) { try { @@ -616,7 +616,7 @@ public class CKANPackage extends CKAN { } } - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.package_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.package_update @Override public String update(String json) { try { @@ -689,7 +689,7 @@ public class CKANPackage extends CKAN { } } - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.package_patch + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.package_patch @Override public String patch(String json) { try { diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java index 5badd46..0fc6144 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANResource.java @@ -36,15 +36,15 @@ public class CKANResource extends CKAN { private static final Logger logger = LoggerFactory.getLogger(CKANResource.class); - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.resource_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.resource_create public static final String RESOURCE_CREATE = CKAN.CKAN_API_PATH + "resource_create"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.resource_show + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.resource_show public static final String RESOURCE_SHOW = CKAN.CKAN_API_PATH + "resource_show"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.resource_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.resource_update public static final String RESOURCE_UPDATE = CKAN.CKAN_API_PATH + "resource_update"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.resource_patch + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.patch.resource_patch public static final String RESOURCE_PATCH = CKAN.CKAN_API_PATH + "resource_patch"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.resource_delete + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.resource_delete public static final String RESOURCE_DELETE = CKAN.CKAN_API_PATH + "resource_delete"; protected static final String URL_KEY = "url"; diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java index b91fbf9..1327a80 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANUser.java @@ -26,13 +26,13 @@ public class CKANUser extends CKAN { /* User Paths */ // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.user_list public static final String USER_LIST = CKAN.CKAN_API_PATH + "user_list"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.user_create + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.user_create public static final String USER_CREATE = CKAN.CKAN_API_PATH + "user_create"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.get.user_show + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.get.user_show public static final String USER_SHOW = CKAN.CKAN_API_PATH + "user_show"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.update.user_update + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.update.user_update public static final String USER_UPDATE = CKAN.CKAN_API_PATH + "user_update"; - // see http://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.user_delete + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.delete.user_delete public static final String USER_DELETE = CKAN.CKAN_API_PATH + "user_delete"; public static final String ADD_USER_TO_GROUP = CKAN.CKAN_API_PATH + "member_create"; diff --git a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java index d5068af..62f9180 100644 --- a/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java +++ b/src/test/java/org/gcube/gcat/persistence/ckan/CKANPackageTest.java @@ -286,7 +286,7 @@ public class CKANPackageTest extends ContextTest { itemObjectNode.put(CKANPackage.LICENSE_KEY, LICENSE_VALUE); itemObjectNode.put(PRIVATE_KEY, false); itemObjectNode.put(NOTES_KEY, "A research of Luca Frosini"); - itemObjectNode.put(URL_KEY, "http://www.d4science.org"); + itemObjectNode.put(URL_KEY, "https://www.d4science.org"); itemObjectNode.put(CKANPackage.OWNER_ORG_KEY, ckanOrganizationName); ArrayNode tagArrayNode = itemObjectNode.putArray(CKANPackage.TAGS_KEY); @@ -430,14 +430,14 @@ public class CKANPackageTest extends ContextTest { public void testUpdate() { CKANPackage ckanPackage = new CKANPackage(); ckanPackage.setName("knime_workflow_with_joined_consumer_phase_and_dose_response_model"); - ckanPackage.update("{\"rating\":0.0,\"license_title\":\"Academic Free License 3.0\",\"maintainer\":\"\",\"relationships_as_object\":[],\"private\":false,\"maintainer_email\":\"\",\"num_tags\":5,\"id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"metadata_created\":\"2020-01-07T16:40:16.987780\",\"owner_org\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"metadata_modified\":\"2020-02-03T14:24:59.221160\",\"author\":\"Buschhardt Tasja\",\"author_email\":\"tasja.buschhardt@bfr.bund.de\",\"state\":\"active\",\"version\":\"1\",\"license_id\":\"AFL-3.0\",\"type\":\"dataset\",\"resources\":[{\"cache_last_updated\":null,\"cache_url\":null,\"mimetype_inner\":null,\"hash\":\"\",\"description\":\"\",\"format\":\"knwf\",\"url\":\"https://data.d4science.net/g9QY\",\"created\":\"2019-09-16T20:49:02.168666\",\"state\":\"active\",\"package_id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"last_modified\":null,\"mimetype\":null,\"url_type\":null,\"position\":0,\"revision_id\":\"a84a35ec-2786-4835-9f50-ad52202c4e33\",\"size\":null,\"datastore_active\":false,\"id\":\"0734b380-ea5d-4c99-be03-c38ff6ae6fbf\",\"resource_type\":null,\"name\":\"KNIME_WF_ICPMF11\"}],\"num_resources\":1,\"tags\":[{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"Campylobacter\",\"id\":\"84c76669-d135-4c5e-9e3a-b163689a10de\",\"name\":\"Campylobacter\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"KNIME workflow\",\"id\":\"30bce4d2-fc45-46ab-8f8b-5da582fff3c3\",\"name\":\"KNIME workflow\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"chicken meat\",\"id\":\"f1aac698-a865-4bf4-ac55-b53f8bf7ecac\",\"name\":\"chicken meat\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"consumer phase model\",\"id\":\"9e6b2337-9ac0-4bfc-8e7f-4327c531bbec\",\"name\":\"consumer phase model\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"dose response model\",\"id\":\"21311c09-a928-4a9a-83de-7ef98b257af5\",\"name\":\"dose response model\"}],\"groups\":[],\"creator_user_id\":\"7020f836-45f4-4ee8-9c65-e7504209644f\",\"relationships_as_subject\":[],\"name\":\"knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"isopen\":true,\"url\":\"\",\"notes\":\"This KNIME workflow shows how to use FSK-Lab to read, customise, run, \\r\\ncombine and change simulation settings for food safety models- specifically \\r\\nthis workflow exemplifies a joined consumer phase model for Campylobacter \\r\\nin chicken meat and a dose response model for Campylobacter\",\"title\":\"KNIME workflow with joined consumer phase and dose response model\",\"extras\":[{\"value\":\"\",\"key\":\"Author\"},{\"value\":\"http://data.d4science.org/ctlg/RAKIP_trial/knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"key\":\"Item URL\"},{\"value\":\"ResearchObject\",\"key\":\"system:type\"},{\"value\":\"{\\\"relatedIdentifierType\\\":\\\"URL\\\",\\\"relationType\\\":\\\"isReferencedBy\\\",\\\"link\\\":\\\"https://doi.org/10.5072/zenodo.488235\\\",\\\"zenodoId\\\":488235}\",\"key\":\"relatedIdentifier:Zenodo.DOI\"}],\"license_url\":\"http://www.opensource.org/licenses/AFL-3.0\",\"ratings_count\":0,\"organization\":{\"description\":\"\",\"title\":\"devVRE\",\"created\":\"2016-05-30T11:30:41.710079\",\"approval_status\":\"approved\",\"is_organization\":true,\"state\":\"active\",\"image_url\":\"\",\"revision_id\":\"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\",\"type\":\"organization\",\"id\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"name\":\"devvre\"},\"revision_id\":\"9f51fa28-0732-46c9-a208-9a0e6da0cd2c\"}"); + ckanPackage.update("{\"rating\":0.0,\"license_title\":\"Academic Free License 3.0\",\"maintainer\":\"\",\"relationships_as_object\":[],\"private\":false,\"maintainer_email\":\"\",\"num_tags\":5,\"id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"metadata_created\":\"2020-01-07T16:40:16.987780\",\"owner_org\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"metadata_modified\":\"2020-02-03T14:24:59.221160\",\"author\":\"Buschhardt Tasja\",\"author_email\":\"tasja.buschhardt@bfr.bund.de\",\"state\":\"active\",\"version\":\"1\",\"license_id\":\"AFL-3.0\",\"type\":\"dataset\",\"resources\":[{\"cache_last_updated\":null,\"cache_url\":null,\"mimetype_inner\":null,\"hash\":\"\",\"description\":\"\",\"format\":\"knwf\",\"url\":\"https://data.d4science.net/g9QY\",\"created\":\"2019-09-16T20:49:02.168666\",\"state\":\"active\",\"package_id\":\"f4292d0e-c94f-4542-bfa3-25f78638fc1b\",\"last_modified\":null,\"mimetype\":null,\"url_type\":null,\"position\":0,\"revision_id\":\"a84a35ec-2786-4835-9f50-ad52202c4e33\",\"size\":null,\"datastore_active\":false,\"id\":\"0734b380-ea5d-4c99-be03-c38ff6ae6fbf\",\"resource_type\":null,\"name\":\"KNIME_WF_ICPMF11\"}],\"num_resources\":1,\"tags\":[{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"Campylobacter\",\"id\":\"84c76669-d135-4c5e-9e3a-b163689a10de\",\"name\":\"Campylobacter\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"KNIME workflow\",\"id\":\"30bce4d2-fc45-46ab-8f8b-5da582fff3c3\",\"name\":\"KNIME workflow\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"chicken meat\",\"id\":\"f1aac698-a865-4bf4-ac55-b53f8bf7ecac\",\"name\":\"chicken meat\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"consumer phase model\",\"id\":\"9e6b2337-9ac0-4bfc-8e7f-4327c531bbec\",\"name\":\"consumer phase model\"},{\"vocabulary_id\":null,\"state\":\"active\",\"display_name\":\"dose response model\",\"id\":\"21311c09-a928-4a9a-83de-7ef98b257af5\",\"name\":\"dose response model\"}],\"groups\":[],\"creator_user_id\":\"7020f836-45f4-4ee8-9c65-e7504209644f\",\"relationships_as_subject\":[],\"name\":\"knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"isopen\":true,\"url\":\"\",\"notes\":\"This KNIME workflow shows how to use FSK-Lab to read, customise, run, \\r\\ncombine and change simulation settings for food safety models- specifically \\r\\nthis workflow exemplifies a joined consumer phase model for Campylobacter \\r\\nin chicken meat and a dose response model for Campylobacter\",\"title\":\"KNIME workflow with joined consumer phase and dose response model\",\"extras\":[{\"value\":\"\",\"key\":\"Author\"},{\"value\":\"https://data.d4science.org/ctlg/RAKIP_trial/knime_workflow_with_joined_consumer_phase_and_dose_response_model\",\"key\":\"Item URL\"},{\"value\":\"ResearchObject\",\"key\":\"system:type\"},{\"value\":\"{\\\"relatedIdentifierType\\\":\\\"URL\\\",\\\"relationType\\\":\\\"isReferencedBy\\\",\\\"link\\\":\\\"https://doi.org/10.5072/zenodo.488235\\\",\\\"zenodoId\\\":488235}\",\"key\":\"relatedIdentifier:Zenodo.DOI\"}],\"license_url\":\"https://www.opensource.org/licenses/AFL-3.0\",\"ratings_count\":0,\"organization\":{\"description\":\"\",\"title\":\"devVRE\",\"created\":\"2016-05-30T11:30:41.710079\",\"approval_status\":\"approved\",\"is_organization\":true,\"state\":\"active\",\"image_url\":\"\",\"revision_id\":\"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\",\"type\":\"organization\",\"id\":\"3571cca5-b0ae-4dc6-b791-434a8e062ce5\",\"name\":\"devvre\"},\"revision_id\":\"9f51fa28-0732-46c9-a208-9a0e6da0cd2c\"}"); } @Test public void testUpdate2() { CKANPackage ckanPackage = new CKANPackage(); ckanPackage.setName("vre_picture"); - ckanPackage.update("{\"rating\": 0.0, \"license_title\": \"Academic Free License 3.0\", \"maintainer\": \"Kerekes Kata\", \"relationships_as_object\": [], \"private\": false, \"maintainer_email\": \"kerekeska@nebih.gov.hu\", \"num_tags\": 1, \"id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"metadata_created\": \"2020-01-07T16:40:24.822719\", \"owner_org\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"metadata_modified\": \"2020-02-03T15:16:42.596068\", \"author\": \"Kerekes Kata\", \"author_email\": \"kerekeska@nebih.gov.hu\", \"state\": \"active\", \"version\": \"1\", \"license_id\": \"AFL-3.0\", \"type\": \"dataset\", \"resources\": [{\"cache_last_updated\": null, \"cache_url\": null, \"mimetype_inner\": null, \"hash\": \"\", \"description\": \"\", \"format\": \"JPEG\", \"url\": \"https://goo.gl/SnwAM7\", \"created\": \"2019-04-01T13:24:40.738838\", \"state\": \"active\", \"package_id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"last_modified\": null, \"mimetype\": \"image/jpeg\", \"url_type\": null, \"position\": 0, \"revision_id\": \"06d61000-a0c1-4155-ad2d-78ede56d6bb5\", \"size\": null, \"datastore_active\": false, \"id\": \"1de8851d-1385-47ae-9c93-6040d170a9cc\", \"resource_type\": null, \"name\": \"th.jpeg\"}], \"num_resources\": 1, \"tags\": [{\"vocabulary_id\": null, \"state\": \"active\", \"display_name\": \"DEMETER\", \"id\": \"4e05058b-a006-4dbf-94f5-277a30318323\", \"name\": \"DEMETER\"}], \"groups\": [], \"creator_user_id\": \"7020f836-45f4-4ee8-9c65-e7504209644f\", \"relationships_as_subject\": [], \"name\": \"vre_picture\", \"isopen\": true, \"url\": \"\", \"notes\": \"This is a nice picture of a VRE ;)\", \"title\": \"VRE picture\", \"extras\": [{\"value\": \"http://data.d4science.org/ctlg/DEMETER_trial/vre_picture\", \"key\": \"Item URL\"}, {\"value\": \"ResearchObject\", \"key\": \"system:type\"}], \"license_url\": \"http://www.opensource.org/licenses/AFL-3.0\", \"ratings_count\": 0, \"organization\": {\"description\": \"\", \"title\": \"devVRE\", \"created\": \"2016-05-30T11:30:41.710079\", \"approval_status\": \"approved\", \"is_organization\": true, \"state\": \"active\", \"image_url\": \"\", \"revision_id\": \"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\", \"type\": \"organization\", \"id\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"name\": \"devvre\"}, \"revision_id\": \"bdb6169a-6268-43d6-b7e1-265c0c9e1a1c\"}"); + ckanPackage.update("{\"rating\": 0.0, \"license_title\": \"Academic Free License 3.0\", \"maintainer\": \"Kerekes Kata\", \"relationships_as_object\": [], \"private\": false, \"maintainer_email\": \"kerekeska@nebih.gov.hu\", \"num_tags\": 1, \"id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"metadata_created\": \"2020-01-07T16:40:24.822719\", \"owner_org\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"metadata_modified\": \"2020-02-03T15:16:42.596068\", \"author\": \"Kerekes Kata\", \"author_email\": \"kerekeska@nebih.gov.hu\", \"state\": \"active\", \"version\": \"1\", \"license_id\": \"AFL-3.0\", \"type\": \"dataset\", \"resources\": [{\"cache_last_updated\": null, \"cache_url\": null, \"mimetype_inner\": null, \"hash\": \"\", \"description\": \"\", \"format\": \"JPEG\", \"url\": \"https://goo.gl/SnwAM7\", \"created\": \"2019-04-01T13:24:40.738838\", \"state\": \"active\", \"package_id\": \"7731b70f-47ff-4b74-b943-188215e82d07\", \"last_modified\": null, \"mimetype\": \"image/jpeg\", \"url_type\": null, \"position\": 0, \"revision_id\": \"06d61000-a0c1-4155-ad2d-78ede56d6bb5\", \"size\": null, \"datastore_active\": false, \"id\": \"1de8851d-1385-47ae-9c93-6040d170a9cc\", \"resource_type\": null, \"name\": \"th.jpeg\"}], \"num_resources\": 1, \"tags\": [{\"vocabulary_id\": null, \"state\": \"active\", \"display_name\": \"DEMETER\", \"id\": \"4e05058b-a006-4dbf-94f5-277a30318323\", \"name\": \"DEMETER\"}], \"groups\": [], \"creator_user_id\": \"7020f836-45f4-4ee8-9c65-e7504209644f\", \"relationships_as_subject\": [], \"name\": \"vre_picture\", \"isopen\": true, \"url\": \"\", \"notes\": \"This is a nice picture of a VRE ;)\", \"title\": \"VRE picture\", \"extras\": [{\"value\": \"https://data.d4science.org/ctlg/DEMETER_trial/vre_picture\", \"key\": \"Item URL\"}, {\"value\": \"ResearchObject\", \"key\": \"system:type\"}], \"license_url\": \"https://www.opensource.org/licenses/AFL-3.0\", \"ratings_count\": 0, \"organization\": {\"description\": \"\", \"title\": \"devVRE\", \"created\": \"2016-05-30T11:30:41.710079\", \"approval_status\": \"approved\", \"is_organization\": true, \"state\": \"active\", \"image_url\": \"\", \"revision_id\": \"7c8463df-ed3f-4d33-87d8-6c0bcbe30d5d\", \"type\": \"organization\", \"id\": \"3571cca5-b0ae-4dc6-b791-434a8e062ce5\", \"name\": \"devvre\"}, \"revision_id\": \"bdb6169a-6268-43d6-b7e1-265c0c9e1a1c\"}"); } /* diff --git a/src/test/java/org/gcube/gcat/social/SocialPostTest.java b/src/test/java/org/gcube/gcat/social/SocialPostTest.java index 47e44ca..e2daea2 100644 --- a/src/test/java/org/gcube/gcat/social/SocialPostTest.java +++ b/src/test/java/org/gcube/gcat/social/SocialPostTest.java @@ -25,7 +25,7 @@ public class SocialPostTest extends ContextTest { SocialPost socialService = new SocialPost(); socialService.setItemID(UUID.randomUUID().toString()); socialService.setItemTitle("Test Item"); - socialService.setItemURL("http://www.d4science.org"); + socialService.setItemURL("https://www.d4science.org"); List tags = new ArrayList<>(); tags.add("Test"); tags.add("ThisIsATest"); From 93d886ba376e7702aeabfd7690314dba9c06366c Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 2 Mar 2021 16:16:53 +0100 Subject: [PATCH 15/25] Fixed wiki link due to wiki reoganization --- .../java/org/gcube/gcat/profile/ResourceRegistryProfile.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java index 297397e..d2224a6 100644 --- a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java @@ -97,7 +97,7 @@ public class ResourceRegistryProfile { } /* - * https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Configuration + * https://wiki.gcube-system.org/gcube/GCube_Model#Configuration */ protected Configuration instantiateConfiguration(String name, String xml) throws Exception { Configuration configuration = new ConfigurationImpl(); From 4ece53108f3562d8918a7ec1e8381ce45f354d92 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Tue, 9 Mar 2021 12:16:42 +0100 Subject: [PATCH 16/25] Ported bug fix made in version 1.4.5 --- CHANGELOG.md | 4 ++++ .../gcube/gcat/persistence/ckan/CKANPackage.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7c592f..ca92742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Switched JSON management to gcube-jackson [#19735] - Added support to publish an item organizations not matching the current context [#19365] +## [v1.4.5] + +- Removed 'owner_org' field from result when reading an item #20919 + ## [v1.4.4] diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index 92625ac..0d65025 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -569,6 +569,21 @@ public class CKANPackage extends CKAN { } } + @Override + public String read() { + try { + String ret = super.read(); + result = mapper.readTree(ret); + result = cleanResult(result); + return getAsString(result); + } catch(WebApplicationException e) { + throw e; + } catch(Exception e) { + throw new InternalServerErrorException(e); + } + + } + // see https://docs.ckan.org/en/latest/api/#ckan.logic.action.create.package_create @Override public String create(String json) { From 2f5885579bd95e5ab6fc9af4d165c44e576b0dac Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 12 Mar 2021 12:52:19 +0100 Subject: [PATCH 17/25] Ported patch from branch feature/20965 --- .../org/gcube/gcat/oldutils/Validator.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index 4d16ed2..df5633b 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -148,8 +148,12 @@ public class Validator { // now validate fields int metadataIndex = 0; + + Map metadataFieldMap = new HashMap<>(); for(MetadataField metadataField : metadataFields) { + metadataFieldMap.put(metadataField.getFieldName(), metadataField); + int categoryIdIndex = categoriesIds.indexOf(metadataField.getCategoryRef()); logger.debug("Found index for category " + metadataField.getCategoryRef() + " " + categoryIdIndex); List validCFs = validateAgainstMetadataField(metadataIndex, categoryIdIndex, @@ -168,7 +172,20 @@ public class Validator { Map.Entry entry = (Map.Entry) iteratorLowerBounds .next(); int lowerBound = entry.getValue(); - int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey()); + + // int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey()); + String maxOccurs = metadataFieldMap.get(entry.getKey()).getMaxOccurs(); + int upperBound = Integer.MAX_VALUE; + if(maxOccurs.compareTo("*")==0) { + upperBound = Integer.MAX_VALUE; + }else { + try { + upperBound = Integer.valueOf(maxOccurs); + }catch (Exception e) { + + } + } + int inserted = numberFieldsMandatorySameKeyMap.get(entry.getKey()); logger.info("Field with key '" + entry.getKey() + "' has been found " + inserted From 1a6d5733a23d5bd6218b5567399e91b22fd9f766 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 12 Mar 2021 18:18:25 +0100 Subject: [PATCH 18/25] Improving error message --- src/main/java/org/gcube/gcat/utils/HTTPUtility.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/utils/HTTPUtility.java b/src/main/java/org/gcube/gcat/utils/HTTPUtility.java index e31bbea..5bedb90 100644 --- a/src/main/java/org/gcube/gcat/utils/HTTPUtility.java +++ b/src/main/java/org/gcube/gcat/utils/HTTPUtility.java @@ -51,7 +51,7 @@ public class HTTPUtility { InputStream inputStream = httpURLConnection.getErrorStream(); StringBuilder result = getStringBuilder(inputStream); logger.trace(result.toString()); - throw new WebApplicationException(status); + throw new WebApplicationException(result.toString(), status); } InputStream inputStream = httpURLConnection.getInputStream(); String ret = getStringBuilder(inputStream).toString(); From 4f3b7055e1fdee12d8a80c384882fdd1eb549913 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 12 Mar 2021 18:25:36 +0100 Subject: [PATCH 19/25] Ported CHANGELOG updates --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca92742..f8e3640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v1.4.5] - Removed 'owner_org' field from result when reading an item #20919 +- Dirty patched item validator [#20965] +- Improved error message return with message got from CKAN [#19516] ## [v1.4.4] From 81218d3e5c6423fda6a17720736dd3c01cfca33d Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 12 Mar 2021 18:27:23 +0100 Subject: [PATCH 20/25] Fixed CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e3640..84236f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm # Changelog for gCube Catalogue (gCat) Service - ## [v2.0.0-SNAPSHOT] - Improved check on controlled vocabulary to match corner cases [#20742] @@ -12,7 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [v1.4.5] -- Removed 'owner_org' field from result when reading an item #20919 +- Removed 'owner_org' field from result when reading an item [#20919] - Dirty patched item validator [#20965] - Improved error message return with message got from CKAN [#19516] @@ -21,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Added count method for Item collection [#20627] - Added count method for Organization, Group and Profile collection [#20629] +- Switched JSON management to gcube-jackson [#19735] ## [v1.4.3] [r4.23.0] - 2020-06-19 From 0d5c734d5b5262d73d43be48c39a7a9ba4b1a1f8 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 15 Mar 2021 10:02:38 +0100 Subject: [PATCH 21/25] Improved error management --- .../org/gcube/gcat/persistence/ckan/CKAN.java | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java index 53da22b..f19b274 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKAN.java @@ -1,6 +1,7 @@ package org.gcube.gcat.persistence.ckan; import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.util.HashMap; @@ -12,18 +13,18 @@ import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; -import org.gcube.common.gxhttp.request.GXHTTPStringRequest; -import org.gcube.gcat.utils.HTTPUtility; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.NullNode; import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; +import org.gcube.common.gxhttp.request.GXHTTPStringRequest; +import org.gcube.gcat.utils.HTTPUtility; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) @@ -128,6 +129,7 @@ public abstract class CKAN { throw new BadRequestException(e); } } + /** * Validate the CKAN response and return the @@ -241,8 +243,31 @@ public abstract class CKAN { return gxhttpStringRequest; } + protected String getResultAsString(HttpURLConnection httpURLConnection) throws IOException { + int responseCode = httpURLConnection.getResponseCode(); + if(responseCode >= Status.BAD_REQUEST.getStatusCode()) { + Status status = Status.fromStatusCode(responseCode); + InputStream inputStream = httpURLConnection.getErrorStream(); + StringBuilder result = HTTPUtility.getStringBuilder(inputStream); + logger.trace(result.toString()); + try { + JsonNode jsonNode = getAsJsonNode(result.toString()); + JsonNode error = jsonNode.get(ERROR_KEY); + throw new WebApplicationException(getAsString(error), status); + }catch (WebApplicationException e) { + throw e; + }catch (Exception e) { + throw new WebApplicationException(result.toString(), status); + } + } + InputStream inputStream = httpURLConnection.getInputStream(); + String ret = HTTPUtility.getStringBuilder(inputStream).toString(); + logger.trace("Got Respose is {}", ret); + return ret; + } + protected String getResultAndValidate(HttpURLConnection httpURLConnection) throws IOException { - String ret = HTTPUtility.getResultAsString(httpURLConnection); + String ret = getResultAsString(httpURLConnection); logger.trace("Got Respose is {}", ret); result = validateCKANResponse(ret); if(result instanceof NullNode) { From 98aec729ccf0000b33e8b176dd59a1ef4576863a Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 29 Mar 2021 10:58:42 +0200 Subject: [PATCH 22/25] Fixing GeoJson validation --- src/main/java/org/gcube/gcat/oldutils/Validator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index df5633b..c49250d 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -591,7 +591,7 @@ public class Validator { case GeoJSON: try { - new ObjectMapper().readValue(fieldToValidate.getValue(), GeoJsonObject.class); + new com.fasterxml.jackson.databind.ObjectMapper().readValue(fieldToValidate.getValue(), GeoJsonObject.class); } catch(Exception e) { throw new BadRequestException("GeoJSON field with key '" + key + "' seems not valid!"); } From 34d9c0759d8c23214416739f42f0f63cbf1d470c Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 29 Mar 2021 14:13:57 +0200 Subject: [PATCH 23/25] Fixed null pointer exception --- src/main/java/org/gcube/gcat/oldutils/Validator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index c49250d..62cddea 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -176,7 +176,7 @@ public class Validator { // int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey()); String maxOccurs = metadataFieldMap.get(entry.getKey()).getMaxOccurs(); int upperBound = Integer.MAX_VALUE; - if(maxOccurs.compareTo("*")==0) { + if(maxOccurs==null || maxOccurs.compareTo("*")==0) { upperBound = Integer.MAX_VALUE; }else { try { From dd8919f9de6288a65a63aaaa0192d2e49a0e3307 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 29 Mar 2021 16:15:49 +0200 Subject: [PATCH 24/25] Fixing validation bug --- .../org/gcube/gcat/oldutils/Validator.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/gcube/gcat/oldutils/Validator.java b/src/main/java/org/gcube/gcat/oldutils/Validator.java index 62cddea..9f23d8d 100644 --- a/src/main/java/org/gcube/gcat/oldutils/Validator.java +++ b/src/main/java/org/gcube/gcat/oldutils/Validator.java @@ -174,16 +174,20 @@ public class Validator { int lowerBound = entry.getValue(); // int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey()); - String maxOccurs = metadataFieldMap.get(entry.getKey()).getMaxOccurs(); int upperBound = Integer.MAX_VALUE; - if(maxOccurs==null || maxOccurs.compareTo("*")==0) { - upperBound = Integer.MAX_VALUE; - }else { - try { - upperBound = Integer.valueOf(maxOccurs); - }catch (Exception e) { - + try { + String maxOccurs = metadataFieldMap.get(entry.getKey()).getMaxOccurs(); + if(maxOccurs==null || maxOccurs.compareTo("*")==0) { + upperBound = Integer.MAX_VALUE; + }else { + try { + upperBound = Integer.valueOf(maxOccurs); + }catch (Exception e) { + + } } + }catch (Exception e) { + upperBound = Integer.MAX_VALUE; } int inserted = numberFieldsMandatorySameKeyMap.get(entry.getKey()); From 08a2b09b57d89b3cd58930368fcb0a1d935c62f9 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Wed, 14 Apr 2021 14:53:18 +0200 Subject: [PATCH 25/25] removed uneeded imports --- .../org/gcube/gcat/profile/ResourceRegistryProfile.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java index d2224a6..f8a4bee 100644 --- a/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java +++ b/src/main/java/org/gcube/gcat/profile/ResourceRegistryProfile.java @@ -17,7 +17,6 @@ import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.Resources; -import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader; import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery; import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil; import org.gcube.gcat.persistence.ckan.CKANUser; @@ -29,18 +28,13 @@ import org.gcube.informationsystem.publisher.RegistryPublisherFactory; import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient; import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory; -import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SchemaFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl; import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl; -import org.gcube.resourcemanagement.model.impl.properties.ValueSchemaImpl; -import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl; import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet; -import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType; import org.gcube.resourcemanagement.model.reference.entities.facets.SchemaFacet; import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet; import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration; -import org.gcube.resourcemanagement.model.reference.properties.ValueSchema; import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.Query;