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"/>
</attributes>
</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>
<attribute name="owner.project.facets" value="java"/>
</attributes>

View File

@ -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

View File

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

View File

@ -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<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 + "!");
}

View File

@ -188,14 +188,14 @@ public class Validator {
extrasArrayUpdated = new JSONArray();
List<NamespaceCategory> categories = CatalogueUtils.getNamespaceCategories();
logger.debug("Retrieved namespaces are " + categories);
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());
else
for (NamespaceCategory metadataCategory : categories)
categoriesIds.add(metadataCategory.getId()); // save them later for matching with custom fields
// the list of already validated customFields
List<CustomField> validatedCustomFields = new ArrayList<CustomField>(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+")!");
}