2021-09-20 16:47:35 +02:00
|
|
|
package org.gcube.application.geoportal.service.engine.providers;
|
|
|
|
|
2021-12-07 13:05:08 +01:00
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
2022-02-18 15:34:22 +01:00
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
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;
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.profile.Profile;
|
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
|
|
|
|
2021-12-07 13:05:08 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
import java.util.HashMap;
|
2021-09-20 16:47:35 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
2021-12-07 13:05:08 +01:00
|
|
|
@Slf4j
|
2022-02-18 15:34:22 +01:00
|
|
|
public class ProfileMapCache extends AbstractScopedMap<ProfileMapCache.ProfileMap> {
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
public static class ProfileMap {
|
|
|
|
@Getter
|
|
|
|
Map<String,Profile> profileMap=new HashMap<>();
|
|
|
|
}
|
2021-09-20 16:47:35 +02:00
|
|
|
|
2021-12-07 12:16:29 +01:00
|
|
|
public ProfileMapCache() {
|
|
|
|
super("Profiles CACHE");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-02-18 15:34:22 +01:00
|
|
|
protected ProfileMap retrieveObject() throws ConfigurationException {
|
2021-12-07 12:16:29 +01:00
|
|
|
|
|
|
|
|
2021-12-07 13:05:08 +01:00
|
|
|
// Load from resources
|
|
|
|
HashMap<String,Profile> toReturn=new HashMap<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Profile p=Serialization.read(Files.
|
2022-01-12 18:42:22 +01:00
|
|
|
readFileAsString(Files.getFileFromResources("profiles/profiledConcessioni.json").getAbsolutePath(), Charset.defaultCharset()), Profile.class);
|
2021-12-07 13:05:08 +01:00
|
|
|
log.debug("Loaded "+p.getName()+" ID "+p.getId());
|
|
|
|
toReturn.put(p.getId(),p);
|
2021-12-07 12:16:29 +01:00
|
|
|
|
|
|
|
|
2021-12-07 13:05:08 +01:00
|
|
|
}catch (JsonProcessingException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2022-02-18 15:34:22 +01:00
|
|
|
return new ProfileMap(toReturn);
|
2021-12-07 12:16:29 +01:00
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|