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
This commit is contained in:
Costantino Perciante 2017-06-26 16:46:19 +00:00
parent 7b39907a01
commit 96d24bb334
5 changed files with 26 additions and 19 deletions

View File

@ -23,7 +23,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="owner.project.facets" value="java"/> <attribute name="owner.project.facets" value="java"/>
</attributes> </attributes>

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.8

View File

@ -4,5 +4,5 @@
<installed facet="jst.web" version="3.0"/> <installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="2.0"/> <installed facet="jst.jaxrs" version="2.0"/>
<installed facet="java" version="1.7"/> <installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>

View File

@ -1,7 +1,9 @@
package org.gcube.datacatalogue.catalogue.utils; package org.gcube.datacatalogue.catalogue.utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map;
import net.sf.ehcache.Cache; import net.sf.ehcache.Cache;
import net.sf.ehcache.Element; import net.sf.ehcache.Element;
@ -25,6 +27,7 @@ import org.json.simple.parser.JSONParser;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import eu.trentorise.opendata.jackan.model.CkanGroup; import eu.trentorise.opendata.jackan.model.CkanGroup;
import eu.trentorise.opendata.jackan.model.CkanOrganization;
/** /**
* Utils methods. * Utils methods.
@ -61,9 +64,7 @@ public class CatalogueUtils {
* @throws Exception * @throws Exception
*/ */
public static CkanGroup createGroupAsSysAdmin(String title, String groupName, String description) throws Exception{ public static CkanGroup createGroupAsSysAdmin(String title, String groupName, String description) throws Exception{
return getCatalogue().createGroup(groupName, title, description); return getCatalogue().createGroup(groupName, title, description);
} }
/** /**
@ -244,11 +245,17 @@ public class CatalogueUtils {
public static void checkRole(String username, String organization) throws Exception { public static void checkRole(String username, String organization) throws Exception {
DataCatalogue catalogue = getCatalogue(); DataCatalogue catalogue = getCatalogue();
boolean res = catalogue.checkRoleIntoOrganization(username, organization, RolesCkanGroupOrOrg.ADMIN);
if(!res) // check organization exists
res = catalogue.checkRoleIntoOrganization(username, organization, RolesCkanGroupOrOrg.EDITOR); 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<String, List<RolesCkanGroupOrOrg>> 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 + "!"); throw new Exception("It seems you are neither Catalogue-Admin nor Catalogue-Editor in organization " + organization + "!");
} }

View File

@ -188,14 +188,14 @@ public class Validator {
extrasArrayUpdated = new JSONArray(); extrasArrayUpdated = new JSONArray();
List<NamespaceCategory> categories = CatalogueUtils.getNamespaceCategories(); List<NamespaceCategory> categories = CatalogueUtils.getNamespaceCategories();
logger.debug("Retrieved namespaces are " + categories);
List<String> categoriesIds = new ArrayList<String>(categories == null ? 0 : categories.size()); List<String> categoriesIds = new ArrayList<String>(categories == null ? 0 : categories.size());
if(categoriesIds.isEmpty()) if(categories == null || categories.isEmpty())
logger.warn("No category defined in context " + ScopeProvider.instance.get()); logger.warn("No category defined in context " + ScopeProvider.instance.get());
else else
for (NamespaceCategory metadataCategory : categories) for (NamespaceCategory metadataCategory : categories)
categoriesIds.add(metadataCategory.getId()); // save them later for matching with custom fields categoriesIds.add(metadataCategory.getId()); // save them later for matching with custom fields
// the list of already validated customFields // the list of already validated customFields
List<CustomField> validatedCustomFields = new ArrayList<CustomField>(customFields.size()); List<CustomField> validatedCustomFields = new ArrayList<CustomField>(customFields.size());
@ -393,16 +393,16 @@ public class Validator {
switch(tagging.getTaggingValue()){ switch(tagging.getTaggingValue()){
case onFieldName: case onFieldName:
tag = fieldToValidate.getKey(); tag = metadataField.getFieldName();
break; break;
case onValue: case onValue:
tag = fieldToValidate.getValue(); tag = fieldToValidate.getValue();
break; break;
case onFieldName_onValue: case onFieldName_onValue:
tag = fieldToValidate.getKey() + tagging.getSeparator() + fieldToValidate.getValue(); tag = metadataField.getFieldName() + tagging.getSeparator() + fieldToValidate.getValue();
break; break;
case onValue_onFieldName: case onValue_onFieldName:
tag = fieldToValidate.getValue() + tagging.getSeparator() + fieldToValidate.getKey(); tag = fieldToValidate.getValue() + tagging.getSeparator() + metadataField.getFieldName();
break; break;
default: default:
return; return;
@ -441,7 +441,7 @@ public class Validator {
switch(grouping.getGroupingValue()){ switch(grouping.getGroupingValue()){
case onFieldName: case onFieldName:
groupNames.add(fieldToValidate.getKey()); groupNames.add(metadataField.getFieldName());
break; break;
case onValue: case onValue:
if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty()) if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty())
@ -449,7 +449,7 @@ public class Validator {
break; break;
case onFieldName_onValue: case onFieldName_onValue:
case onValue_onFieldName: case onValue_onFieldName:
groupNames.add(fieldToValidate.getKey()); groupNames.add(metadataField.getFieldName());
if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty()) if(fieldToValidate.getValue() != null && !fieldToValidate.getValue().isEmpty())
groupNames.add(fieldToValidate.getValue()); groupNames.add(fieldToValidate.getValue());
break; break;
@ -536,7 +536,7 @@ public class Validator {
} }
if(!match) 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+")!");
} }