#22890 overloaded method

This commit is contained in:
Francesco Mangiacrapa 2022-03-01 16:39:43 +01:00
parent e0d5c00e5f
commit b7b702f8e9
5 changed files with 139 additions and 46 deletions

View File

@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId"/>

View File

@ -4,8 +4,14 @@
All notable changes to this project will be documented in this file. 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). 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 ## [v1.0.0] - 2020-09-30
#### First release #### First release
[#19880] Create the library metadata-profile-discovery - [#19880] Create the library metadata-profile-discovery

14
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>metadata-profile-discovery</artifactId> <artifactId>metadata-profile-discovery</artifactId>
<version>1.0.0</version> <version>1.1.0-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>The Metadata Profile discovery library</name> <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: <description>The metadata-profile-discovery library is able to build java objects parsing the 'gCube Metadata Profiles' models:
@ -108,12 +108,12 @@
</dependency> </dependency>
<!-- Required to log on tests --> <!-- Required to log on tests -->
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>ch.qos.logback</groupId> --> <!-- <groupId>ch.qos.logback</groupId> -->
<!-- <artifactId>logback-classic</artifactId> --> <!-- <artifactId>logback-classic</artifactId> -->
<!-- <version>1.0.13</version> --> <!-- <version>1.0.13</version> -->
<!-- <scope>test</scope> --> <!-- <scope>test</scope> -->
<!-- </dependency> --> <!-- </dependency> -->
</dependencies> </dependencies>

View File

@ -40,13 +40,12 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
/** /**
* The Class MetadataProfileReader. * 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 { public class MetadataProfileReader implements MetadataProfileDiscovery {
@ -63,22 +62,61 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
private String grMetadataProfileSecondaryType; private String grMetadataProfileSecondaryType;
private static Logger logger = LoggerFactory.getLogger(MetadataProfileReader.class); private String grMetadataProfileResourceName;
private static Logger logger = LoggerFactory.getLogger(MetadataProfileReader.class);
/** /**
* Instantiates a new metadata profile reader. * 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 * @throws Exception the exception
*/ */
public MetadataProfileReader(String grMetadataProfileSecondaryType) throws Exception { public MetadataProfileReader(String grMetadataProfileSecondaryType) throws Exception {
if(grMetadataProfileSecondaryType==null || grMetadataProfileSecondaryType.isEmpty()) if (grMetadataProfileSecondaryType == null || grMetadataProfileSecondaryType.isEmpty())
throw new NullPointerException("Invalid input parameter"); throw new NullPointerException("Invalid input parameter: grMetadataProfileSecondaryType");
this.grMetadataProfileSecondaryType = 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(); String scopeString = ScopeProvider.instance.get();
logger.debug("Read scope " + scopeString + " from ScopeProvider"); logger.debug("Read scope " + scopeString + " from ScopeProvider");
@ -98,8 +136,10 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/ */
private void readMetadataFormats() throws Exception { private void readMetadataFormats() throws Exception {
//reading from Generic Resource for Secondary Type passed in input // reading from Generic Resource for Secondary Type and Resource Name passed in
medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType); // input
medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType,
grMetadataProfileResourceName);
logger.info("MedataFormatDiscovery has retrieved: " + medataFormatDiscovery.getMetadataProfiles().size() logger.info("MedataFormatDiscovery has retrieved: " + medataFormatDiscovery.getMetadataProfiles().size()
+ " metadata type/s"); + " metadata type/s");
@ -118,7 +158,8 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
/** /**
* Read namespaces. * Read namespaces.
* @throws Exception *
* @throws Exception the exception
*/ */
private void readNamespaces() throws Exception { private void readNamespaces() throws Exception {
@ -154,13 +195,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/ */
public static InputStream getProfileSchemaInputStream() { public static InputStream getProfileSchemaInputStream() {
try { 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(); return new URL(URL_OF_GCDCMETADATAPROFILEV3_XSD).openStream();
} catch (Exception e) { } 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); return MetadataProfileReader.class.getResourceAsStream(SCHEMA_FILENAME);
} }
@ -171,13 +212,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/ */
public static URL getProfileSchemaURL() { public static URL getProfileSchemaURL() {
try { 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); return new URL(URL_OF_GCDCMETADATAPROFILEV3_XSD);
} catch (Exception e) { } 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); return MetadataProfileReader.class.getResource(SCHEMA_FILENAME);
} }
@ -206,6 +247,13 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
validateAgainstXSD(new StreamSource(xml), getProfileSchemaURL()); 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) * (non-Javadoc)
* *
@ -227,6 +275,12 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return reader.getMetadataFormat(); return reader.getMetadataFormat();
} }
/**
* Gets the list of metadata profiles.
*
* @return the list of metadata profiles
* @throws Exception the exception
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -242,6 +296,12 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return medataFormatDiscovery.getMetadataProfiles(); return medataFormatDiscovery.getMetadataProfiles();
} }
/**
* Gets the list of namespace categories.
*
* @return the list of namespace categories
* @throws Exception the exception
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -257,6 +317,9 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return namespaceCategories; return namespaceCategories;
} }
/**
* Reset metadata profile.
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -270,6 +333,9 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
hashMetadataFormats = null; hashMetadataFormats = null;
} }
/**
* Reset namespace categories.
*/
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@ -282,6 +348,11 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
namespaceCategories = null; namespaceCategories = null;
} }
/**
* Gets the profile schema.
*
* @return the profile schema
*/
/* /*
* (non-Javadoc) * (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) * (non-Javadoc)
* *
@ -312,15 +392,16 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
} }
/** /**
* 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 * @param metadataProfileStream the metadata profile stream
* @return the metadata format * @return the metadata format
* @throws JAXBException the JAXB exception * @throws JAXBException the JAXB exception
*/ */
public static MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException{ public static MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException {
if(metadataProfileStream==null) if (metadataProfileStream == null)
throw new NullPointerException("Invalid input parameter"); throw new NullPointerException("Invalid input parameter");
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class); JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
@ -328,5 +409,4 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
return (MetadataFormat) jaxbUnmarshaller.unmarshal(metadataProfileStream); return (MetadataFormat) jaxbUnmarshaller.unmarshal(metadataProfileStream);
} }
} }

View File

@ -40,6 +40,7 @@ public class MetadataFormatDiscovery {
private String secondaryType; private String secondaryType;
private ScopeBean scope; private ScopeBean scope;
private List<MetadataProfile> metadataProfiles; private List<MetadataProfile> metadataProfiles;
private String resourceName;
/** /**
@ -49,9 +50,10 @@ public class MetadataFormatDiscovery {
* @param secondaryType the secondary type * @param secondaryType the secondary type
* @throws Exception the exception * @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.scope = scope;
this.secondaryType = secondaryType; this.secondaryType = secondaryType;
this.resourceName = resourceName;
this.metadataProfiles = readMetadataProfilesFromInfrastrucure(); this.metadataProfiles = readMetadataProfilesFromInfrastrucure();
} }
@ -79,8 +81,12 @@ public class MetadataFormatDiscovery {
// ScopeProvider.instance.set(scopeString); // ScopeProvider.instance.set(scopeString);
logger.info("Using scope from ScopeProvider: "+scopeString); logger.info("Using scope from ScopeProvider: "+scopeString);
String queryString = null;
if(resourceName!=null)
queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryTypeAndName(resourceName, secondaryType);
else
queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryType(secondaryType);
String queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryType(secondaryType);
logger.trace("queryString: " +queryString); logger.trace("queryString: " +queryString);
Query q = new QueryBox(queryString); Query q = new QueryBox(queryString);