#22890 overloaded method
This commit is contained in:
parent
e0d5c00e5f
commit
b7b702f8e9
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId"/>
|
|
@ -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
|
||||
- [#19880] Create the library metadata-profile-discovery
|
14
pom.xml
14
pom.xml
|
@ -12,7 +12,7 @@
|
|||
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>metadata-profile-discovery</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.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:
|
||||
|
@ -108,12 +108,12 @@
|
|||
</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> -->
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>ch.qos.logback</groupId> -->
|
||||
<!-- <artifactId>logback-classic</artifactId> -->
|
||||
<!-- <version>1.0.13</version> -->
|
||||
<!-- <scope>test</scope> -->
|
||||
<!-- </dependency> -->
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ public class MetadataFormatDiscovery {
|
|||
private String secondaryType;
|
||||
private ScopeBean scope;
|
||||
private List<MetadataProfile> 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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue