Improving service

This commit is contained in:
luca.frosini 2023-06-28 14:23:57 +02:00
parent 76f0269d91
commit 1f91635443
5 changed files with 42 additions and 31 deletions

View File

@ -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)

View File

@ -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<String,String> organizationMap = OrganizationUtils.getInstance().getOrganizations();
Set<String> 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);
}
}
}

View File

@ -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());

View File

@ -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() {

View File

@ -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() {