From 96d24bb334da0e0f7db7290c444c17cd283faf77 Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Mon, 26 Jun 2017 16:46:19 +0000 Subject: [PATCH] fixed check of organization existence and roles in it. Minor fixes for tags and groups creation (original field key is still used) git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@150551 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 2 +- .settings/org.eclipse.jdt.core.prefs | 6 +++--- ....eclipse.wst.common.project.facet.core.xml | 2 +- .../catalogue/utils/CatalogueUtils.java | 19 +++++++++++++------ .../catalogue/utils/Validator.java | 16 ++++++++-------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.classpath b/.classpath index cfb27f6..3a7e746 100644 --- a/.classpath +++ b/.classpath @@ -23,7 +23,7 @@ - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 443e085..6e80039 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,8 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index cc493bb..dcea5a1 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -4,5 +4,5 @@ - + diff --git a/src/main/java/org/gcube/datacatalogue/catalogue/utils/CatalogueUtils.java b/src/main/java/org/gcube/datacatalogue/catalogue/utils/CatalogueUtils.java index 732d0aa..18dd47a 100644 --- a/src/main/java/org/gcube/datacatalogue/catalogue/utils/CatalogueUtils.java +++ b/src/main/java/org/gcube/datacatalogue/catalogue/utils/CatalogueUtils.java @@ -1,7 +1,9 @@ package org.gcube.datacatalogue.catalogue.utils; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; @@ -25,6 +27,7 @@ import org.json.simple.parser.JSONParser; import org.slf4j.LoggerFactory; import eu.trentorise.opendata.jackan.model.CkanGroup; +import eu.trentorise.opendata.jackan.model.CkanOrganization; /** * Utils methods. @@ -61,9 +64,7 @@ public class CatalogueUtils { * @throws Exception */ public static CkanGroup createGroupAsSysAdmin(String title, String groupName, String description) throws Exception{ - return getCatalogue().createGroup(groupName, title, description); - } /** @@ -244,11 +245,17 @@ public class CatalogueUtils { public static void checkRole(String username, String organization) throws Exception { DataCatalogue catalogue = getCatalogue(); - boolean res = catalogue.checkRoleIntoOrganization(username, organization, RolesCkanGroupOrOrg.ADMIN); - if(!res) - res = catalogue.checkRoleIntoOrganization(username, organization, RolesCkanGroupOrOrg.EDITOR); + + // check organization exists + CkanOrganization org = catalogue.getOrganizationByName(organization); + + if(org == null) + throw new Exception("It seems that an organization with name " + organization + " doesn't exist!"); - if(!res) + Map> rolesPerUser = catalogue.getOrganizationsAndRolesByUser(username, + Arrays.asList(RolesCkanGroupOrOrg.ADMIN, RolesCkanGroupOrOrg.EDITOR)); + + if(!rolesPerUser.containsKey(organization)) throw new Exception("It seems you are neither Catalogue-Admin nor Catalogue-Editor in organization " + organization + "!"); } diff --git a/src/main/java/org/gcube/datacatalogue/catalogue/utils/Validator.java b/src/main/java/org/gcube/datacatalogue/catalogue/utils/Validator.java index f4eb2d5..3ee35d3 100644 --- a/src/main/java/org/gcube/datacatalogue/catalogue/utils/Validator.java +++ b/src/main/java/org/gcube/datacatalogue/catalogue/utils/Validator.java @@ -188,14 +188,14 @@ public class Validator { extrasArrayUpdated = new JSONArray(); List categories = CatalogueUtils.getNamespaceCategories(); + logger.debug("Retrieved namespaces are " + categories); List categoriesIds = new ArrayList(categories == null ? 0 : categories.size()); - if(categoriesIds.isEmpty()) + if(categories == null || categories.isEmpty()) logger.warn("No category defined in context " + ScopeProvider.instance.get()); else for (NamespaceCategory metadataCategory : categories) categoriesIds.add(metadataCategory.getId()); // save them later for matching with custom fields - // the list of already validated customFields List validatedCustomFields = new ArrayList(customFields.size()); @@ -393,16 +393,16 @@ public class Validator { switch(tagging.getTaggingValue()){ case onFieldName: - tag = fieldToValidate.getKey(); + tag = metadataField.getFieldName(); break; case onValue: tag = fieldToValidate.getValue(); break; case onFieldName_onValue: - tag = fieldToValidate.getKey() + tagging.getSeparator() + fieldToValidate.getValue(); + tag = metadataField.getFieldName() + tagging.getSeparator() + fieldToValidate.getValue(); break; case onValue_onFieldName: - tag = fieldToValidate.getValue() + tagging.getSeparator() + fieldToValidate.getKey(); + tag = fieldToValidate.getValue() + tagging.getSeparator() + metadataField.getFieldName(); break; default: return; @@ -441,7 +441,7 @@ public class Validator { switch(grouping.getGroupingValue()){ case onFieldName: - groupNames.add(fieldToValidate.getKey()); + groupNames.add(metadataField.getFieldName()); break; case onValue: if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty()) @@ -449,7 +449,7 @@ public class Validator { break; case onFieldName_onValue: case onValue_onFieldName: - groupNames.add(fieldToValidate.getKey()); + groupNames.add(metadataField.getFieldName()); if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty()) groupNames.add(fieldToValidate.getValue()); break; @@ -536,7 +536,7 @@ public class Validator { } if(!match) - throw new Exception("Field with key '" + key + "' has a value '" + value + "' but it doesn't match any of the vocabulary's values!"); + throw new Exception("Field with key '" + key + "' has a value '" + value + "' but it doesn't match any of the vocabulary's values ("+valuesVocabulary+")!"); }