4184: Create datacatalogue-metadata-discovery library
Task-Url: https://support.d4science.org/issues/4184 Added MetadataFormatDiscovery Added MetadataFormatReader git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@129013 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
dac0ef075b
commit
fc1993dd43
|
@ -7,9 +7,10 @@ import java.io.Serializable;
|
|||
|
||||
|
||||
/**
|
||||
* The Class MetadataType.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 7, 2016
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
public class MetadataType implements Serializable{
|
||||
|
||||
|
@ -23,16 +24,18 @@ public class MetadataType implements Serializable{
|
|||
private String description;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new metadata type.
|
||||
*/
|
||||
public MetadataType() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param name
|
||||
* @param description
|
||||
* Instantiates a new metadata type.
|
||||
*
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param description the description
|
||||
*/
|
||||
public MetadataType(String id, String name, String description) {
|
||||
|
||||
|
@ -44,6 +47,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
|
@ -53,6 +58,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
|
@ -62,6 +69,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Gets the description.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
|
@ -71,6 +80,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Sets the id.
|
||||
*
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
|
@ -80,6 +91,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
|
@ -89,6 +102,8 @@ public class MetadataType implements Serializable{
|
|||
|
||||
|
||||
/**
|
||||
* Sets the description.
|
||||
*
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
|
|
|
@ -9,10 +9,12 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class MetadataField.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 27, 2016
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
@XmlRootElement(name="metadatafield")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
@ -32,20 +34,22 @@ public class MetadataField {
|
|||
private MetadataValidator validator;
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new metadata field.
|
||||
*/
|
||||
public MetadataField() {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param fieldName
|
||||
* @param mandatory
|
||||
* @param isBoolean
|
||||
* @param defaulValue
|
||||
* @param note
|
||||
* @param vocabulary
|
||||
* @param validator
|
||||
* Instantiates a new metadata field.
|
||||
*
|
||||
* @param fieldName the field name
|
||||
* @param mandatory the mandatory
|
||||
* @param isBoolean the is boolean
|
||||
* @param defaulValue the defaul value
|
||||
* @param note the note
|
||||
* @param vocabulary the vocabulary
|
||||
* @param validator the validator
|
||||
*/
|
||||
public MetadataField(
|
||||
String fieldName, Boolean mandatory, Boolean isBoolean,
|
||||
|
@ -64,6 +68,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the field name.
|
||||
*
|
||||
* @return the fieldName
|
||||
*/
|
||||
public String getFieldName() {
|
||||
|
@ -74,6 +80,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the mandatory.
|
||||
*
|
||||
* @return the mandatory
|
||||
*/
|
||||
public Boolean getMandatory() {
|
||||
|
@ -84,6 +92,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the checks if is boolean.
|
||||
*
|
||||
* @return the isBoolean
|
||||
*/
|
||||
public Boolean getIsBoolean() {
|
||||
|
@ -94,6 +104,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the defaul value.
|
||||
*
|
||||
* @return the defaulValue
|
||||
*/
|
||||
public String getDefaulValue() {
|
||||
|
@ -104,6 +116,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the note.
|
||||
*
|
||||
* @return the note
|
||||
*/
|
||||
public String getNote() {
|
||||
|
@ -114,6 +128,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the vocabulary.
|
||||
*
|
||||
* @return the vocabulary
|
||||
*/
|
||||
public MetadataVocabulary getVocabulary() {
|
||||
|
@ -124,6 +140,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the validator.
|
||||
*
|
||||
* @return the validator
|
||||
*/
|
||||
public MetadataValidator getValidator() {
|
||||
|
@ -134,6 +152,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the field name.
|
||||
*
|
||||
* @param fieldName the fieldName to set
|
||||
*/
|
||||
public void setFieldName(String fieldName) {
|
||||
|
@ -144,6 +164,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the mandatory.
|
||||
*
|
||||
* @param mandatory the mandatory to set
|
||||
*/
|
||||
public void setMandatory(Boolean mandatory) {
|
||||
|
@ -154,6 +176,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the checks if is boolean.
|
||||
*
|
||||
* @param isBoolean the isBoolean to set
|
||||
*/
|
||||
public void setIsBoolean(Boolean isBoolean) {
|
||||
|
@ -164,6 +188,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the defaul value.
|
||||
*
|
||||
* @param defaulValue the defaulValue to set
|
||||
*/
|
||||
public void setDefaulValue(String defaulValue) {
|
||||
|
@ -174,6 +200,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the note.
|
||||
*
|
||||
* @param note the note to set
|
||||
*/
|
||||
public void setNote(String note) {
|
||||
|
@ -184,6 +212,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the vocabulary.
|
||||
*
|
||||
* @param vocabulary the vocabulary to set
|
||||
*/
|
||||
public void setVocabulary(MetadataVocabulary vocabulary) {
|
||||
|
@ -194,6 +224,8 @@ public class MetadataField {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the validator.
|
||||
*
|
||||
* @param validator the validator to set
|
||||
*/
|
||||
public void setValidator(MetadataValidator validator) {
|
||||
|
|
|
@ -12,11 +12,12 @@ import javax.xml.bind.annotation.XmlElement;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class MetadataFormat.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 27, 2016
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
@XmlRootElement(name="metadataformat")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
@ -27,6 +28,8 @@ public class MetadataFormat {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the metadata fields.
|
||||
*
|
||||
* @return the metadataFields
|
||||
*/
|
||||
public List<MetadataField> getMetadataFields() {
|
||||
|
@ -36,6 +39,8 @@ public class MetadataFormat {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the metadata fields.
|
||||
*
|
||||
* @param metadataFields the metadataFields to set
|
||||
*/
|
||||
public void setMetadataFields(List<MetadataField> metadataFields) {
|
||||
|
|
|
@ -9,9 +9,10 @@ import javax.xml.bind.annotation.XmlRootElement;
|
|||
|
||||
|
||||
/**
|
||||
* The Class MetadataValidator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 27, 2016
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
@XmlRootElement(name = "metadatavalidator")
|
||||
@XmlAccessorType (XmlAccessType.FIELD)
|
||||
|
@ -21,7 +22,7 @@ public class MetadataValidator {
|
|||
|
||||
|
||||
/**
|
||||
*
|
||||
* Instantiates a new metadata validator.
|
||||
*/
|
||||
public MetadataValidator() {
|
||||
|
||||
|
@ -30,7 +31,9 @@ public class MetadataValidator {
|
|||
|
||||
|
||||
/**
|
||||
* @param regularExpression
|
||||
* Instantiates a new metadata validator.
|
||||
*
|
||||
* @param regularExpression the regular expression
|
||||
*/
|
||||
public MetadataValidator(String regularExpression) {
|
||||
|
||||
|
@ -40,6 +43,8 @@ public class MetadataValidator {
|
|||
|
||||
|
||||
/**
|
||||
* Gets the regular expression.
|
||||
*
|
||||
* @return the regularExpression
|
||||
*/
|
||||
public String getRegularExpression() {
|
||||
|
@ -49,6 +54,8 @@ public class MetadataValidator {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the regular expression.
|
||||
*
|
||||
* @param regularExpression the regularExpression to set
|
||||
*/
|
||||
public void setRegularExpression(String regularExpression) {
|
||||
|
|
|
@ -10,11 +10,12 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class MetadataVocabulary.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 27, 2016
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
@XmlRootElement(name = "metadatavocabulary")
|
||||
@XmlAccessorType (XmlAccessType.FIELD)
|
||||
|
|
|
@ -21,11 +21,12 @@ import org.slf4j.LoggerFactory;
|
|||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
|
||||
/**
|
||||
* The Class MedataFormatReader.
|
||||
* The Class MedataFormatDiscovery.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* @Jul 26, 2013
|
||||
* Jun 8, 2016
|
||||
*/
|
||||
public class MedataFormatDiscovery {
|
||||
|
||||
|
@ -150,77 +151,11 @@ public class MedataFormatDiscovery {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata type from resource.
|
||||
* Gets the gcube generic query string.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @return the metadata type from resource
|
||||
* @return the gcube generic query string
|
||||
*/
|
||||
/*private MetadataType getMetadataTypeFromResource(XPathHelper helper) throws ApplicationProfileNotFoundException{
|
||||
|
||||
List<String> metadataformat;
|
||||
|
||||
List<GeoexplorerDefaultLayer> listGeoexplorerDefaultLayer = new ArrayList<GeoexplorerDefaultLayer>();
|
||||
|
||||
try {
|
||||
|
||||
metadataformat = helper.evaluate("/Resource/Profile/Body/metadataformat");
|
||||
|
||||
if (metadataformat != null && metadataformat.size() > 0) {
|
||||
|
||||
List<String> metadatafields = helper.evaluate("/Resource/Profile/Body/metadataformat/metadatafield/text()");
|
||||
|
||||
List<String> currValue = null;
|
||||
|
||||
for (String metafield : metadatafields) {
|
||||
logger.trace("found metafield : "+metafield);
|
||||
GeoexplorerDefaultLayer geoDefLayer = new GeoexplorerDefaultLayer();
|
||||
geoDefLayer.setUUID(uuid);
|
||||
geoDefLayer.setScope(scope.toString());
|
||||
|
||||
// currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/@isBaseLayer");
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/IsBaseLayer/text()");
|
||||
|
||||
logger.trace("is base layer?" +currValue);
|
||||
if (currValue != null && currValue.size() > 0){
|
||||
boolean isBase = Boolean.parseBoolean(currValue.get(0));
|
||||
geoDefLayer.setBaseLayer(isBase);
|
||||
// logger.trace("isBaseLayer : "+isBase);
|
||||
}
|
||||
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/Description/text()");
|
||||
|
||||
String descr = "";
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
descr = currValue.get(0);
|
||||
geoDefLayer.setDescription(descr);
|
||||
// logger.trace("description: "+descr+" for UUID: "+uuid);
|
||||
}
|
||||
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/Name/text()");
|
||||
descr = "";
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
descr = currValue.get(0);
|
||||
geoDefLayer.setName(descr);
|
||||
// logger.trace("name: "+descr+" for UUID: "+uuid);
|
||||
}
|
||||
|
||||
logger.trace("Filled object: "+geoDefLayer);
|
||||
listGeoexplorerDefaultLayer.add(geoDefLayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile with scope "+scope.toString()+" is wrong, consider adding <DefaultLayer><UUID> element in <Body>");
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred in getListDefaultLayerFromNode ", e);
|
||||
return listGeoexplorerDefaultLayer;
|
||||
}
|
||||
|
||||
return listGeoexplorerDefaultLayer;
|
||||
}*/
|
||||
|
||||
|
||||
public synchronized String getGcubeGenericQueryString(String secondaryType){
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource" +
|
||||
|
|
|
@ -2,17 +2,22 @@ package org.gcube.datacatalogue.metadatadiscovery.reader;
|
|||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.common.resources.gcore.utils.XPathHelper;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.scope.impl.ScopeBean;
|
||||
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.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||
|
@ -30,32 +35,34 @@ import org.xml.sax.InputSource;
|
|||
public class MedataFormatReader {
|
||||
|
||||
public static Logger logger = LoggerFactory.getLogger(MedataFormatReader.class);
|
||||
protected static final String DATA_CATALOGUE_METADATA_SECONDARY_TYPE = "DataCatalogueMetadata";
|
||||
private String secondaryType;
|
||||
private ScopeBean scope;
|
||||
private List<MetadataType> metadataTypes;
|
||||
private MetadataFormat metadataFormat;
|
||||
private String resourceID;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new medata format reader.
|
||||
*
|
||||
* @param scope - the scope to be searched
|
||||
* @param scope the scope
|
||||
* @param resourceID the resource id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public MedataFormatReader(ScopeBean scope, String resourceID) throws Exception {
|
||||
this.scope = scope;
|
||||
this.resourceID = resourceID;
|
||||
this.metadataTypes = getMedataFormatByID();
|
||||
this.metadataFormat = getMedataFormatByID(resourceID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this method looks up the applicationProfile profile among the ones available in the infrastructure.
|
||||
* Gets the medata format by id.
|
||||
*
|
||||
* @return the applicationProfile profile
|
||||
* @param resourceID the resource id
|
||||
* @return the medata format by id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private List<MetadataType> getMedataFormatByID() throws Exception {
|
||||
logger.trace("read secondary type: "+secondaryType);
|
||||
private MetadataFormat getMedataFormatByID(String resourceID) throws Exception {
|
||||
logger.trace("Get MedataFormat with resourceID: "+resourceID);
|
||||
|
||||
if(this.scope==null)
|
||||
throw new Exception("Scope is null");
|
||||
|
@ -63,14 +70,14 @@ public class MedataFormatReader {
|
|||
String scopeString = this.scope.toString();
|
||||
logger.trace("read scope: "+scopeString);
|
||||
|
||||
List<MetadataType> list = new ArrayList<MetadataType>();
|
||||
MetadataFormat mf = new MetadataFormat();
|
||||
|
||||
try {
|
||||
|
||||
ScopeProvider.instance.set(scopeString);
|
||||
logger.info("scope provider set instance: "+scopeString);
|
||||
|
||||
String queryString = getGcubeGenericQueryString(secondaryType);
|
||||
String queryString = getQuesryStringForGenericResourceById(resourceID);
|
||||
logger.trace("queryString: " +queryString);
|
||||
Query q = new QueryBox(queryString);
|
||||
|
||||
|
@ -78,70 +85,71 @@ public class MedataFormatReader {
|
|||
List<String> appProfile = client.submit(q);
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new ApplicationProfileNotFoundException("Your applicationProfile is not registered in the infrastructure, the scope is "+scopeString);
|
||||
throw new ApplicationProfileNotFoundException("Your resourceID "+resourceID+" is not registered in the infrastructure, the scope is "+scopeString);
|
||||
else {
|
||||
|
||||
for (String elem : appProfile) {
|
||||
try{
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
MetadataType meta = getMetadataTypeFromResource(helper);
|
||||
list.add(meta);
|
||||
}catch(Exception e){
|
||||
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, ",e);
|
||||
}
|
||||
String theResource = null;
|
||||
try{
|
||||
theResource = appProfile.get(0);
|
||||
// logger.trace("Resource with resourceID "+resourceID+" matched "+theResource);
|
||||
logger.trace("Resource with resourceID "+resourceID+" found ");
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(theResource))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
List<MetadataField> fields = getMetadataFieldsFromResource(helper);
|
||||
mf.setMetadataFields(fields);
|
||||
}catch(Exception e){
|
||||
logger.error("Error while parsing Resource "+theResource+" from the infrastructure, the scope is "+scopeString,e);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, "+e);
|
||||
return list;
|
||||
logger.error("Error while trying to fetch resourceID "+resourceID+" from the infrastructure, the scope is "+scopeString,e);
|
||||
return mf;
|
||||
} finally{
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
return list;
|
||||
|
||||
return mf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata type from resource.
|
||||
* Gets the metadata fields from resource.
|
||||
*
|
||||
* @param helper the helper
|
||||
* @return the metadata type from resource
|
||||
* @return the metadata fields from resource
|
||||
* @throws ApplicationProfileNotFoundException the application profile not found exception
|
||||
*/
|
||||
private MetadataType getMetadataTypeFromResource(XPathHelper helper) throws ApplicationProfileNotFoundException{
|
||||
|
||||
private List<MetadataField> getMetadataFieldsFromResource(XPathHelper helper) throws Exception{
|
||||
|
||||
try {
|
||||
|
||||
MetadataType metaType = new MetadataType();
|
||||
List<String> metadatafields = helper.evaluate("/Resource/Profile/Body/metadataformat/metadatafield");
|
||||
|
||||
List<String> id = helper.evaluate("/Resource/ID/text()");
|
||||
if(metadatafields==null || metadatafields.isEmpty())
|
||||
throw new Exception("Metadata fields not found");
|
||||
|
||||
if(id==null || id.isEmpty())
|
||||
throw new ApplicationProfileNotFoundException("Resource ID not found for "+helper.toString());
|
||||
else{
|
||||
metaType.setId(id.get(0));
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataField.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
||||
// for (String string : metadatafields) {
|
||||
// logger.debug("mf "+string);
|
||||
// }
|
||||
|
||||
List<MetadataField> mfs = new ArrayList<MetadataField>();
|
||||
logger.debug("MetadataFields are: "+metadatafields.size());
|
||||
|
||||
for (String mfield : metadatafields) {
|
||||
try{
|
||||
InputStream stream = new ByteArrayInputStream(mfield.getBytes());
|
||||
MetadataField mtdf = (MetadataField) jaxbUnmarshaller.unmarshal(stream);
|
||||
logger.debug("Unmarshalled: "+mtdf);
|
||||
mfs.add(mtdf);
|
||||
}catch(Exception e){
|
||||
logger.error("An error occurred during unmarshall performing on "+mfield+", skipping this metadatafield");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> name = helper.evaluate("/Resource/Profile/Name/text()");
|
||||
|
||||
if(name==null || name.isEmpty())
|
||||
throw new ApplicationProfileNotFoundException("Resource Name not found for "+helper.toString());
|
||||
else
|
||||
metaType.setName(name.get(0));
|
||||
|
||||
List<String> description = helper.evaluate("/Resource/Profile/Description/text()");
|
||||
|
||||
if(description==null || description.isEmpty())
|
||||
throw new ApplicationProfileNotFoundException("Resource Name not found for "+helper.toString());
|
||||
else
|
||||
metaType.setDescription(description.get(0));
|
||||
|
||||
return metaType;
|
||||
return mfs;
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred in getListDefaultLayerFromNode ", e);
|
||||
|
@ -150,114 +158,42 @@ public class MedataFormatReader {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata type from resource.
|
||||
*
|
||||
* @param secondaryType the secondary type
|
||||
* @return the metadata type from resource
|
||||
*/
|
||||
/*private MetadataType getMetadataTypeFromResource(XPathHelper helper) throws ApplicationProfileNotFoundException{
|
||||
public synchronized String getQuesryStringForGenericResourceById(String resourceId){
|
||||
|
||||
List<String> metadataformat;
|
||||
|
||||
List<GeoexplorerDefaultLayer> listGeoexplorerDefaultLayer = new ArrayList<GeoexplorerDefaultLayer>();
|
||||
|
||||
try {
|
||||
|
||||
metadataformat = helper.evaluate("/Resource/Profile/Body/metadataformat");
|
||||
|
||||
if (metadataformat != null && metadataformat.size() > 0) {
|
||||
|
||||
List<String> metadatafields = helper.evaluate("/Resource/Profile/Body/metadataformat/metadatafield/text()");
|
||||
|
||||
List<String> currValue = null;
|
||||
|
||||
for (String metafield : metadatafields) {
|
||||
logger.trace("found metafield : "+metafield);
|
||||
GeoexplorerDefaultLayer geoDefLayer = new GeoexplorerDefaultLayer();
|
||||
geoDefLayer.setUUID(uuid);
|
||||
geoDefLayer.setScope(scope.toString());
|
||||
|
||||
// currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/@isBaseLayer");
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/IsBaseLayer/text()");
|
||||
|
||||
logger.trace("is base layer?" +currValue);
|
||||
if (currValue != null && currValue.size() > 0){
|
||||
boolean isBase = Boolean.parseBoolean(currValue.get(0));
|
||||
geoDefLayer.setBaseLayer(isBase);
|
||||
// logger.trace("isBaseLayer : "+isBase);
|
||||
}
|
||||
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/Description/text()");
|
||||
|
||||
String descr = "";
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
descr = currValue.get(0);
|
||||
geoDefLayer.setDescription(descr);
|
||||
// logger.trace("description: "+descr+" for UUID: "+uuid);
|
||||
}
|
||||
|
||||
currValue = helper.evaluate("/Resource/Profile/Body/DefaultLayers/DefaultLayer[UUID='"+uuid+"']/Name/text()");
|
||||
descr = "";
|
||||
if (currValue != null && currValue.size() > 0) {
|
||||
descr = currValue.get(0);
|
||||
geoDefLayer.setName(descr);
|
||||
// logger.trace("name: "+descr+" for UUID: "+uuid);
|
||||
}
|
||||
|
||||
logger.trace("Filled object: "+geoDefLayer);
|
||||
listGeoexplorerDefaultLayer.add(geoDefLayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else throw new ApplicationProfileNotFoundException("Your applicationProfile with scope "+scope.toString()+" is wrong, consider adding <DefaultLayer><UUID> element in <Body>");
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred in getListDefaultLayerFromNode ", e);
|
||||
return listGeoexplorerDefaultLayer;
|
||||
}
|
||||
|
||||
return listGeoexplorerDefaultLayer;
|
||||
}*/
|
||||
|
||||
|
||||
public synchronized String getGcubeGenericQueryString(String secondaryType){
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource" +
|
||||
" where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"'" +
|
||||
" return $profile";
|
||||
return String.format("declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; " +
|
||||
"for $resource in collection('/db/Profiles')//Document/Data/ic:Profile/Resource " +
|
||||
"where ($resource/ID/text() eq '%s') return $resource", resourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the secondary type.
|
||||
*
|
||||
* @return the secondary type
|
||||
*/
|
||||
public String getSecondaryType() {
|
||||
return secondaryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scope.
|
||||
*
|
||||
* @return the scope
|
||||
*/
|
||||
public ScopeBean getScope() {
|
||||
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the metadata types.
|
||||
*
|
||||
* @return the metadataTypes
|
||||
*/
|
||||
public List<MetadataType> getMetadataTypes() {
|
||||
|
||||
return metadataTypes;
|
||||
/**
|
||||
* @return the metadataFormat
|
||||
*/
|
||||
public MetadataFormat getMetadataFormat() {
|
||||
|
||||
return metadataFormat;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the resourceID
|
||||
*/
|
||||
public String getResourceID() {
|
||||
|
||||
return resourceID;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
|
@ -270,8 +206,8 @@ public class MedataFormatReader {
|
|||
final ScopeBean scope = new ScopeBean(scopeString);
|
||||
MedataFormatReader reader;
|
||||
try {
|
||||
reader = new MedataFormatReader(scope, "");
|
||||
System.out.println(reader.getMetadataTypes());
|
||||
reader = new MedataFormatReader(scope, "78355412-b45a-4519-adce-679452583aa2");
|
||||
System.out.println(reader.getMetadataFormat());
|
||||
|
||||
// String value = "true";
|
||||
// if (value != null){
|
||||
|
|
|
@ -1,111 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.datacatalogue.metadatadiscovery;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
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.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* May 27, 2016
|
||||
*/
|
||||
public class MainJaxb {
|
||||
|
||||
static MetadataField ckanMetadata;
|
||||
static MetadataFormat metadatas;
|
||||
static String tmpFileXML = "." + File.separator + "CkanMetadatas.xml";
|
||||
|
||||
@Test
|
||||
public static void createMetadata() {
|
||||
|
||||
metadatas = new MetadataFormat();
|
||||
|
||||
ckanMetadata = new MetadataField();
|
||||
ckanMetadata.setFieldName("Name");
|
||||
ckanMetadata.setMandatory(true);
|
||||
ckanMetadata.setDefaulValue("default value");
|
||||
List<String> vocabulary = new ArrayList<String>();
|
||||
vocabulary.add("field1");
|
||||
vocabulary.add("field2");
|
||||
vocabulary.add("field3");
|
||||
MetadataVocabulary cvc = new MetadataVocabulary(vocabulary);
|
||||
ckanMetadata.setVocabulary(cvc);
|
||||
ckanMetadata.setNote("shown as suggestions in the insert/update metadata form of CKAN");
|
||||
MetadataValidator validator = new MetadataValidator("a regular expression for validating values");
|
||||
ckanMetadata.setValidator(validator);
|
||||
metadatas.addMetadata(ckanMetadata);
|
||||
|
||||
ckanMetadata = new MetadataField();
|
||||
ckanMetadata.setFieldName("Accessibility");
|
||||
ckanMetadata.setMandatory(true);
|
||||
ckanMetadata.setDefaulValue("virtual/public");
|
||||
List<String> vocabulary2 = new ArrayList<String>();
|
||||
vocabulary2.add("virtual/public");
|
||||
vocabulary2.add("virtual/private");
|
||||
vocabulary2.add("transactional");
|
||||
MetadataVocabulary cvc2 = new MetadataVocabulary(vocabulary2);
|
||||
ckanMetadata.setVocabulary(cvc2);
|
||||
ckanMetadata.setNote("shown as suggestions in the insert metadata form of CKAN");
|
||||
MetadataValidator validator2 = new MetadataValidator("a regular expression for validating values");
|
||||
ckanMetadata.setValidator(validator2);
|
||||
|
||||
metadatas.addMetadata(ckanMetadata);
|
||||
|
||||
try {
|
||||
|
||||
marshalingExample();
|
||||
unMarshalingExample();
|
||||
}
|
||||
catch (JAXBException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void marshalingExample() throws JAXBException
|
||||
{
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
||||
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
||||
|
||||
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
|
||||
//Marshal the employees list in console
|
||||
// jaxbMarshaller.marshal(employees, System.out);
|
||||
|
||||
//Marshal the employees list in file
|
||||
jaxbMarshaller.marshal(metadatas, new File(tmpFileXML));
|
||||
}
|
||||
|
||||
|
||||
private static void unMarshalingExample() throws JAXBException
|
||||
{
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
||||
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
|
||||
|
||||
//We had written this file in marshalling example
|
||||
MetadataFormat mtds = (MetadataFormat) jaxbUnmarshaller.unmarshal(new File(tmpFileXML));
|
||||
|
||||
for(MetadataField mtd : mtds.getMetadataFields())
|
||||
{
|
||||
System.out.println(mtd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ import org.junit.Test;
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Jun 7, 2016
|
||||
*/
|
||||
public class TestMetadataDiscovery {
|
||||
public class TestJaxbMetadataMarshUnmarsh {
|
||||
|
||||
static MetadataField ckanMetadata;
|
||||
static MetadataFormat metadatas;
|
Loading…
Reference in New Issue