Adding Configuration read/create to switch to the new IS
This commit is contained in:
parent
7a434f999a
commit
275880c428
22
pom.xml
22
pom.xml
|
@ -63,6 +63,28 @@
|
||||||
<!-- <artifactId>common-encryption</artifactId> -->
|
<!-- <artifactId>common-encryption</artifactId> -->
|
||||||
<!-- </dependency> -->
|
<!-- </dependency> -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>information-system-model</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.resource-management</groupId>
|
||||||
|
<artifactId>gcube-model</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-client</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.information-system</groupId>
|
||||||
|
<artifactId>resource-registry-publisher</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.data-catalogue</groupId>
|
<groupId>org.gcube.data-catalogue</groupId>
|
||||||
<artifactId>gcubedatacatalogue-metadata-discovery</artifactId>
|
<artifactId>gcubedatacatalogue-metadata-discovery</artifactId>
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package org.gcube.gcat.profile;
|
package org.gcube.gcat.profile;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.InternalServerErrorException;
|
import javax.ws.rs.InternalServerErrorException;
|
||||||
|
@ -9,8 +13,11 @@ import javax.ws.rs.NotAuthorizedException;
|
||||||
import javax.ws.rs.NotFoundException;
|
import javax.ws.rs.NotFoundException;
|
||||||
import javax.ws.rs.WebApplicationException;
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import org.gcube.common.resources.gcore.GenericResource;
|
import org.gcube.common.resources.gcore.GenericResource;
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
|
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery;
|
import org.gcube.datacatalogue.metadatadiscovery.reader.MetadataFormatDiscovery;
|
||||||
import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil;
|
import org.gcube.datacatalogue.metadatadiscovery.reader.QueryForResourceUtil;
|
||||||
import org.gcube.gcat.persistence.ckan.CKANUser;
|
import org.gcube.gcat.persistence.ckan.CKANUser;
|
||||||
|
@ -19,6 +26,20 @@ import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
||||||
import org.gcube.gcat.utils.Constants;
|
import org.gcube.gcat.utils.Constants;
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
import org.gcube.informationsystem.publisher.RegistryPublisher;
|
||||||
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
import org.gcube.informationsystem.publisher.RegistryPublisherFactory;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.IdentifierFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.facets.XSDSchemaFacetImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.entities.resources.ConfigurationImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.IdentifierFacet.IdentificationType;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.facets.XSDSchemaFacet;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
||||||
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
import org.gcube.resources.discovery.client.queries.api.Query;
|
import org.gcube.resources.discovery.client.queries.api.Query;
|
||||||
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
|
||||||
|
@ -29,13 +50,24 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
|
||||||
|
|
||||||
public class ISProfile {
|
public class ISProfile {
|
||||||
|
|
||||||
public static int PRETTY_PRINT_INDENT_FACTOR = 4;
|
public static int PRETTY_PRINT_INDENT_FACTOR = 4;
|
||||||
|
|
||||||
|
public static final String PROFILE = "profile";
|
||||||
|
public static final String PROFILE_SCHEMA = "profileSchema";
|
||||||
|
|
||||||
|
public static final String SCHEMA_URL_ADDRESS = "https://wiki.gcube-system.org/images_gcube/e/e8/Gcdcmetadataprofilev3.xsd";
|
||||||
|
public static final URL SCHEMA_URL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
SCHEMA_URL = new URL(SCHEMA_URL_ADDRESS);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(ISProfile.class);
|
private static Logger logger = LoggerFactory.getLogger(ISProfile.class);
|
||||||
|
|
||||||
protected ObjectMapper mapper;
|
protected ObjectMapper mapper;
|
||||||
|
@ -62,6 +94,41 @@ public class ISProfile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* https://wiki.gcube-system.org/gcube/Facet_Based_Resource_Model#Configuration
|
||||||
|
*/
|
||||||
|
protected Configuration instantiateConfiguration(String name, String xml) throws Exception {
|
||||||
|
Configuration configuration = new ConfigurationImpl();
|
||||||
|
|
||||||
|
IdentifierFacet identifierFacet = new IdentifierFacetImpl();
|
||||||
|
identifierFacet.setValue(name);
|
||||||
|
identifierFacet.setType(IdentificationType.STRING);
|
||||||
|
IsIdentifiedBy<Configuration, IdentifierFacet> isIdentifiedBy = new IsIdentifiedByImpl<Configuration, IdentifierFacet>(configuration, identifierFacet);
|
||||||
|
configuration.addFacet(isIdentifiedBy);
|
||||||
|
|
||||||
|
SimpleFacet profile = new SimpleFacetImpl();
|
||||||
|
profile.setAdditionalProperty(PROFILE, xml);
|
||||||
|
configuration.addFacet(profile);
|
||||||
|
|
||||||
|
XSDSchemaFacet xsdSchemaFacet = new XSDSchemaFacetImpl();
|
||||||
|
xsdSchemaFacet.setName("gCube Item Profile");
|
||||||
|
xsdSchemaFacet.setSchemaURL(SCHEMA_URL);
|
||||||
|
xsdSchemaFacet.setDescription("gCube Metadata Profile defines a Metadata schema XML-based for adding custom metadata fields.");
|
||||||
|
xsdSchemaFacet.setContent(DataCalogueMetadataFormatReader.getProfileSchemaString());
|
||||||
|
configuration.addFacet(xsdSchemaFacet);
|
||||||
|
|
||||||
|
return configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected Configuration getConfiguration(String name) throws ResourceRegistryException {
|
||||||
|
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
map.put(IdentifierFacet.VALUE_PROPERTY, name);
|
||||||
|
List<Configuration> configurations = resourceRegistryClient.getFilteredResources(Configuration.class, IsIdentifiedBy.class, IdentifierFacet.class, false, map);
|
||||||
|
return configurations.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO Check the Queries because the name in the Profile differs from the name in
|
* TODO Check the Queries because the name in the Profile differs from the name in
|
||||||
* <metadataformat type="Dataset">
|
* <metadataformat type="Dataset">
|
||||||
|
|
Loading…
Reference in New Issue