minor fixes
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@148344 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
82dd47b70c
commit
5d5b872f08
|
@ -93,6 +93,8 @@ public class CatalogueUtils {
|
|||
public static final short MAX_UPLOADABLE_FILE_SIZE_MB = 100;
|
||||
public static final String EMAIL_IN_PROFILE_KEY = "email";
|
||||
public static final String FULLNAME_IN_PROFILE_KEY = "fullname";
|
||||
private static final Object RESOURCE_NAME_KEY = "name";
|
||||
private static final Object RESOURCE_URL_KEY = "url";
|
||||
|
||||
|
||||
// =======================================================================
|
||||
|
@ -310,8 +312,8 @@ public class CatalogueUtils {
|
|||
while (it.hasNext()) {
|
||||
JSONObject resource = (JSONObject) it.next();
|
||||
|
||||
String name = (String)resource.get("name");
|
||||
String url = (String)resource.get("url");
|
||||
String name = (String)resource.get(RESOURCE_NAME_KEY);
|
||||
String url = (String)resource.get(RESOURCE_URL_KEY);
|
||||
|
||||
if(url == null || name == null || url.isEmpty() || name.isEmpty())
|
||||
throw new Exception("Resources must have at least a name and an url field set!");
|
||||
|
@ -399,7 +401,7 @@ public class CatalogueUtils {
|
|||
}
|
||||
|
||||
if(metadataTypeCF == null)
|
||||
throw new Exception("'" + TYPE_KEY + "' field is missing in context where metadata profile(s) are defined!");
|
||||
throw new Exception("'" + TYPE_KEY + "' extra field is missing in context where metadata profile(s) are defined!");
|
||||
|
||||
if(groupsArrayOriginal == null)
|
||||
groupsArrayOriginal = new JSONArray();
|
||||
|
@ -418,8 +420,7 @@ public class CatalogueUtils {
|
|||
}
|
||||
|
||||
if(profile == null)
|
||||
throw new Exception("'" + TYPE_KEY + "' specified as custom field doesn't match any of the profiles defined in this context!");
|
||||
|
||||
throw new Exception("'" + TYPE_KEY + "' extra field's value specified as custom field doesn't match any of the profiles defined in this context!");
|
||||
else{
|
||||
|
||||
JSONArray extrasArrayUpdated = null;
|
||||
|
@ -433,7 +434,7 @@ public class CatalogueUtils {
|
|||
List<NamespaceCategory> categories = getNamespaceCategories();
|
||||
List<String> categoriesIds = new ArrayList<String>(categories == null ? 0 : categories.size());
|
||||
if(categoriesIds.isEmpty())
|
||||
logger.warn("No category defined");
|
||||
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
|
||||
|
@ -445,9 +446,9 @@ public class CatalogueUtils {
|
|||
// keep track of mandatory fields and their cardinality
|
||||
Map<String, Integer> fieldsMandatoryLowerBoundMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
Map<String, Integer> fieldsMandatoryUpperBoundMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
Map<String, Integer> numberFieldsSameKeyMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
Map<String, Integer> numberFieldsMandatorySameKeyMap = new HashMap<String, Integer>(metadataFields.size());
|
||||
|
||||
// keep track of the groups that must be created after validation but before item creation.
|
||||
// keep track of the groups that must be created AFTER validation but BEFORE item creation.
|
||||
List<String> groupsToCreateAfterValidation = new ArrayList<String>();
|
||||
|
||||
// now validate fields
|
||||
|
@ -466,7 +467,7 @@ public class CatalogueUtils {
|
|||
categories,
|
||||
fieldsMandatoryLowerBoundMap,
|
||||
fieldsMandatoryUpperBoundMap,
|
||||
numberFieldsSameKeyMap,
|
||||
numberFieldsMandatorySameKeyMap,
|
||||
groupsToCreateAfterValidation);
|
||||
validatedCustomFields.addAll(validCFs);
|
||||
metadataIndex++;
|
||||
|
@ -480,7 +481,7 @@ public class CatalogueUtils {
|
|||
.next();
|
||||
int lowerBound = entry.getValue();
|
||||
int upperBound = fieldsMandatoryUpperBoundMap.get(entry.getKey());
|
||||
int inserted = numberFieldsSameKeyMap.get(entry.getKey());
|
||||
int inserted = numberFieldsMandatorySameKeyMap.get(entry.getKey());
|
||||
|
||||
logger.info("Field with key '" + entry.getKey() + "' has been found " + inserted + " times and its lower bound is " + lowerBound + " and upper bound " + upperBound);
|
||||
|
||||
|
@ -497,7 +498,7 @@ public class CatalogueUtils {
|
|||
for(CustomField cf : customFields)
|
||||
validatedCustomFields.add(cf);
|
||||
|
||||
// retransform to json
|
||||
// convert back to json
|
||||
for (CustomField customField : validatedCustomFields) {
|
||||
JSONObject jsonObj = new JSONObject();
|
||||
jsonObj.put(EXTRA_KEY, customField.getQualifiedKey());
|
||||
|
@ -512,13 +513,18 @@ public class CatalogueUtils {
|
|||
extrasArrayUpdated.add(metadataTypeJSON);
|
||||
|
||||
// create groups
|
||||
for (String title : groupsToCreateAfterValidation)
|
||||
for (String title : groupsToCreateAfterValidation){
|
||||
try {
|
||||
createGroupAsSysAdmin(title, title, "");
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to create group with title " + title, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if there are no tags, throw an exception
|
||||
if(tagsArrayOriginal.isEmpty())
|
||||
throw new Exception("Please define at least one tag for this item!");
|
||||
|
||||
obj.put(TAGS_KEY, tagsArrayOriginal);
|
||||
obj.put(GROUPS_KEY, groupsArrayOriginal);
|
||||
|
@ -553,13 +559,12 @@ public class CatalogueUtils {
|
|||
List<NamespaceCategory> categories,
|
||||
Map<String, Integer> fieldsMandatoryLowerBoundMap,
|
||||
Map<String, Integer> fieldsMandatoryUpperBoundMap,
|
||||
Map<String, Integer> numberFieldsSameKeyMap,
|
||||
Map<String, Integer> numberFieldsMandatorySameKeyMap,
|
||||
List<String> groupToCreate) throws Exception {
|
||||
|
||||
List<CustomField> toReturn = new ArrayList<CustomField>();
|
||||
String metadataFieldName = metadataField.getFieldName();
|
||||
|
||||
// keep track of the number of elements with this key
|
||||
String metadataFieldName = metadataField.getFieldName();
|
||||
int fieldsFoundWithThisKey = 0;
|
||||
|
||||
Iterator<CustomField> iterator = customFields.iterator();
|
||||
|
@ -590,22 +595,18 @@ public class CatalogueUtils {
|
|||
|
||||
// upper bound
|
||||
boolean hasVocabulary = metadataField.getVocabulary() != null;
|
||||
int upperBound = hasVocabulary ? (metadataField.getVocabulary().isMultiSelection() ? Integer.MAX_VALUE : 1) : 1;
|
||||
int upperBound = hasVocabulary ? (metadataField.getVocabulary().isMultiSelection() ? metadataField.getVocabulary().getVocabularyFields().size() : 1) : 1;
|
||||
|
||||
if(fieldsMandatoryUpperBoundMap.containsKey(metadataFieldName))
|
||||
upperBound += fieldsMandatoryUpperBoundMap.get(metadataFieldName);
|
||||
|
||||
if(fieldsMandatoryUpperBoundMap.containsKey(metadataFieldName)){
|
||||
long tempSum = upperBound + fieldsMandatoryUpperBoundMap.get(metadataFieldName);
|
||||
if(tempSum > Integer.MAX_VALUE)
|
||||
upperBound = Integer.MAX_VALUE;
|
||||
else
|
||||
upperBound = (int) tempSum;
|
||||
}
|
||||
fieldsMandatoryUpperBoundMap.put(metadataFieldName, upperBound);
|
||||
|
||||
// fields with this same key
|
||||
int countPerFields = fieldsFoundWithThisKey;
|
||||
if(numberFieldsSameKeyMap.containsKey(metadataFieldName))
|
||||
countPerFields += numberFieldsSameKeyMap.get(metadataFieldName);
|
||||
numberFieldsSameKeyMap.put(metadataFieldName, countPerFields);
|
||||
if(numberFieldsMandatorySameKeyMap.containsKey(metadataFieldName))
|
||||
countPerFields += numberFieldsMandatorySameKeyMap.get(metadataFieldName);
|
||||
numberFieldsMandatorySameKeyMap.put(metadataFieldName, countPerFields);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ public class Item {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@POST
|
||||
@Path(Constants.CREATE_METHOD)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
|
@ -76,11 +77,10 @@ public class Item {
|
|||
|
||||
obj = (JSONObject)parser.parse(CatalogueUtils.delegatePost(caller, context, Constants.ITEM_CREATE, obj.toJSONString(), uriInfo));
|
||||
|
||||
// after creation, if it was ok ...
|
||||
// after creation, if it is ok ...
|
||||
if((boolean)obj.get(CatalogueUtils.SUCCESS_KEY)){
|
||||
|
||||
JSONObject result = (JSONObject)obj.get(CatalogueUtils.RESULT_KEY);
|
||||
|
||||
DataCatalogue utils = CatalogueUtils.getCatalogue();
|
||||
|
||||
// add also this information as custom field
|
||||
|
|
Reference in New Issue