fixed default value usage

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/catalogue-ws@149380 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2017-06-11 08:25:13 +00:00
parent 8039286ec9
commit 30bbf3d21f
1 changed files with 10 additions and 2 deletions

View File

@ -765,6 +765,7 @@ public class CatalogueUtils {
boolean hasControlledVocabulary = metadataField.getVocabulary() != null;
String value = fieldToValidate.getValue();
String key = fieldToValidate.getKey();
String defaultValue = metadataField.getDefaultValue();
// replace key by prepending the qualified name of the category, if needed
fieldToValidate.setQualifiedKey(metadataField.getCategoryFieldQName());
@ -772,7 +773,14 @@ public class CatalogueUtils {
if((value == null || value.isEmpty()))
if(metadataField.getMandatory() || hasControlledVocabulary)
throw new Exception("Mandatory field with name '" + key + "' doesn't have a value but it is mandatory or has a controlled vocabulary!");
else return;
else {
if(defaultValue != null && !defaultValue.isEmpty()){
value = defaultValue;
fieldToValidate.setValue(defaultValue);
}
else
return;
}
switch(dataType){
@ -785,7 +793,7 @@ public class CatalogueUtils {
if(hasControlledVocabulary){
List<String> valuesVocabulary = metadataField.getVocabulary().getVocabularyFields();
if(valuesVocabulary == null || valuesVocabulary.isEmpty())
return;