2022-02-16 22:34:30 +01:00
|
|
|
package org.gcube.gcat.configuration;
|
2022-02-15 09:59:02 +01:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2022-02-28 15:43:40 +01:00
|
|
|
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
|
2022-11-29 14:42:20 +01:00
|
|
|
import org.gcube.gcat.configuration.isproxies.GCoreISConfigurationProxy;
|
2022-12-07 09:36:19 +01:00
|
|
|
import org.gcube.gcat.configuration.isproxies.GCoreISConfigurationProxyFactory;
|
|
|
|
import org.gcube.gcat.configuration.isproxies.FacetBasedISConfigurationProxyFactory;
|
2022-12-05 14:31:10 +01:00
|
|
|
import org.gcube.gcat.configuration.isproxies.FacetBasedISConfigurationProxy;
|
2022-11-29 14:42:20 +01:00
|
|
|
import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration;
|
2022-04-21 17:18:02 +02:00
|
|
|
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
2022-02-15 09:59:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
|
|
|
public class CatalogueConfigurationFactory {
|
|
|
|
|
2022-02-17 16:32:54 +01:00
|
|
|
private static final Map<String, ServiceCatalogueConfiguration> catalogueConfigurations;
|
2022-02-15 09:59:02 +01:00
|
|
|
|
|
|
|
static {
|
|
|
|
catalogueConfigurations = new HashMap<>();
|
|
|
|
}
|
|
|
|
|
2022-11-29 15:03:35 +01:00
|
|
|
private static ServiceCatalogueConfiguration load(String context) {
|
2022-12-07 09:36:19 +01:00
|
|
|
ServiceCatalogueConfiguration serviceCatalogueConfiguration = null;
|
|
|
|
try {
|
|
|
|
FacetBasedISConfigurationProxy facetBasedISConfigurationProxy = FacetBasedISConfigurationProxyFactory.getInstance(context);
|
|
|
|
serviceCatalogueConfiguration = facetBasedISConfigurationProxy.getCatalogueConfiguration();
|
|
|
|
} catch(Exception e){
|
|
|
|
GCoreISConfigurationProxy gCoreISConfigurationProxy = GCoreISConfigurationProxyFactory.getInstance();
|
2022-11-29 15:03:35 +01:00
|
|
|
serviceCatalogueConfiguration = gCoreISConfigurationProxy.getCatalogueConfiguration();
|
|
|
|
}
|
|
|
|
return serviceCatalogueConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void purgeFromIS(String context) {
|
2022-12-07 09:36:19 +01:00
|
|
|
FacetBasedISConfigurationProxy restISConfigurationProxy = FacetBasedISConfigurationProxyFactory.getInstance(context);
|
2022-11-29 15:03:35 +01:00
|
|
|
restISConfigurationProxy.delete();
|
2022-12-07 09:36:19 +01:00
|
|
|
|
|
|
|
GCoreISConfigurationProxy gCoreISConfigurationProxy = GCoreISConfigurationProxyFactory.getInstance();
|
2022-11-29 15:03:35 +01:00
|
|
|
gCoreISConfigurationProxy.delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void createOrUpdateOnIS(String context, ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
2022-12-07 09:36:19 +01:00
|
|
|
FacetBasedISConfigurationProxy restISConfigurationProxy = FacetBasedISConfigurationProxyFactory.getInstance(context);
|
2022-12-06 18:29:31 +01:00
|
|
|
restISConfigurationProxy.setCatalogueConfiguration(catalogueConfiguration);
|
2022-11-29 15:03:35 +01:00
|
|
|
restISConfigurationProxy.createOrUpdateOnIS();
|
2022-12-07 09:36:19 +01:00
|
|
|
|
|
|
|
GCoreISConfigurationProxy gCoreISConfigurationProxy = GCoreISConfigurationProxyFactory.getInstance();
|
2022-12-06 18:29:31 +01:00
|
|
|
gCoreISConfigurationProxy.setCatalogueConfiguration(catalogueConfiguration);
|
2022-11-29 15:03:35 +01:00
|
|
|
gCoreISConfigurationProxy.createOrUpdateOnIS();
|
2022-02-15 09:59:02 +01:00
|
|
|
}
|
|
|
|
|
2022-11-29 15:03:35 +01:00
|
|
|
|
2022-02-17 16:32:54 +01:00
|
|
|
public synchronized static ServiceCatalogueConfiguration getInstance() {
|
2022-02-28 15:43:40 +01:00
|
|
|
String context = SecretManagerProvider.instance.get().getContext();
|
2022-02-17 16:32:54 +01:00
|
|
|
ServiceCatalogueConfiguration catalogueConfiguration = catalogueConfigurations.get(context);
|
2022-02-15 09:59:02 +01:00
|
|
|
if(catalogueConfiguration == null) {
|
|
|
|
catalogueConfiguration = load(context);
|
|
|
|
catalogueConfigurations.put(context, catalogueConfiguration);
|
|
|
|
}
|
|
|
|
return catalogueConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized static void renew() {
|
2022-02-28 15:43:40 +01:00
|
|
|
String context = SecretManagerProvider.instance.get().getContext();
|
2022-02-15 09:59:02 +01:00
|
|
|
catalogueConfigurations.remove(context);
|
2022-02-17 16:32:54 +01:00
|
|
|
ServiceCatalogueConfiguration catalogueConfiguration = load(context);
|
2022-02-15 09:59:02 +01:00
|
|
|
catalogueConfigurations.put(context, catalogueConfiguration);
|
|
|
|
}
|
|
|
|
|
|
|
|
public synchronized static void purge() {
|
|
|
|
// Remove the resource from IS
|
2022-02-28 15:43:40 +01:00
|
|
|
String context = SecretManagerProvider.instance.get().getContext();
|
2022-02-15 09:59:02 +01:00
|
|
|
catalogueConfigurations.remove(context);
|
2022-11-29 15:03:35 +01:00
|
|
|
purgeFromIS(context);
|
2022-02-15 09:59:02 +01:00
|
|
|
}
|
|
|
|
|
2022-02-17 16:32:54 +01:00
|
|
|
public synchronized static ServiceCatalogueConfiguration createOrUpdate(ServiceCatalogueConfiguration catalogueConfiguration) throws Exception {
|
2022-02-28 15:43:40 +01:00
|
|
|
String context = SecretManagerProvider.instance.get().getContext();
|
2022-02-15 09:59:02 +01:00
|
|
|
catalogueConfigurations.remove(context);
|
2022-11-29 12:33:42 +01:00
|
|
|
|
2022-11-29 15:03:35 +01:00
|
|
|
createOrUpdateOnIS(context, catalogueConfiguration);
|
2022-02-15 09:59:02 +01:00
|
|
|
catalogueConfigurations.put(context, catalogueConfiguration);
|
2022-04-21 17:18:02 +02:00
|
|
|
|
|
|
|
// The supported organizations could be changed we need to empty the user cache for the context
|
|
|
|
// to avoid to miss to add an user in an organization which has been added.
|
2022-05-27 17:25:36 +02:00
|
|
|
CKANUserCache.emptyUserCache();
|
2022-04-21 17:18:02 +02:00
|
|
|
|
2022-02-15 09:59:02 +01:00
|
|
|
return catalogueConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|