Added Guava Cache for gcubeProfiles Per UCD_ID

This commit is contained in:
Francesco Mangiacrapa 2022-10-12 11:13:40 +02:00
parent aba4e0dca0
commit 7647628716
5 changed files with 425 additions and 269 deletions

View File

@ -6,7 +6,6 @@ import org.gcube.application.geoportalcommon.shared.geoportal.view.FilesetDV;
import org.gcube.application.geoportalcommon.shared.geoportal.view.PayloadDV;
import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView;
import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView;
import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV;
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.cms.gallery.ImagesSectionGallery;
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.CustomFlexTable;

View File

@ -0,0 +1,163 @@
/**
*
*/
package org.gcube.portlets.user.geoportaldataviewer.server;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
/**
* The Class GcubeProfilesPerUCDIdCache.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Oct 12, 2022
*/
public class GcubeProfilesPerUCDIdCache {
private static Logger LOG = LoggerFactory.getLogger(GcubeProfilesPerUCDIdCache.class);
private static LoadingCache<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>> gCubeProfilesPerProfileIDCache;
static {
CacheLoader<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>> loader = new CacheLoader<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>>() {
@Override
public LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> load(String scope) throws Exception {
LOG.info("Loading the cache for scope: " + scope);
return loadGcubeProfilesForUCDIdInTheScope(scope);
}
};
RemovalListener<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>> removalListener = new RemovalListener<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>>() {
public void onRemoval(
RemovalNotification<String, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>> removal) {
LOG.debug("cache expired");
}
};
gCubeProfilesPerProfileIDCache = CacheBuilder.newBuilder().maximumSize(1000)
.expireAfterWrite(15, TimeUnit.MINUTES).removalListener(removalListener).build(loader);
LOG.info("cache instancied");
}
/**
* Gets the.
*
* @param scope the scope
* @return the geonetwork instance
* @throws Exception
*/
public static LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> get(String scope) throws Exception {
LOG.info("GcubeProfilesPerUCDIdCache get - called in the scope: " + scope);
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> map = gCubeProfilesPerProfileIDCache.get(scope);
LOG.info("GcubeProfilesPerUCDIdCache returning map null? " + (map==null));
return map;
}
/**
* Load geonetwork instance.
*
* @param scope the scope
* @return the linked hash map
* @throws Exception the exception
*/
private static LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> loadGcubeProfilesForUCDIdInTheScope(
String scope) throws Exception {
LOG.info("loadGcubeProfilesForUCDIdInTheScope called in the scope: " + scope);
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = new LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>();
try {
ScopeProvider.instance.set(scope);
UseCaseDescriptorCaller clientUCD = GeoportalClientCaller.useCaseDescriptors();
List<UseCaseDescriptor> listUCDs = clientUCD.getList();
LOG.debug("listUCDs: " + listUCDs);
for (UseCaseDescriptor ucd : listUCDs) {
LOG.info("Loaded UCD for ID: " + ucd.getId());
String profileID = ucd.getId();
GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_data_entry;
List<HandlerDeclaration> handlers = ucd.getHandlersByType(theHandler.getType());
if (handlers.size() == 0) {
LOG.warn("No handler " + theHandler + "found into UCD " + ucd.getId() + ", continue...");
continue;
}
// Loading Handler gcube_profiles
HandlerDeclaration dataEntryHandler = handlers.get(0);
HandlerDeclarationDV handlerGcubeProfiles = ConvertToDataValueObjectModel
.toHandlerDeclarationDV(dataEntryHandler, ucd, GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles);
LOG.debug("Handler " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " for PROFILE_ID: " + ucd.getId());
LOG.debug("" + handlerGcubeProfiles);
ConfigurationDV<?> config = handlerGcubeProfiles.getConfiguration();
// List of gCube Profiles defined in the UCD
List<GcubeProfileDV> listGcubeProfiles = (List<GcubeProfileDV>) config.getConfiguration();
LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles);
List<GcubeProfilesMetadataForUCD> listProfilesBean = new ArrayList<GcubeProfilesMetadataForUCD>();
// Loading Metadata Profile from IS
MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
ScopeProvider.instance.set(scope);
GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD();
List<MetaDataProfileBean> listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(scope,
gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName();
LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles);
gCubeProfileMetadataForUCD.setGcubeProfile(gcubeProfileDV);
gCubeProfileMetadataForUCD.setListMetadataProfileBean(listProfiles);
listProfilesBean.add(gCubeProfileMetadataForUCD);
}
linkedMap_UCDId_gCubeProfiles.put(ucd.getId(), listProfilesBean);
if (LOG.isDebugEnabled()) {
for (String key : linkedMap_UCDId_gCubeProfiles.keySet()) {
LOG.debug("For key '" + key + "' got profiles: " + linkedMap_UCDId_gCubeProfiles.get(key));
}
}
}
} catch (Exception e) {
String erroMsg = "Error occurred on preloadgCubeProfilesForUCDs: ";
LOG.error(erroMsg, e);
}
LOG.info("GcubeProfilesPerUCDIdCache loaded with " + linkedMap_UCDId_gCubeProfiles.size() + " item/s");
return linkedMap_UCDId_gCubeProfiles;
}
}

View File

@ -20,7 +20,5 @@ public class GeoportalDataViewerHttpSessionListener implements HttpSessionListen
@Override
public void sessionCreated(HttpSessionEvent arg0) {
LOG.info("sessionCreated called. Session id is: "+arg0.getSession().getId());
new GeoportalDataViewerServiceImpl().preloadgCubeProfilesForUCDs();
}
}

View File

@ -6,18 +6,17 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.bson.Document;
import org.gcube.application.geoportal.client.utils.Serialization;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
import org.gcube.application.geoportalcommon.geoportal.access.GeportalCheckAccessPolicy;
import org.gcube.application.geoportalcommon.geoportal.serdes.Payload;
import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile;
@ -25,14 +24,11 @@ import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.application.geoportalcommon.shared.LayerItem;
import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData;
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.FilePathDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV;
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER;
import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV;
import org.gcube.application.geoportalcommon.shared.geoportal.view.FilesetDV;
import org.gcube.application.geoportalcommon.shared.geoportal.view.PayloadDV;
import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView;
@ -56,7 +52,6 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformation
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.Styles;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper;
import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility;
@ -68,6 +63,7 @@ import org.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
@ -87,13 +83,13 @@ import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements GeoportalDataViewerService {
public static final String PRODUCT_ID = "product_id";
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class);
private static final String CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE = "MAP_IMAGE_PREVIEW_FOR_CONCESSIONE";
public static final String JSON_$_POINTER = "$";
public static enum COMMON_IMAGES_FORMAT {
gif, png, jpeg, jpg, bmp, tif, tiff, svg, avif, webp
}
@ -275,8 +271,6 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
return getUploadedImagesForId(this.getThreadLocalRequest(), itemType, itemId, maxImages);
}
/**
* Gets the concessione for id.
*
@ -290,109 +284,92 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
throw new Exception("getConcessioneForId must be removed!");
/*
ConcessioneDV concessionDV = null;
if (mongoId == null)
throw new Exception("Invalid parameter. The itemId is null");
try {
LOG.info("Trying to get record for id " + mongoId);
GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
Concessione concessione = cms.getItemById(mongoId);
LOG.info("Got concessione for mongoId: " + mongoId);
if (concessione != null) {
concessionDV = ConvertToDataViewModel.toConcessione(concessione);
String userName = null;
try {
userName = SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername();
} catch (Exception e) {
LOG.info("User not found in session, so going to apply the acess policies");
}
// TODO THIS IS A WORKAROUND WAITING FOR ADOPTING OF USER ROLES. AT THE MOMENT,
// A USER AUTHENTICATED CAN ACCESS EVERYTHING
// I CAN CHECK THE ACCCESS POLICIES IF AND ONLY IF THE USER IS NOT LOGGED IN.
if (userName == null) {
// CHECKING ACCESS POLICY
LOG.info("Applying access policies for concessione " + mongoId + " returned by service");
LayerConcessioneDV layerPosizionamento = concessionDV.getPosizionamentoScavo();
if (layerPosizionamento != null) {
if (!GeoNACheckAccessPolicy.isAccessible(layerPosizionamento.getPolicy(), userName)) {
concessionDV.setPosizionamentoScavo(null);
LOG.info("Posizionamento di Scavo is not accessible by current user: " + userName);
}
}
List<LayerConcessioneDV> listLayersDV = concessionDV.getPianteFineScavo();
if (listLayersDV != null) {
List<LayerConcessioneDV> accessibleListLayersDV = new ArrayList<LayerConcessioneDV>();
for (LayerConcessioneDV layerDV : listLayersDV) {
if (GeoNACheckAccessPolicy.isAccessible(layerDV.getPolicy(), userName)) {
accessibleListLayersDV.add(layerDV);
} else {
LOG.info("(Pianta) Layer " + layerDV.getLayerName()
+ " is not accessible by current user: " + userName);
}
}
concessionDV.setPianteFineScavo(accessibleListLayersDV);
}
AbstractRelazioneScavoDV abstractRS = concessionDV.getAbstractRelazioneScavo();
if (abstractRS != null) {
if (!GeoNACheckAccessPolicy.isAccessible(abstractRS.getPolicy(), userName)) {
concessionDV.setAbstractRelazioneScavo(null);
LOG.info("Abstract relazione is not accessible by current user: " + userName);
}
}
RelazioneScavoDV relazioneScavo = concessionDV.getRelazioneScavo();
if (relazioneScavo != null) {
if (!GeoNACheckAccessPolicy.isAccessible(relazioneScavo.getPolicy(), userName)) {
concessionDV.setRelazioneScavo(null);
LOG.info("Relazione scavo is not accessible by current user: " + userName);
}
}
List<UploadedImageDV> immagini = concessionDV.getImmaginiRappresentative();
if (immagini != null && immagini.size() > 0) {
List<UploadedImageDV> accessibleListImages = new ArrayList<UploadedImageDV>();
// SHOWING ACESSIBLE IMAGES
for (UploadedImageDV uploadedImageDV : immagini) {
if (GeoNACheckAccessPolicy.isAccessible(uploadedImageDV.getPolicy(), userName)) {
accessibleListImages.add(uploadedImageDV);
} else {
LOG.info("Immagine " + uploadedImageDV.getTitolo()
+ " is not accessible by current user: " + userName);
}
}
concessionDV.setImmaginiRappresentative(accessibleListImages);
}
// END CHECKING ACCESS POLICY
LOG.info("Access policies applied");
}
}
if (concessionDV == null)
throw new Exception("Concessione with id '" + mongoId + "' not available");
LOG.debug("For id " + mongoId + " returning " + ConcessioneDV.class.getSimpleName() + ": " + concessionDV);
return concessionDV;
} catch (Exception e) {
String erroMsg = Concessione.class.getSimpleName() + " with id '" + mongoId + "' not available";
LOG.error(erroMsg, e);
throw new Exception(erroMsg);
}
* ConcessioneDV concessionDV = null;
*
* if (mongoId == null) throw new
* Exception("Invalid parameter. The itemId is null");
*
* try { LOG.info("Trying to get record for id " + mongoId);
*
* GeoportalServiceIdentityProxy cms = new
* GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); Concessione
* concessione = cms.getItemById(mongoId);
*
* LOG.info("Got concessione for mongoId: " + mongoId); if (concessione != null)
* { concessionDV = ConvertToDataViewModel.toConcessione(concessione);
*
* String userName = null; try { userName =
* SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername();
*
* } catch (Exception e) {
* LOG.info("User not found in session, so going to apply the acess policies");
* }
*
* // TODO THIS IS A WORKAROUND WAITING FOR ADOPTING OF USER ROLES. AT THE
* MOMENT, // A USER AUTHENTICATED CAN ACCESS EVERYTHING // I CAN CHECK THE
* ACCCESS POLICIES IF AND ONLY IF THE USER IS NOT LOGGED IN. if (userName ==
* null) {
*
* // CHECKING ACCESS POLICY
* LOG.info("Applying access policies for concessione " + mongoId +
* " returned by service"); LayerConcessioneDV layerPosizionamento =
* concessionDV.getPosizionamentoScavo(); if (layerPosizionamento != null) { if
* (!GeoNACheckAccessPolicy.isAccessible(layerPosizionamento.getPolicy(),
* userName)) { concessionDV.setPosizionamentoScavo(null);
* LOG.info("Posizionamento di Scavo is not accessible by current user: " +
* userName); } }
*
* List<LayerConcessioneDV> listLayersDV = concessionDV.getPianteFineScavo(); if
* (listLayersDV != null) { List<LayerConcessioneDV> accessibleListLayersDV =
* new ArrayList<LayerConcessioneDV>(); for (LayerConcessioneDV layerDV :
* listLayersDV) { if (GeoNACheckAccessPolicy.isAccessible(layerDV.getPolicy(),
* userName)) { accessibleListLayersDV.add(layerDV); } else {
* LOG.info("(Pianta) Layer " + layerDV.getLayerName() +
* " is not accessible by current user: " + userName); } }
* concessionDV.setPianteFineScavo(accessibleListLayersDV); }
*
* AbstractRelazioneScavoDV abstractRS =
* concessionDV.getAbstractRelazioneScavo(); if (abstractRS != null) { if
* (!GeoNACheckAccessPolicy.isAccessible(abstractRS.getPolicy(), userName)) {
* concessionDV.setAbstractRelazioneScavo(null);
* LOG.info("Abstract relazione is not accessible by current user: " +
* userName); } }
*
* RelazioneScavoDV relazioneScavo = concessionDV.getRelazioneScavo(); if
* (relazioneScavo != null) { if
* (!GeoNACheckAccessPolicy.isAccessible(relazioneScavo.getPolicy(), userName))
* { concessionDV.setRelazioneScavo(null);
* LOG.info("Relazione scavo is not accessible by current user: " + userName); }
* }
*
* List<UploadedImageDV> immagini = concessionDV.getImmaginiRappresentative();
* if (immagini != null && immagini.size() > 0) { List<UploadedImageDV>
* accessibleListImages = new ArrayList<UploadedImageDV>();
*
* // SHOWING ACESSIBLE IMAGES for (UploadedImageDV uploadedImageDV : immagini)
* {
*
* if (GeoNACheckAccessPolicy.isAccessible(uploadedImageDV.getPolicy(),
* userName)) { accessibleListImages.add(uploadedImageDV); } else {
* LOG.info("Immagine " + uploadedImageDV.getTitolo() +
* " is not accessible by current user: " + userName); }
*
* } concessionDV.setImmaginiRappresentative(accessibleListImages);
*
* }
*
* // END CHECKING ACCESS POLICY LOG.info("Access policies applied"); } }
*
* if (concessionDV == null) throw new Exception("Concessione with id '" +
* mongoId + "' not available");
*
* LOG.debug("For id " + mongoId + " returning " +
* ConcessioneDV.class.getSimpleName() + ": " + concessionDV); return
* concessionDV;
*
* } catch (Exception e) { String erroMsg = Concessione.class.getSimpleName() +
* " with id '" + mongoId + "' not available"; LOG.error(erroMsg, e); throw new
* Exception(erroMsg); }
*/
}
@ -628,47 +605,41 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
LOG.info("getUploadedImagesForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
throw new Exception("getUploadedImagesForId must be revisited");
/*if (itemType == null)
throw new Exception("Invalid parameter. The itemType is null");
if (itemId == null)
throw new Exception("Invalid parameter. The itemId is null");
List<UploadedImageDV> listUI = null;
try {
if (itemType.equalsIgnoreCase("concessione")) {
LOG.info("Trying to get concessione for id " + itemId);
GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(httpServletRequest);
Concessione concessione = cms.getItemById(itemId);
if (concessione != null) {
LOG.info("For id " + itemId + ", got concessione " + concessione.getNome() + " from service");
List<UploadedImage> images = concessione.getImmaginiRappresentative();
if (images != null) {
listUI = new ArrayList<UploadedImageDV>();
int max = maxImages < images.size() ? maxImages : images.size();
for (int i = 0; i < max; i++) {
UploadedImageDV ui = ConvertToDataViewModel.toUploadedImage(images.get(i));
listUI.add(ui);
}
LOG.info("For id " + itemId + ", got " + listUI.size() + " image/s");
}
} else
throw new Exception("Concessione with id '" + itemId + "' not available");
}
return listUI;
} catch (Exception e) {
String erroMsg = UploadedImage.class.getSimpleName() + " not available for "
+ Concessione.class.getSimpleName() + " with id " + itemId;
LOG.error(erroMsg, e);
throw new Exception(erroMsg);
}*/
/*
* if (itemType == null) throw new
* Exception("Invalid parameter. The itemType is null");
*
* if (itemId == null) throw new
* Exception("Invalid parameter. The itemId is null");
*
* List<UploadedImageDV> listUI = null;
*
* try {
*
* if (itemType.equalsIgnoreCase("concessione")) {
*
* LOG.info("Trying to get concessione for id " + itemId);
* GeoportalServiceIdentityProxy cms = new
* GeoportalServiceIdentityProxy(httpServletRequest); Concessione concessione =
* cms.getItemById(itemId); if (concessione != null) { LOG.info("For id " +
* itemId + ", got concessione " + concessione.getNome() + " from service");
* List<UploadedImage> images = concessione.getImmaginiRappresentative();
*
* if (images != null) { listUI = new ArrayList<UploadedImageDV>(); int max =
* maxImages < images.size() ? maxImages : images.size(); for (int i = 0; i <
* max; i++) { UploadedImageDV ui =
* ConvertToDataViewModel.toUploadedImage(images.get(i)); listUI.add(ui); }
* LOG.info("For id " + itemId + ", got " + listUI.size() + " image/s"); } }
* else throw new Exception("Concessione with id '" + itemId +
* "' not available"); }
*
* return listUI;
*
* } catch (Exception e) { String erroMsg = UploadedImage.class.getSimpleName()
* + " not available for " + Concessione.class.getSimpleName() + " with id " +
* itemId; LOG.error(erroMsg, e); throw new Exception(erroMsg); }
*/
}
@ -705,7 +676,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
return profile.getListItemFields();
}
/**
*
*
@ -738,11 +709,30 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
*/
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
LOG.info("init called");
//Init one GcubeProfilesPerUCDIdCache for the application
new GcubeProfilesPerUCDIdCache();
}
@Override
protected void onBeforeRequestDeserialized(String serializedRequest) {
LOG.info("onBeforeRequestDeserialized called");
String scope = "";
try {
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
//Loading GcubeProfilesPerUCDIdCache per scope
GcubeProfilesPerUCDIdCache.get(scope);
} catch (Exception e) {
LOG.error("Error on loading the " + GcubeProfilesPerUCDIdCache.class.getSimpleName() + " for scope: "+scope, e);
e.printStackTrace();
}
super.onBeforeRequestDeserialized(serializedRequest);
}
/**
* Gets the list concessioni.
*
@ -783,81 +773,79 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
}
/**
* Preloadg cube profiles for UC ds.
*/
public void preloadgCubeProfilesForUCDs() {
LOG.info("preloadgCubeProfilesForUCDs called");
try {
String currentContext = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
LOG.info("preloadgCubeProfilesForUCDs context: "+currentContext);
UseCaseDescriptorCaller clientUCD = GeoportalClientCaller.useCaseDescriptors();
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
List<UseCaseDescriptor> listUCDs = clientUCD.getList();
LOG.debug("listUCDs: "+listUCDs);
for (UseCaseDescriptor ucd : listUCDs) {
// /**
// * Preloadg cube profiles for UC ds.
// */
// public void preloadgCubeProfilesForUCDs() {
// LOG.info("preloadgCubeProfilesForUCDs called");
// try {
//
// String currentContext = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
// LOG.info("preloadgCubeProfilesForUCDs context: " + currentContext);
// UseCaseDescriptorCaller clientUCD = GeoportalClientCaller.useCaseDescriptors();
// SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
// List<UseCaseDescriptor> listUCDs = clientUCD.getList();
// LOG.debug("listUCDs: " + listUCDs);
//
// for (UseCaseDescriptor ucd : listUCDs) {
//
// LOG.info("Loaded UCD for ID: " + ucd.getId());
// String profileID = ucd.getId();
// GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_data_entry;
// List<HandlerDeclaration> handlers = ucd.getHandlersByType(theHandler.getType());
//
// if (handlers.size() == 0) {
// LOG.warn("No handler " + theHandler + "found into UCD " + ucd.getId() + ", continue...");
// continue;
// }
//
// // Loading Handler gcube_profiles
// HandlerDeclaration dataEntryHandler = handlers.get(0);
// HandlerDeclarationDV handlerGcubeProfiles = ConvertToDataValueObjectModel
// .toHandlerDeclarationDV(dataEntryHandler, ucd, GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles);
//
// LOG.debug("Handler " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " for PROFILE_ID: " + ucd.getId());
// LOG.debug("" + handlerGcubeProfiles);
//
// ConfigurationDV<?> config = handlerGcubeProfiles.getConfiguration();
// // List of gCube Profiles defined in the UCD
// List<GcubeProfileDV> listGcubeProfiles = (List<GcubeProfileDV>) config.getConfiguration();
// LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles);
//
// List<GcubeProfilesMetadataForUCD> listProfilesBean = new ArrayList<GcubeProfilesMetadataForUCD>();
// // Loading Metadata Profile from IS
// MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
//
// LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = new LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>();
// for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
// String context = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
// GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD();
// List<MetaDataProfileBean> listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(context,
// gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
//
// String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName();
// LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles);
// gCubeProfileMetadataForUCD.setGcubeProfile(gcubeProfileDV);
// gCubeProfileMetadataForUCD.setListMetadataProfileBean(listProfiles);
// listProfilesBean.add(gCubeProfileMetadataForUCD);
//
// }
// linkedMap_UCDId_gCubeProfiles.put(ucd.getId(), listProfilesBean);
//
// for (String key : linkedMap_UCDId_gCubeProfiles.keySet()) {
// LOG.debug("For key '" + key + "' got profiles: " + linkedMap_UCDId_gCubeProfiles.get(key));
// }
//
// SessionUtil.setMap_UCDId_gCubeProfiles(getThreadLocalRequest(), profileID,
// linkedMap_UCDId_gCubeProfiles);
// }
//
// } catch (Exception e) {
// String erroMsg = "Error occurred on preloadgCubeProfilesForUCDs: ";
// LOG.error(erroMsg, e);
// }
// }
LOG.info("Loaded UCD for ID: " + ucd.getId());
String profileID = ucd.getId();
GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_data_entry;
List<HandlerDeclaration> handlers = ucd.getHandlersByType(theHandler.getType());
if (handlers.size() == 0) {
LOG.warn("No handler " + theHandler + "found into UCD " + ucd.getId() + ", continue...");
continue;
}
// Loading Handler gcube_profiles
HandlerDeclaration dataEntryHandler = handlers.get(0);
HandlerDeclarationDV handlerGcubeProfiles = ConvertToDataValueObjectModel
.toHandlerDeclarationDV(dataEntryHandler, ucd, GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles);
LOG.debug("Handler " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " for PROFILE_ID: " + ucd.getId());
LOG.debug("" + handlerGcubeProfiles);
ConfigurationDV<?> config = handlerGcubeProfiles.getConfiguration();
// List of gCube Profiles defined in the UCD
List<GcubeProfileDV> listGcubeProfiles = (List<GcubeProfileDV>) config.getConfiguration();
LOG.debug("List of GcubeProfileDV are: " + listGcubeProfiles);
List<GcubeProfilesMetadataForUCD> listProfilesBean = new ArrayList<GcubeProfilesMetadataForUCD>();
// Loading Metadata Profile from IS
MetadataProfileFormBuilderServiceImpl metaProfileBUilder = new MetadataProfileFormBuilderServiceImpl();
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = new LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>();
for (GcubeProfileDV gcubeProfileDV : listGcubeProfiles) {
String context = SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
GcubeProfilesMetadataForUCD gCubeProfileMetadataForUCD = new GcubeProfilesMetadataForUCD();
List<MetaDataProfileBean> listProfiles = metaProfileBUilder.getProfilesInTheScopeForName(context,
gcubeProfileDV.getGcubeSecondaryType(), gcubeProfileDV.getGcubeName());
String key = gcubeProfileDV.getGcubeSecondaryType() + gcubeProfileDV.getGcubeName();
LOG.debug("for key: " + key + " readi profiles: " + listGcubeProfiles);
gCubeProfileMetadataForUCD.setGcubeProfile(gcubeProfileDV);
gCubeProfileMetadataForUCD.setListMetadataProfileBean(listProfiles);
listProfilesBean.add(gCubeProfileMetadataForUCD);
}
linkedMap_UCDId_gCubeProfiles.put(ucd.getId(), listProfilesBean);
for (String key : linkedMap_UCDId_gCubeProfiles.keySet()) {
LOG.debug("For key '" + key + "' got profiles: " + linkedMap_UCDId_gCubeProfiles.get(key));
}
SessionUtil.setMap_UCDId_gCubeProfiles(getThreadLocalRequest(), profileID,
linkedMap_UCDId_gCubeProfiles);
}
} catch (Exception e) {
String erroMsg = "Error occurred on preloadgCubeProfilesForUCDs: ";
LOG.error(erroMsg, e);
}
}
/**
* Gets the layers for id.
*
@ -951,7 +939,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
try {
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
String userName = null;
try {
userName = SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername();
@ -972,14 +960,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
ProjectView projectView = new ProjectView();
projectView.setTheProjectDV(theProjectDV);
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = SessionUtil
.getMap_UCDId_gCubeProfiles(getThreadLocalRequest(), profileID);
if(linkedMap_UCDId_gCubeProfiles==null) {
preloadgCubeProfilesForUCDs();
linkedMap_UCDId_gCubeProfiles = SessionUtil
.getMap_UCDId_gCubeProfiles(getThreadLocalRequest(), profileID);
}
LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> linkedMap_UCDId_gCubeProfiles = GcubeProfilesPerUCDIdCache.get(scope);
// NO UCD defined, applyong default
if (linkedMap_UCDId_gCubeProfiles.size() == 0) {
@ -988,9 +969,44 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
SectionView sectionView = new SectionView();
sectionView.setSectionTitle("Document");
SubDocumentView subDocumentView = new SubDocumentView();
subDocumentView.setMetadataAsJSON(theProjectDV.getTheDocument().getDocumentAsJSON());
sectionView.addSubDocument(subDocumentView);
projectView.addSectionView(sectionView);
Document sectionDoc = Document.parse(theProjectDV.getTheDocument().getDocumentAsJSON());
boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, JSON_$_POINTER,
userName);
// If is accessible
if (isAccessibleSection) {
// Creating one Project with one SectionView and SubDocumentView
String wholeSectionDoc = sectionDoc.toJson();
subDocumentView.setMetadataAsJSON(wholeSectionDoc);
List<FilesetDV> listFiles = new ArrayList<FilesetDV>();
List<FilesetDV> listImages = new ArrayList<FilesetDV>();
String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, "fileset");
List<Payload> listPayloads = readPayloadsForFileset(filesetJSONPath, wholeSectionDoc);
FilesetDV filesetDV = new FilesetDV();
filesetDV.setName("fileset");
for (Payload payload : listPayloads) {
PayloadDV payloadDV = ConvertToDataValueObjectModel.toPayloadDV(payload);
filesetDV.addPayloadDV(payloadDV);
boolean isImage = ImageDetector.isImage(payload.getMimetype());
if (isImage) {
listImages.add(filesetDV);
} else {
listFiles.add(filesetDV);
}
}
// TODO LAYERS
subDocumentView.setListImages(listImages);
subDocumentView.setListFiles(listFiles);
sectionView.addSubDocument(subDocumentView);
projectView.addSectionView(sectionView);
}
}
List<GcubeProfilesMetadataForUCD> listProfilesBean = linkedMap_UCDId_gCubeProfiles.get(profileID);

View File

@ -3,7 +3,6 @@
*/
package org.gcube.portlets.user.geoportaldataviewer.server.util;
import java.util.LinkedHashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@ -15,7 +14,6 @@ import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataviewer.server.GNABaseMapsResourceReader;
import org.gcube.portlets.user.geoportaldataviewer.server.GcubeProfilesMetadataForUCD;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.gcube.vomanagement.usermanagement.GroupManager;
@ -182,24 +180,6 @@ public class SessionUtil {
return shortener;
}
public static LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> getMap_UCDId_gCubeProfiles(
HttpServletRequest httpServletRequest, String profileID) {
HttpSession session = httpServletRequest.getSession();
return (LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>>) session
.getAttribute(MAP_UCD_ID_TO_GCUBE_PROFILES +"_"+profileID);
}
public static void setMap_UCDId_gCubeProfiles(HttpServletRequest httpServletRequest,
String profileID, LinkedHashMap<String, List<GcubeProfilesMetadataForUCD>> map) {
HttpSession session = httpServletRequest.getSession();
session.setAttribute(MAP_UCD_ID_TO_GCUBE_PROFILES +"_"+profileID, map);
}
/**
* Gets the GNA base maps.
*