Fixed metadata parsing

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@131428 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-09-15 16:44:52 +00:00
parent 7231aa455b
commit 780eac0d9b
2 changed files with 84 additions and 10 deletions

View File

@ -334,7 +334,8 @@ public class Utils {
try {
// set the scope
ScopeProvider.instance.set(scopeInWhichDiscover);
if(oldScope != scopeInWhichDiscover)
ScopeProvider.instance.set(scopeInWhichDiscover);
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
@ -358,11 +359,10 @@ public class Utils {
wrapperObj.setValidator(validator.getRegularExpression());
MetadataVocabulary vocabulary = metadataField.getVocabulary();
if(vocabulary != null)
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
// multi selection?
wrapperObj.setMultiSelection(metadataField.getVocabulary().isMultiSelection());
if(vocabulary != null){
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
}
// add to the list
wrapperList.add(wrapperObj);
@ -385,8 +385,10 @@ public class Utils {
} catch (Exception e) {
logger.error("Error while retrieving metadata beans ", e);
}finally{
// set the scope back
ScopeProvider.instance.set(oldScope);
if(oldScope != scopeInWhichDiscover)
ScopeProvider.instance.set(oldScope);
}
}

View File

@ -1,15 +1,87 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary;
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
import org.junit.Test;
public class TestClass {
@Test
//@Test
public void testUser() {
assert(new CKANPublisherServicesImpl().getDevelopmentUser().equals(CKANPublisherServicesImpl.TEST_USER));
}
@Test
public void testMetadata(){
List<MetaDataProfileBean> beans = new ArrayList<MetaDataProfileBean>();
try {
ScopeProvider.instance.set("/gcube/devNext/NextNext");
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
for (MetadataType mt : reader.getListOfMetadataTypes()) {
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
// we need to wrap the list of metadata
List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
List<MetadataField> toWrap = metadata.getMetadataFields();
for(MetadataField metadataField: toWrap){
System.out.println(metadataField.toString());
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
wrapperObj.setDefaultValue(metadataField.getDefaulValue());
wrapperObj.setFieldName(metadataField.getFieldName());
wrapperObj.setType(DataType.valueOf(metadataField.getDataType().toString()));
wrapperObj.setMandatory(metadataField.getMandatory());
wrapperObj.setNote(metadataField.getNote());
MetadataValidator validator = metadataField.getValidator();
if(validator != null)
wrapperObj.setValidator(validator.getRegularExpression());
MetadataVocabulary vocabulary = metadataField.getVocabulary();
if(vocabulary != null){
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
}
// add to the list
wrapperList.add(wrapperObj);
}
// wrap the mt as well
MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
typeWrapper.setDescription(mt.getDescription());
typeWrapper.setId(mt.getId());
typeWrapper.setName(mt.getName());
MetaDataProfileBean bean = new MetaDataProfileBean(typeWrapper, wrapperList);
beans.add(bean);
}
System.out.println("List of beans is " + beans);
} catch (Exception e) {
System.out.println("Error while retrieving metadata beans " + e);
}
}
}