diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
new file mode 100644
index 0000000..bcc91bc
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.component
@@ -0,0 +1 @@
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 04aa045..d782b48 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,8 +4,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [v1.1.0-SNAPSHOT] - 2022-03-01
+
+#### Enhancement
+
+- [#22890] Extend the MetadataDiscovery logic
+
## [v1.0.0] - 2020-09-30
#### First release
-[#19880] Create the library metadata-profile-discovery
\ No newline at end of file
+- [#19880] Create the library metadata-profile-discovery
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index bb0ca56..2030bd4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
org.gcube.common
metadata-profile-discovery
- 1.0.0
+ 1.1.0-SNAPSHOT
jar
The Metadata Profile discovery library
The metadata-profile-discovery library is able to build java objects parsing the 'gCube Metadata Profiles' models:
@@ -108,12 +108,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/main/java/org/gcube/common/metadataprofilediscovery/MetadataProfileReader.java b/src/main/java/org/gcube/common/metadataprofilediscovery/MetadataProfileReader.java
index a199d5e..6911357 100644
--- a/src/main/java/org/gcube/common/metadataprofilediscovery/MetadataProfileReader.java
+++ b/src/main/java/org/gcube/common/metadataprofilediscovery/MetadataProfileReader.java
@@ -40,13 +40,12 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-
/**
* The Class MetadataProfileReader.
*
- * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
+ * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
- * Sep 30, 2020
+ * Mar 1, 2022
*/
public class MetadataProfileReader implements MetadataProfileDiscovery {
@@ -63,22 +62,61 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
private String grMetadataProfileSecondaryType;
+ private String grMetadataProfileResourceName;
+
private static Logger logger = LoggerFactory.getLogger(MetadataProfileReader.class);
-
-
+
/**
* Instantiates a new metadata profile reader.
*
- * @param grMetadataProfileSecondaryType the SecondaryType that must be used to discover the "gCube Metadata Profiles" from Information System
+ * @param grMetadataProfileSecondaryType the SecondaryType that must be used to
+ * discover the "gCube Metadata Profiles"
+ * from Information System
* @throws Exception the exception
*/
public MetadataProfileReader(String grMetadataProfileSecondaryType) throws Exception {
-
- if(grMetadataProfileSecondaryType==null || grMetadataProfileSecondaryType.isEmpty())
- throw new NullPointerException("Invalid input parameter");
-
+
+ if (grMetadataProfileSecondaryType == null || grMetadataProfileSecondaryType.isEmpty())
+ throw new NullPointerException("Invalid input parameter: grMetadataProfileSecondaryType");
+
this.grMetadataProfileSecondaryType = grMetadataProfileSecondaryType;
-
+
+ readNamespacesAndProfiles();
+ }
+
+ /**
+ * Instantiates a new metadata profile reader.
+ *
+ * @param grMetadataProfileSecondaryType the gr metadata profile secondary type
+ * @param resourceName the resource name
+ *
+ * the SecondaryType and the ResourceName
+ * that must be used to discover the
+ * "gCube Metadata Profiles" from
+ * Information System
+ * @throws Exception the exception
+ */
+ public MetadataProfileReader(String grMetadataProfileSecondaryType, String resourceName) throws Exception {
+
+ if (grMetadataProfileSecondaryType == null || grMetadataProfileSecondaryType.isEmpty())
+ throw new NullPointerException("Invalid input parameter: grMetadataProfileSecondaryType");
+
+ if (resourceName == null || resourceName.isEmpty())
+ throw new NullPointerException("Invalid input parameter: resourceName");
+
+ this.grMetadataProfileSecondaryType = grMetadataProfileSecondaryType;
+ this.grMetadataProfileResourceName = resourceName;
+
+ readNamespacesAndProfiles();
+ }
+
+ /**
+ * Read namespaces and profiles.
+ *
+ * @throws Exception the exception
+ */
+ private void readNamespacesAndProfiles() throws Exception {
+
String scopeString = ScopeProvider.instance.get();
logger.debug("Read scope " + scopeString + " from ScopeProvider");
@@ -86,20 +124,22 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
throw new Exception("Please set a valid scope into ScopeProvider");
scope = new ScopeBean(scopeString);
-
+
readNamespaces();
readMetadataFormats();
}
-
+
/**
* Read metada formats.
*
* @throws Exception the exception
*/
private void readMetadataFormats() throws Exception {
-
- //reading from Generic Resource for Secondary Type passed in input
- medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType);
+
+ // reading from Generic Resource for Secondary Type and Resource Name passed in
+ // input
+ medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType,
+ grMetadataProfileResourceName);
logger.info("MedataFormatDiscovery has retrieved: " + medataFormatDiscovery.getMetadataProfiles().size()
+ " metadata type/s");
@@ -113,12 +153,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
hashMetadataFormats.put(mT.getId(), reader.getMetadataFormat());
logger.debug("MetadataType id: " + mT.getId() + " cached as: " + reader.getMetadataFormat());
}
-
+
}
/**
* Read namespaces.
- * @throws Exception
+ *
+ * @throws Exception the exception
*/
private void readNamespaces() throws Exception {
@@ -154,13 +195,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/
public static InputStream getProfileSchemaInputStream() {
try {
- logger.info("Trying to return the URL resource: "+URL_OF_GCDCMETADATAPROFILEV3_XSD);
+ logger.info("Trying to return the URL resource: " + URL_OF_GCDCMETADATAPROFILEV3_XSD);
return new URL(URL_OF_GCDCMETADATAPROFILEV3_XSD).openStream();
-
+
} catch (Exception e) {
- logger.warn("Error on reading the URL: "+URL_OF_GCDCMETADATAPROFILEV3_XSD);
+ logger.warn("Error on reading the URL: " + URL_OF_GCDCMETADATAPROFILEV3_XSD);
}
- logger.info("Returning local resource: "+SCHEMA_FILENAME);
+ logger.info("Returning local resource: " + SCHEMA_FILENAME);
return MetadataProfileReader.class.getResourceAsStream(SCHEMA_FILENAME);
}
@@ -171,13 +212,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/
public static URL getProfileSchemaURL() {
try {
- logger.info("Trying to return the URL object: "+URL_OF_GCDCMETADATAPROFILEV3_XSD);
+ logger.info("Trying to return the URL object: " + URL_OF_GCDCMETADATAPROFILEV3_XSD);
return new URL(URL_OF_GCDCMETADATAPROFILEV3_XSD);
-
+
} catch (Exception e) {
- logger.warn("Error on reading the URL: "+URL_OF_GCDCMETADATAPROFILEV3_XSD);
+ logger.warn("Error on reading the URL: " + URL_OF_GCDCMETADATAPROFILEV3_XSD);
}
- logger.info("Returning local URL of: "+SCHEMA_FILENAME);
+ logger.info("Returning local URL of: " + SCHEMA_FILENAME);
return MetadataProfileReader.class.getResource(SCHEMA_FILENAME);
}
@@ -206,6 +247,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
validateAgainstXSD(new StreamSource(xml), getProfileSchemaURL());
}
+ /**
+ * Gets the metadata format for metadata profile.
+ *
+ * @param profile the profile
+ * @return the metadata format for metadata profile
+ * @throws Exception the exception
+ */
/*
* (non-Javadoc)
*
@@ -227,6 +275,12 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return reader.getMetadataFormat();
}
+ /**
+ * Gets the list of metadata profiles.
+ *
+ * @return the list of metadata profiles
+ * @throws Exception the exception
+ */
/*
* (non-Javadoc)
*
@@ -242,6 +296,12 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return medataFormatDiscovery.getMetadataProfiles();
}
+ /**
+ * Gets the list of namespace categories.
+ *
+ * @return the list of namespace categories
+ * @throws Exception the exception
+ */
/*
* (non-Javadoc)
*
@@ -257,6 +317,9 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return namespaceCategories;
}
+ /**
+ * Reset metadata profile.
+ */
/*
* (non-Javadoc)
*
@@ -270,6 +333,9 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
hashMetadataFormats = null;
}
+ /**
+ * Reset namespace categories.
+ */
/*
* (non-Javadoc)
*
@@ -282,6 +348,11 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
namespaceCategories = null;
}
+ /**
+ * Gets the profile schema.
+ *
+ * @return the profile schema
+ */
/*
* (non-Javadoc)
*
@@ -297,6 +368,15 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
}
+ /**
+ * Validate profile.
+ *
+ * @param xmlProfile the xml profile
+ * @throws ParserConfigurationException the parser configuration exception
+ * @throws SAXException the SAX exception
+ * @throws IOException Signals that an I/O exception has
+ * occurred.
+ */
/*
* (non-Javadoc)
*
@@ -310,23 +390,23 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
DOMSource source = new DOMSource(doc);
validateAgainstXSD(source, getProfileSchemaURL());
}
-
+
/**
- * Utility method to get a metadata format from a "gCube Metadata Profiles" model (XML-based)
+ * Utility method to get a metadata format from a "gCube Metadata Profiles"
+ * model (XML-based).
*
* @param metadataProfileStream the metadata profile stream
* @return the metadata format
* @throws JAXBException the JAXB exception
*/
- public static MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException{
-
- if(metadataProfileStream==null)
+ public static MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException {
+
+ if (metadataProfileStream == null)
throw new NullPointerException("Invalid input parameter");
-
+
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
- Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
- return (MetadataFormat) jaxbUnmarshaller.unmarshal(metadataProfileStream);
+ Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
+ return (MetadataFormat) jaxbUnmarshaller.unmarshal(metadataProfileStream);
}
-
}
diff --git a/src/main/java/org/gcube/common/metadataprofilediscovery/reader/MetadataFormatDiscovery.java b/src/main/java/org/gcube/common/metadataprofilediscovery/reader/MetadataFormatDiscovery.java
index 73114a2..54d7a8c 100644
--- a/src/main/java/org/gcube/common/metadataprofilediscovery/reader/MetadataFormatDiscovery.java
+++ b/src/main/java/org/gcube/common/metadataprofilediscovery/reader/MetadataFormatDiscovery.java
@@ -40,6 +40,7 @@ public class MetadataFormatDiscovery {
private String secondaryType;
private ScopeBean scope;
private List metadataProfiles;
+ private String resourceName;
/**
@@ -49,9 +50,10 @@ public class MetadataFormatDiscovery {
* @param secondaryType the secondary type
* @throws Exception the exception
*/
- public MetadataFormatDiscovery(ScopeBean scope, String secondaryType) throws Exception {
+ public MetadataFormatDiscovery(ScopeBean scope, String secondaryType, String resourceName) throws Exception {
this.scope = scope;
this.secondaryType = secondaryType;
+ this.resourceName = resourceName;
this.metadataProfiles = readMetadataProfilesFromInfrastrucure();
}
@@ -79,8 +81,12 @@ public class MetadataFormatDiscovery {
// ScopeProvider.instance.set(scopeString);
logger.info("Using scope from ScopeProvider: "+scopeString);
-
- String queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryType(secondaryType);
+ String queryString = null;
+ if(resourceName!=null)
+ queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryTypeAndName(resourceName, secondaryType);
+ else
+ queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryType(secondaryType);
+
logger.trace("queryString: " +queryString);
Query q = new QueryBox(queryString);