2016-06-08 12:14:15 +02:00
|
|
|
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;
|
2017-03-24 16:05:52 +01:00
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
|
2016-06-08 12:14:15 +02:00
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
2017-03-24 12:43:57 +01:00
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery;
|
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatReader;
|
2016-06-08 12:14:15 +02:00
|
|
|
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{
|
|
|
|
|
2017-03-24 12:43:57 +01:00
|
|
|
private MetadataFormatDiscovery medataFormatDiscovery;
|
2016-06-08 12:14:15 +02:00
|
|
|
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);
|
2017-03-24 12:43:57 +01:00
|
|
|
medataFormatDiscovery = new MetadataFormatDiscovery(scope);
|
2017-03-24 16:05:52 +01:00
|
|
|
logger.info("MedataFormatDiscovery has retrieved: "+medataFormatDiscovery.getMetadataProfiles().size() +" metadata type/s");
|
2016-06-08 12:14:15 +02:00
|
|
|
logger.debug("filling cache for MedataFormat");
|
2017-03-24 16:05:52 +01:00
|
|
|
for (MetadataProfile mT : medataFormatDiscovery.getMetadataProfiles()) {
|
|
|
|
if(mT==null)
|
|
|
|
continue;
|
|
|
|
|
2017-03-24 12:43:57 +01:00
|
|
|
MetadataFormatReader reader = new MetadataFormatReader(scope, mT.getId());
|
2016-06-08 12:14:15 +02:00
|
|
|
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
|
2017-03-24 16:05:52 +01:00
|
|
|
public List<MetadataProfile> getListOfMetadataProfiles() throws Exception {
|
2016-06-08 12:14:15 +02:00
|
|
|
|
2017-03-24 16:05:52 +01:00
|
|
|
return medataFormatDiscovery.getMetadataProfiles();
|
2016-06-08 12:14:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see org.gcube.datacatalogue.metadatadiscovery.DataCatalogueMetadataDiscovery#getMetadataFormatForMetadataType(org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType)
|
|
|
|
*/
|
|
|
|
@Override
|
2017-03-24 16:05:52 +01:00
|
|
|
public MetadataFormat getMetadataFormatForMetadataProfile(MetadataProfile profile) throws Exception {
|
2016-06-08 12:14:15 +02:00
|
|
|
|
2017-03-24 16:05:52 +01:00
|
|
|
if(profile==null)
|
|
|
|
throw new Exception("Input "+ MetadataProfile.class.getSimpleName() + " is null");
|
2016-06-08 12:14:15 +02:00
|
|
|
|
2017-03-24 16:05:52 +01:00
|
|
|
MetadataFormat format = hash.get(profile.getId());
|
2016-06-08 12:14:15 +02:00
|
|
|
if(format!=null)
|
|
|
|
return format;
|
|
|
|
|
2017-03-24 16:05:52 +01:00
|
|
|
MetadataFormatReader reader = new MetadataFormatReader(scope, profile.getId());
|
2016-06-08 12:14:15 +02:00
|
|
|
return reader.getMetadataFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|