diff --git a/gcube/extra-resources/WEB-INF/gcube-app.xml b/gcube/extra-resources/WEB-INF/gcube-app.xml index f77abc3..44b06dc 100644 --- a/gcube/extra-resources/WEB-INF/gcube-app.xml +++ b/gcube/extra-resources/WEB-INF/gcube-app.xml @@ -2,7 +2,7 @@ ${project.artifactId} - ${project.groupId} + ${serviceClass} ${project.version} ${project.description} \ No newline at end of file diff --git a/pom.xml b/pom.xml index fee96c9..3d282e6 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ UTF-8 ${project.basedir}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF + data-catalogue diff --git a/src/main/java/org/gcube/gcat/configuration/GCoreISConfigurationProxy.java b/src/main/java/org/gcube/gcat/configuration/GCoreISConfigurationProxy.java index 4922d2c..23da2cf 100644 --- a/src/main/java/org/gcube/gcat/configuration/GCoreISConfigurationProxy.java +++ b/src/main/java/org/gcube/gcat/configuration/GCoreISConfigurationProxy.java @@ -3,6 +3,7 @@ package org.gcube.gcat.configuration; import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; +import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -12,13 +13,14 @@ import java.util.Set; import java.util.UUID; import javax.ws.rs.InternalServerErrorException; +import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; import org.gcube.com.fasterxml.jackson.core.JsonProcessingException; import org.gcube.com.fasterxml.jackson.databind.JsonNode; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode; -import org.gcube.common.encryption.encrypter.StringEncrypter; +import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode; import org.gcube.common.resources.gcore.GenericResource; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; @@ -27,6 +29,7 @@ import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.resources.gcore.ServiceEndpoint.Runtime; import org.gcube.common.resources.gcore.common.Platform; import org.gcube.common.resources.gcore.utils.Group; +import org.gcube.gcat.api.GCatConstants; import org.gcube.gcat.api.configuration.CatalogueConfiguration; import org.gcube.informationsystem.publisher.RegistryPublisher; import org.gcube.informationsystem.publisher.RegistryPublisherFactory; @@ -85,16 +88,18 @@ public class GCoreISConfigurationProxy { private final static String OLD_NAME = "CKanDataCatalogue"; protected final String context; + protected ObjectMapper mapper; protected ServiceCatalogueConfiguration catalogueConfiguration; public GCoreISConfigurationProxy(String context) { this.context = context; + this.mapper = new ObjectMapper(); } public GCoreISConfigurationProxy(String context, ServiceCatalogueConfiguration catalogueConfiguration) { this(context); this.catalogueConfiguration = catalogueConfiguration; - + this.mapper = new ObjectMapper(); } public ServiceCatalogueConfiguration getCatalogueConfiguration() { @@ -119,10 +124,122 @@ public class GCoreISConfigurationProxy { return stringBuffer.toString(); } - protected ServiceCatalogueConfiguration getCatalogueConfigurationFromIS() { - return getOLDCatalogueConfigurationFromIS(); + protected ObjectNode setValue(ObjectNode node, String key, String value) throws IOException { + if(value.toLowerCase().compareTo("true")==0 || value.toLowerCase().compareTo("false")==0) { + node.put(key, Boolean.parseBoolean(value)); + return node; + } + + if(value.startsWith("{") || value.startsWith("[")){ + JsonNode n = mapper.readTree(value); + node.set(key, n); + return node; + + } + + node.put(key, value); + return node; } + protected ServiceCatalogueConfiguration getConfiguration(ServiceEndpoint serviceEndpoint) throws IOException { + Profile profile = serviceEndpoint.profile(); + AccessPoint accessPoint = getAccessPoint(profile); + Map propertyMap = accessPoint.propertyMap(); + + ObjectNode node = mapper.createObjectNode(); + node.put(CatalogueConfiguration.ID_KEY, serviceEndpoint.id()); + + for(String key : propertyMap.keySet()) { + String value = propertyMap.get(key).value().trim(); + setValue(node, key, value); + } + + return mapper.treeToValue(node, ServiceCatalogueConfiguration.class); + } + + /** + * Retrieve endpoints information from IS for DataCatalogue URL + * + * @return list of endpoints for ckan data catalogue + * @throws Exception + */ + private List getServiceEndpoints(String category, String name) { + SimpleQuery query = queryFor(ServiceEndpoint.class); + query.addCondition("$resource/Profile/Category/text() eq '" + category + "'"); + query.addCondition("$resource/Profile/Name/text() eq '" + name + "'"); + DiscoveryClient client = clientFor(ServiceEndpoint.class); + List serviceEndpoints = client.submit(query); + return serviceEndpoints; + } + + protected ServiceEndpoint getServiceEndpoint() { + List serviceEndpoints = getServiceEndpoints(GCatConstants.CONFIGURATION_CATEGORY, GCatConstants.CONFIGURATION_NAME); + if (serviceEndpoints==null || serviceEndpoints.size() == 0) { + logger.error("There is no {} having Category {} and Name {} in this context.", + ServiceEndpoint.class.getSimpleName(), GCatConstants.CONFIGURATION_CATEGORY, GCatConstants.CONFIGURATION_NAME); + return null; + } + ServiceEndpoint serviceEndpoint = serviceEndpoints.get(0); + return serviceEndpoint; + } + + protected ServiceCatalogueConfiguration getCatalogueConfigurationFromIS() throws IOException { + ServiceEndpoint serviceEndpoint = getServiceEndpoint(); + if(serviceEndpoint==null) { + return getOLDCatalogueConfigurationFromIS(); + } + return getConfiguration(serviceEndpoint); + } + + @Deprecated + private ServiceEndpoint getOldServiceEndpoint() { + List serviceEndpoints = getServiceEndpoints(OLD_CATEGORY, OLD_NAME); + + if (serviceEndpoints.size() == 0) { + logger.error("There is no {} having Category {} and Name {} in this context.", + ServiceEndpoint.class.getSimpleName(), OLD_CATEGORY, OLD_NAME); + return null; + } + + ServiceEndpoint serviceEndpoint = null; + + if (serviceEndpoints.size() > 1) { + logger.info("Too many {} having Category {} and Name {} in this context. Looking for the one that has the property {}", + ServiceEndpoint.class.getSimpleName(), OLD_CATEGORY, OLD_NAME, IS_ROOT_MASTER_PROPERTY_KEY); + + for (ServiceEndpoint se : serviceEndpoints) { + Iterator accessPointIterator = se.profile().accessPoints().iterator(); + while (accessPointIterator.hasNext()) { + ServiceEndpoint.AccessPoint accessPoint = accessPointIterator.next(); + + // get the is master property + Property entry = accessPoint.propertyMap().get(IS_ROOT_MASTER_PROPERTY_KEY); + String isMaster = entry != null ? entry.value() : null; + + if (isMaster == null || !isMaster.equals("true")) { + continue; + } + + // set this variable + serviceEndpoint = se; + return serviceEndpoint; + } + } + + // if none of them was master, throw an exception + if (serviceEndpoint == null) { + throw new InternalServerErrorException( + "Too many catalogue configuration on IS and no one with MASTER property"); + } + + } else { + serviceEndpoint = serviceEndpoints.get(0); + } + + return serviceEndpoint; + } + + @Deprecated protected ServiceCatalogueConfiguration getOLDCatalogueConfigurationFromIS() { ServiceCatalogueConfiguration catalogueConfiguration = new ServiceCatalogueConfiguration(context); try { @@ -130,7 +247,7 @@ public class GCoreISConfigurationProxy { ServiceEndpoint serviceEndpoint = getOldServiceEndpoint(); if (serviceEndpoint == null) { - throw new InternalServerErrorException("No CKAN configuration on IS"); + throw new NotFoundException("No configuration found in this context"); } catalogueConfiguration.setID(serviceEndpoint.id()); @@ -208,87 +325,23 @@ public class GCoreISConfigurationProxy { return catalogueConfiguration; } - /** - * Retrieve endpoints information from IS for DataCatalogue URL - * - * @return list of endpoints for ckan data catalogue - * @throws Exception - */ - private List getServiceEndpoints(String category, String name) { - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Category/text() eq '" + category + "'"); - query.addCondition("$resource/Profile/Name/text() eq '" + name + "'"); - - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List serviceEndpoints = client.submit(query); - if(serviceEndpoints.size() == 0) { - String error = String.format("There is no %s having category '%s' and name '%s' in this context.", - ServiceEndpoint.class.getSimpleName(), category, name); - logger.error(error); - throw new InternalServerErrorException(error); - } - return serviceEndpoints; - } - - /** - * Retrieve endpoints information from IS for DataCatalogue URL - * @return list of endpoints for ckan data catalogue - * @throws Exception - */ - private ServiceEndpoint getOldServiceEndpoint() { - List serviceEndpoints = getServiceEndpoints(OLD_CATEGORY, OLD_NAME); - - if (serviceEndpoints.size() == 0) { - logger.error("There is no {} having Category {} and Name {} in this context.", - ServiceEndpoint.class.getSimpleName(), OLD_CATEGORY, OLD_NAME); - return null; - } - - ServiceEndpoint serviceEndpoint = null; - - if (serviceEndpoints.size() > 1) { - logger.info("Too many {} having Category {} and Name {} in this context. Looking for the one that has the property {}", - ServiceEndpoint.class.getSimpleName(), OLD_CATEGORY, OLD_NAME, IS_ROOT_MASTER_PROPERTY_KEY); - - for (ServiceEndpoint se : serviceEndpoints) { - Iterator accessPointIterator = se.profile().accessPoints().iterator(); - while (accessPointIterator.hasNext()) { - ServiceEndpoint.AccessPoint accessPoint = accessPointIterator.next(); - - // get the is master property - Property entry = accessPoint.propertyMap().get(IS_ROOT_MASTER_PROPERTY_KEY); - String isMaster = entry != null ? entry.value() : null; - - if (isMaster == null || !isMaster.equals("true")) { - continue; - } - - // set this variable - serviceEndpoint = se; - return serviceEndpoint; - } - } - - // if none of them was master, throw an exception - if (serviceEndpoint == null) { - throw new InternalServerErrorException( - "Too many catalogue configuration on IS and no one with MASTER property"); - } - - } else { - serviceEndpoint = serviceEndpoints.get(0); - } - - return serviceEndpoint; - } - // CKAN Instance info + @Deprecated private final static String CKAN_DB_SERVICE_ENDPOINT_CATEGORY= "Database"; + @Deprecated private final static String CKAN_DB_SERVICE_ENDPOINT_NAME = "CKanDatabase"; - + + @Deprecated protected ServiceCKANDB getCKANDBFromIS() { try { List serviceEndpoints = getServiceEndpoints(CKAN_DB_SERVICE_ENDPOINT_CATEGORY, CKAN_DB_SERVICE_ENDPOINT_NAME); + if(serviceEndpoints.size() == 0) { + String error = String.format("There is no %s having category '%s' and name '%s' in this context.", + ServiceEndpoint.class.getSimpleName(), CKAN_DB_SERVICE_ENDPOINT_CATEGORY, CKAN_DB_SERVICE_ENDPOINT_NAME); + logger.error(error); + throw new InternalServerErrorException(error); + } + ServiceEndpoint serviceEndpoint = null; if(serviceEndpoints.size() > 1) { @@ -349,10 +402,14 @@ public class GCoreISConfigurationProxy { } + @Deprecated public static final String GENERIC_RESOURCE_SECONDARY_TYPE_FOR_ORGANIZATIONS = "ApplicationProfile"; + @Deprecated public static final String GENERIC_RESOURCE_NAME_FOR_ORGANIZATIONS = "Supported CKAN Organizations"; + @Deprecated public static final String GENERIC_RESOURCE_CKAN_ORGANIZATIONS = "CKANOrganizations"; + @Deprecated private List getGenericResources() { SimpleQuery query = ICFactory.queryFor(GenericResource.class); query.addCondition(String.format("$resource/Profile/SecondaryType/text() eq '%s'", @@ -379,6 +436,7 @@ public class GCoreISConfigurationProxy { return objectMapper.writeValueAsString(arrayNode); } + @Deprecated protected Set unmarshallSupportedOrganizations(String supportedOrganizationsJsonArray){ try { ObjectMapper objectMapper = new ObjectMapper(); @@ -399,18 +457,7 @@ public class GCoreISConfigurationProxy { } } - protected void removeAllGenericResources() { - List genericResources = getGenericResources(); - removeAllGenericResources(genericResources); - } - - protected void removeAllGenericResources(List genericResources) { - RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); - for(GenericResource genericResource : genericResources) { - registryPublisher.remove(genericResource); - } - } - + @Deprecated protected Set getSupportedOrganizationsFromGenericResource() { List genericResources = getGenericResources(); @@ -427,15 +474,17 @@ public class GCoreISConfigurationProxy { Set supportedOrganizatins = unmarshallSupportedOrganizations(supportedOrganizationsJsonArray); - removeAllGenericResources(genericResources); - return supportedOrganizatins; } - - public void delete() { + @Deprecated + public void deleteOldConfiguration() { RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); - + deleteOldConfiguration(registryPublisher); + } + + @Deprecated + protected void deleteOldConfiguration(RegistryPublisher registryPublisher) { ServiceEndpoint serviceEndpoint = getOldServiceEndpoint(); if(serviceEndpoint!=null) { registryPublisher.remove(serviceEndpoint); @@ -449,6 +498,17 @@ public class GCoreISConfigurationProxy { } } + public void delete() { + RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); + + ServiceEndpoint serviceEndpoint = getServiceEndpoint(); + if(serviceEndpoint!=null) { + registryPublisher.remove(serviceEndpoint); + } + + deleteOldConfiguration(); + } + protected Property addProperty(Group properties, String name, String value) { return addProperty(properties, name, value, false); } @@ -456,38 +516,41 @@ public class GCoreISConfigurationProxy { protected Property addProperty(Group properties, String name, String value, boolean encrypted) { Property property = new Property(); property.nameAndValue(name, value); - property.encrypted(encrypted); + if(encrypted) { + property.encrypted(encrypted); + } properties.add(property); return property; } - protected Group setAccessPointProperties(AccessPoint accessPoint, boolean update) throws JsonProcessingException { + protected Group setAccessPointProperties(AccessPoint accessPoint, String address, boolean update) throws JsonProcessingException { accessPoint.description(String.format("Access Point %s by gcat %s", update ? "updated" : "created", getGcatVersion().toString())); - accessPoint.address(catalogueConfiguration.getCkanURL()); - - // TODO Change ASAP - //accessPoint.name("gcat Configuration"); - accessPoint.name("CKan Data Catalogue"); + accessPoint.address(address); + accessPoint.name(GCatConstants.CONFIGURATION_NAME); Group properties = accessPoint.properties(); - addProperty(properties, SOLR_INDEX_ADDRESS_PROPERTY_KEY, catalogueConfiguration.getSolrURL()); - addProperty(properties, DEFAULT_ORGANIZATION_PROPERTY_KEY, catalogueConfiguration.getDefaultOrganization()); - addProperty(properties, API_KEY_PROPERTY_KEY, catalogueConfiguration.getSysAdminToken(), true); - addProperty(properties, SOCIAL_POST_PROPERTY_KEY, Boolean.toString(catalogueConfiguration.isSocialPostEnabled())); - addProperty(properties, ALERT_USERS_ON_POST_CREATION_PROPERTY_KEY, Boolean.toString(catalogueConfiguration.isNotificationToUsersEnabled())); - addProperty(properties, MODERATION_ENABLED_KEY_PROPERTY_KEY, Boolean.toString(catalogueConfiguration.isModerationEnabled())); - addProperty(properties, SUPPORTED_ORGANIZATION_PROPERTY_KEY, marshallSupportedOrganizations()); + JsonNode jsonNode = mapper.valueToTree(catalogueConfiguration); + Iterator iterator = jsonNode.fieldNames(); + while (iterator.hasNext()) { + String key = iterator.next(); + JsonNode valueJsonNode = jsonNode.get(key); + + String value = valueJsonNode.toString(); + addProperty(properties, key, value); + } return properties; } - private final static String PLATFORM_NAME = "Tomcat"; - protected Version getGcatVersion() { - ApplicationContext applicationContext = ContextProvider.get(); - ApplicationConfiguration applicationConfiguration = applicationContext.configuration(); - Version version = new Version(applicationConfiguration.version()); - return version; + try { + ApplicationContext applicationContext = ContextProvider.get(); + ApplicationConfiguration applicationConfiguration = applicationContext.configuration(); + Version version = new Version(applicationConfiguration.version()); + return version; + }catch (Exception e) { + return new Version("2.2.0"); + } } /** @@ -509,19 +572,15 @@ public class GCoreISConfigurationProxy { protected Platform setPlatformProperty(Platform platform) { /* * - * Tomcat - * - * The version of gcat + * gcat + * * 2 * 2 * 0 * 0 * */ - - // TODO change to gcat ASAP - // platform.name("gcat"); - platform.name(PLATFORM_NAME); + platform.name(GCatConstants.SERVICE_NAME); platform = setVersion(platform); return platform; } @@ -531,13 +590,19 @@ public class GCoreISConfigurationProxy { } protected Runtime setRuntimeProperties(Runtime runtime) { - ApplicationContext applicationContext = ContextProvider.get(); - ContainerContext containerContext = applicationContext.container(); - ContainerConfiguration containerConfiguration = containerContext.configuration(); - String runningOn = getRunningOn(containerConfiguration); - runtime.hostedOn(runningOn); - runtime.ghnId(containerContext.id()); - runtime.status(applicationContext.configuration().mode().toString()); + try { + ApplicationContext applicationContext = ContextProvider.get(); + ContainerContext containerContext = applicationContext.container(); + ContainerConfiguration containerConfiguration = containerContext.configuration(); + String runningOn = getRunningOn(containerConfiguration); + runtime.hostedOn(runningOn); + runtime.ghnId(containerContext.id()); + runtime.status(applicationContext.configuration().mode().toString()); + }catch (Exception e) { + runtime.hostedOn("localhost"); + runtime.ghnId(""); + runtime.status("READY"); + } return runtime; } @@ -548,47 +613,27 @@ public class GCoreISConfigurationProxy { * CKanDataCatalogue * gCat Configuration created/updated by the service via REST */ - profile.category(OLD_CATEGORY); - profile.name(OLD_NAME); + profile.category(GCatConstants.CONFIGURATION_CATEGORY); + profile.name(GCatConstants.CONFIGURATION_NAME); profile.description(String.format("gCat configuration %s by the service via REST", update ? "updated" : "created")); return profile; } - protected boolean isRootMaster(ServiceEndpoint serviceEndpoint) { - Profile profile = serviceEndpoint.profile(); - AccessPoint accessPoint = getAccessPoint(profile); - Map propertyMap = accessPoint.propertyMap(); - if (propertyMap.containsKey(IS_ROOT_MASTER_PROPERTY_KEY)) { - if (propertyMap.get(IS_ROOT_MASTER_PROPERTY_KEY).value().trim().equalsIgnoreCase("true")) { - return true; - } - } - return false; - } +// @Deprecated +// protected boolean isRootMaster(ServiceEndpoint serviceEndpoint) { +// Profile profile = serviceEndpoint.profile(); +// AccessPoint accessPoint = getAccessPoint(profile); +// Map propertyMap = accessPoint.propertyMap(); +// if (propertyMap.containsKey(IS_ROOT_MASTER_PROPERTY_KEY)) { +// if (propertyMap.get(IS_ROOT_MASTER_PROPERTY_KEY).value().trim().equalsIgnoreCase("true")) { +// return true; +// } +// } +// return false; +// } protected ServiceEndpoint createServiceEndpoint(ServiceEndpoint serviceEndpoint) throws Exception { boolean update = serviceEndpoint != null; - boolean rootMaster = false; - - if(update) { - if(catalogueConfiguration.getSysAdminToken()==null) { - Profile profile = serviceEndpoint.profile(); - AccessPoint accessPoint = getAccessPoint(profile); - Map propertyMap = accessPoint.propertyMap(); - - // add this host - String ckanURL = accessPoint.address(); - catalogueConfiguration.setCkanURL(ckanURL); - - // retrieve sys admin token - String encryptedSysAdminToken = propertyMap.get(API_KEY_PROPERTY_KEY).value(); - catalogueConfiguration.setSysAdminToken(StringEncrypter.getEncrypter().decrypt(encryptedSysAdminToken)); - } - - rootMaster = isRootMaster(serviceEndpoint); - - } - serviceEndpoint = new ServiceEndpoint(); serviceEndpoint.setId(catalogueConfiguration.getID()); @@ -604,12 +649,8 @@ public class GCoreISConfigurationProxy { Group accessPoints = profile.accessPoints(); AccessPoint accessPoint = accessPoints.add(); - Group properties = setAccessPointProperties(accessPoint, update); - - if(rootMaster) { - addProperty(properties, IS_ROOT_MASTER_PROPERTY_KEY, Boolean.toString(rootMaster)); - } - + setAccessPointProperties(accessPoint, runtime.hostedOn(), update); + return serviceEndpoint; } diff --git a/src/main/java/org/gcube/gcat/configuration/Version.java b/src/main/java/org/gcube/gcat/configuration/Version.java index de35bf6..40fae1c 100644 --- a/src/main/java/org/gcube/gcat/configuration/Version.java +++ b/src/main/java/org/gcube/gcat/configuration/Version.java @@ -1,5 +1,6 @@ package org.gcube.gcat.configuration; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -10,7 +11,7 @@ public class Version implements Comparable { /** * Regex validating the version */ - public final static String VERSION_REGEX = "^[1-9][0-9]{0,}\\.(0|([1-9][0-9]{0,}))\\.(0|([1-9][0-9]{0,}))$"; + public final static String VERSION_REGEX = "^[1-9][0-9]{0,}\\.(0|([1-9][0-9]{0,}))\\.(0|([1-9][0-9]{0,}))"; private final static Pattern VERSION_PATTERN; @@ -35,10 +36,13 @@ public class Version implements Comparable { } public void setVersion(String version) { - if(!VERSION_PATTERN.matcher(version).find()) { + Matcher matcher = VERSION_PATTERN.matcher(version); + if(!matcher.find()) { throw new RuntimeException("The provided version (i.e. " + version + ") MUST comply with the regex " + VERSION_REGEX); } - String[] parts = version.split("\\."); + + String matched = matcher.group(0); + String[] parts = matched.split("\\."); this.major = Integer.valueOf(parts[0]); this.minor = Integer.valueOf(parts[1]); this.revision = Integer.valueOf(parts[2]); diff --git a/src/main/java/org/gcube/gcat/rest/Configuration.java b/src/main/java/org/gcube/gcat/rest/Configuration.java index 214f719..6fad6d4 100644 --- a/src/main/java/org/gcube/gcat/rest/Configuration.java +++ b/src/main/java/org/gcube/gcat/rest/Configuration.java @@ -15,6 +15,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; @@ -82,7 +83,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf String configuration = gotCatalogueConfiguration.toJsonString(); logger.debug("The new configuration in context {} is {}", catalogueConfiguration.getContext(), configuration); return configuration; - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -103,7 +104,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf responseBuilder.entity(ret).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8); } return responseBuilder.build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -117,7 +118,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf try { checkContext(context); return read(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -135,7 +136,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf responseBuilder.entity(configuration).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8); } return responseBuilder.build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -151,7 +152,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json); checkContext(context, catalogueConfiguration); return createOrUpdate(catalogueConfiguration); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -171,7 +172,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf responseBuilder.entity(configuration).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8); } return responseBuilder.build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -186,7 +187,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf try { checkContext(context); return patch(json); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -226,7 +227,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf responseBuilder.entity(ret).type(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8); } return responseBuilder.build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -234,7 +235,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf } @DELETE - @PathParam(CONTEXT_FULLNAME_PARAMETER) + @Path("/{" + CONTEXT_FULLNAME_PARAMETER + "}") public Response delete(@PathParam(CONTEXT_FULLNAME_PARAMETER) String context, @QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) throws WebServiceException { try { @@ -244,7 +245,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf }else { return delete(); } - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -257,7 +258,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf try { CatalogueConfigurationFactory.renew(); return Response.status(Status.NO_CONTENT).build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -265,12 +266,12 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf } @PURGE - @PathParam(CONTEXT_FULLNAME_PARAMETER) + @Path("/{" + CONTEXT_FULLNAME_PARAMETER + "}") public Response purge(@PathParam(CONTEXT_FULLNAME_PARAMETER) String context) throws WebServiceException { try { checkContext(context); return purge(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); @@ -283,7 +284,7 @@ public class Configuration extends BaseREST implements org.gcube.gcat.api.interf try { CatalogueConfigurationFactory.purge(); return Response.status(Status.NO_CONTENT).build(); - }catch (WebServiceException e) { + }catch (WebApplicationException e) { throw e; }catch (Exception e) { throw new InternalServerErrorException(e); diff --git a/src/test/java/org/gcube/gcat/configuration/GCoreISConfigurationProxyTest.java b/src/test/java/org/gcube/gcat/configuration/GCoreISConfigurationProxyTest.java index fa84492..ffd38e4 100644 --- a/src/test/java/org/gcube/gcat/configuration/GCoreISConfigurationProxyTest.java +++ b/src/test/java/org/gcube/gcat/configuration/GCoreISConfigurationProxyTest.java @@ -1,9 +1,18 @@ package org.gcube.gcat.configuration; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.Set; +import java.util.stream.Collectors; import org.gcube.common.authorization.utils.manager.SecretManager; import org.gcube.gcat.ContextTest; +import org.gcube.smartgears.ContextProvider; +import org.gcube.smartgears.configuration.application.ApplicationConfiguration; +import org.gcube.smartgears.configuration.application.DefaultApplicationConfiguration; +import org.gcube.smartgears.context.application.ApplicationContext; +import org.gcube.smartgears.context.application.DefaultApplicationContext; import org.junit.Assert; import org.junit.Test; import org.slf4j.Logger; @@ -41,7 +50,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest { logger.info("All as JsonArray [{},{},{},{}]", json, secondJson, decryptedJson, thirdJson); } - @Test + // @Test public void updateConfigurationToNewVersion() throws Exception { ContextTest.setContextByName("/gcube/devsec/devVRE"); String context = SecretManager.instance.get().getContext(); @@ -54,6 +63,18 @@ public class GCoreISConfigurationProxyTest extends ContextTest { logger.debug("Updated configuration {}", json); } + public static String DEVVRE_CONFIG_JSON = "devvre.conf.json"; + + @Test + public void createConfiguration() throws Exception { + ContextTest.setContextByName("/gcube/devsec/devVRE"); + String context = SecretManager.instance.get().getContext(); + InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(DEVVRE_CONFIG_JSON); + String json = new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining("\n")); + ServiceCatalogueConfiguration catalogueConfiguration = ServiceCatalogueConfiguration.getServiceCatalogueConfiguration(json); + GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context, catalogueConfiguration); + gCoreISConfigurationProxy.createOnIS(null); + } // protected GenericResource instantiateGenericResource(String secondaryType, String name, String xml) throws Exception { diff --git a/src/test/java/org/gcube/gcat/configuration/VersionTest.java b/src/test/java/org/gcube/gcat/configuration/VersionTest.java new file mode 100644 index 0000000..449f50e --- /dev/null +++ b/src/test/java/org/gcube/gcat/configuration/VersionTest.java @@ -0,0 +1,23 @@ +package org.gcube.gcat.configuration; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) + */ +public class VersionTest { + + private static final Logger logger = LoggerFactory.getLogger(VersionTest.class); + + @Test + public void testVersions() { + String[] versions = new String[]{"2.2.0-SNAPSHOT", "1.3.5", "1.4.5-beta", "1.5.6-gcore"}; + for(String v : versions) { + Version version = new Version(v); + logger.debug("Version is {}", version); + } + } + +} diff --git a/src/test/resources/.gitignore b/src/test/resources/.gitignore index 6c67de3..0d87605 100644 --- a/src/test/resources/.gitignore +++ b/src/test/resources/.gitignore @@ -5,3 +5,4 @@ /config.properties.old-authz /config.properties.old /config.properties-new-authz +/devvre.conf.json