From 1f916354433031e54a9f6635cc6bfac7f4992e62 Mon Sep 17 00:00:00 2001 From: "luca.frosini" Date: Wed, 28 Jun 2023 14:23:57 +0200 Subject: [PATCH] Improving service --- .../GRSFFacetBasedISConfigurationProxy.java | 3 --- .../impl/GRSFGCoreISConfigurationProxy.java | 22 ++++++++--------- .../grsf/publisher/freemarker/FreeMarker.java | 24 +++++++++---------- .../publisher/freemarker/FreeMarkerTest.java | 12 ++++++++-- .../grsf/publisher/record/RecordTest.java | 12 ++++++++-- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFFacetBasedISConfigurationProxy.java b/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFFacetBasedISConfigurationProxy.java index 2255969..c1d8f03 100644 --- a/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFFacetBasedISConfigurationProxy.java +++ b/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFFacetBasedISConfigurationProxy.java @@ -2,14 +2,11 @@ package org.gcube.grsf.publisher.configuration.isproxies.impl; import java.io.File; import java.net.URL; -import java.util.Map; -import java.util.Set; import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.gcat.configuration.isproxies.impl.FacetBasedISConfigurationProxy; import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration; import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfiguration; -import org.gcube.grsf.publisher.utils.OrganizationUtils; /** * @author Luca Frosini (ISTI - CNR) diff --git a/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFGCoreISConfigurationProxy.java b/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFGCoreISConfigurationProxy.java index 0178928..4222b44 100644 --- a/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFGCoreISConfigurationProxy.java +++ b/src/main/java/org/gcube/grsf/publisher/configuration/isproxies/impl/GRSFGCoreISConfigurationProxy.java @@ -1,11 +1,9 @@ package org.gcube.grsf.publisher.configuration.isproxies.impl; -import java.util.Map; -import java.util.Set; - +import org.gcube.com.fasterxml.jackson.databind.ObjectMapper; import org.gcube.gcat.configuration.isproxies.impl.GCoreISConfigurationProxy; import org.gcube.gcat.configuration.service.ServiceCatalogueConfiguration; -import org.gcube.grsf.publisher.utils.OrganizationUtils; +import org.gcube.grsf.publisher.configuration.GRSFCatalogueConfiguration; /** * @author Luca Frosini (ISTI - CNR) @@ -18,14 +16,14 @@ public class GRSFGCoreISConfigurationProxy extends GCoreISConfigurationProxy { @Override protected ServiceCatalogueConfiguration readFromIS() { - ServiceCatalogueConfiguration scc = super.readFromIS(); - scc.setModerationEnabled(false); - scc.setSocialPostEnabled(false); - scc.setNotificationToUsersEnabled(false); - Map organizationMap = OrganizationUtils.getInstance().getOrganizations(); - Set organizations = organizationMap.keySet(); - scc.setSupportedOrganizations(organizations); - return scc; + try { + ServiceCatalogueConfiguration scc = super.readFromIS(); + ObjectMapper objectMapper = new ObjectMapper(); + GRSFCatalogueConfiguration grsfCC = objectMapper.treeToValue(objectMapper.valueToTree(scc), GRSFCatalogueConfiguration.class); + return grsfCC; + }catch (Exception e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/org/gcube/grsf/publisher/freemarker/FreeMarker.java b/src/main/java/org/gcube/grsf/publisher/freemarker/FreeMarker.java index 806e505..bf0e89d 100644 --- a/src/main/java/org/gcube/grsf/publisher/freemarker/FreeMarker.java +++ b/src/main/java/org/gcube/grsf/publisher/freemarker/FreeMarker.java @@ -17,25 +17,25 @@ import freemarker.template.TemplateExceptionHandler; */ public class FreeMarker { - protected static Configuration configuration; - protected static File freemarkerDirectory; + protected Configuration configuration; + protected File freemarkerDirectory; - public static File getResourcesDirectory() throws Exception { - URL fileURL = FreeMarker.class.getClassLoader().getResource("config.properties"); - File logbackFile = new File(fileURL.toURI()); - File resourcesDirectory = logbackFile.getParentFile(); - return resourcesDirectory; - } +// protected File getResourcesDirectory() throws Exception { +// URL fileURL = FreeMarker.class.getClassLoader().getResource("config.properties"); +// File logbackFile = new File(fileURL.toURI()); +// File resourcesDirectory = logbackFile.getParentFile(); +// return resourcesDirectory; +// } - public static File getFreemarkerDirectory() throws Exception { + protected File getFreemarkerDirectory() throws Exception { if(freemarkerDirectory==null) { - File resourcesDirectory = getResourcesDirectory(); - freemarkerDirectory = new File(resourcesDirectory, "freemarker"); + URL directoryURL = FreeMarker.class.getClassLoader().getResource("freemarker"); + freemarkerDirectory = new File(directoryURL.toURI()); } return freemarkerDirectory; } - public static Configuration getConfiguration() throws Exception { + protected Configuration getConfiguration() throws Exception { if(configuration ==null) { configuration = new Configuration(Configuration.VERSION_2_3_23); configuration.setDirectoryForTemplateLoading(getFreemarkerDirectory()); diff --git a/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java b/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java index 10c4466..46448b7 100644 --- a/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java +++ b/src/test/java/org/gcube/grsf/publisher/freemarker/FreeMarkerTest.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileWriter; import java.io.FilenameFilter; import java.io.Writer; +import java.net.URL; import java.util.Calendar; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -24,10 +25,17 @@ public class FreeMarkerTest { private static Logger logger = LoggerFactory.getLogger(FreeMarkerTest.class); public File getExampleDirectory(String type) throws Exception { - File resourcesDirectory = FreeMarker.getResourcesDirectory(); + File resourcesDirectory = getResourcesDirectory(); return new File(resourcesDirectory, "examples/" + type); } + protected File getResourcesDirectory() throws Exception { + URL fileURL = FreeMarker.class.getClassLoader().getResource("config.properties"); + File logbackFile = new File(fileURL.toURI()); + File resourcesDirectory = logbackFile.getParentFile(); + return resourcesDirectory; + } + @Test public void testIt() throws Exception { FreeMarker freeMarker = new FreeMarker(); @@ -44,7 +52,7 @@ public class FreeMarkerTest { int countRecord = 0; int countTimeSeries = 0; - File outputDir = new File(FreeMarker.getResourcesDirectory(), "output"); + File outputDir = new File(getResourcesDirectory(), "output"); outputDir.mkdir(); FilenameFilter dirnameFilter = new FilenameFilter() { diff --git a/src/test/java/org/gcube/grsf/publisher/record/RecordTest.java b/src/test/java/org/gcube/grsf/publisher/record/RecordTest.java index e18fd0b..ec883a8 100644 --- a/src/test/java/org/gcube/grsf/publisher/record/RecordTest.java +++ b/src/test/java/org/gcube/grsf/publisher/record/RecordTest.java @@ -3,6 +3,7 @@ package org.gcube.grsf.publisher.record; import java.io.File; import java.io.FilenameFilter; import java.net.URI; +import java.net.URL; import java.util.Calendar; import java.util.List; import java.util.concurrent.TimeUnit; @@ -26,7 +27,7 @@ public class RecordTest extends ContextTest { private static Logger logger = LoggerFactory.getLogger(RecordTest.class); public File getExampleDirectory(String type) throws Exception { - File resourcesDirectory = FreeMarker.getResourcesDirectory(); + File resourcesDirectory = getResourcesDirectory(); return new File(resourcesDirectory, "examples/" + type); } @@ -132,6 +133,13 @@ public class RecordTest extends ContextTest { return uriInfo; } + protected File getResourcesDirectory() throws Exception { + URL fileURL = FreeMarker.class.getClassLoader().getResource("config.properties"); + File logbackFile = new File(fileURL.toURI()); + File resourcesDirectory = logbackFile.getParentFile(); + return resourcesDirectory; + } + @Test public void testRecords() throws Exception { @@ -149,7 +157,7 @@ public class RecordTest extends ContextTest { int countRecord = 0; int countTimeSeries = 0; - File outputDir = new File(FreeMarker.getResourcesDirectory(), "output"); + File outputDir = new File(getResourcesDirectory(), "output"); outputDir.mkdir(); FilenameFilter dirnameFilter = new FilenameFilter() {