|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|