fix for null metadatafields
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@149115 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3bb6a3155f
commit
37041ebf38
|
@ -177,73 +177,74 @@ public class MetadataDiscovery {
|
||||||
Map<String, List<MetadataFieldWrapper>> fieldsPerCategory = new HashMap<String, List<MetadataFieldWrapper>>(categoriesWrapper.size());
|
Map<String, List<MetadataFieldWrapper>> fieldsPerCategory = new HashMap<String, List<MetadataFieldWrapper>>(categoriesWrapper.size());
|
||||||
|
|
||||||
// manage the fields
|
// manage the fields
|
||||||
for(MetadataField metadataField: fields){
|
if(fields != null)
|
||||||
|
for(MetadataField metadataField: fields){
|
||||||
|
|
||||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||||
wrapperObj.setFieldNameFromCategory(metadataField.getCategoryFieldQName());
|
wrapperObj.setFieldNameFromCategory(metadataField.getCategoryFieldQName());
|
||||||
wrapperObj.setType(DataTypeWrapper.valueOf(metadataField.getDataType().toString()));
|
wrapperObj.setType(DataTypeWrapper.valueOf(metadataField.getDataType().toString()));
|
||||||
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
|
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
|
||||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||||
wrapperObj.setNote(metadataField.getNote());
|
wrapperObj.setNote(metadataField.getNote());
|
||||||
MetadataValidator validator = metadataField.getValidator();
|
MetadataValidator validator = metadataField.getValidator();
|
||||||
if(validator != null)
|
if(validator != null)
|
||||||
wrapperObj.setValidator(validator.getRegularExpression());
|
wrapperObj.setValidator(validator.getRegularExpression());
|
||||||
|
|
||||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||||
|
|
||||||
if(vocabulary != null){
|
if(vocabulary != null){
|
||||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||||
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
|
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
|
||||||
}
|
|
||||||
|
|
||||||
MetadataTagging tagging = metadataField.getTagging();
|
|
||||||
if(tagging != null){
|
|
||||||
|
|
||||||
FieldAsTag tag = new FieldAsTag();
|
|
||||||
tag.setCreate(tagging.getCreate());
|
|
||||||
tag.setSeparator(tagging.getSeparator());
|
|
||||||
tag.setTaggingValue(TaggingGroupingValue.valueOf(tagging.getTaggingValue().toString()));
|
|
||||||
wrapperObj.setAsTag(tag);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
MetadataGrouping grouping = metadataField.getGrouping();
|
|
||||||
if(grouping != null){
|
|
||||||
|
|
||||||
FieldAsGroup group = new FieldAsGroup();
|
|
||||||
group.setCreate(grouping.getCreate());
|
|
||||||
group.setPropagateUp(grouping.getPropagateUp());
|
|
||||||
group.setGroupingValue(TaggingGroupingValue.valueOf(grouping.getGroupingValue().toString()));
|
|
||||||
wrapperObj.setAsGroup(group);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// set to which category this field belongs to and vice-versa
|
|
||||||
if(metadataField.getCategoryRef() != null){
|
|
||||||
CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef());
|
|
||||||
|
|
||||||
if(ownerCategory == null){
|
|
||||||
logger.warn("A field with categoryref " + metadataField.getCategoryRef() + " has been found, but"
|
|
||||||
+ " such category is not defined within the namespaces");
|
|
||||||
}else{
|
|
||||||
|
|
||||||
wrapperObj.setOwnerCategory(ownerCategory);
|
|
||||||
|
|
||||||
List<MetadataFieldWrapper> fieldsPerCategoryN = fieldsPerCategory.get(metadataField.getCategoryRef());
|
|
||||||
if(fieldsPerCategoryN == null)
|
|
||||||
fieldsPerCategoryN = new ArrayList<MetadataFieldWrapper>();
|
|
||||||
|
|
||||||
fieldsPerCategoryN.add(wrapperObj);
|
|
||||||
fieldsPerCategory.put(metadataField.getCategoryRef(), fieldsPerCategoryN);
|
|
||||||
|
|
||||||
// instead of re-looping on the fieldsPerCategory map later, just set this potentially partial list
|
|
||||||
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fieldsWrapper.add(wrapperObj);
|
MetadataTagging tagging = metadataField.getTagging();
|
||||||
}
|
if(tagging != null){
|
||||||
|
|
||||||
|
FieldAsTag tag = new FieldAsTag();
|
||||||
|
tag.setCreate(tagging.getCreate());
|
||||||
|
tag.setSeparator(tagging.getSeparator());
|
||||||
|
tag.setTaggingValue(TaggingGroupingValue.valueOf(tagging.getTaggingValue().toString()));
|
||||||
|
wrapperObj.setAsTag(tag);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
MetadataGrouping grouping = metadataField.getGrouping();
|
||||||
|
if(grouping != null){
|
||||||
|
|
||||||
|
FieldAsGroup group = new FieldAsGroup();
|
||||||
|
group.setCreate(grouping.getCreate());
|
||||||
|
group.setPropagateUp(grouping.getPropagateUp());
|
||||||
|
group.setGroupingValue(TaggingGroupingValue.valueOf(grouping.getGroupingValue().toString()));
|
||||||
|
wrapperObj.setAsGroup(group);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// set to which category this field belongs to and vice-versa
|
||||||
|
if(metadataField.getCategoryRef() != null){
|
||||||
|
CategoryWrapper ownerCategory = idToCategory.get(metadataField.getCategoryRef());
|
||||||
|
|
||||||
|
if(ownerCategory == null){
|
||||||
|
logger.warn("A field with categoryref " + metadataField.getCategoryRef() + " has been found, but"
|
||||||
|
+ " such category is not defined within the namespaces");
|
||||||
|
}else{
|
||||||
|
|
||||||
|
wrapperObj.setOwnerCategory(ownerCategory);
|
||||||
|
|
||||||
|
List<MetadataFieldWrapper> fieldsPerCategoryN = fieldsPerCategory.get(metadataField.getCategoryRef());
|
||||||
|
if(fieldsPerCategoryN == null)
|
||||||
|
fieldsPerCategoryN = new ArrayList<MetadataFieldWrapper>();
|
||||||
|
|
||||||
|
fieldsPerCategoryN.add(wrapperObj);
|
||||||
|
fieldsPerCategory.put(metadataField.getCategoryRef(), fieldsPerCategoryN);
|
||||||
|
|
||||||
|
// instead of re-looping on the fieldsPerCategory map later, just set this potentially partial list
|
||||||
|
ownerCategory.setFieldsForThisCategory(fieldsPerCategoryN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldsWrapper.add(wrapperObj);
|
||||||
|
}
|
||||||
|
|
||||||
// filter the categories without children here
|
// filter the categories without children here
|
||||||
Iterator<CategoryWrapper> categoryToRemoveIT = categoriesWrapper.iterator();
|
Iterator<CategoryWrapper> categoryToRemoveIT = categoriesWrapper.iterator();
|
||||||
|
|
Loading…
Reference in New Issue