created project copying class form gcubedatacatalogue-metadata-discovery

This commit is contained in:
Francesco Mangiacrapa 2020-09-30 10:36:30 +02:00
commit 9380c394f2
35 changed files with 3442 additions and 0 deletions

28
.classpath Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/bin/
/target/

29
.project Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>metadata-profile-discovery</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

View File

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<installed facet="java" version="1.8"/>
</faceted-project>

134
pom.xml Normal file
View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<relativePath />
</parent>
<groupId>org.gcube.common</groupId>
<artifactId>metadata-profile-discovery</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>The Metadata Profile discovery library</name>
<description>The metadata-profile-discovery library is able to build java objects parsing the 'gCube Metadata Profiles' models:
* defined in the contexts (scopes) of the D4Science Infrastructure;
* passed as an input stream;
</description>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<developers>
<developer>
<name>Francesco Mangiacrapa</name>
<email>francesco.mangiacrapa@isti.cnr.it</email>
<organization>CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"</organization>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<!-- FWS -->
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<scope>provided</scope>
</dependency>
<!-- END FWS -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.2.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.11</version>
<scope>provided</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- JUNIT -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<!-- Required to log on tests -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-servicearchive</id>
<phase>package</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,275 @@
package org.gcube.common.metadataprofilediscovery;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.gcube.common.metadataprofilediscovery.bean.MetadataProfile;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
import org.gcube.common.metadataprofilediscovery.reader.MetadataFormatDiscovery;
import org.gcube.common.metadataprofilediscovery.reader.MetadataFormatReader;
import org.gcube.common.metadataprofilediscovery.reader.NamespaceCategoryReader;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* The Class DataCalogueMetadataReader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 8, 2016
*/
public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDiscovery {
private static String SCHEMA_FILENAME = "Gdcmetadataprofilev3.xsd";
private MetadataFormatDiscovery medataFormatDiscovery;
private ScopeBean scope;
private Map<String, MetadataFormat> hashMetadataFormats = null;
private List<NamespaceCategory> namespaceCategories = null;
private String profileSchema = null;
private static Logger logger = LoggerFactory.getLogger(DataCalogueMetadataFormatReader.class);
/**
* Instantiates a new data calogue metadata format reader.
*
* @throws Exception the exception
*/
public DataCalogueMetadataFormatReader() throws Exception {
String scopeString = ScopeProvider.instance.get();
logger.debug("Read scope " + scopeString + " from ScopeProvider");
if (scopeString == null || scopeString.isEmpty())
throw new Exception("Please set a valid scope into ScopeProvider");
scope = new ScopeBean(scopeString);
readNamespaces();
readMetadaFormats();
}
/**
* Read metada formats.
*
* @throws Exception the exception
*/
private void readMetadaFormats() throws Exception {
medataFormatDiscovery = new MetadataFormatDiscovery(scope);
logger.info("MedataFormatDiscovery has retrieved: " + medataFormatDiscovery.getMetadataProfiles().size()
+ " metadata type/s");
logger.debug("filling cache for MedataFormat");
hashMetadataFormats = new HashMap<String, MetadataFormat>(medataFormatDiscovery.getMetadataProfiles().size());
for (MetadataProfile mT : medataFormatDiscovery.getMetadataProfiles()) {
if (mT == null)
continue;
MetadataFormatReader reader = new MetadataFormatReader(scope, mT.getId());
hashMetadataFormats.put(mT.getId(), reader.getMetadataFormat());
logger.debug("MetadataType id: " + mT.getId() + " cached as: " + reader.getMetadataFormat());
}
}
/**
* Read namespaces.
*/
private void readNamespaces() {
try {
if (namespaceCategories == null || namespaceCategories.isEmpty()) {
if (namespaceCategories == null)
namespaceCategories = new ArrayList<NamespaceCategory>();
NamespaceCategoryReader rd = new NamespaceCategoryReader(scope);
namespaceCategories.addAll(rd.getNamespaces().getNamespaceCategories());
}
} catch (Exception e) {
logger.debug("An error occurred during read namespaces for categories: ", e);
}
}
/**
* Gets the profile schema string.
*
* @return the profile schema string
*/
public static String getProfileSchemaString() {
InputStream inputStream = DataCalogueMetadataFormatReader.getProfileSchemaInputStream();
return new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining("\n"));
}
/**
* Gets the profile schema input stream.
*
* @return the profile schema input stream
*/
public static InputStream getProfileSchemaInputStream() {
return DataCalogueMetadataFormatReader.class.getResourceAsStream(SCHEMA_FILENAME);
}
/**
* Gets the profile schema URL.
*
* @return the profile schema URL
*/
public static URL getProfileSchemaURL() {
return DataCalogueMetadataFormatReader.class.getResource(SCHEMA_FILENAME);
}
/**
* Validate against XSD.
*
* @param xml the xml
* @param xsd the xsd
* @throws SAXException the SAX exception
* @throws IOException Signals that an I/O exception has occurred.
*/
static void validateAgainstXSD(Source xml, URL xsd) throws SAXException, IOException {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsd);
Validator validator = schema.newValidator();
validator.validate(xml);
}
/**
* Validate profile.
*
* @param xml the xml
* @throws Exception the exception
*/
public static void validateProfile(InputStream xml) throws Exception {
validateAgainstXSD(new StreamSource(xml), getProfileSchemaURL());
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* getMetadataFormatForMetadataProfile(org.gcube.common.metadataprofilediscovery
* .bean.MetadataProfile)
*/
public MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile profile) throws Exception {
if (profile == null)
throw new Exception("Input " + MetadataProfile.class.getSimpleName() + " is null");
MetadataFormat format = hashMetadataFormats.get(profile.getId());
if (format != null)
return format;
MetadataFormatReader reader = new MetadataFormatReader(scope, profile.getId());
return reader.getMetadataFormat();
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* getListOfMetadataProfiles()
*/
public List<MetadataProfile> getListOfMetadataProfiles() throws Exception {
if (medataFormatDiscovery == null)
readMetadaFormats();
return medataFormatDiscovery.getMetadataProfiles();
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* getListOfNamespaceCategories()
*/
public List<NamespaceCategory> getListOfNamespaceCategories() throws Exception {
if (namespaceCategories == null)
readNamespaces();
return namespaceCategories;
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* resetMetadataProfile()
*/
public void resetMetadataProfile() {
medataFormatDiscovery = null;
hashMetadataFormats = null;
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* resetNamespaceCategories()
*/
public void resetNamespaceCategories() {
namespaceCategories = null;
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* getProfileSchema()
*/
public String getProfileSchema() {
if (profileSchema == null) {
profileSchema = DataCalogueMetadataFormatReader.getProfileSchemaString();
}
return profileSchema;
}
/*
* (non-Javadoc)
*
* @see
* org.gcube.common.metadataprofilediscovery.DataCatalogueMetadataDiscovery#
* validateProfile(java.lang.String)
*/
public void validateProfile(String xmlProfile) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new InputSource(new StringReader(xmlProfile)));
DOMSource source = new DOMSource(doc);
validateAgainstXSD(source, getProfileSchemaURL());
}
}

View File

@ -0,0 +1,79 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
import java.util.List;
import org.gcube.common.metadataprofilediscovery.bean.MetadataProfile;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
/**
* The Interface DataCatalogueMetadataDiscovery.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Sep 30, 2020
*/
public interface DataCatalogueMetadataDiscovery {
/**
* Gets the list of metadata types.
*
* @return the list of metadata types
* @throws Exception the exception
*/
List<MetadataProfile> getListOfMetadataProfiles() throws Exception;
/**
* Gets the list of namespace categories.
*
* @return the list of namespace categories
* @throws Exception the exception
*/
List<NamespaceCategory> getListOfNamespaceCategories() throws Exception;
/**
* Gets the metadata format for metadata type.
*
* @param type the type
* @return the metadata format for metadata type
* @throws Exception the exception
*/
MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile type) throws Exception;
/**
* Reset metadata profile.
* Forces current list of Metadata Profile at null in order to read it from IS againg
*/
void resetMetadataProfile();
/**
* Reset namespace categories.
* Forces current list of Namespace Categories Profile at null in order to read it from IS againg
*/
void resetNamespaceCategories();
/**
* Return the XSD of the profile schema.
*
* @return the String representation of the XSD containing the schema for a profile
*/
String getProfileSchema();
/**
* Validate the xml provided as argument.
*
* @param xmlProfile the string representation of the XML to validate again the schema
* @throws Exception the exception
*/
void validateProfile(String xmlProfile) throws Exception;
}

View File

@ -0,0 +1,19 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
/**
* The Interface Namespace.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2017
*/
public interface Namespace {
public static final String Separator = ":";
public String id = null;
public String name = null;
public String title = null;
public String description = "";
}

View File

@ -0,0 +1,35 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.adapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.gcube.common.metadataprofilediscovery.jaxb.DataType;
/**
* The Class DataTypeAdapter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
public class DataTypeAdapter extends XmlAdapter<String, DataType> {
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
*/
public String marshal(DataType dt) {
return dt.name();
}
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
public DataType unmarshal(String dt) {
return DataType.fromValue(dt);
}
}

View File

@ -0,0 +1,36 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.adapter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.gcube.common.metadataprofilediscovery.jaxb.TaggingGroupingValue;
/**
* The Class TaggingGroupingAdapter.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
*/
public class TaggingGroupingAdapter extends XmlAdapter<String, TaggingGroupingValue> {
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#marshal(java.lang.Object)
*/
public String marshal(TaggingGroupingValue dt) {
return dt.value();
}
/* (non-Javadoc)
* @see javax.xml.bind.annotation.adapters.XmlAdapter#unmarshal(java.lang.Object)
*/
public TaggingGroupingValue unmarshal(String dt) {
return TaggingGroupingValue.fromValue(dt);
}
}

View File

@ -0,0 +1,159 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.bean;
import java.io.Serializable;
/**
* The Class MetadataProfile.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 19, 2017
*/
public class MetadataProfile implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8829173012445264057L;
private String id;
private String name;
private String description;
private String metadataType;
/**
* Instantiates a new metadata type.
*/
public MetadataProfile() {
}
/**
* Instantiates a new metadata type.
*
* @param id the id
* @param name the name
* @param description the description
* @param metadataType the metadata type
*/
public MetadataProfile(String id, String name, String description, String metadataType) {
super();
this.id = id;
this.name = name;
this.description = description;
this.metadataType = metadataType;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets the id.
*
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* Sets the name.
*
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the description.
*
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Gets the metadata type.
*
* @return the metadataType
*/
public String getMetadataType() {
return metadataType;
}
/**
* Sets the metadata type.
*
* @param metadataType the metadataType to set
*/
public void setMetadataType(String metadataType) {
this.metadataType = metadataType;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
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

@ -0,0 +1,54 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* The Enum DataType.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
@XmlType(name = "dataType")
@XmlEnum
public enum DataType {
String,
Time,
Time_Interval,
Times_ListOf,
Text,
Boolean,
Number,
GeoJSON;
/**
* Value.
*
* @return the string
*/
public String value() {
return name();
}
/**
* From value.
*
* @param v the v
* @return the data type
*/
public static DataType fromValue(String v) {
DataType vv;
try{
vv = valueOf(v);
}catch(Exception e){
return DataType.String;
}
return vv;
}
}

View File

@ -0,0 +1,389 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.common.metadataprofilediscovery.Namespace;
import org.gcube.common.metadataprofilediscovery.adapter.DataTypeAdapter;
/**
* The Class MetadataField.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
@XmlRootElement(name="metadatafield")
@XmlAccessorType(XmlAccessType.FIELD)
public class MetadataField implements Serializable{
/**
*
*/
private static final String LOCAL_NAME_CATEGORYREF = "categoryref";
/**
*
*/
private static final long serialVersionUID = 5935573474465015727L;
@XmlAttribute(name=LOCAL_NAME_CATEGORYREF)
private String categoryRef = null; //ITS VALUE IS A CATEGORY-ID
@XmlElement(required = true)
private String fieldName;
@XmlElement(required = true)
private Boolean mandatory = false;
@XmlElement(name = "maxOccurs")
private String maxOccurs;
// private Boolean isBoolean = false;
@XmlJavaTypeAdapter(DataTypeAdapter.class)
private DataType dataType = DataType.String;
private String defaultValue;
private String note;
//It's the list of eligible values;
@XmlElement(name = "vocabulary")
private MetadataVocabulary vocabulary;
@XmlElement(name = "validator")
private MetadataValidator validator;
@XmlElement(name = "tagging")
private MetadataTagging tagging;
@XmlElement(name = "grouping")
private MetadataGrouping grouping;
/**
* Instantiates a new metadata field.
*/
public MetadataField() {
}
/**
* Instantiates a new metadata field.
*
* @param fieldName the field name
* @param mandatory the mandatory
*/
public MetadataField(String fieldName, Boolean mandatory) {
super();
this.fieldName = fieldName;
this.mandatory = mandatory;
}
/**
* Instantiates a new metadata field.
*
* @param fieldName the field name
* @param mandatory the mandatory
* @param categoryID the category id
*/
public MetadataField(String fieldName, Boolean mandatory, String categoryID) {
super();
this.fieldName = fieldName;
this.mandatory = mandatory;
setCategoryRefToCategoryId(categoryID);
}
/**
* Gets the category ref. If exists its value is a Category-ID
*
* @return the categoryRef
*/
public String getCategoryRef() {
return categoryRef;
}
/**
* Sets the category ref to category id.
*
* @param categoryID the new category ref to category id
*/
public void setCategoryRefToCategoryId(String categoryID) {
this.categoryRef = categoryID;
}
/**
* Gets the category field qualified name.
*
* If the Metadata Field belongs to a category, returns the qualified name: {@link MetadataField#categoryRef} {@link Namespace#Separator}} fieldName;
* Otherwise returns the fieldName
*
* @return the category q name
*/
public String getCategoryFieldQName(){
return categoryRef==null?fieldName:categoryRef+Namespace.Separator+fieldName;
}
/**
* Gets the field name.
*
* @return the fieldName
*/
public String getFieldName() {
return fieldName;
}
/**
* Gets the mandatory.
*
* @return the mandatory
*/
public Boolean getMandatory() {
return mandatory;
}
/**
* Gets the data type.
*
* @return the dataType
*/
public DataType getDataType() {
return dataType;
}
/**
* Gets the max occurs.
*
* @return the maxOccurs
*/
public String getMaxOccurs() {
return maxOccurs;
}
/**
* @param maxOccurs the maxOccurs to set
*/
public void setMaxOccurs(String maxOccurs) {
this.maxOccurs = maxOccurs;
}
/**
* Gets the default value.
*
* @return the defaultValue
*/
public String getDefaultValue() {
return defaultValue;
}
/**
* Gets the note.
*
* @return the note
*/
public String getNote() {
return note;
}
/**
* Gets the vocabulary.
*
* @return the vocabulary
*/
public MetadataVocabulary getVocabulary() {
return vocabulary;
}
/**
* Gets the validator.
*
* @return the validator
*/
public MetadataValidator getValidator() {
return validator;
}
/**
* Gets the tagging.
*
* @return the tagging
*/
public MetadataTagging getTagging() {
return tagging;
}
/**
* Gets the grouping.
*
* @return the grouping
*/
public MetadataGrouping getGrouping() {
return grouping;
}
/**
* Sets the field name.
*
* @param fieldName the fieldName to set
*/
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
/**
* Sets the mandatory.
*
* @param mandatory the mandatory to set
*/
public void setMandatory(Boolean mandatory) {
this.mandatory = mandatory;
}
/**
* Sets the data type.
*
* @param dataType the dataType to set
*/
public void setDataType(DataType dataType) {
this.dataType = dataType;
}
/**
* Sets the default value.
*
* @param defaultValue the defaultValue to set
*/
public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}
/**
* Sets the note.
*
* @param note the note to set
*/
public void setNote(String note) {
this.note = note;
}
/**
* Sets the vocabulary.
*
* @param vocabulary the vocabulary to set
*/
public void setVocabulary(MetadataVocabulary vocabulary) {
this.vocabulary = vocabulary;
}
/**
* Sets the validator.
*
* @param validator the validator to set
*/
public void setValidator(MetadataValidator validator) {
this.validator = validator;
}
/**
* Sets the tagging.
*
* @param tagging the tagging to set
*/
public void setTagging(MetadataTagging tagging) {
this.tagging = tagging;
}
/**
* Sets the grouping.
*
* @param grouping the grouping to set
*/
public void setGrouping(MetadataGrouping grouping) {
this.grouping = grouping;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataField [categoryRef=");
builder.append(categoryRef);
builder.append(", fieldName=");
builder.append(fieldName);
builder.append(", mandatory=");
builder.append(mandatory);
builder.append(", maxOccurs=");
builder.append(maxOccurs);
builder.append(", dataType=");
builder.append(dataType);
builder.append(", defaultValue=");
builder.append(defaultValue);
builder.append(", note=");
builder.append(note);
builder.append(", vocabulary=");
builder.append(vocabulary);
builder.append(", validator=");
builder.append(validator);
builder.append(", tagging=");
builder.append(tagging);
builder.append(", grouping=");
builder.append(grouping);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,142 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
/**
* The Class MetadataFormat.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
@XmlRootElement(name="metadataformat")
@XmlAccessorType(XmlAccessType.FIELD)
public class MetadataFormat implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5881074882343424963L;
public static final String LOCAL_NAME_METADATA_TYPE = "type";
public static final String LOCAL_NAME_METADATA_FORMAT = "metadataformat";
/**
* Instantiates a new metadata format.
*/
public MetadataFormat() {
}
@XmlElement(name = "metadatafield")
private List<MetadataField> metadataFields;
@XmlAttribute(name = LOCAL_NAME_METADATA_TYPE, required=true)
private String type = "";
@XmlTransient
private String metadataSource = null;
/**
* Gets the metadata fields.
*
* @return the metadataFields
*/
public List<MetadataField> getMetadataFields() {
return metadataFields;
}
/**
* Gets the type.
*
* @return the type
*/
public String getType() {
return type;
}
/**
* Sets the type.
*
* @param type the type to set
*/
public void setType(String type) {
this.type = type;
}
/**
* Adds the metadata.
*
* @param Field the field
*/
public void addMetadata(MetadataField Field){
if(this.metadataFields==null)
this.metadataFields = new ArrayList<MetadataField>();
this.metadataFields.add(Field);
}
/**
* Gets the metadata source.
*
* @return the metadata source
*/
public String getMetadataSource() {
return metadataSource;
}
/**
* Sets the metadata source.
*
* @param metadataSource the new metadata source
*/
public void setMetadataSource(String metadataSource) {
this.metadataSource = metadataSource;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataFormat [metadataFields=");
builder.append(metadataFields);
builder.append(", type=");
builder.append(type);
builder.append(", metadataSource=");
builder.append(metadataSource);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,144 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.common.metadataprofilediscovery.adapter.TaggingGroupingAdapter;
/**
* The Class MetadataGrouping.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
*/
@XmlRootElement(name = "grouping")
@XmlAccessorType (XmlAccessType.FIELD)
public class MetadataGrouping implements Serializable{
/**
*
*/
private static final long serialVersionUID = 4684835556193102991L;
@XmlAttribute
private Boolean create = false;
@XmlAttribute
private Boolean propagateUp = false;
@XmlJavaTypeAdapter(TaggingGroupingAdapter.class)
@XmlValue
private TaggingGroupingValue groupingValue = null;
/**
* Instantiates a new metadata grouping.
*/
public MetadataGrouping() {
}
/**
* Instantiates a new metadata grouping.
*
* @param create the create
* @param groupingValue the grouping value
*/
public MetadataGrouping(Boolean create, TaggingGroupingValue groupingValue) {
this.create = create;
this.groupingValue = groupingValue;
}
/**
* Gets the creates the.
*
* @return the create
*/
public Boolean getCreate() {
return create;
}
/**
* Gets the grouping value.
*
* @return the groupingValue
*/
public TaggingGroupingValue getGroupingValue() {
return groupingValue;
}
/**
* Sets the creates the.
*
* @param create the create to set
*/
public void setCreate(Boolean create) {
this.create = create;
}
/**
* Sets the grouping value.
*
* @param groupingValue the groupingValue to set
*/
public void setGroupingValue(TaggingGroupingValue groupingValue) {
this.groupingValue = groupingValue;
}
/**
* @return the propagateUp
*/
public Boolean getPropagateUp() {
return propagateUp;
}
/**
* @param propagateUp the propagateUp to set
*/
public void setPropagateUp(Boolean propagateUp) {
this.propagateUp = propagateUp;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataGrouping [create=");
builder.append(create);
builder.append(", propagateUp=");
builder.append(propagateUp);
builder.append(", groupingValue=");
builder.append(groupingValue);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,155 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.gcube.common.metadataprofilediscovery.adapter.TaggingGroupingAdapter;
/**
* The Class MetadataTagging.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
*/
@XmlRootElement(name = "tagging")
@XmlAccessorType (XmlAccessType.FIELD)
public class MetadataTagging implements Serializable{
public static final String DEFAULT_SEPARATOR = "-";
/**
*
*/
private static final long serialVersionUID = 641412896487091012L;
@XmlAttribute
private Boolean create = false;
@XmlAttribute
private String separator = DEFAULT_SEPARATOR;
@XmlJavaTypeAdapter(TaggingGroupingAdapter.class)
@XmlValue
private TaggingGroupingValue taggingValue = null;
/**
* Instantiates a new metadata tagging.
*/
public MetadataTagging() {
}
/**
* Instantiates a new metadata tagging.
*
* @param create the create
* @param separator the separator
* @param taggingValue the tagging value
*/
public MetadataTagging(Boolean create, String separator, TaggingGroupingValue taggingValue) {
super();
this.create = create;
this.separator = separator;
this.taggingValue = taggingValue;
}
/**
* Gets the creates the.
*
* @return the create
*/
public Boolean getCreate() {
return create;
}
/**
* Gets the separator.
*
* @return the separator
*/
public String getSeparator() {
return separator;
}
/**
* Gets the tagging value.
*
* @return the taggingValue
*/
public TaggingGroupingValue getTaggingValue() {
return taggingValue;
}
/**
* Sets the creates the.
*
* @param create the create to set
*/
public void setCreate(Boolean create) {
this.create = create;
}
/**
* Sets the separator.
*
* @param separator the separator to set
*/
public void setSeparator(String separator) {
this.separator = separator;
}
/**
* Sets the tagging value.
*
* @param taggingValue the taggingValue to set
*/
public void setTaggingValue(TaggingGroupingValue taggingValue) {
this.taggingValue = taggingValue;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataTagging [create=");
builder.append(create);
builder.append(", separator=");
builder.append(separator);
builder.append(", taggingValue=");
builder.append(taggingValue);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,81 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class MetadataValidator.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
@XmlRootElement(name = "metadatavalidator")
@XmlAccessorType (XmlAccessType.FIELD)
public class MetadataValidator implements Serializable{
private static final long serialVersionUID = -5394122378302593873L;
private String regularExpression;
/**
* Instantiates a new metadata validator.
*/
public MetadataValidator() {
}
/**
* Instantiates a new metadata validator.
*
* @param regularExpression the regular expression
*/
public MetadataValidator(String regularExpression) {
super();
this.regularExpression = regularExpression;
}
/**
* Gets the regular expression.
*
* @return the regularExpression
*/
public String getRegularExpression() {
return regularExpression;
}
/**
* Sets the regular expression.
*
* @param regularExpression the regularExpression to set
*/
public void setRegularExpression(String regularExpression) {
this.regularExpression = regularExpression;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataValidator [regularExpression=");
builder.append(regularExpression);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,143 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class MetadataVocabulary.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 12, 2016
*/
@XmlRootElement(name = "metadatavocabulary")
@XmlAccessorType (XmlAccessType.FIELD)
public class MetadataVocabulary implements Serializable{
/**
*
*/
private static final long serialVersionUID = 506451021936766592L;
private List<String> vocabularyField;
@XmlAttribute
private Boolean isMultiSelection = false;
/**
* Instantiates a new metadata vocabulary.
*/
public MetadataVocabulary() {
}
/**
* Instantiates a new metadata vocabulary.
*
* @param vocabularyFields the vocabulary fields
*/
public MetadataVocabulary(List<String> vocabularyFields) {
super();
this.vocabularyField = vocabularyFields;
}
/**
* Instantiates a new metadata vocabulary.
*
* @param vocabularyField the vocabulary field
* @param isMultiSelection the is multi selection
*/
public MetadataVocabulary(List<String> vocabularyField, Boolean isMultiSelection) {
super();
this.vocabularyField = vocabularyField;
this.isMultiSelection = isMultiSelection;
}
/**
* Gets the vocabulary fields.
*
* @return the vocabularyField
*/
public List<String> getVocabularyFields() {
return vocabularyField;
}
/**
* Sets the vocabulary field.
*
* @param vocabularyField the vocabularyField to set
*/
public void setVocabularyField(List<String> vocabularyField) {
this.vocabularyField = vocabularyField;
}
/**
* Gets the vocabulary field.
*
* @return the vocabularyField
*/
public List<String> getVocabularyField() {
return vocabularyField;
}
/**
* Checks if is multi selection.
*
* @return the isMultiSelection
*/
public Boolean isMultiSelection() {
return isMultiSelection;
}
/**
* Sets the checks if is multi selection.
*
* @param isMultiSelection the isMultiSelection to set
*/
public void setIsMultiSelection(Boolean isMultiSelection) {
this.isMultiSelection = isMultiSelection;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("MetadataVocabulary [vocabularyField=");
builder.append(vocabularyField);
builder.append(", isMultiSelection=");
builder.append(isMultiSelection);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,85 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* The Class NamespaceCategories.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 19, 2017
*/
@XmlRootElement(name="namespaces")
@XmlAccessorType(XmlAccessType.FIELD)
public class NamespaceCategories {
@XmlElement(name = "namespace")
private List<NamespaceCategory> namespaceCategories;
/**
* Instantiates a new namespace categories.
*/
public NamespaceCategories() {
}
/**
* Instantiates a new namespace categories.
*
* @param namespaceCategories the namespace categories
*/
public NamespaceCategories(List<NamespaceCategory> namespaceCategories) {
this.namespaceCategories = namespaceCategories;
}
/**
* Gets the namespace categories.
*
* @return the namespaceCategories
*/
public List<NamespaceCategory> getNamespaceCategories() {
return namespaceCategories;
}
/**
* Sets the namespace categories.
*
* @param namespaceCategories the namespaceCategories to set
*/
public void setNamespaceCategories(List<NamespaceCategory> namespaceCategories) {
this.namespaceCategories = namespaceCategories;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NamespaceCategories [namespaceCategories=");
builder.append(namespaceCategories);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,182 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlID;
import javax.xml.bind.annotation.XmlRootElement;
import org.gcube.common.metadataprofilediscovery.Namespace;
/**
* The Class NamespaceCategory.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 19, 2017
*/
@XmlRootElement(name = "namespace")
@XmlAccessorType (XmlAccessType.FIELD)
public class NamespaceCategory implements Namespace, Serializable{
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -1632300992065668875L;
@XmlAttribute(required = true)
@XmlID
private String id = null;
@XmlElement(required = true)
private String name = null;
@XmlElement(required = true)
private String title = null;
private String description = "";
/**
* Instantiates a new namespace category.
*/
public NamespaceCategory() {
}
/**
* Instantiates a new namespace category.
*
* @param id the id
* @param name the name
* @param title the title
*/
public NamespaceCategory(String id, String name, String title) {
super();
this.id = id;
this.name = name;
this.title = title;
}
/**
* Instantiates a new namespace category.
*
* @param id the id
* @param name the name
* @param title the title
* @param description the description
*/
public NamespaceCategory(String id, String name, String title, String description) {
super();
this.id = id;
this.name = name;
this.title = title;
this.description = description;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Gets the title.
*
* @return the title
*/
public String getTitle() {
return title;
}
/**
* Gets the description.
*
* @return the description
*/
public String getDescription() {
return description;
}
/**
* Sets the id.
*
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* Gets the namespace category qualifier name. The QName is a unique name to identify the category. It corresponds to {@link NamespaceCategory#id}
* @return the namespace category q name
*/
public String getNamespaceCategoryQName(){
return id;
}
/**
* Sets the title.
*
* @param title the title to set
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Sets the description.
*
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NamespaceCategory [id=");
builder.append(id);
builder.append(", name=");
builder.append(name);
builder.append(", title=");
builder.append(title);
builder.append(", description=");
builder.append(description);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,65 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.jaxb;
import javax.xml.bind.annotation.XmlEnum;
/**
* The Enum TaggingGroupingValue.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Mar 21, 2017
*/
@XmlEnum
public enum TaggingGroupingValue {
onFieldName("onFieldName"),
onValue("onValue"),
onFieldName_onValue("onFieldName_onValue"),
onValue_onFieldName("onValue_onFieldName");
private String value;
/**
* Instantiates a new tagging grouping value.
*
* @param value the value
*/
TaggingGroupingValue(String value) {
this.value = value;
}
/**
* Value.
*
* @return the string
*/
public String value() {
return this.value;
}
/**
* From value.
*
* @param value the value
* @return the TaggingGroupingValue matching the input value or default value {@link TaggingGroupingValue#onValue}
*/
public static TaggingGroupingValue fromValue(String value) {
try{
for (TaggingGroupingValue tgv : TaggingGroupingValue.values()) {
if(tgv.value.equals(value))
return tgv;
}
}catch(Exception e){
return TaggingGroupingValue.onValue;
}
return TaggingGroupingValue.onValue;
}
}

View File

@ -0,0 +1,197 @@
package org.gcube.common.metadataprofilediscovery.reader;
import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.StringReader;
import java.util.ArrayList;
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.metadataprofilediscovery.bean.MetadataProfile;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.impl.ScopeBean;
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;
/**
* The Class MedataFormatDiscovery.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
public class MetadataFormatDiscovery {
private static Logger logger = LoggerFactory.getLogger(MetadataFormatDiscovery.class);
public static final String DATA_CATALOGUE_METADATA_SECONDARY_TYPE = "DataCatalogueMetadata";
private String secondaryType;
private ScopeBean scope;
private List<MetadataProfile> metadataProfiles;
/**
* Instantiates a new medata format reader.
*
* @param scope - the scope to be searched
* @throws Exception the exception
*/
public MetadataFormatDiscovery(ScopeBean scope) throws Exception {
this.scope = scope;
this.secondaryType = DATA_CATALOGUE_METADATA_SECONDARY_TYPE;
this.metadataProfiles = readMetadataProfilesFromInfrastrucure();
}
/**
* this method looks up the applicationProfile profile among the ones available in the infrastructure.
*
* @return the applicationProfile profile
* @throws Exception the exception
*/
private List<MetadataProfile> readMetadataProfilesFromInfrastrucure() throws Exception {
logger.trace("read secondary type: "+secondaryType);
if(this.scope==null)
throw new Exception("Scope is null");
String scopeString = this.scope.toString();
logger.trace("read scope: "+scopeString);
List<MetadataProfile> list = new ArrayList<MetadataProfile>();
try {
// ScopeProvider.instance.set(scopeString);
// logger.info("scope provider set instance: "+scopeString);
// ScopeProvider.instance.set(scopeString);
logger.info("Using scope from ScopeProvider: "+scopeString);
String queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryType(secondaryType);
logger.trace("queryString: " +queryString);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> metaProfile = client.submit(q);
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 : metaProfile) {
try{
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = docBuilder.parse(new InputSource(new StringReader(elem)));
Node node = doc.getDocumentElement();
XPathHelper helper = new XPathHelper(node);
MetadataProfile meta = getMetadataProfileFromResource(doc, helper);
list.add(meta);
}catch(Exception e){
logger.error("Error while trying to fetch resource with secondary type "+secondaryType+" from the infrastructure, scope: "+scopeString,e);
}
}
}
} catch (Exception e) {
logger.error("Error while trying to fetch applicationProfile "+secondaryType+" from the infrastructure, "+e);
return list;
}
return list;
}
/**
* Gets the metadata type from resource.
*
* @param helper the helper
* @return the metadata type from resource
* @throws MetadataProfileNotFoundException the application profile not found exception
*/
private MetadataProfile getMetadataProfileFromResource(Document doc, XPathHelper helper) throws MetadataProfileNotFoundException{
try {
MetadataProfile metadataProfile = new MetadataProfile();
List<String> id = helper.evaluate("/Resource/ID/text()");
if(id==null || id.isEmpty())
throw new MetadataProfileNotFoundException("Resource ID not found for "+helper.toString());
else{
metadataProfile.setId(id.get(0));
}
List<String> name = helper.evaluate("/Resource/Profile/Name/text()");
if(name==null || name.isEmpty())
throw new MetadataProfileNotFoundException("Resource Name not found for Resource Id: "+metadataProfile.getId());
else
metadataProfile.setName(name.get(0));
logger.info("Building Profile for Resource Name: "+metadataProfile.getName());
List<String> description = helper.evaluate("/Resource/Profile/Description/text()");
if(description==null || description.isEmpty())
logger.info("Description not found for Resource ID: "+metadataProfile.getId()+", continuing.. ");
else
metadataProfile.setDescription(description.get(0));
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 (within Resource) Id: "+metadataProfile.getId());
else
metadataProfile.setMetadataType(metadataType);
return metadataProfile;
} catch (Exception e) {
logger.error("An error occurred in getMetadataProfileFromResource ", e);
return null;
}
}
/**
* 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<MetadataProfile> getMetadataProfiles() {
return metadataProfiles;
}
}

View File

@ -0,0 +1,258 @@
package org.gcube.common.metadataprofilediscovery.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.metadataprofilediscovery.jaxb.MetadataField;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.impl.ScopeBean;
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.Node;
import org.xml.sax.InputSource;
/**
* The Class MetadataFormatReader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 19, 2017
*/
public class MetadataFormatReader {
private static Logger logger = LoggerFactory.getLogger(MetadataFormatReader.class);
private ScopeBean scope;
private MetadataFormat metadataFormat;
private String resourceID;
/**
* Instantiates a new medata format reader.
*
* @param scope the scope
* @param resourceID the resource id
* @throws Exception the exception
*/
public MetadataFormatReader(ScopeBean scope, String resourceID) throws Exception {
this.scope = scope;
this.resourceID = resourceID;
this.metadataFormat = getMetadataFormatByResourceID(resourceID);
}
/**
* Gets the metadata format by id.
*
* @param resourceID the resource id
* @return the metadata format by id
* @throws Exception the exception
*/
private MetadataFormat getMetadataFormatByResourceID(String resourceID) throws Exception {
logger.trace("Getting MedataFormat for resourceID: "+resourceID);
if(this.scope==null)
throw new Exception("Scope is null");
String scopeString = this.scope.toString();
logger.trace("read scope: "+scopeString);
MetadataFormat mf = new MetadataFormat();
try {
logger.info("Using scope from ScopeProvider: "+scopeString);
String queryString = QueryForResourceUtil.queryForGenericResourceById(resourceID);
logger.trace("queryString: " +queryString);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new MetadataProfileNotFoundException("Your resourceID "+resourceID+" is not registered in the infrastructure, the scope is "+scopeString);
else {
String theResource = null;
try{
theResource = appProfile.get(0);
// logger.trace("Resource with resourceID "+resourceID+" matched "+theResource);
logger.debug("Resource (Metadata Format) 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);
logger.debug("Unmarshalling it..");
mf = getMetadataFormatFromResource(helper);
String metadataSource = getMetadataFormatSourceFromResource(helper);
mf.setMetadataSource(metadataSource);
}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 resourceID "+resourceID+" from the infrastructure, the scope is "+scopeString,e);
return mf;
} finally{
// ScopeProvider.instance.reset();
}
return mf;
}
/**
* Gets the metadata format source from resource.
*
* @param helper the helper
* @return the metadata format source from resource
* @throws Exception the exception
*/
private String getMetadataFormatSourceFromResource(XPathHelper helper) throws Exception{
try {
List<String> metadataFormatSource = helper.evaluate("/Resource/Profile/Body/metadataformat");
if(metadataFormatSource==null || metadataFormatSource.isEmpty())
throw new Exception("metadataformat not found in the body, consider to add <metadataformat>");
return metadataFormatSource.get(0);
}catch(Exception e){
logger.error("An error occurred in getMetadataFormatSourceFromResource ", e);
return null;
}
}
/**
* Gets the metadata format from resource.
*
* @param helper the helper
* @return the metadata format from resource
* @throws Exception the exception
*/
private MetadataFormat getMetadataFormatFromResource(XPathHelper helper) throws Exception{
try {
List<String> metadataFormatSource = helper.evaluate("/Resource/Profile/Body/metadataformat");
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
if(metadataFormatSource==null || metadataFormatSource.size()==0)
throw new Exception("Resource does not contain <metadataformat> in the body");
InputStream stream = new ByteArrayInputStream(metadataFormatSource.get(0).getBytes());
MetadataFormat mtdf = (MetadataFormat) jaxbUnmarshaller.unmarshal(stream);
logger.debug("returning metadata format with medata type: "+mtdf.getType());
return mtdf;
}catch(Exception e){
logger.error("An error occurred in getMetadataFormatSourceFromResource ", e);
return null;
}
}
/**
* Gets the metadata fields from resource.
*
* @param helper the helper
* @return the metadata fields from resource
* @throws Exception the exception
*/
private List<MetadataField> getMetadataFieldsFromResource(XPathHelper helper) throws Exception{
try {
List<String> metadatafields = helper.evaluate("/Resource/Profile/Body/metadataformat/metadatafield");
if(metadatafields==null || metadatafields.isEmpty())
throw new Exception("Metadata fields not found");
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");
}
}
return mfs;
} catch (Exception e) {
logger.error("An error occurred in getMetadataFieldsFromResource ", e);
return null;
}
}
/**
* Gets the scope.
*
* @return the scope
*/
public ScopeBean getScope() {
return scope;
}
/**
* Gets the metadata format.
*
* @return the metadataFormat
*/
public MetadataFormat getMetadataFormat() {
return metadataFormat;
}
/**
* Gets the resource id.
*
* @return the resourceID
*/
public String getResourceID() {
return resourceID;
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.common.metadataprofilediscovery.reader;
/**
* The Class ApplicationProfileNotFoundException.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 7, 2016
*/
@SuppressWarnings("serial")
public class MetadataProfileNotFoundException extends Exception {
/**
* Instantiates a new application profile not found exception.
*
* @param message the message
*/
public MetadataProfileNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,167 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.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.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.metadataprofilediscovery.jaxb.NamespaceCategories;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.impl.ScopeBean;
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.Node;
import org.xml.sax.InputSource;
/**
* The Class NamespaceCategoryReader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2017
*/
public class NamespaceCategoryReader {
private static Logger logger = LoggerFactory.getLogger(NamespaceCategoryReader.class);
private static final String GENERIC_RESOURCE_NAMESPACES_NAME = "Namespaces Catalogue Categories";
private static final String GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE = "DataCatalogueNamespace";
private ScopeBean scope;
private NamespaceCategories namespaces;
/**
* Instantiates a new medata format reader.
*
* @param scope the scope
* @throws Exception the exception
*/
public NamespaceCategoryReader(ScopeBean scope) throws Exception {
this.scope = scope;
readNamespaceCategory();
}
/**
* Gets the metadata format by id.
*
* @return the metadata format by id
* @throws Exception the exception
*/
private void readNamespaceCategory() throws Exception {
logger.trace("Getting Namespace Category");
if(this.scope==null)
throw new Exception("Scope is null");
String scopeString = this.scope.toString();
logger.trace("read scope: "+scopeString);
namespaces = new NamespaceCategories();
try {
logger.info("Using scope from ScopeProvider: "+scopeString);
String queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryTypeAndName(GENERIC_RESOURCE_NAMESPACES_NAME, GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE);
logger.trace("queryString: " +queryString);
Query q = new QueryBox(queryString);
DiscoveryClient<String> client = client();
List<String> appProfile = client.submit(q);
if (appProfile == null || appProfile.size() == 0)
throw new MetadataProfileNotFoundException("Your resource is not registered in the infrastructure, the scope is "+scopeString);
else {
String theResource = null;
try{
theResource = appProfile.get(0);
logger.debug("Resource (Namespaces Catalogue Categories) found");
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Node node = docBuilder.parse(new InputSource(new StringReader(theResource))).getDocumentElement();
XPathHelper helper = new XPathHelper(node);
logger.debug("Unmarshalling it..");
readNamespaceCategoryFromResource(helper);
}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 resource with name " + GENERIC_RESOURCE_NAMESPACES_NAME + " and secondary type " + GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE +
" from the infrastructure, the scope is "+scopeString, e);
throw new Exception("Error while trying to fetch resource with name " + GENERIC_RESOURCE_NAMESPACES_NAME + " and secondary type " + GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE +
" from the infrastructure, the scope is "+scopeString, e);
} finally{
}
}
/**
* Read namespace category from resource.
*
* @param helper the helper
* @throws Exception the exception
*/
private void readNamespaceCategoryFromResource(XPathHelper helper) throws Exception{
try {
List<String> namespaceSources = helper.evaluate("/Resource/Profile/Body/namespaces");
JAXBContext jaxbContext = JAXBContext.newInstance(NamespaceCategories.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
if(namespaceSources==null || namespaceSources.size()==0){
throw new Exception("Resource does not contain <namespaces> <namespace>...</namespace> </namespaces> in the body");
}
InputStream stream = new ByteArrayInputStream(namespaceSources.get(0).getBytes());
namespaces = (NamespaceCategories) jaxbUnmarshaller.unmarshal(stream);
}catch(Exception e){
String error = "An error occurred in readNamespaceCategoryFromResource " + e.getMessage();
logger.error("An error occurred in readNamespaceCategoryFromResource ", e);
throw new Exception(error);
}
}
/**
* Gets the namespaces.
*
* @return the namespaces
*/
public NamespaceCategories getNamespaces() {
return namespaces;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("NamespaceCategoryReader [scope=");
builder.append(scope);
builder.append(", namespaces=");
builder.append(namespaces);
builder.append("]");
return builder.toString();
}
}

View File

@ -0,0 +1,8 @@
package org.gcube.common.metadataprofilediscovery.reader;
@SuppressWarnings("serial")
public class PropertyFileNotFoundException extends Exception {
public PropertyFileNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,58 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery.reader;
/**
* The Class QueryForResourceUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Apr 26, 2017
*/
public class QueryForResourceUtil {
/**
* Query for generic resource by id. Returns a query string to get a generic resource by input resource id
*
* @param resourceId the resource id
* @return the string
*/
public static synchronized String queryForGenericResourceById(String resourceId){
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 gcube generic query string for secondary type.
*
* @param secondaryType the secondary type
* @return the gcube generic query string for secondary type
*/
public static synchronized String getGcubeGenericQueryStringForSecondaryType(String secondaryType){
return "for $profile in collection('/db/Profiles/GenericResource')//Resource" +
" where $profile/Profile/SecondaryType/string() eq '"+secondaryType+"'" +
" return $profile";
}
/**
* Gets the gcube generic query string for secondary type.
* @param name the resource name
* @param secondaryType the secondary type
* @return the gcube generic query string for secondary type
*/
public static String getGcubeGenericQueryStringForSecondaryTypeAndName(String name, String secondaryType){
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
"where $profile/Profile/SecondaryType/string() eq '" + secondaryType + "' and $profile/Profile/Name/string() " +
" eq '" + name + "'" +
"return $profile";
}
}

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="metadataformat">
<xs:complexType>
<xs:sequence>
<xs:element name="metadatafield" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="fieldName" />
<xs:element type="xs:boolean" name="mandatory"
minOccurs="0" maxOccurs="1" />
<xs:element name="dataType">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="String" />
<xs:enumeration value="Time" />
<xs:enumeration value="Time_Interval" />
<xs:enumeration value="Times_ListOf" />
<xs:enumeration value="Text" />
<xs:enumeration value="Boolean" />
<xs:enumeration value="Number" />
<xs:enumeration value="GeoJSON" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element type="xs:string" name="maxOccurs"
minOccurs="0" maxOccurs="1" />
<xs:element type="xs:string" name="defaultValue"
minOccurs="0" maxOccurs="1" />
<xs:element type="xs:string" name="note" minOccurs="0"
maxOccurs="1" />
<xs:element name="vocabulary" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="vocabularyField"
minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
<xs:attribute type="xs:boolean" name="isMultiSelection" />
</xs:complexType>
</xs:element>
<xs:element name="validator" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="regularExpression" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="tagging" type="TaggingType"
minOccurs="0" maxOccurs="1">
</xs:element>
<xs:element name="grouping" type="GroupingType"
minOccurs="0" maxOccurs="1">
</xs:element>
</xs:sequence>
<xs:attribute name="categoryref" use="optional" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="NotEmpty" use="required" name="type" />
</xs:complexType>
</xs:element>
<xs:simpleType name="TaggingGroupingValue">
<xs:restriction base="xs:string">
<xs:enumeration value="onFieldName" />
<xs:enumeration value="onValue" />
<xs:enumeration value="onFieldName_onValue" />
<xs:enumeration value="onValue_onFieldName" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="TaggingType">
<xs:simpleContent>
<xs:extension base="TaggingGroupingValue">
<xs:attribute type="xs:boolean" name="create" />
<xs:attribute type="NotEmpty" name="separator" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="GroupingType">
<xs:simpleContent id="TaggingGroupingValue">
<xs:extension base="TaggingGroupingValue">
<xs:attribute type="xs:boolean" name="create" />
<xs:attribute type="xs:boolean" name="propagateUp" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="NotEmpty">
<xs:restriction base="xs:string">
<xs:minLength value="1" />
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:category="http://www.w3.org/TR/html4/">
<xs:element name="namespaces">
<xs:complexType>
<xs:sequence>
<xs:element name="namespace" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name" minOccurs="1"
maxOccurs="1" />
<xs:element type="xs:string" name="title" minOccurs="1"
maxOccurs="1" />
<xs:element type="xs:string" name="description"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
<xs:attribute type="xs:string" name="id" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:unique name="unique-namespace-id">
<xs:selector xpath="namespace" />
<xs:field xpath="@id" />
</xs:unique>
</xs:element>
</xs:schema>

View File

@ -0,0 +1,70 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
import java.io.InputStream;
import java.util.List;
import org.gcube.common.metadataprofilediscovery.bean.MetadataProfile;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
import org.gcube.common.scope.api.ScopeProvider;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class TestDataCatalogueMetadataFormatReader.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
public class TestDataCatalogueMetadataFormatReader {
private static final Logger logger = LoggerFactory.getLogger(TestDataCatalogueMetadataFormatReader.class);
/**
* Test.
*/
// @Test
public void test() {
try {
String scopeString = "/gcube/devsec/devVRE";
ScopeProvider.instance.set(scopeString);
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
int i = 0;
List<NamespaceCategory> categs = reader.getListOfNamespaceCategories();
for (NamespaceCategory namespaceCategory : categs) {
logger.trace("\n\n "+ ++i +".) Category: "+namespaceCategory);
}
i = 0;
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));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String PROFILE_EXAMPLE_FILENAME = "EmptyProfileExample.xml";
// @Test
public void validateAgainstProfileSchema() throws Exception {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(PROFILE_EXAMPLE_FILENAME);
DataCalogueMetadataFormatReader.validateProfile(inputStream);
}
}

View File

@ -0,0 +1,210 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
import java.io.File;
import java.util.ArrayList;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataField;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategories;
import org.gcube.common.metadataprofilediscovery.jaxb.NamespaceCategory;
import org.junit.Test;
/**
* The Class TestJaxbMetadataMarshUnmarsh.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 7, 2016
*/
public class TestJaxbMetadataMarshUnmarsh {
static MetadataField ckanMetadata;
static MetadataFormat metadatas;
static String tmpFileXML = "." + File.separator + "CkanMetadatas.xml";
static String tmpCategoriesXML = "." + File.separator + "NamespacesCatalogueCategories.xml";
private ArrayList<NamespaceCategory> ckanCategories;
public static int MAX_CATEGORIES = 3;
/**
* Test.
*/
// @Test
public void test() {
/*metadatas = new MetadataFormat();
ckanCategories = new ArrayList<MetadataCategory>();
for (int i=0; i<MAX_CATEGORIES; i++) {
ckanCategories.add(new MetadataCategory("cat "+i, "title cat "+i, "description "+i));
}
metadatas.setMetadataCategories(ckanCategories);
ckanMetadata = new MetadataField();
ckanMetadata.setFieldName("Name");
ckanMetadata.setMandatory(true);
ckanMetadata.setDefaultValue("default value");
ckanMetadata.setDataType(DataType.Time);
ckanMetadata.setCategoryRef(ckanCategories.get(new Random().nextInt(MAX_CATEGORIES)).getId());
List<String> vocabulary = new ArrayList<String>();
vocabulary.add("field1");
vocabulary.add("field2");
vocabulary.add("field3");
MetadataVocabulary cvc = new MetadataVocabulary(vocabulary);
ckanMetadata.setVocabulary(cvc);
cvc.setIsMultiSelection(true);
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.setDefaultValue("virtual/public");
ckanMetadata.setTagging(new MetadataTagging(true, ":", TaggingGroupingValue.onValue_onFieldName));
MetadataGrouping grouping = new MetadataGrouping();
grouping.setCreate(true);
grouping.setGroupingValue(TaggingGroupingValue.onValue);
ckanMetadata.setGrouping(grouping);
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();
unMarshalingMetadataFields();
//unMarshalingCategories();
}
catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* Marshaling example.
*
* @throws JAXBException the JAXB exception
*/
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));
}
/**
* Un marshaling example.
*
* @throws JAXBException the JAXB exception
*/
private static void unMarshalingMetadataFields() throws JAXBException
{
//unMarshalingCategories();
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));
System.out.println("Metadata Format");
System.out.println(mtds);
// System.out.println("Metadata Categories");
// if(mtds.getMetadataCategories()!=null){
// for (MetadataCategory cat : mtds.getMetadataCategories()) {
// System.out.println(cat);
// System.out.println(cat.getCategoryQName());
// }
// }
System.out.println("\n\nMetadata Fields");
for (MetadataField field : mtds.getMetadataFields()) {
System.out.println(field);
System.out.println("Category Ref: "+field.getCategoryRef());
System.out.println("Category CategoryField Q Name: "+field.getCategoryFieldQName());
System.out.println("QName: "+field.getCategoryFieldQName());
System.out.println("MaxOccurs: "+field.getMaxOccurs());
// System.out.println(field.getGrouping());
// System.out.println(field.getTagging());
}
}
/**
* Un marshaling example.
*
* @throws JAXBException the JAXB exception
*/
private static void unMarshalingCategories() throws JAXBException
{
JAXBContext jaxbContext = JAXBContext.newInstance(NamespaceCategories.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
//We had written this file in marshalling example
NamespaceCategories mtds = (NamespaceCategories) jaxbUnmarshaller.unmarshal(new File(tmpCategoriesXML));
System.out.println("NamespaceCategories: ");
System.out.println(mtds);
// System.out.println("Metadata Categories");
// if(mtds.getMetadataCategories()!=null){
// for (MetadataCategory cat : mtds.getMetadataCategories()) {
// System.out.println(cat);
// System.out.println(cat.getCategoryQName());
// }
// }
System.out.println("\nCategories: ");
for (NamespaceCategory category : mtds.getNamespaceCategories()) {
System.out.println(category);
// System.out.println(field.getGrouping());
// System.out.println(field.getTagging());
}
}
public static void main(String[] args) {
//System.out.println(DataType.valueOf("aa"));
try {
unMarshalingMetadataFields();
}
catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,43 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
import org.gcube.common.metadataprofilediscovery.bean.MetadataProfile;
import org.gcube.common.metadataprofilediscovery.reader.MetadataFormatDiscovery;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.junit.Test;
/**
* The Class TestMetadataFormatDiscovery.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
public class TestMetadataFormatDiscovery {
/**
* Test.
*/
// @Test
public void test() {
String scopeString = "/gcube/devsec/devVRE";
final ScopeBean scope = new ScopeBean(scopeString);
MetadataFormatDiscovery reader;
try {
ScopeProvider.instance.set(scopeString);
reader = new MetadataFormatDiscovery(scope);
//System.out.println(reader.getMetadataProfiles());
for (MetadataProfile metaProfile : reader.getMetadataProfiles()) {
System.out.println(metaProfile.getId() +", name: "+metaProfile.getName() +", type: "+metaProfile.getMetadataType());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,33 @@
/**
*
*/
package org.gcube.common.metadataprofilediscovery;
import org.gcube.common.metadataprofilediscovery.reader.MetadataFormatReader;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.junit.Test;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 8, 2016
*/
public class TestMetadataFormatReader {
// @Test
public void test() {
String scopeString = "/gcube/devsec/devVRE";
final ScopeBean scope = new ScopeBean(scopeString);
MetadataFormatReader reader;
try {
ScopeProvider.instance.set(scopeString);
reader = new MetadataFormatReader(scope, "0d29d7a9-d779-478c-a13d-d70708dc66c4");
System.out.println(reader.getMetadataFormat());
} catch (Exception e) {
e.printStackTrace();
}
}
}