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;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-02-18 14:41:41 +01:00
|
|
|
import org.gcube.application.cms.caches.AbstractScopedMap;
|
2022-09-26 16:11:20 +02:00
|
|
|
import org.gcube.application.cms.serialization.Serialization;
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
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;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
2022-03-30 18:39:10 +02:00
|
|
|
import java.io.File;
|
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
|
2022-02-18 15:34:22 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|