namespaces are now retrieved per scope
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-catalogue/gcubedatacatalogue-metadata-discovery@152442 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3fd17d33e7
commit
631cd86682
|
@ -1,4 +1,9 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset
|
||||
component="org.gcube.data-catalogue.gcubedatacatalogue-metadata-discovery.3-2-0"
|
||||
date="2017-04-26">
|
||||
<Change>Namespaces are retrieved per scope</Change>
|
||||
</Changeset>
|
||||
<Changeset
|
||||
component="org.gcube.data-catalogue.gcubedatacatalogue-metadata-discovery.3-1-0"
|
||||
date="2017-04-26">
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -13,7 +13,7 @@
|
|||
<groupId>org.gcube.data-catalogue</groupId>
|
||||
<artifactId>gcubedatacatalogue-metadata-discovery</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>3.1.0-SNAPSHOT</version>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
<name>The gCube data catalogue metadata discovery library</name>
|
||||
<description>The gCube data catalogue metadata discovery library</description>
|
||||
<scm>
|
||||
|
|
|
@ -85,7 +85,7 @@ public class DataCalogueMetadataFormatReader implements DataCatalogueMetadataDis
|
|||
if(namespaceCategories == null)
|
||||
namespaceCategories = new ArrayList<NamespaceCategory>();
|
||||
|
||||
NamespaceCategoryReader rd = new NamespaceCategoryReader(scope, NamespaceCategoryReader.NamespacesCatalogueCategoriesResourceID());
|
||||
NamespaceCategoryReader rd = new NamespaceCategoryReader(scope);
|
||||
namespaceCategories.addAll(rd.getNamespaces().getNamespaceCategories());
|
||||
}
|
||||
}catch(Exception e){
|
||||
|
|
|
@ -6,11 +6,9 @@ package org.gcube.datacatalogue.metadatadiscovery.reader;
|
|||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
@ -37,13 +35,12 @@ import org.xml.sax.InputSource;
|
|||
*/
|
||||
public class NamespaceCategoryReader {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String NAMESPACES_CATALOGUE_CATEGORIES_PROPERTIES = "NamespacesCatalogueCategories.properties";
|
||||
private static Logger logger = LoggerFactory.getLogger(NamespaceCategoryReader.class);
|
||||
|
||||
private static final String GENERIC_RESOURCE_NAMESPACES_NAME = "Namespaces Catalogue Categories";
|
||||
private static final String GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE = "DataCatalogueNamespace";
|
||||
|
||||
private ScopeBean scope;
|
||||
private String resourceID;
|
||||
|
||||
private NamespaceCategories namespaces;
|
||||
|
||||
|
@ -51,16 +48,11 @@ public class NamespaceCategoryReader {
|
|||
* Instantiates a new medata format reader.
|
||||
*
|
||||
* @param scope the scope
|
||||
* @param resourceID the resource id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
public NamespaceCategoryReader(ScopeBean scope, String resourceID) throws Exception {
|
||||
public NamespaceCategoryReader(ScopeBean scope) throws Exception {
|
||||
this.scope = scope;
|
||||
this.resourceID = resourceID;
|
||||
if(resourceID == null || resourceID.isEmpty())
|
||||
throw new Exception("Please, specify a valid ResourceID in the property file: "+NAMESPACES_CATALOGUE_CATEGORIES_PROPERTIES);
|
||||
|
||||
readNamespaceCategoryByResourceID();
|
||||
readNamespaceCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,8 +61,8 @@ public class NamespaceCategoryReader {
|
|||
* @return the metadata format by id
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private void readNamespaceCategoryByResourceID() throws Exception {
|
||||
logger.trace("Getting Namespace Category for resourceID: "+resourceID);
|
||||
private void readNamespaceCategory() throws Exception {
|
||||
logger.trace("Getting Namespace Category");
|
||||
|
||||
if(this.scope==null)
|
||||
throw new Exception("Scope is null");
|
||||
|
@ -84,7 +76,7 @@ public class NamespaceCategoryReader {
|
|||
|
||||
logger.info("Using scope from ScopeProvider: "+scopeString);
|
||||
|
||||
String queryString = QueryForResourceUtil.queryForGenericResourceById(resourceID);
|
||||
String queryString = QueryForResourceUtil.getGcubeGenericQueryStringForSecondaryTypeAndName(GENERIC_RESOURCE_NAMESPACES_NAME, GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE);
|
||||
logger.trace("queryString: " +queryString);
|
||||
Query q = new QueryBox(queryString);
|
||||
|
||||
|
@ -92,18 +84,15 @@ public class NamespaceCategoryReader {
|
|||
List<String> appProfile = client.submit(q);
|
||||
|
||||
if (appProfile == null || appProfile.size() == 0)
|
||||
throw new MetadataProfileNotFoundException("Your resourceID "+resourceID+" is not registered in the infrastructure, the scope is "+scopeString);
|
||||
throw new MetadataProfileNotFoundException("Your resource is not registered in the infrastructure, the scope is "+scopeString);
|
||||
else {
|
||||
String theResource = null;
|
||||
try{
|
||||
theResource = appProfile.get(0);
|
||||
// logger.trace("Resource with resourceID "+resourceID+" matched "+theResource);
|
||||
logger.debug("Resource (Namespaces Catalogue Categories) within resourceID "+resourceID+" found");
|
||||
logger.debug("Resource (Namespaces Catalogue Categories) found");
|
||||
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||
Node node = docBuilder.parse(new InputSource(new StringReader(theResource))).getDocumentElement();
|
||||
XPathHelper helper = new XPathHelper(node);
|
||||
// List<MetadataField> fields = getMetadataFieldsFromResource(helper);
|
||||
// mf.setMetadataFields(fields);
|
||||
logger.debug("Unmarshalling it..");
|
||||
readNamespaceCategoryFromResource(helper);
|
||||
}catch(Exception e){
|
||||
|
@ -112,10 +101,11 @@ public class NamespaceCategoryReader {
|
|||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error while trying to fetch resourceID "+resourceID+" from the infrastructure, the scope is "+scopeString,e);
|
||||
throw new Exception("Error while trying to fetch resourceID "+resourceID+" from the infrastructure, the scope is "+scopeString, e);
|
||||
logger.error("Error while trying to fetch resource with name " + GENERIC_RESOURCE_NAMESPACES_NAME + " and secondary type " + GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE +
|
||||
" from the infrastructure, the scope is "+scopeString, e);
|
||||
throw new Exception("Error while trying to fetch resource with name " + GENERIC_RESOURCE_NAMESPACES_NAME + " and secondary type " + GENERIC_RESOURCE_NAMESPACES_SECONDARY_TYPE +
|
||||
" from the infrastructure, the scope is "+scopeString, e);
|
||||
} finally{
|
||||
// ScopeProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,31 +139,6 @@ public class NamespaceCategoryReader {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Namespaces catalogue categories resource id.
|
||||
*
|
||||
* @return the string
|
||||
* @throws PropertyFileNotFoundException the property file not found exception
|
||||
*/
|
||||
public static String NamespacesCatalogueCategoriesResourceID() throws PropertyFileNotFoundException {
|
||||
|
||||
Properties prop = new Properties();
|
||||
|
||||
try {
|
||||
|
||||
InputStream in = NamespaceCategoryReader.class.getResourceAsStream(NAMESPACES_CATALOGUE_CATEGORIES_PROPERTIES);
|
||||
// load a properties file
|
||||
prop.load(in);
|
||||
return prop.getProperty("RESOURCE_ID");
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error("An error occurred on read property file "+NAMESPACES_CATALOGUE_CATEGORIES_PROPERTIES, e);
|
||||
throw new PropertyFileNotFoundException("An error occurred on read property file "+NAMESPACES_CATALOGUE_CATEGORIES_PROPERTIES+": "+e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the namespaces.
|
||||
*
|
||||
|
@ -193,8 +158,6 @@ public class NamespaceCategoryReader {
|
|||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("NamespaceCategoryReader [scope=");
|
||||
builder.append(scope);
|
||||
builder.append(", resourceID=");
|
||||
builder.append(resourceID);
|
||||
builder.append(", namespaces=");
|
||||
builder.append(namespaces);
|
||||
builder.append("]");
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# Property files
|
||||
#
|
||||
# author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
# created 04/2017
|
||||
#
|
||||
# Generic resource id of "Namespaces Calogue Categories"
|
||||
#
|
||||
#
|
||||
|
||||
RESOURCE_ID = cdc52c27-6d7b-4d55-b4cd-314d7cc2e224
|
|
@ -4,6 +4,7 @@
|
|||
package org.gcube.datacatalogue.metadatadiscovery.reader;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class QueryForResourceUtil.
|
||||
*
|
||||
|
@ -27,7 +28,6 @@ public class QueryForResourceUtil {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string for secondary type.
|
||||
*
|
||||
|
@ -41,4 +41,18 @@ public class QueryForResourceUtil {
|
|||
" return $profile";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gcube generic query string for secondary type.
|
||||
* @param name the resource name
|
||||
* @param secondaryType the secondary type
|
||||
* @return the gcube generic query string for secondary type
|
||||
*/
|
||||
public static String getGcubeGenericQueryStringForSecondaryTypeAndName(String name, String secondaryType){
|
||||
|
||||
return "for $profile in collection('/db/Profiles/GenericResource')//Resource " +
|
||||
"where $profile/Profile/SecondaryType/string() eq '" + secondaryType + "' and $profile/Profile/Name/string() " +
|
||||
" eq '" + name + "'" +
|
||||
"return $profile";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue