|
|
|
@ -1,224 +1,220 @@
|
|
|
|
|
package org.gcube.gcat.configuration.isproxies;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.InternalServerErrorException;
|
|
|
|
|
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import org.gcube.gcat.api.GCatConstants;
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
|
|
|
|
|
import org.gcube.gcat.configuration.service.ServiceCKANDB;
|
|
|
|
|
import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration;
|
|
|
|
|
import org.gcube.informationsystem.base.reference.Direction;
|
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Facet;
|
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
|
|
|
|
import org.gcube.informationsystem.model.impl.relations.ConsistsOfImpl;
|
|
|
|
|
import org.gcube.informationsystem.model.reference.entities.Entity;
|
|
|
|
|
import org.gcube.informationsystem.model.reference.properties.Encrypted;
|
|
|
|
|
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
|
|
|
|
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.informationsystem.types.TypeMapper;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
|
|
|
|
|
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
|
|
|
|
|
import org.gcube.informationsystem.utils.ElementMapper;
|
|
|
|
|
import org.gcube.resourcemanagement.model.impl.entities.facets.SimpleFacetImpl;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SimpleFacet;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.Configuration;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.entities.resources.VirtualService;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.CallsFor;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.IsCustomizedBy;
|
|
|
|
|
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Uses;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
|
*/
|
|
|
|
|
public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<Configuration> {
|
|
|
|
|
public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<SimpleFacet> {
|
|
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(FacetBasedISConfigurationProxy.class);
|
|
|
|
|
|
|
|
|
|
public static final String QUERY_DIRECTORY_NAME = "query";
|
|
|
|
|
|
|
|
|
|
public static final String GET_CATALOGUE_VIRTUAL_SERVICE_FILENAME = "01-get-catalogue-virtual-service.json";
|
|
|
|
|
|
|
|
|
|
public static final String GET_GCAT_CONFIGURATION_FILENAME = "02-get-gcat-configuration.json";
|
|
|
|
|
|
|
|
|
|
public static final String GET_SIMPLE_FACET_OF_GCAT_CONFIGURATION_FILENAME = "03-get-simple-facet-of-gcat-configuration.json";
|
|
|
|
|
public static final String GET_ACCESS_POINT_FACET_OF_CKAN_SERVICE_FILENAME = "05-get-access-point-facet-of-ckan-service.json";
|
|
|
|
|
public static final String GET_ACCESS_POINT_FACET_OF_POSTGRES_CKAN_DB_FILENAME = "07-get-access-point-facet-of-postgres-ckan-db.json";
|
|
|
|
|
public static final String GET_ACCESS_POINT_FACET_OF_SOLR_SERVICE_FILENAME = "09-get-access-point-facet-of-solr-service.json";
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Configuration
|
|
|
|
|
// ----------------------
|
|
|
|
|
// IsCustomizedBy | |
|
|
|
|
|
// -----------------> | gcat-configuration |
|
|
|
|
|
// / | |
|
|
|
|
|
// / ----------------------
|
|
|
|
|
// EService VirtualService /
|
|
|
|
|
// ------------ -----------------------------
|
|
|
|
|
// | | CallsFor | |
|
|
|
|
|
// | gcat | ------------> | catalogue-virtual-service |
|
|
|
|
|
// | | | |
|
|
|
|
|
// ------------ -----------------------------
|
|
|
|
|
// \ EService
|
|
|
|
|
// \ --------------------
|
|
|
|
|
// \ Uses | |
|
|
|
|
|
// \ ------------------> | postgres-ckan-db |
|
|
|
|
|
// \ / | |
|
|
|
|
|
// \ EService / --------------------
|
|
|
|
|
// \ -----------------
|
|
|
|
|
// \ CallsFor | |
|
|
|
|
|
// -------------> | ckan |
|
|
|
|
|
// | |
|
|
|
|
|
// ----------------- EService
|
|
|
|
|
// \ --------------------
|
|
|
|
|
// \ Uses | |
|
|
|
|
|
// ------------------> | solr |
|
|
|
|
|
// | |
|
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Some resources are not needed to be queried and maintained.
|
|
|
|
|
* Leaving comment to remember that is not an error
|
|
|
|
|
* protected Configuration configuration;
|
|
|
|
|
*
|
|
|
|
|
* public static final String GET_CKAN_SERVICE_FILENAME = "04-get-ckan-service.json";
|
|
|
|
|
* protected EService ckanService;
|
|
|
|
|
*
|
|
|
|
|
* public static final String GET_POSTGRES_CKAN_DB_FILENAME = "06-get-postgres-ckan-db.json";
|
|
|
|
|
* protected EService solrService;
|
|
|
|
|
*
|
|
|
|
|
* public static final String GET_SOLR_SERVICE_FILENAME = "08-get-solr-service.json";
|
|
|
|
|
* protected EService ckanDB;
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
protected final ObjectMapper objectMapper;
|
|
|
|
|
protected final ResourceRegistryClient resourceRegistryClient;
|
|
|
|
|
protected final ResourceRegistryPublisher resourceRegistryPublisher;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We need to keep this resource because we want to create
|
|
|
|
|
* an IsRelatedTo relation
|
|
|
|
|
* i.e. EService(gcat) --CallsFor--> VirtualService(catalogue-virtual-service)
|
|
|
|
|
*/
|
|
|
|
|
protected VirtualService virtualService;
|
|
|
|
|
protected Configuration configuration;
|
|
|
|
|
|
|
|
|
|
protected SimpleFacet configurationSimpleFacet;
|
|
|
|
|
|
|
|
|
|
protected EService ckanService;
|
|
|
|
|
protected EService solrService;
|
|
|
|
|
protected EService ckanDB;
|
|
|
|
|
|
|
|
|
|
public FacetBasedISConfigurationProxy(String context) {
|
|
|
|
|
super(context);
|
|
|
|
|
objectMapper = new ObjectMapper();
|
|
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
|
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public FacetBasedISConfigurationProxy(String context, ServiceCatalogueConfiguration catalogueConfiguration) {
|
|
|
|
|
super(context, catalogueConfiguration);
|
|
|
|
|
objectMapper = new ObjectMapper();
|
|
|
|
|
resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
|
resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public File getJsonQueryFromFile(String filename) throws Exception {
|
|
|
|
|
URL queryDirectoryURL = FacetBasedISConfigurationProxy.class.getClassLoader().getResource(QUERY_DIRECTORY_NAME);
|
|
|
|
|
File queryDirectory = new File(queryDirectoryURL.toURI());
|
|
|
|
|
return new File(queryDirectory, filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected VirtualService queryVirtualService(ResourceRegistryClient resourceRegistryClient) throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
|
Map<String,String> facetConstraint = new HashMap<>();
|
|
|
|
|
facetConstraint.put(SoftwareFacet.GROUP_PROPERTY, GCatConstants.CONFIGURATION_CATEGORY);
|
|
|
|
|
facetConstraint.put(SoftwareFacet.NAME_PROPERTY, GCatConstants.CATALOGUE_SERVICE_VIRTUAL_SERVICE_ID);
|
|
|
|
|
|
|
|
|
|
logger.trace("Going to query for {} --{}--> ({} with {})",
|
|
|
|
|
VirtualService.NAME, IsIdentifiedBy.NAME, SoftwareFacet.NAME, facetConstraint);
|
|
|
|
|
|
|
|
|
|
List<VirtualService> virtualServices = resourceRegistryClient.getFilteredResources(VirtualService.class, IsIdentifiedBy.class, SoftwareFacet.class, false, facetConstraint);
|
|
|
|
|
int size = virtualServices.size();
|
|
|
|
|
if(virtualServices==null || size==0) {
|
|
|
|
|
String message = String.format("No %s --%s--> (%s with %s) found",
|
|
|
|
|
VirtualService.NAME, IsIdentifiedBy.NAME, SoftwareFacet.NAME, facetConstraint.toString());
|
|
|
|
|
protected List<Entity> query(String query) throws Exception {
|
|
|
|
|
logger.trace("Going to request the following query:\n{}", query);
|
|
|
|
|
String result = resourceRegistryClient.jsonQuery(query);
|
|
|
|
|
logger.trace("The query:\n{}\nproduced the following result:\n{}", query, result);
|
|
|
|
|
List<Entity> entities = ElementMapper.unmarshalList(Entity.class, result);
|
|
|
|
|
return entities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected JsonNode getQuery(File jsonQueryFile) throws Exception {
|
|
|
|
|
JsonNode query = objectMapper.readTree(jsonQueryFile);
|
|
|
|
|
return query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected <E extends Entity> E getUniqueEntity(List<E> entities, String originalQuery) throws JsonProcessingException {
|
|
|
|
|
int size = entities.size();
|
|
|
|
|
if(entities==null || size==0) {
|
|
|
|
|
String message = String.format("No instance found with query:\n%s", originalQuery);
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(size>1) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"Too many %s --%s--> (%s with %s) found (i.e. expected 1, found %d)). %s",
|
|
|
|
|
VirtualService.NAME, IsIdentifiedBy.NAME, SoftwareFacet.NAME,
|
|
|
|
|
facetConstraint.toString(), size, ElementMapper.marshal(virtualServices));
|
|
|
|
|
"Too many instances found (i.e. expected 1, found %d) with query:\n%s\nthe obtained result is:\n%s",
|
|
|
|
|
size, originalQuery, ElementMapper.marshal(entities));
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return virtualServices.get(0);
|
|
|
|
|
return entities.get(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Configuration queryConfiguration(ResourceRegistryClient resourceRegistryClient, VirtualService virtualService) throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
|
List<Configuration> configurations = resourceRegistryClient.getRelatedResourcesFromReferenceResource(
|
|
|
|
|
Configuration.class, IsCustomizedBy.class, virtualService, Direction.IN, true);
|
|
|
|
|
int size = configurations.size();
|
|
|
|
|
if(configurations==null || size==0) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"No %s <--%s-- (%s uuid:%s) found",
|
|
|
|
|
Configuration.NAME, IsCustomizedBy.NAME, VirtualService.NAME,
|
|
|
|
|
virtualService.getHeader().getUUID());
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(size>1) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"Too many %s <--%s-- (%s uuid:%s) found (i.e. expected 1, found %d)). %s",
|
|
|
|
|
Configuration.NAME, IsCustomizedBy.NAME, VirtualService.NAME,
|
|
|
|
|
virtualService.getHeader().getUUID(), size, ElementMapper.marshal(configurations));
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return configurations.get(0);
|
|
|
|
|
protected Entity queryEntity(String filename) throws Exception{
|
|
|
|
|
File jsonQueryFile = getJsonQueryFromFile(filename);
|
|
|
|
|
JsonNode query = getQuery(jsonQueryFile);
|
|
|
|
|
String jsonQueryAsString = objectMapper.writeValueAsString(query);
|
|
|
|
|
List<Entity> entities = query(jsonQueryAsString);
|
|
|
|
|
return getUniqueEntity(entities, jsonQueryAsString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected <F extends Facet, C extends ConsistsOf<? extends Resource, F>> F getFacetFromResource(Resource resource, Class<C> coClz, Class<F> fClz) throws JsonProcessingException {
|
|
|
|
|
List<F> facets = resource.getFacets(coClz, fClz);
|
|
|
|
|
int size = facets.size();
|
|
|
|
|
if(facets==null || size==0) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"No %s <--%s-- %s found",
|
|
|
|
|
TypeMapper.getType(fClz), TypeMapper.getType(coClz), TypeMapper.getType(resource.getClass()));
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(size>1) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"Too many %s <--%s-- %s found (i.e. expected 1, found %d)). %s",
|
|
|
|
|
TypeMapper.getType(fClz), TypeMapper.getType(coClz), TypeMapper.getType(resource.getClass()),
|
|
|
|
|
size, ElementMapper.marshal(facets));
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return facets.get(0);
|
|
|
|
|
protected VirtualService queryVirtualService() throws Exception {
|
|
|
|
|
VirtualService virtualService = (VirtualService) queryEntity(GET_CATALOGUE_VIRTUAL_SERVICE_FILENAME);
|
|
|
|
|
return virtualService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
protected SimpleFacet getConfigurationSimpleFacet() throws JsonProcessingException {
|
|
|
|
|
return getFacetFromResource(configuration, ConsistsOf.class, SimpleFacet.class);
|
|
|
|
|
protected Configuration queryGcatConfiguration() throws Exception {
|
|
|
|
|
Configuration configuration = (Configuration) queryEntity(GET_GCAT_CONFIGURATION_FILENAME);
|
|
|
|
|
return configuration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected EService queryCkanService(ResourceRegistryClient resourceRegistryClient, VirtualService virtualService) throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
|
List<EService> eServices = resourceRegistryClient.getRelatedResourcesFromReferenceResource(
|
|
|
|
|
EService.class, CallsFor.class, virtualService, Direction.IN, true);
|
|
|
|
|
int size = eServices.size();
|
|
|
|
|
if(eServices==null || size==0) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"No %s <--%s-- (%s uuid:%s) found",
|
|
|
|
|
EService.NAME, Uses.NAME, VirtualService.NAME,
|
|
|
|
|
virtualService.getHeader().getUUID());
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(size>1) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"Too many %s <--%s-- (%s uuid:%s) found (i.e. expected 1, found %d)). %s",
|
|
|
|
|
EService.NAME, CallsFor.NAME, VirtualService.NAME,
|
|
|
|
|
virtualService.getHeader().getUUID(), size, ElementMapper.marshal(eServices));
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return eServices.get(0);
|
|
|
|
|
protected SimpleFacet queryConfigurationSimpleFacet() throws Exception {
|
|
|
|
|
SimpleFacet configurationSimpleFacet = (SimpleFacet) queryEntity(GET_SIMPLE_FACET_OF_GCAT_CONFIGURATION_FILENAME);
|
|
|
|
|
return configurationSimpleFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected List<EService> queryEServicesUsedByCkanService(ResourceRegistryClient resourceRegistryClient, EService ckanService) throws ResourceRegistryException, JsonProcessingException {
|
|
|
|
|
List<EService> eServices = resourceRegistryClient.getRelatedResourcesFromReferenceResource(
|
|
|
|
|
EService.class, Uses.class, ckanService, Direction.IN, true);
|
|
|
|
|
int size = eServices.size();
|
|
|
|
|
if(eServices==null || size==0) {
|
|
|
|
|
String message = String.format(
|
|
|
|
|
"No %s <--%s-- (%s uuid:%s) found",
|
|
|
|
|
EService.NAME, Uses.NAME, EService.NAME,
|
|
|
|
|
ckanService.getHeader().getUUID());
|
|
|
|
|
logger.error(message);
|
|
|
|
|
throw new InternalServerErrorException(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return eServices;
|
|
|
|
|
protected AccessPointFacet queryCkanServiceAccessPointFacet() throws Exception {
|
|
|
|
|
AccessPointFacet accessPointFacet = (AccessPointFacet) queryEntity(GET_ACCESS_POINT_FACET_OF_CKAN_SERVICE_FILENAME);
|
|
|
|
|
return accessPointFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void getSolrServiceAndCKanDB(List<EService> eServices) throws JsonProcessingException {
|
|
|
|
|
for(EService eService : eServices) {
|
|
|
|
|
SoftwareFacet softwareFacet = getFacetFromResource(eService, IsIdentifiedBy.class, SoftwareFacet.class);
|
|
|
|
|
String group = softwareFacet.getGroup();
|
|
|
|
|
String name = softwareFacet.getName();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if(group.compareTo()==0 && name.compareTo()==0) {
|
|
|
|
|
// // TODO
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if(group.compareTo()==0 && name.compareTo()==0) {
|
|
|
|
|
// // TODO
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(solrService==null) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ckanDB==null) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
protected AccessPointFacet queryPostgresCkanDBAccessPointFacet() throws Exception {
|
|
|
|
|
AccessPointFacet accessPointFacet = (AccessPointFacet) queryEntity(GET_ACCESS_POINT_FACET_OF_POSTGRES_CKAN_DB_FILENAME);
|
|
|
|
|
return accessPointFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ServiceCatalogueConfiguration createServiceCatalogueConfiguration() {
|
|
|
|
|
ServiceCatalogueConfiguration serviceCatalogueConfiguration = new ServiceCatalogueConfiguration(context);
|
|
|
|
|
public AccessPointFacet querySolrServiceAccessPointFacet() throws Exception {
|
|
|
|
|
AccessPointFacet accessPointFacet = (AccessPointFacet) queryEntity(GET_ACCESS_POINT_FACET_OF_SOLR_SERVICE_FILENAME);
|
|
|
|
|
return accessPointFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected ServiceCatalogueConfiguration setGcatConfiguration(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
|
|
|
|
SimpleFacet configurationSimpleFacet = getISResource();
|
|
|
|
|
UUID uuid = configurationSimpleFacet.getHeader().getUUID();
|
|
|
|
|
if(uuid!=null) {
|
|
|
|
|
catalogueConfiguration.setID(uuid.toString());
|
|
|
|
|
}
|
|
|
|
|
catalogueConfiguration.setModerationEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.MODERATION_ENABLED_KEY));
|
|
|
|
|
catalogueConfiguration.setNotificationToUsersEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.NOTIFICATION_TO_USER_ENABLED_KEY));
|
|
|
|
|
catalogueConfiguration.setSocialPostEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.SOCIAL_POST_ENABLED_KEY));
|
|
|
|
|
|
|
|
|
|
serviceCatalogueConfiguration.setID(configuration.getHeader().getUUID().toString());
|
|
|
|
|
serviceCatalogueConfiguration.setModerationEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.MODERATION_ENABLED_KEY));
|
|
|
|
|
serviceCatalogueConfiguration.setNotificationToUsersEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.NOTIFICATION_TO_USER_ENABLED_KEY));
|
|
|
|
|
serviceCatalogueConfiguration.setSocialPostEnabled((boolean) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.SOCIAL_POST_ENABLED_KEY));
|
|
|
|
|
|
|
|
|
|
serviceCatalogueConfiguration.setDefaultOrganization((String) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.DEFAULT_ORGANIZATION_KEY));
|
|
|
|
|
catalogueConfiguration.setDefaultOrganization((String) configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.DEFAULT_ORGANIZATION_KEY));
|
|
|
|
|
|
|
|
|
|
Object supportedOrganizationsObj = configurationSimpleFacet.getAdditionalProperty(CatalogueConfiguration.SUPPORTED_ORGANIZATIONS_KEY);
|
|
|
|
|
Set<String> supportedOrganizations = new HashSet<>();
|
|
|
|
@ -227,38 +223,77 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<Configu
|
|
|
|
|
supportedOrganizations = new HashSet<String>((Collection<String>) supportedOrganizationsObj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
supportedOrganizations.add(serviceCatalogueConfiguration.getDefaultOrganization());
|
|
|
|
|
serviceCatalogueConfiguration.setSupportedOrganizations(supportedOrganizations);
|
|
|
|
|
supportedOrganizations.add(catalogueConfiguration.getDefaultOrganization());
|
|
|
|
|
catalogueConfiguration.setSupportedOrganizations(supportedOrganizations);
|
|
|
|
|
|
|
|
|
|
Map<String,Object> additionalProperties = new HashMap<>(configurationSimpleFacet.getAdditionalProperties());
|
|
|
|
|
|
|
|
|
|
for(String key : additionalProperties.keySet()) {
|
|
|
|
|
if(!CatalogueConfiguration.KNOWN_PROPERTIES.contains(key)) {
|
|
|
|
|
serviceCatalogueConfiguration.setAdditionalProperty(key, additionalProperties.get(key));
|
|
|
|
|
catalogueConfiguration.setAdditionalProperty(key, additionalProperties.get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return serviceCatalogueConfiguration;
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServiceCatalogueConfiguration setCkanServiceInfo(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
|
|
|
|
AccessPointFacet ckanServiceAccessPointFacet = queryCkanServiceAccessPointFacet();
|
|
|
|
|
catalogueConfiguration.setCkanURL(ckanServiceAccessPointFacet.getEndpoint().toString());
|
|
|
|
|
Encrypted encrypted = (Encrypted) ckanServiceAccessPointFacet.getAuthorization();
|
|
|
|
|
String encryptedPassword = encrypted.getEncryptedValue();
|
|
|
|
|
catalogueConfiguration.setSysAdminToken(encryptedPassword);
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServiceCatalogueConfiguration setCkanDBInfo(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
|
|
|
|
AccessPointFacet postgresCkanDBAccessPointFacet = queryPostgresCkanDBAccessPointFacet();
|
|
|
|
|
ServiceCKANDB ckanDB = new ServiceCKANDB();
|
|
|
|
|
String ckanDbURL = postgresCkanDBAccessPointFacet.getEndpoint().toString();
|
|
|
|
|
ckanDB.setUrl(ckanDbURL);
|
|
|
|
|
Encrypted encrypted = (Encrypted) postgresCkanDBAccessPointFacet.getAuthorization();
|
|
|
|
|
String encryptedPassword = encrypted.getEncryptedValue();
|
|
|
|
|
ckanDB.setEncryptedPassword(encryptedPassword);
|
|
|
|
|
String username = (String) postgresCkanDBAccessPointFacet.getAdditionalProperty(ServiceCKANDB.USERNAME_KEY);
|
|
|
|
|
ckanDB.setUsername(username);
|
|
|
|
|
catalogueConfiguration.setCkanDB(ckanDB);
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServiceCatalogueConfiguration setSolrServiceInfo(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
|
|
|
|
AccessPointFacet solrServiceAccessPointFacet = querySolrServiceAccessPointFacet();
|
|
|
|
|
String solrURL = solrServiceAccessPointFacet.getEndpoint().toString();
|
|
|
|
|
catalogueConfiguration.setSolrURL(solrURL);
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected SimpleFacet instatiateSimpleFacetUsingDefaultValues(ServiceCatalogueConfiguration catalogueConfiguration) {
|
|
|
|
|
SimpleFacet simpleFacet = new SimpleFacetImpl();
|
|
|
|
|
simpleFacet.setAdditionalProperty(CatalogueConfiguration.MODERATION_ENABLED_KEY, catalogueConfiguration.isModerationEnabled());
|
|
|
|
|
simpleFacet.setAdditionalProperty(CatalogueConfiguration.NOTIFICATION_TO_USER_ENABLED_KEY, catalogueConfiguration.isNotificationToUsersEnabled());
|
|
|
|
|
simpleFacet.setAdditionalProperty(CatalogueConfiguration.SOCIAL_POST_ENABLED_KEY, catalogueConfiguration.isSocialPostEnabled());
|
|
|
|
|
|
|
|
|
|
simpleFacet.setAdditionalProperty(CatalogueConfiguration.DEFAULT_ORGANIZATION_KEY, catalogueConfiguration.getDefaultOrganization());
|
|
|
|
|
simpleFacet.setAdditionalProperty(CatalogueConfiguration.SUPPORTED_ORGANIZATIONS_KEY, catalogueConfiguration.getSupportedOrganizations());
|
|
|
|
|
return simpleFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected ServiceCatalogueConfiguration readFromIS() {
|
|
|
|
|
try {
|
|
|
|
|
ResourceRegistryClient resourceRegistryClient = ResourceRegistryClientFactory.create();
|
|
|
|
|
|
|
|
|
|
virtualService = queryVirtualService(resourceRegistryClient);
|
|
|
|
|
|
|
|
|
|
configuration = queryConfiguration(resourceRegistryClient, virtualService);
|
|
|
|
|
configurationSimpleFacet = getConfigurationSimpleFacet();
|
|
|
|
|
|
|
|
|
|
ckanService = queryCkanService(resourceRegistryClient, virtualService);
|
|
|
|
|
|
|
|
|
|
List<EService> eServices = queryEServicesUsedByCkanService(resourceRegistryClient, ckanService);
|
|
|
|
|
getSolrServiceAndCKanDB(eServices);
|
|
|
|
|
|
|
|
|
|
catalogueConfiguration = createServiceCatalogueConfiguration();
|
|
|
|
|
catalogueConfiguration = new ServiceCatalogueConfiguration(context);
|
|
|
|
|
virtualService = queryVirtualService();
|
|
|
|
|
|
|
|
|
|
configurationSimpleFacet = getISResource();
|
|
|
|
|
if(configurationSimpleFacet==null) {
|
|
|
|
|
configurationSimpleFacet = instatiateSimpleFacetUsingDefaultValues(catalogueConfiguration);
|
|
|
|
|
}else {
|
|
|
|
|
catalogueConfiguration = setGcatConfiguration(catalogueConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catalogueConfiguration = setCkanServiceInfo(catalogueConfiguration);
|
|
|
|
|
catalogueConfiguration = setCkanDBInfo(catalogueConfiguration);
|
|
|
|
|
catalogueConfiguration = setSolrServiceInfo(catalogueConfiguration);
|
|
|
|
|
|
|
|
|
|
}catch (InternalServerErrorException e) {
|
|
|
|
|
throw e;
|
|
|
|
@ -271,25 +306,49 @@ public class FacetBasedISConfigurationProxy extends ISConfigurationProxy<Configu
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void delete() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
SimpleFacet simpleFacet = getISResource();
|
|
|
|
|
if(simpleFacet!=null) {
|
|
|
|
|
try {
|
|
|
|
|
resourceRegistryPublisher.delete(simpleFacet);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new InternalServerErrorException("Unable to delete SimpleFacet with UUID " + simpleFacet.getHeader().getUUID().toString(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected ServiceCatalogueConfiguration createOnIS() throws Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
UUID uuid = configurationSimpleFacet.getHeader().getUUID();
|
|
|
|
|
if(uuid==null) {
|
|
|
|
|
Configuration gcatConfiguration = queryGcatConfiguration();
|
|
|
|
|
ConsistsOf<Configuration, SimpleFacet> co = new ConsistsOfImpl<>(gcatConfiguration, configurationSimpleFacet);
|
|
|
|
|
co = resourceRegistryPublisher.create(co);
|
|
|
|
|
configurationSimpleFacet = co.getTarget();
|
|
|
|
|
setGcatConfiguration(catalogueConfiguration);
|
|
|
|
|
}
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Configuration getISResource() {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
protected SimpleFacet getISResource() {
|
|
|
|
|
if(configurationSimpleFacet==null) {
|
|
|
|
|
try {
|
|
|
|
|
configurationSimpleFacet = queryConfigurationSimpleFacet();
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return configurationSimpleFacet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected ServiceCatalogueConfiguration updateOnIS(Configuration configuration) throws Exception {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return null;
|
|
|
|
|
protected ServiceCatalogueConfiguration updateOnIS(SimpleFacet configurationSimpleFacet) throws Exception {
|
|
|
|
|
UUID uuid = configurationSimpleFacet.getHeader().getUUID();
|
|
|
|
|
if(uuid!=null) {
|
|
|
|
|
this.configurationSimpleFacet = resourceRegistryPublisher.update(configurationSimpleFacet);
|
|
|
|
|
setGcatConfiguration(catalogueConfiguration);
|
|
|
|
|
}
|
|
|
|
|
return catalogueConfiguration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|