2019-01-10 12:29:47 +01:00
|
|
|
package org.gcube.gcat.profile;
|
|
|
|
|
2019-09-09 14:20:09 +02:00
|
|
|
import java.io.IOException;
|
2019-01-10 12:29:47 +01:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2019-09-09 14:20:09 +02:00
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
2019-01-10 12:29:47 +01:00
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataProfile;
|
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
|
|
|
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.NamespaceCategory;
|
2019-09-09 14:20:09 +02:00
|
|
|
import org.xml.sax.SAXException;
|
2019-01-10 12:29:47 +01:00
|
|
|
|
|
|
|
public class MetadataUtility {
|
|
|
|
|
|
|
|
private DataCalogueMetadataFormatReader dataCalogueMetadataFormatReader;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* this map contains the Metadata Profiles. The key is the name of the profile.
|
|
|
|
*/
|
|
|
|
private Map<String,MetadataProfile> metadataProfiles;
|
|
|
|
|
2019-09-16 14:48:18 +02:00
|
|
|
public MetadataUtility() throws Exception {
|
2019-05-20 17:23:49 +02:00
|
|
|
dataCalogueMetadataFormatReader = new DataCalogueMetadataFormatReader();
|
2019-01-10 12:29:47 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 14:20:09 +02:00
|
|
|
public void validateProfile(String xmlProfile) throws ParserConfigurationException, SAXException, IOException {
|
2019-05-20 17:23:49 +02:00
|
|
|
dataCalogueMetadataFormatReader.validateProfile(xmlProfile);
|
2019-01-10 12:29:47 +01:00
|
|
|
}
|
|
|
|
|
2019-09-16 14:48:18 +02:00
|
|
|
public Map<String,MetadataProfile> getMetadataProfiles() throws Exception {
|
|
|
|
if(metadataProfiles == null) {
|
2019-01-10 12:29:47 +01:00
|
|
|
metadataProfiles = new HashMap<>();
|
|
|
|
List<MetadataProfile> list = dataCalogueMetadataFormatReader.getListOfMetadataProfiles();
|
|
|
|
for(MetadataProfile profile : list) {
|
|
|
|
metadataProfiles.put(profile.getName(), profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return metadataProfiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the names of the metadata profiles in a given context
|
2019-10-04 17:04:50 +02:00
|
|
|
* @return the set of profile names
|
2019-01-10 12:29:47 +01:00
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public Set<String> getProfilesNames() throws Exception {
|
|
|
|
return getMetadataProfiles().keySet();
|
|
|
|
}
|
|
|
|
|
|
|
|
public MetadataFormat getMetadataFormat(String profileName) throws Exception {
|
|
|
|
MetadataProfile profile = getMetadataProfiles().get(profileName);
|
2019-09-16 14:48:18 +02:00
|
|
|
if(profile != null) {
|
2019-01-10 12:29:47 +01:00
|
|
|
return dataCalogueMetadataFormatReader.getMetadataFormatForMetadataProfile(profile);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<NamespaceCategory> getNamespaceCategories() throws Exception {
|
|
|
|
return dataCalogueMetadataFormatReader.getListOfNamespaceCategories();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|