Rename MeatadataType as MedataProfile

Added metadatatype attribute also to MedataProfile


git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@146329 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-03-24 15:05:52 +00:00
parent 05c7e92b08
commit 6fc07e7469
10 changed files with 114 additions and 62 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/gcubedatacatalogue-metadata-discovery-1.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry including="**/*.java" kind="src" output="target/gcubedatacatalogue-metadata-discovery-3.0.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -27,5 +27,5 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/gcubedatacatalogue-metadata-discovery-1.0.0-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/gcubedatacatalogue-metadata-discovery-3.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -6,7 +6,7 @@ import java.util.Map;
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.MetadataProfile;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery;
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatReader;
@ -44,9 +44,12 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
scope = new ScopeBean(scopeString);
medataFormatDiscovery = new MetadataFormatDiscovery(scope);
logger.info("MedataFormatDiscovery has retrieved: "+medataFormatDiscovery.getMetadataTypes().size() +" metadata type/s");
logger.info("MedataFormatDiscovery has retrieved: "+medataFormatDiscovery.getMetadataProfiles().size() +" metadata type/s");
logger.debug("filling cache for MedataFormat");
for (MetadataType mT : medataFormatDiscovery.getMetadataTypes()) {
for (MetadataProfile mT : medataFormatDiscovery.getMetadataProfiles()) {
if(mT==null)
continue;
MetadataFormatReader reader = new MetadataFormatReader(scope, mT.getId());
hash.put(mT.getId(), reader.getMetadataFormat());
logger.debug("MetadataType id: "+mT.getId() +" cached as: "+reader.getMetadataFormat());
@ -57,25 +60,25 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#getListOfMetadataTypes()
*/
@Override
public List<MetadataType> getListOfMetadataTypes() throws Exception {
public List<MetadataProfile> getListOfMetadataProfiles() throws Exception {
return medataFormatDiscovery.getMetadataTypes();
return medataFormatDiscovery.getMetadataProfiles();
}
/* (non-Javadoc)
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#getMetadataFormatForMetadataType(org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType)
*/
@Override
public MetadataFormat getMetadataFormatForMetadataType(MetadataType type) throws Exception {
public MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile profile) throws Exception {
if(type==null)
throw new Exception("MetadataType is null");
if(profile==null)
throw new Exception("Input "+ MetadataProfile.class.getSimpleName() + " is null");
MetadataFormat format = hash.get(type.getId());
MetadataFormat format = hash.get(profile.getId());
if(format!=null)
return format;
MetadataFormatReader reader = new MetadataFormatReader(scope, type.getId());
MetadataFormatReader reader = new MetadataFormatReader(scope, profile.getId());
return reader.getMetadataFormat();
}

View File

@ -5,16 +5,17 @@ package org.gcube.datacatalogue.metadatadiscovery;
import java.util.List;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
/**
* The Interface DataCatalogueMetadataDiscovery.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
* Mar 24, 2017
*/
public interface DataCatalogueMetadataDiscovery {
@ -23,9 +24,9 @@ public interface DataCatalogueMetadataDiscovery {
* Gets the list of metadata types.
*
* @return the list of metadata types
* @throws Exception
* @throws Exception the exception
*/
List<MetadataType> getListOfMetadataTypes() throws Exception;
List<MetadataProfile> getListOfMetadataProfiles() throws Exception;
/**
@ -33,8 +34,8 @@ public interface DataCatalogueMetadataDiscovery {
*
* @param type the type
* @return the metadata format for metadata type
* @throws Exception
* @throws Exception the exception
*/
MetadataFormat getMetadataFormatForMetadataType(MetadataType type) throws Exception;
MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile type) throws Exception;
}

View File

@ -6,27 +6,29 @@ package org.gcube.datacatalogue.metadatadiscovery.bean;
import java.io.Serializable;
/**
* The Class MetadataType.
* The Class MetadataProfile.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
* Mar 24, 2017
*/
public class MetadataType implements Serializable{
public class MetadataProfile implements Serializable{
/**
*
*/
private static final long serialVersionUID = -975360133066572549L;
private static final long serialVersionUID = 8829173012445264057L;
private String id;
private String name;
private String description;
private String metadataType;
/**
* Instantiates a new metadata type.
*/
public MetadataType() {
public MetadataProfile() {
}
@ -37,12 +39,13 @@ public class MetadataType implements Serializable{
* @param name the name
* @param description the description
*/
public MetadataType(String id, String name, String description) {
public MetadataProfile(String id, String name, String description, String metadataType) {
super();
this.id = id;
this.name = name;
this.description = description;
this.metadataType = metadataType;
}
@ -111,6 +114,23 @@ public class MetadataType implements Serializable{
this.description = description;
}
/**
* @return the metadataType
*/
public String getMetadataType() {
return metadataType;
}
/**
* @param metadataType the metadataType to set
*/
public void setMetadataType(String metadataType) {
this.metadataType = metadataType;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@ -118,14 +138,17 @@ public class MetadataType implements Serializable{
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataType [id=");
builder.append("MetadataProfile [id=");
builder.append(id);
builder.append(", name=");
builder.append(name);
builder.append(", description=");
builder.append(description);
builder.append(", metadataType=");
builder.append(metadataType);
builder.append("]");
return builder.toString();
}
}

View File

@ -31,6 +31,10 @@ public class MetadataFormat implements Serializable{
*/
private static final long serialVersionUID = -5881074882343424963L;
public static final String LOCAL_NAME_METADATA_TYPE = "metadatatype";
public static final String LOCAL_NAME_METADATA_FORMAT = "metadataformat";
/**
* Instantiates a new metadata format.
*/
@ -44,7 +48,7 @@ public class MetadataFormat implements Serializable{
@XmlElement(name = "metadatafield")
private List<MetadataField> metadataFields;
@XmlAttribute(name = "metadatatype", required=true)
@XmlAttribute(name = LOCAL_NAME_METADATA_TYPE, required=true)
private String metadataType = "";
@XmlTransient

View File

@ -8,15 +8,21 @@ import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
@ -33,7 +39,7 @@ public class MetadataFormatDiscovery {
protected static final String DATA_CATALOGUE_METADATA_SECONDARY_TYPE = "DataCatalogueMetadata";
private String secondaryType;
private ScopeBean scope;
private List<MetadataType> metadataTypes;
private List<MetadataProfile> metadataProfiles;
/**
* Instantiates a new medata format reader.
@ -44,7 +50,7 @@ public class MetadataFormatDiscovery {
public MetadataFormatDiscovery(ScopeBean scope) throws Exception {
this.scope = scope;
this.secondaryType = DATA_CATALOGUE_METADATA_SECONDARY_TYPE;
this.metadataTypes = readProfileFromInfrastrucure();
this.metadataProfiles = readMetadataProfilesFromInfrastrucure();
}
/**
@ -53,7 +59,7 @@ public class MetadataFormatDiscovery {
* @return the applicationProfile profile
* @throws Exception the exception
*/
private List<MetadataType> readProfileFromInfrastrucure() throws Exception {
private List<MetadataProfile> readMetadataProfilesFromInfrastrucure() throws Exception {
logger.trace("read secondary type: "+secondaryType);
if(this.scope==null)
@ -62,7 +68,7 @@ public class MetadataFormatDiscovery {
String scopeString = this.scope.toString();
logger.trace("read scope: "+scopeString);
List<MetadataType> list = new ArrayList<MetadataType>();
List<MetadataProfile> list = new ArrayList<MetadataProfile>();
try {
@ -77,21 +83,22 @@ public class MetadataFormatDiscovery {
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
List<String> metaProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("ApplicationProfile with secondaryType: "+secondaryType+" is not registered in the scope: "+scopeString);
if (metaProfile == null || metaProfile.size() == 0)
throw new MetadataProfileNotFoundException("Resource/s with secondaryType: "+secondaryType+" is/are not registered in the scope: "+scopeString);
else {
for (String elem : appProfile) {
for (String elem : metaProfile) {
try{
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Node node = docBuilder.parse(new InputSource(new StringReader(elem))).getDocumentElement();
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
Node node = doc.getDocumentElement();
XPathHelper helper = new XPathHelper(node);
MetadataType meta = getMetadataTypeFromResource(helper);
MetadataProfile meta = getMetadataProfileFromResource(doc, helper);
list.add(meta);
}catch(Exception e){
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, ",e);
logger.error("Error while trying to fetch resource with secondary type "+secondaryType+" from the infrastructure, scope: "+scopeString,e);
}
}
}
@ -110,41 +117,51 @@ public class MetadataFormatDiscovery {
*
* @param helper the helper
* @return the metadata type from resource
* @throws ApplicationProfileNotFoundException the application profile not found exception
* @throws MetadataProfileNotFoundException the application profile not found exception
*/
private MetadataType getMetadataTypeFromResource(XPathHelper helper) throws ApplicationProfileNotFoundException{
private MetadataProfile getMetadataProfileFromResource(Document doc, XPathHelper helper) throws MetadataProfileNotFoundException{
try {
MetadataType metaType = new MetadataType();
MetadataProfile metadataProfile = new MetadataProfile();
List<String> id = helper.evaluate("/Resource/ID/text()");
if(id==null || id.isEmpty())
throw new ApplicationProfileNotFoundException("Resource ID not found for "+helper.toString());
throw new MetadataProfileNotFoundException("Resource ID not found for "+helper.toString());
else{
metaType.setId(id.get(0));
metadataProfile.setId(id.get(0));
}
List<String> name = helper.evaluate("/Resource/Profile/Name/text()");
if(name==null || name.isEmpty())
throw new ApplicationProfileNotFoundException("Resource Name not found for "+helper.toString());
throw new MetadataProfileNotFoundException("Resource Name not found for Resource Id: "+metadataProfile.getId());
else
metaType.setName(name.get(0));
metadataProfile.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());
logger.info("Description not found for Resource ID: "+metadataProfile.getId()+", continuing.. ");
else
metaType.setDescription(description.get(0));
metadataProfile.setDescription(description.get(0));
return metaType;
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
XPathExpression expr = xpath.compile("/Resource/Profile/Body/metadataformat/@"+MetadataFormat.LOCAL_NAME_METADATA_TYPE);
String metadataType = (String) expr.evaluate(doc, XPathConstants.STRING);
if(metadataType==null || metadataType.isEmpty())
throw new MetadataProfileNotFoundException("Required attribute '"+MetadataFormat.LOCAL_NAME_METADATA_TYPE+"' not found in the element '"+MetadataFormat.LOCAL_NAME_METADATA_FORMAT+"' for Metadata Profile (with Resource) Id: "+metadataProfile.getId());
else
metadataProfile.setMetadataType(metadataType);
return metadataProfile;
} catch (Exception e) {
logger.error("An error occurred in getListDefaultLayerFromNode ", e);
logger.error("An error occurred in getMetadataProfileFromResource ", e);
return null;
}
@ -186,8 +203,8 @@ public class MetadataFormatDiscovery {
*
* @return the metadataTypes
*/
public List<MetadataType> getMetadataTypes() {
public List<MetadataProfile> getMetadataProfiles() {
return metadataTypes;
return metadataProfiles;
}
}

View File

@ -84,7 +84,7 @@ public class MetadataFormatReader {
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new ApplicationProfileNotFoundException("Your resourceID "+resourceID+" is not registered in the infrastructure, the scope is "+scopeString);
throw new MetadataProfileNotFoundException("Your resourceID "+resourceID+" is not registered in the infrastructure, the scope is "+scopeString);
else {
String theResource = null;
try{

View File

@ -7,14 +7,14 @@ package org.gcube.datacatalogue.metadatadiscovery.reader;
* Jun 7, 2016
*/
@SuppressWarnings("serial")
public class ApplicationProfileNotFoundException extends Exception {
public class MetadataProfileNotFoundException extends Exception {
/**
* Instantiates a new application profile not found exception.
*
* @param message the message
*/
public ApplicationProfileNotFoundException(String message) {
public MetadataProfileNotFoundException(String message) {
super(message);
}
}

View File

@ -4,7 +4,7 @@
package org.gcube.datacatalogue.metadatadiscovery;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
import org.junit.Test;
import org.slf4j.Logger;
@ -31,8 +31,12 @@ public class TestDataCatalogueMetadataFormatReader {
ScopeProvider.instance.set(scopeString);
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
int i = 0;
for (MetadataType mt : reader.getListOfMetadataTypes()) {
MetadataFormat metadataFormat = reader.getMetadataFormatForMetadataType(mt);
for (MetadataProfile mt : reader.getListOfMetadataProfiles()) {
if(mt==null)
continue;
MetadataFormat metadataFormat = reader.getMetadataFormatForMetadataProfile(mt);
logger.trace("\n\n "+ ++i +".) Metadata source: "+metadataFormat.getMetadataSource().substring(0, 100));
}

View File

@ -5,7 +5,7 @@ package org.gcube.datacatalogue.metadatadiscovery;
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.MetadataProfile;
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery;
import org.junit.Test;
@ -30,10 +30,10 @@ public class TestMetadataFormatDiscovery {
try {
ScopeProvider.instance.set(scopeString);
reader = new MetadataFormatDiscovery(scope);
System.out.println(reader.getMetadataTypes());
//System.out.println(reader.getMetadataProfiles());
for (MetadataType type : reader.getMetadataTypes()) {
System.out.println(type);
for (MetadataProfile metaProfile : reader.getMetadataProfiles()) {
System.out.println(metaProfile.getId() +" name: "+metaProfile.getName() +" type: "+metaProfile.getMetadataType());
}
} catch (Exception e) {