gcube-cms-suite/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/providers/ucd/LocalFolderProfileMapCache....

69 lines
1.8 KiB
Java
Raw Normal View History

2022-03-23 18:38:07 +01:00
package org.gcube.application.geoportal.service.engine.providers.ucd;
2021-09-20 16:47:35 +02:00
2021-12-07 13:05:08 +01:00
import com.fasterxml.jackson.core.JsonProcessingException;
2022-03-30 18:39:10 +02:00
import com.mongodb.util.JSON;
2021-12-07 13:05:08 +01:00
import lombok.extern.slf4j.Slf4j;
2022-02-18 14:41:41 +01:00
import org.gcube.application.cms.caches.AbstractScopedMap;
2022-03-04 14:23:20 +01:00
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
2021-12-07 13:05:08 +01:00
import org.gcube.application.geoportal.common.utils.Files;
2022-02-04 17:45:47 +01:00
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
2022-02-01 15:24:39 +01:00
import org.gcube.application.cms.serialization.Serialization;
2021-09-20 16:47:35 +02:00
2022-03-30 18:39:10 +02:00
import java.io.File;
import java.io.FileFilter;
2021-12-07 13:05:08 +01:00
import java.io.IOException;
import java.nio.charset.Charset;
2021-09-20 16:47:35 +02:00
2021-12-07 13:05:08 +01:00
@Slf4j
2022-03-23 18:38:07 +01:00
public class LocalFolderProfileMapCache extends AbstractScopedMap<ProfileMap> {
2021-12-07 12:16:29 +01:00
2022-03-30 18:39:10 +02:00
String folderPath = null;
public LocalFolderProfileMapCache(String folderPath) {
2022-03-23 18:38:07 +01:00
super("Local Profiles CACHE");
2022-03-30 18:39:10 +02:00
this.folderPath=folderPath;
2021-09-20 16:47:35 +02:00
}
@Override
public void init() {
}
@Override
protected void dispose(ProfileMap toDispose) {
2021-12-07 12:16:29 +01:00
2021-09-20 16:47:35 +02:00
}
2022-03-30 18:39:10 +02:00
2021-09-20 16:47:35 +02:00
@Override
2022-03-10 18:15:10 +01:00
protected ProfileMap retrieveObject(String context) throws ConfigurationException {
2021-12-07 12:16:29 +01:00
2021-12-07 13:05:08 +01:00
// Load from resources
2022-02-18 18:11:34 +01:00
ProfileMap toReturn=new ProfileMap();
2021-12-07 13:05:08 +01:00
try {
2022-03-30 18:39:10 +02:00
log.debug("Loading from {} ",folderPath);
File baseFolder = new File (folderPath);
for (File file : baseFolder.listFiles(pathname -> pathname.getName().endsWith(".json"))) {
try {
2022-04-01 19:11:11 +02:00
String jsonString = Files.readFileAsString(file.getAbsolutePath(), Charset.defaultCharset());
log.trace("JSON IS {}",jsonString);
UseCaseDescriptor p = Serialization.read(jsonString, UseCaseDescriptor.class);
2022-03-30 18:39:10 +02:00
toReturn.put(p.getId(),p);
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
2021-12-07 12:16:29 +01:00
2022-03-30 18:39:10 +02:00
}catch(Throwable t){
t.printStackTrace();
2021-12-07 13:05:08 +01:00
}
2022-03-30 18:39:10 +02:00
2022-02-18 18:11:34 +01:00
return toReturn;
2021-12-07 12:16:29 +01:00
2021-09-20 16:47:35 +02:00
}
}