Moving configuration to the new IS

This commit is contained in:
Luca Frosini 2022-11-29 12:33:42 +01:00
parent f8e6a0cc43
commit fdabed4a87
11 changed files with 158 additions and 58 deletions

View File

@ -3,6 +3,12 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for gCube Catalogue (gCat) Service
## [v2.4.2-SNAPSHOT]
- Switched from commons-lang3 to commons-lang to avoid duplicates
- Set resource-registry-publisher dependency scope to provided
## [v2.4.1]
- Integrating Sphinx for documentation [#23833]

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.data-catalogue</groupId>
<artifactId>gcat</artifactId>
<packaging>war</packaging>
<version>2.4.1</version>
<version>2.4.2-SNAPSHOT</version>
<name>gCube Catalogue (gCat) Service</name>
<description>
This service allows any client to publish on the gCube Catalogue.
@ -208,9 +208,9 @@
<!-- Used by Validator -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!--

View File

@ -50,8 +50,10 @@ public class CatalogueConfigurationFactory {
public synchronized static ServiceCatalogueConfiguration createOrUpdate(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
String context = SecretManagerProvider.instance.get().getContext();
catalogueConfigurations.remove(context);
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context, catalogueConfiguration);
catalogueConfiguration = gCoreISConfigurationProxy.createOrUpdateOnIS();
catalogueConfigurations.put(context, catalogueConfiguration);
// The supported organizations could be changed we need to empty the user cache for the context

View File

@ -38,7 +38,6 @@ import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.icclient.ICFactory;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.container.ContainerContext;
@ -48,7 +47,7 @@ import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class GCoreISConfigurationProxy {
public class GCoreISConfigurationProxy extends ISConfigurationProxy<ServiceEndpoint> {
private static final Logger logger = LoggerFactory.getLogger(GCoreISConfigurationProxy.class);
@ -88,24 +87,21 @@ public class GCoreISConfigurationProxy {
private final static String OLD_CATEGORY = "Application";
private final static String OLD_NAME = "CKanDataCatalogue";
protected final String context;
protected ObjectMapper mapper;
protected ServiceCatalogueConfiguration catalogueConfiguration;
public GCoreISConfigurationProxy(String context) {
this.context = context;
super(context);
this.mapper = new ObjectMapper();
}
public GCoreISConfigurationProxy(String context, ServiceCatalogueConfiguration catalogueConfiguration) {
this(context);
this.catalogueConfiguration = catalogueConfiguration;
super(context, catalogueConfiguration);
this.mapper = new ObjectMapper();
}
public ServiceCatalogueConfiguration getCatalogueConfiguration() throws WebApplicationException {
if (catalogueConfiguration == null) {
catalogueConfiguration = getCatalogueConfigurationFromIS();
catalogueConfiguration = readFromIS();
}
return catalogueConfiguration;
}
@ -168,7 +164,8 @@ public class GCoreISConfigurationProxy {
return serviceEndpoints;
}
protected ServiceEndpoint getServiceEndpoint() {
@Override
protected ServiceEndpoint getISResource() {
List<ServiceEndpoint> 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.",
@ -179,10 +176,11 @@ public class GCoreISConfigurationProxy {
return serviceEndpoint;
}
protected ServiceCatalogueConfiguration getCatalogueConfigurationFromIS() throws WebApplicationException {
ServiceEndpoint serviceEndpoint = getServiceEndpoint();
@Override
protected ServiceCatalogueConfiguration readFromIS() throws WebApplicationException {
ServiceEndpoint serviceEndpoint = getISResource();
if(serviceEndpoint==null) {
return getOLDCatalogueConfigurationFromIS();
return getOLDCatalogueConfigurationFromGCoreIS();
}
try {
return getConfiguration(serviceEndpoint);
@ -240,7 +238,7 @@ public class GCoreISConfigurationProxy {
}
@Deprecated
protected ServiceCatalogueConfiguration getOLDCatalogueConfigurationFromIS() {
protected ServiceCatalogueConfiguration getOLDCatalogueConfigurationFromGCoreIS() {
ServiceCatalogueConfiguration catalogueConfiguration = new ServiceCatalogueConfiguration(context);
try {
// boolean mustBeUpdated = false;
@ -251,7 +249,7 @@ public class GCoreISConfigurationProxy {
}
// catalogueConfiguration.setID(serviceEndpoint.id());
Profile profile = serviceEndpoint.profile();
AccessPoint accessPoint = getAccessPoint(profile);
@ -498,14 +496,13 @@ public class GCoreISConfigurationProxy {
}
}
@Override
public void delete() {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
ServiceEndpoint serviceEndpoint = getServiceEndpoint();
ServiceEndpoint serviceEndpoint = getISResource();
if(serviceEndpoint!=null) {
registryPublisher.remove(serviceEndpoint);
}
}
protected Property addProperty(Group<Property> properties, String name, String value) {
@ -554,17 +551,6 @@ public class GCoreISConfigurationProxy {
return properties;
}
protected Version getGcatVersion() {
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");
}
}
/**
* Set the version of gcat so that in future implementation
* we can understand if the configuration must be updated.
@ -668,7 +654,8 @@ public class GCoreISConfigurationProxy {
return serviceEndpoint;
}
public ServiceCatalogueConfiguration createOnIS() throws Exception {
@Override
protected ServiceCatalogueConfiguration createOnIS() throws Exception {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = catalogueConfiguration.getID();
if(id==null || id.compareTo("")==0) {
@ -680,7 +667,8 @@ public class GCoreISConfigurationProxy {
return catalogueConfiguration;
}
public ServiceCatalogueConfiguration updateOnIS(ServiceEndpoint serviceEndpoint) throws Exception {
@Override
protected ServiceCatalogueConfiguration updateOnIS(ServiceEndpoint serviceEndpoint) throws Exception {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = serviceEndpoint.id();
catalogueConfiguration.setID(id);
@ -689,16 +677,4 @@ public class GCoreISConfigurationProxy {
return catalogueConfiguration;
}
public ServiceCatalogueConfiguration createOrUpdateOnIS() throws Exception {
ServiceEndpoint serviceEndpoint = getServiceEndpoint();
if(serviceEndpoint!=null) {
// It's an update
updateOnIS(serviceEndpoint);
}else {
// It's a create
createOnIS();
}
return catalogueConfiguration;
}
}

View File

@ -0,0 +1,66 @@
package org.gcube.gcat.configuration;
import javax.ws.rs.WebApplicationException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public abstract class ISConfigurationProxy<ISResource extends Object> {
protected final String context;
protected ServiceCatalogueConfiguration catalogueConfiguration;
public ISConfigurationProxy(String context) {
this.context = context;
}
public ISConfigurationProxy(String context, ServiceCatalogueConfiguration catalogueConfiguration) {
this(context);
this.catalogueConfiguration = catalogueConfiguration;
}
public ServiceCatalogueConfiguration getCatalogueConfiguration() throws WebApplicationException {
if (catalogueConfiguration == null) {
catalogueConfiguration = readFromIS();
}
return catalogueConfiguration;
}
public ServiceCatalogueConfiguration createOrUpdateOnIS() throws Exception {
ISResource isResource = getISResource();
if(isResource!=null) {
// It's an update
catalogueConfiguration = updateOnIS(isResource);
}else {
// It's a create
catalogueConfiguration = createOnIS();
}
return catalogueConfiguration;
}
protected Version getGcatVersion() {
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");
}
}
protected abstract ServiceCatalogueConfiguration createOnIS() throws Exception;
protected abstract ISResource getISResource();
protected abstract ServiceCatalogueConfiguration readFromIS();
protected abstract ServiceCatalogueConfiguration updateOnIS(ISResource isResource) throws Exception;
protected abstract void delete();
}

View File

@ -0,0 +1,45 @@
package org.gcube.gcat.configuration;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class RestISConfigurationProxy extends ISConfigurationProxy {
public RestISConfigurationProxy(String context) {
super(context);
}
public RestISConfigurationProxy(String context, ServiceCatalogueConfiguration catalogueConfiguration) {
super(context, catalogueConfiguration);
}
@Override
protected ServiceCatalogueConfiguration readFromIS() {
// TODO Auto-generated method stub
return null;
}
@Override
protected void delete() {
// TODO Auto-generated method stub
}
@Override
protected ServiceCatalogueConfiguration createOnIS() throws Exception {
// TODO Auto-generated method stub
return null;
}
@Override
protected Object getISResource() {
// TODO Auto-generated method stub
return null;
}
@Override
protected ServiceCatalogueConfiguration updateOnIS(Object isResource) throws Exception {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -16,7 +16,7 @@ import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang.math.NumberUtils;
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;
@ -588,7 +588,7 @@ public class Validator {
break;
case Number:
if(!NumberUtils.isCreatable(value))
if(!NumberUtils.isNumber(value))
throw new BadRequestException("Field's value with key '" + key + "' is not a valid number!");
break;

View File

@ -21,6 +21,7 @@ import javax.ws.rs.core.MultivaluedMap;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.api.configuration.CatalogueConfiguration;
@ -891,7 +892,10 @@ public class CKANPackage extends CKAN implements Moderated {
((ObjectNode) jsonNode).remove(RESOURCES_KEY);
}
if(configuration.getScopeBean().is(Type.VRE)) {
String context = configuration.getContext();
ScopeBean scopeBean = new ScopeBean(context);
if(scopeBean.is(Type.VRE)) {
addItemURLViaResolver(jsonNode);
}
@ -904,7 +908,7 @@ public class CKANPackage extends CKAN implements Moderated {
postItemCreated();
if(!isModerationEnabled()) {
if(configuration.getScopeBean().is(Type.VRE)) {
if(scopeBean.is(Type.VRE)) {
// Actions performed after a package has been correctly created on ckan.
sendSocialPost();
}
@ -1489,7 +1493,10 @@ public class CKANPackage extends CKAN implements Moderated {
moderationThread.setItemCoordinates(itemID, name, itemTitle, itemURL);
moderationThread.postItemApproved(moderatorMessage);
if(configuration.getScopeBean().is(Type.VRE)) {
String context = configuration.getContext();
ScopeBean scopeBean = new ScopeBean(context);
if(scopeBean.is(Type.VRE)) {
// Actions performed after a package has been correctly created on ckan.
sendSocialPost();
}

View File

@ -35,7 +35,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
ContextTest.setContextByName("/gcube/devsec/devVRE");
String context = SecretManagerProvider.instance.get().getContext();
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context);
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getCatalogueConfigurationFromIS();
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.readFromIS();
String json = catalogueConfiguration.toJsonString();
logger.info("Configuration in context {} is {}", context, json);
/*
@ -57,7 +57,7 @@ public class GCoreISConfigurationProxyTest extends ContextTest {
String context = SecretManagerProvider.instance.get().getContext();
GCoreISConfigurationProxy gCoreISConfigurationProxy = new GCoreISConfigurationProxy(context);
@SuppressWarnings("deprecation")
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getOLDCatalogueConfigurationFromIS();
ServiceCatalogueConfiguration catalogueConfiguration = gCoreISConfigurationProxy.getOLDCatalogueConfigurationFromGCoreIS();
String json = catalogueConfiguration.toJsonString();
logger.debug("Read configuration {}", json);
catalogueConfiguration = gCoreISConfigurationProxy.createOrUpdateOnIS();

View File

@ -73,7 +73,7 @@ public class CKANOrganizationTest extends ContextTest {
ScopeBean scopeBean = new ScopeBean(context);
CKANOrganization ckanOrganization = new CKANOrganization();
ckanOrganization.setApiKey(CKANUtility.getSysAdminAPI());
String name = CatalogueConfiguration.getOrganizationName(scopeBean);
String name = CatalogueConfiguration.getOrganizationName(context);
ckanOrganization.setName(name);
String json = "{\"display_name\": \"" + scopeBean.name() + "\",\"description\": \"" + context + " Organization\",\"name\": \"" + name + "\"}";
logger.info("Going to create Organization {} : {}", name, json);

View File

@ -180,8 +180,7 @@ public class CKANPackageTest extends ContextTest {
@Test
public void listWithParameters() throws Exception {
String contextName = "/gcube/devNext/NextNext";
ScopeBean scopeBean = new ScopeBean(contextName);
String ckanOrganizationName = CatalogueConfiguration.getOrganizationName(scopeBean);
String ckanOrganizationName = CatalogueConfiguration.getOrganizationName(contextName);
ContextTest.setContextByName(contextName);
CKANPackage ckanPackage = new CKANPackage();
@ -312,8 +311,7 @@ public class CKANPackageTest extends ContextTest {
protected CKANPackage createPackage(ObjectMapper mapper, Boolean socialPost) throws Exception {
String currentContext = SecretManagerProvider.instance.get().getContext();
ScopeBean scopeBean = new ScopeBean(currentContext);
String organization = CatalogueConfiguration.getOrganizationName(scopeBean);
String organization = CatalogueConfiguration.getOrganizationName(currentContext);
ObjectNode itemObjectNode = mapper.createObjectNode();
itemObjectNode.put(CKAN.NAME_KEY, ITEM_NAME_VALUE);