toMetadataFormat moved to static. commented tests

This commit is contained in:
Francesco Mangiacrapa 2020-09-30 14:28:35 +02:00
parent a6d91a4b7d
commit ee9969f2ba
4 changed files with 41 additions and 19 deletions

View File

@ -86,6 +86,7 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
throw new Exception("Please set a valid scope into ScopeProvider");
scope = new ScopeBean(scopeString);
readNamespaces();
readMetadataFormats();
}
@ -97,23 +98,22 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
*/
private void readMetadataFormats() throws Exception {
//reading from Generic Resource for Secondary Type
if(grMetadataProfileSecondaryType!=null) {
medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType);
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());
}
//reading from Generic Resource for Secondary Type passed in input
medataFormatDiscovery = new MetadataFormatDiscovery(scope, grMetadataProfileSecondaryType);
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());
}
}
/**
@ -316,7 +316,7 @@ public class MetadataProfileReader implements MetadataProfileDiscovery {
* @return the metadata format
* @throws JAXBException the JAXB exception
*/
public MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException{
public static MetadataFormat toMetadataFormat(InputStream metadataProfileStream) throws JAXBException{
if(metadataProfileStream==null)
throw new NullPointerException("Invalid input parameter");

View File

@ -28,7 +28,7 @@ public class TestDataCatalogueMetadataFormatReader {
/**
* Test.
*/
@Test
//@Test
public void test() {
try {
String scopeString = "/gcube/devsec/devVRE";

View File

@ -21,7 +21,7 @@ public class TestMetadataFormatDiscovery {
/**
* Test.
*/
@Test
//@Test
public void test() {
String scopeString = "/gcube/devsec/devVRE";

View File

@ -3,6 +3,11 @@
*/
package org.gcube.common.metadataprofilediscovery;
import java.io.File;
import java.io.InputStream;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataField;
import org.gcube.common.metadataprofilediscovery.jaxb.MetadataFormat;
import org.gcube.common.metadataprofilediscovery.reader.MetadataFormatReader;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
@ -30,4 +35,21 @@ public class TestMetadataFormatReader {
e.printStackTrace();
}
}
//@Test
public void testReadInputStream() {
String fileNameMeatadataProfile = "HarvestedObject.xml";
try {
InputStream in = ClassLoader.getSystemResourceAsStream(fileNameMeatadataProfile);
//InputStream in = TestMetadataFormatReader.class.getResourceAsStream(fileNameMeatadataProfile);
MetadataFormat mf = MetadataProfileReader.toMetadataFormat(in);
System.out.println("Source: "+mf.getMetadataSource());
for (MetadataField field : mf.getMetadataFields()) {
System.out.println(field);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}