From 6d8c9a22bb1b141f2bcd2011cf8908db87ea18a1 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Thu, 8 Feb 2018 15:57:31 +0000 Subject: [PATCH] minor fix git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/ckan-util-library@163065 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../ckanutillibrary/server/DataCatalogue.java | 38 +++++++++---------- .../server/DataCatalogueImpl.java | 17 +++++---- .../server/TestDataCatalogueLib.java | 2 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java index 0b5a3e9..bf1591e 100644 --- a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java +++ b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogue.java @@ -25,14 +25,14 @@ import eu.trentorise.opendata.jackan.model.CkanResource; * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) */ public interface DataCatalogue { - + /** * Returns the statistics for this catalogue * @return * @throws Exception */ Statistics getStatistics() throws Exception; - + /** * Returns the main landing pages for this catalogue (i.e. type, orgs, groups and items pages) * @return @@ -67,7 +67,7 @@ public interface DataCatalogue { * @return a list of groups */ List getGroupsByUser(String username); - + /** * Returns a group given its name * @return return a {@link CkanGroup} or null if no group with this name exists @@ -203,8 +203,8 @@ public interface DataCatalogue { String createCKanDatasetMultipleCustomFields(String apiKey, String title, String name, String organizationNameOrId, String author, String authorMail, String maintainer, String maintainerMail, long version, String description, String licenseId, List tags, Map> customFields, List resources, boolean setPublic) throws Exception; - - + + /** * Update a dataset with those information. The method allows to have multiple values for the same custom field key. * @param apiKey @@ -402,7 +402,7 @@ public interface DataCatalogue { */ boolean assignDatasetToGroup(String groupNameOrId, String datasetNameOrId, String apiKey); - + /** * Assign a dataset to a group and the group's parents (if any) * @param groupNameOrId the id or the name of the destination group. @@ -440,7 +440,7 @@ public interface DataCatalogue { * @return */ CkanDataset getDataset(String datasetId, String apiKey); - + /** * Retrieve a ckan dataset given its id. The CkanClient is used, without api key. The result * is null also when the dataset is private. @@ -491,16 +491,16 @@ public interface DataCatalogue { */ boolean patchResource(String resourceId, String url, String name, String description, String urlType, String apiKey); - /** - * Patch a product with product id productId by using the couples in toChange. + /** Patch a product with product id productId by using the couples in customFieldsToChange. * NOTE: only the specified custom fields will be changed. If a custom field with a given key - * already exists, the new values are added at the end of the list. + * already exists, and removeOld is set to false, the new values are added at the end of the list. Otherwise they are lost. * @param productId * @param apiKey - * @param toChange - * @return true on success, false otherwise + * @param customFieldsToChange + * @param removeOld + * @return */ - boolean patchProductCustomFields(String productId, String apiKey, Map> customFieldsToChange); + boolean patchProductCustomFields(String productId, String apiKey, Map> customFieldsToChange, boolean removeOld); /** * Remove a custom field in the product that has a given key and value. If more than ones are present, the first one is removed. @@ -604,13 +604,13 @@ public interface DataCatalogue { * @return */ Map>getUserRoleByOrganization(String username, String apiKey); - + /** * Check if the users of the current context need to be alerted from a post creation or not. Default is false. * @return a boolean value */ boolean isNotificationToUsersEnabled(); - + /** * Check if the user identified by username has to be registered in other organizations with some role. * @param username @@ -618,7 +618,7 @@ public interface DataCatalogue { * @param currentRole */ void assignRolesOtherOrganization(String username, String sourceOrganization, RolesCkanGroupOrOrg currentRole); - + /** * Search for a package through Solr * @param apiKey @@ -628,7 +628,7 @@ public interface DataCatalogue { * @return a list of matching datasets */ List searchForPackage(String apiKey, String query, int start, int offset) throws Exception; - + /** * Search for a package through Solr in a given organization * @param apiKey @@ -638,13 +638,13 @@ public interface DataCatalogue { * @return a list of matching datasets */ List searchForPackageInOrganization(String apiKey, String query, int start, int offset, String organization) throws Exception; - + /** * Retrieve the catalogue email * @return an email address for sending email to this catalogue */ String getCatalogueEmail(); - + /** * Retrieve a resource by id */ diff --git a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java index 0c4b348..5ba8d04 100644 --- a/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java +++ b/src/main/java/org/gcube/datacatalogue/ckanutillibrary/server/DataCatalogueImpl.java @@ -1886,7 +1886,7 @@ public class DataCatalogueImpl implements DataCatalogue{ } return false; } - + @Override public CkanResource getResource(String id, String apiKey) { logger.info("Request ckan resource with id " + id); @@ -2095,7 +2095,7 @@ public class DataCatalogueImpl implements DataCatalogue{ @Override public boolean patchProductCustomFields(String productId, String apiKey, - Map> customFieldsToChange) { + Map> customFieldsToChange, boolean removeOld) { // checks checkNotNull(productId); @@ -2144,7 +2144,8 @@ public class DataCatalogueImpl implements DataCatalogue{ Set uniqueValues = new HashSet(); if(fromCKANCustomFields.containsKey(key)) - uniqueValues.addAll(fromCKANCustomFields.get(key)); + if(!removeOld) + uniqueValues.addAll(fromCKANCustomFields.get(key)); uniqueValues.addAll(newValues); fromCKANCustomFields.put(key, new ArrayList(uniqueValues)); @@ -2938,7 +2939,7 @@ public class DataCatalogueImpl implements DataCatalogue{ int numGroups = getGroups().size(); int numOrganizations = getOrganizationsNames().size(); - + logger.debug("SOLR address is " + SOLR_URL); HttpSolrServer solr = new HttpSolrServer(SOLR_URL); @@ -2983,13 +2984,13 @@ public class DataCatalogueImpl implements DataCatalogue{ stats.setNumItems(numItems); stats.setNumOrganizations(numOrganizations); stats.setNumTypes(numTypes); - + return stats; } @Override public LandingPages getLandingPages() throws Exception { - + LandingPages landingPages = new LandingPages(); landingPages.setUrlGroups(PORTLET_URL_FOR_SCOPE + "?path=/group/"); landingPages.setUrlItems(PORTLET_URL_FOR_SCOPE + "?path=/dataset/"); @@ -3000,9 +3001,9 @@ public class DataCatalogueImpl implements DataCatalogue{ @Override public String getCatalogueEmail() { - + return CKAN_EMAIL; - + } } \ No newline at end of file diff --git a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java index a5752ab..a9d9365 100644 --- a/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java +++ b/src/test/java/org/gcube/datacatalogue/ckanutillibrary/server/TestDataCatalogueLib.java @@ -440,7 +440,7 @@ public class TestDataCatalogueLib { DataCatalogueImpl instance = factory.getUtilsPerScope(scope); Map> customFieldsToChange = new HashMap>(); customFieldsToChange.put("Status", Arrays.asList("Pending")); - instance.patchProductCustomFields("a-test-to-ignore", instance.getApiKeyFromUsername("costantino_perciante"), customFieldsToChange); + instance.patchProductCustomFields("a-test-to-ignore", instance.getApiKeyFromUsername("costantino_perciante"), customFieldsToChange, false); } //@Test