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,74 +177,75 @@ public class MetadataDiscovery {
|
|||
Map<String, List<MetadataFieldWrapper>> fieldsPerCategory = new HashMap<String, List<MetadataFieldWrapper>>(categoriesWrapper.size());
|
||||
|
||||
// manage the fields
|
||||
for(MetadataField metadataField: fields){
|
||||
if(fields != null)
|
||||
for(MetadataField metadataField: fields){
|
||||
|
||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||
wrapperObj.setFieldNameFromCategory(metadataField.getCategoryFieldQName());
|
||||
wrapperObj.setType(DataTypeWrapper.valueOf(metadataField.getDataType().toString()));
|
||||
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
|
||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||
wrapperObj.setNote(metadataField.getNote());
|
||||
MetadataValidator validator = metadataField.getValidator();
|
||||
if(validator != null)
|
||||
wrapperObj.setValidator(validator.getRegularExpression());
|
||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||
wrapperObj.setFieldNameFromCategory(metadataField.getCategoryFieldQName());
|
||||
wrapperObj.setType(DataTypeWrapper.valueOf(metadataField.getDataType().toString()));
|
||||
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
|
||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||
wrapperObj.setNote(metadataField.getNote());
|
||||
MetadataValidator validator = metadataField.getValidator();
|
||||
if(validator != null)
|
||||
wrapperObj.setValidator(validator.getRegularExpression());
|
||||
|
||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||
|
||||
if(vocabulary != null){
|
||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||
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);
|
||||
if(vocabulary != null){
|
||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||
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);
|
||||
}
|
||||
|
||||
fieldsWrapper.add(wrapperObj);
|
||||
}
|
||||
|
||||
// filter the categories without children here
|
||||
Iterator<CategoryWrapper> categoryToRemoveIT = categoriesWrapper.iterator();
|
||||
while (categoryToRemoveIT.hasNext()) {
|
||||
|
@ -253,7 +254,7 @@ public class MetadataDiscovery {
|
|||
if(categoryWrapper.getFieldsForThisCategory() == null)
|
||||
categoryToRemoveIT.remove();
|
||||
}
|
||||
|
||||
|
||||
MetaDataProfileBean bean = new MetaDataProfileBean(type, title, fieldsWrapper, categoriesWrapper);
|
||||
beans.add(bean);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue