4184: Create datacatalogue-metadata-discovery library
Task-Url: https://support.d4science.org/issues/4184 DataCatalogueMetadataFormatReader completed git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@129014 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
fc1993dd43
commit
65b39783b3
|
@ -1,10 +0,0 @@
|
||||||
package org.gcube.datacatalogue.metadatadiscovery;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entry point classes define <code>onModuleLoad()</code>.
|
|
||||||
*/
|
|
||||||
public class DataCalogueDiscovery {
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
package org.gcube.datacatalogue.metadatadiscovery;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MedataFormatDiscovery;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MedataFormatReader;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class DataCalogueMetadataReader.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 8, 2016
|
||||||
|
*/
|
||||||
|
public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDiscovery{
|
||||||
|
|
||||||
|
private MedataFormatDiscovery medataFormatDiscovery;
|
||||||
|
private final ScopeBean scope;
|
||||||
|
private Map<String, MetadataFormat> hash = new HashMap<String, MetadataFormat>();
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(DataCalogueMetadataFormatReader.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new data calogue metadata format reader.
|
||||||
|
*
|
||||||
|
* @throws Exception the exception
|
||||||
|
*/
|
||||||
|
public DataCalogueMetadataFormatReader() throws Exception {
|
||||||
|
|
||||||
|
String scopeString = ScopeProvider.instance.get();
|
||||||
|
logger.debug("DataCalogueMetadataFormatReader read scope "+scopeString +" from ScopeProvider");
|
||||||
|
|
||||||
|
if(scopeString==null || scopeString.isEmpty())
|
||||||
|
throw new Exception("Please set a valid scope into ScopeProvider");
|
||||||
|
|
||||||
|
scope = new ScopeBean(scopeString);
|
||||||
|
medataFormatDiscovery = new MedataFormatDiscovery(scope);
|
||||||
|
logger.info("MedataFormatDiscovery has retrieved: "+medataFormatDiscovery.getMetadataTypes().size() +" metadata type/s");
|
||||||
|
logger.debug("filling cache for MedataFormat");
|
||||||
|
for (MetadataType mT : medataFormatDiscovery.getMetadataTypes()) {
|
||||||
|
MedataFormatReader reader = new MedataFormatReader(scope, mT.getId());
|
||||||
|
hash.put(mT.getId(), reader.getMetadataFormat());
|
||||||
|
logger.debug("MetadataType id: "+mT.getId() +" cached as: "+reader.getMetadataFormat());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#getListOfMetadataTypes()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MetadataType> getListOfMetadataTypes() throws Exception {
|
||||||
|
|
||||||
|
return medataFormatDiscovery.getMetadataTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#getMetadataFormatForMetadataType(org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetadataFormat getMetadataFormatForMetadataType(MetadataType type) throws Exception {
|
||||||
|
|
||||||
|
if(type==null)
|
||||||
|
throw new Exception("MetadataType is null");
|
||||||
|
|
||||||
|
MetadataFormat format = hash.get(type.getId());
|
||||||
|
if(format!=null)
|
||||||
|
return format;
|
||||||
|
|
||||||
|
MedataFormatReader reader = new MedataFormatReader(scope, type.getId());
|
||||||
|
return reader.getMetadataFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datacatalogue.metadatadiscovery;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Interface DataCatalogueMetadataDiscovery.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 8, 2016
|
||||||
|
*/
|
||||||
|
public interface DataCatalogueMetadataDiscovery {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of metadata types.
|
||||||
|
*
|
||||||
|
* @return the list of metadata types
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
List<MetadataType> getListOfMetadataTypes() throws Exception;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the metadata format for metadata type.
|
||||||
|
*
|
||||||
|
* @param type the type
|
||||||
|
* @return the metadata format for metadata type
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
MetadataFormat getMetadataFormatForMetadataType(MetadataType type) throws Exception;
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ import org.xml.sax.InputSource;
|
||||||
*/
|
*/
|
||||||
public class MedataFormatDiscovery {
|
public class MedataFormatDiscovery {
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(MedataFormatDiscovery.class);
|
private static Logger logger = LoggerFactory.getLogger(MedataFormatDiscovery.class);
|
||||||
protected static final String DATA_CATALOGUE_METADATA_SECONDARY_TYPE = "DataCatalogueMetadata";
|
protected static final String DATA_CATALOGUE_METADATA_SECONDARY_TYPE = "DataCatalogueMetadata";
|
||||||
private String secondaryType;
|
private String secondaryType;
|
||||||
private ScopeBean scope;
|
private ScopeBean scope;
|
||||||
|
@ -190,34 +190,4 @@ public class MedataFormatDiscovery {
|
||||||
|
|
||||||
return metadataTypes;
|
return metadataTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main method.
|
|
||||||
*
|
|
||||||
* @param args the arguments
|
|
||||||
* @throws InterruptedException the interrupted exception
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
|
|
||||||
String scopeString = "/gcube/devsec/devVRE";
|
|
||||||
final ScopeBean scope = new ScopeBean(scopeString);
|
|
||||||
MedataFormatDiscovery reader;
|
|
||||||
try {
|
|
||||||
reader = new MedataFormatDiscovery(scope);
|
|
||||||
System.out.println(reader.getMetadataTypes());
|
|
||||||
|
|
||||||
// String value = "true";
|
|
||||||
// if (value != null){
|
|
||||||
// boolean isBase = Boolean.parseBoolean(value);
|
|
||||||
// System.out.println(isBase);
|
|
||||||
//// logger.trace("isBaseLayer : "+isBase);
|
|
||||||
// }
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.xml.sax.InputSource;
|
||||||
*/
|
*/
|
||||||
public class MedataFormatReader {
|
public class MedataFormatReader {
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(MedataFormatReader.class);
|
private static Logger logger = LoggerFactory.getLogger(MedataFormatReader.class);
|
||||||
private ScopeBean scope;
|
private ScopeBean scope;
|
||||||
private MetadataFormat metadataFormat;
|
private MetadataFormat metadataFormat;
|
||||||
private String resourceID;
|
private String resourceID;
|
||||||
|
@ -117,7 +117,7 @@ public class MedataFormatReader {
|
||||||
*
|
*
|
||||||
* @param helper the helper
|
* @param helper the helper
|
||||||
* @return the metadata fields from resource
|
* @return the metadata fields from resource
|
||||||
* @throws ApplicationProfileNotFoundException the application profile not found exception
|
* @throws Exception the exception
|
||||||
*/
|
*/
|
||||||
private List<MetadataField> getMetadataFieldsFromResource(XPathHelper helper) throws Exception{
|
private List<MetadataField> getMetadataFieldsFromResource(XPathHelper helper) throws Exception{
|
||||||
|
|
||||||
|
@ -158,6 +158,12 @@ public class MedataFormatReader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the quesry string for generic resource by id.
|
||||||
|
*
|
||||||
|
* @param resourceId the resource id
|
||||||
|
* @return the quesry string for generic resource by id
|
||||||
|
*/
|
||||||
public synchronized String getQuesryStringForGenericResourceById(String resourceId){
|
public synchronized String getQuesryStringForGenericResourceById(String resourceId){
|
||||||
|
|
||||||
return String.format("declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; " +
|
return String.format("declare namespace ic = 'http://gcube-system.org/namespaces/informationsystem/registry'; " +
|
||||||
|
@ -167,6 +173,8 @@ public class MedataFormatReader {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the scope.
|
||||||
|
*
|
||||||
* @return the scope
|
* @return the scope
|
||||||
*/
|
*/
|
||||||
public ScopeBean getScope() {
|
public ScopeBean getScope() {
|
||||||
|
@ -176,6 +184,8 @@ public class MedataFormatReader {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the metadata format.
|
||||||
|
*
|
||||||
* @return the metadataFormat
|
* @return the metadataFormat
|
||||||
*/
|
*/
|
||||||
public MetadataFormat getMetadataFormat() {
|
public MetadataFormat getMetadataFormat() {
|
||||||
|
@ -185,41 +195,12 @@ public class MedataFormatReader {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the resource id.
|
||||||
|
*
|
||||||
* @return the resourceID
|
* @return the resourceID
|
||||||
*/
|
*/
|
||||||
public String getResourceID() {
|
public String getResourceID() {
|
||||||
|
|
||||||
return resourceID;
|
return resourceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The main method.
|
|
||||||
*
|
|
||||||
* @param args the arguments
|
|
||||||
* @throws InterruptedException the interrupted exception
|
|
||||||
*/
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
|
|
||||||
String scopeString = "/gcube/devsec/devVRE";
|
|
||||||
final ScopeBean scope = new ScopeBean(scopeString);
|
|
||||||
MedataFormatReader reader;
|
|
||||||
try {
|
|
||||||
reader = new MedataFormatReader(scope, "78355412-b45a-4519-adce-679452583aa2");
|
|
||||||
System.out.println(reader.getMetadataFormat());
|
|
||||||
|
|
||||||
// String value = "true";
|
|
||||||
// if (value != null){
|
|
||||||
// boolean isBase = Boolean.parseBoolean(value);
|
|
||||||
// System.out.println(isBase);
|
|
||||||
//// logger.trace("isBaseLayer : "+isBase);
|
|
||||||
// }
|
|
||||||
} catch (Exception e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datacatalogue.metadatadiscovery;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class TestDataCatalogueMetadataFormatReader.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 8, 2016
|
||||||
|
*/
|
||||||
|
public class TestDataCatalogueMetadataFormatReader {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(TestDataCatalogueMetadataFormatReader.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
try {
|
||||||
|
String scopeString = "/gcube/devsec/devVRE";
|
||||||
|
ScopeProvider.instance.set(scopeString);
|
||||||
|
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
|
||||||
|
logger.trace(""+reader.getListOfMetadataTypes());
|
||||||
|
|
||||||
|
for (MetadataType mt : reader.getListOfMetadataTypes()) {
|
||||||
|
logger.trace(""+reader.getMetadataFormatForMetadataType(mt));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The Class TestJaxbMetadataMarshUnmarsh.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
* Jun 7, 2016
|
* Jun 7, 2016
|
||||||
|
@ -30,6 +31,9 @@ public class TestJaxbMetadataMarshUnmarsh {
|
||||||
static MetadataFormat metadatas;
|
static MetadataFormat metadatas;
|
||||||
static String tmpFileXML = "." + File.separator + "CkanMetadatas.xml";
|
static String tmpFileXML = "." + File.separator + "CkanMetadatas.xml";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test.
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
|
|
||||||
|
@ -77,6 +81,11 @@ public class TestJaxbMetadataMarshUnmarsh {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marshaling example.
|
||||||
|
*
|
||||||
|
* @throws JAXBException the JAXB exception
|
||||||
|
*/
|
||||||
private static void marshalingExample() throws JAXBException
|
private static void marshalingExample() throws JAXBException
|
||||||
{
|
{
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
||||||
|
@ -92,6 +101,11 @@ public class TestJaxbMetadataMarshUnmarsh {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Un marshaling example.
|
||||||
|
*
|
||||||
|
* @throws JAXBException the JAXB exception
|
||||||
|
*/
|
||||||
private static void unMarshalingExample() throws JAXBException
|
private static void unMarshalingExample() throws JAXBException
|
||||||
{
|
{
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(MetadataFormat.class);
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datacatalogue.metadatadiscovery;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MedataFormatDiscovery;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class TestMetadataFormatDiscovery.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 8, 2016
|
||||||
|
*/
|
||||||
|
public class TestMetadataFormatDiscovery {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
String scopeString = "/gcube/devsec/devVRE";
|
||||||
|
final ScopeBean scope = new ScopeBean(scopeString);
|
||||||
|
MedataFormatDiscovery reader;
|
||||||
|
try {
|
||||||
|
reader = new MedataFormatDiscovery(scope);
|
||||||
|
System.out.println(reader.getMetadataTypes());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datacatalogue.metadatadiscovery;
|
||||||
|
|
||||||
|
import org.gcube.common.scope.impl.ScopeBean;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MedataFormatReader;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* Jun 8, 2016
|
||||||
|
*/
|
||||||
|
public class TestMetadataFormatReader {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
String scopeString = "/gcube/devsec/devVRE";
|
||||||
|
final ScopeBean scope = new ScopeBean(scopeString);
|
||||||
|
MedataFormatReader reader;
|
||||||
|
try {
|
||||||
|
reader = new MedataFormatReader(scope, "78355412-b45a-4519-adce-679452583aa2");
|
||||||
|
System.out.println(reader.getMetadataFormat());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue