195 lines
5.9 KiB
Java
195 lines
5.9 KiB
Java
package org.gcube.portlets.user.geoportaldataentry.client;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.TreeMap;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV;
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ui.card.GeoNaFormCardModel;
|
|
|
|
import com.google.gwt.core.client.GWT;
|
|
|
|
/**
|
|
* The Class GeoPortalClientCaches.
|
|
*
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
*
|
|
* Aug 11, 2022
|
|
*/
|
|
public class GeoPortalClientCaches {
|
|
|
|
private TreeMap<String, List<GeoNaFormCardModel>> mapGcubeProfilePerItemType;
|
|
|
|
private Map<String, List<ConfigurationDV<?>>> mapHandlersConfigurationsForProfileId;
|
|
|
|
private Map<String, CacheSearchingFilterParametersFromConfig> mapSearchingFitlerParametersorForProfileId;
|
|
|
|
/**
|
|
* Instantiates a new geo portal client caches.
|
|
*/
|
|
public GeoPortalClientCaches() {
|
|
mapGcubeProfilePerItemType = new TreeMap<String, List<GeoNaFormCardModel>>();
|
|
mapHandlersConfigurationsForProfileId = new HashMap<String, List<ConfigurationDV<?>>>();
|
|
mapSearchingFitlerParametersorForProfileId = new HashMap<String, GeoPortalClientCaches.CacheSearchingFilterParametersFromConfig>();
|
|
}
|
|
|
|
/**
|
|
* Put handler configurations for profile id.
|
|
*
|
|
* @param profileId the profile id
|
|
* @param lsitConfigurations the lsit configurations
|
|
*/
|
|
public void putHandlerConfigurationsForProfileId(String profileId, List<ConfigurationDV<?>> lsitConfigurations) {
|
|
mapHandlersConfigurationsForProfileId.put(profileId, lsitConfigurations);
|
|
}
|
|
|
|
/**
|
|
* Gets the handler configurations for profile id.
|
|
*
|
|
* @param profileId the profile id
|
|
* @return the handler configurations for profile id
|
|
*/
|
|
public List<ConfigurationDV<?>> getHandlerConfigurationsForProfileId(String profileId) {
|
|
return mapHandlersConfigurationsForProfileId.get(profileId);
|
|
}
|
|
|
|
/**
|
|
* Put gcube profile per item type.
|
|
*
|
|
* @param itemType the item type
|
|
* @param listGcubeProfiles the list gcube profiles
|
|
*/
|
|
public void putGcubeProfilePerItemType(String itemType, List<GeoNaFormCardModel> listGcubeProfiles) {
|
|
mapGcubeProfilePerItemType.put(itemType, listGcubeProfiles);
|
|
}
|
|
|
|
/**
|
|
* Gets the gcube profile per item type.
|
|
*
|
|
* @param itemType the item type
|
|
* @return the gcube profile per item type
|
|
*/
|
|
public List<GeoNaFormCardModel> getGcubeProfilePerItemType(String itemType) {
|
|
return mapGcubeProfilePerItemType.get(itemType);
|
|
}
|
|
|
|
public CacheSearchingFilterParametersFromConfig getFilterParametersForProfileId(String profileID) {
|
|
GWT.log("getFilterParametersForProfileId for: " + profileID);
|
|
|
|
CacheSearchingFilterParametersFromConfig searchingFilterParameters = mapSearchingFitlerParametersorForProfileId
|
|
.get(profileID);
|
|
|
|
if (searchingFilterParameters == null) {
|
|
|
|
searchingFilterParameters = new CacheSearchingFilterParametersFromConfig();
|
|
|
|
List<ConfigurationDV<?>> config = mapHandlersConfigurationsForProfileId.get(profileID);
|
|
|
|
GWT.log("For profileID " + profileID + ", read config for : " + config);
|
|
|
|
for (ConfigurationDV<?> configurationDV : config) {
|
|
switch (configurationDV.getConfigurationType()) {
|
|
case item_fields: {
|
|
List<ItemFieldDV> listItemFields = (List<ItemFieldDV>) configurationDV.getConfiguration();
|
|
for (ItemFieldDV itemField : listItemFields) {
|
|
if (itemField.isDisplayAsResult()) {
|
|
searchingFilterParameters.addDisplayField(itemField);
|
|
// adding to projection for filtering
|
|
for (String jsonField : itemField.getJsonFields()) {
|
|
searchingFilterParameters.putMongoProjection("_theDocument." + jsonField, 1);
|
|
}
|
|
}
|
|
|
|
if (itemField.isSearchable()) {
|
|
searchingFilterParameters.addSearchByField(itemField);
|
|
}
|
|
|
|
if (itemField.isSortable()) {
|
|
searchingFilterParameters.addOrderByField(itemField);
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
case gcube_profiles:
|
|
break;
|
|
}
|
|
}
|
|
|
|
mapSearchingFitlerParametersorForProfileId.put(profileID, searchingFilterParameters);
|
|
}
|
|
|
|
return searchingFilterParameters;
|
|
}
|
|
|
|
// DEBUGGING
|
|
public void printCacheHandlerConfigurations() {
|
|
GWT.log("print - mapHandlersConfigurationsForProfileId is:");
|
|
for (String key : mapHandlersConfigurationsForProfileId.keySet()) {
|
|
GWT.log("print - key: " + key + ", value: " + mapHandlersConfigurationsForProfileId.get(key));
|
|
}
|
|
}
|
|
|
|
// DEBUGGING
|
|
public void printCacheGcubeProfilePerItemType() {
|
|
GWT.log("print - mapGcubeProfilePerItemType is:");
|
|
for (String key : mapGcubeProfilePerItemType.keySet()) {
|
|
GWT.log("print - key: " + key + ", value: " + mapGcubeProfilePerItemType.get(key));
|
|
}
|
|
}
|
|
|
|
public class CacheSearchingFilterParametersFromConfig {
|
|
|
|
List<ItemFieldDV> displayFields;
|
|
List<ItemFieldDV> searchByFields;
|
|
List<ItemFieldDV> orderByFields;
|
|
|
|
// The projection
|
|
LinkedHashMap<String, Object> projection;
|
|
|
|
public CacheSearchingFilterParametersFromConfig() {
|
|
displayFields = new ArrayList<ItemFieldDV>();
|
|
searchByFields = new ArrayList<ItemFieldDV>();
|
|
orderByFields = new ArrayList<ItemFieldDV>();
|
|
projection = new LinkedHashMap<String, Object>();
|
|
}
|
|
|
|
public void putMongoProjection(String keyField, Object value) {
|
|
projection.put(keyField, value);
|
|
}
|
|
|
|
public void addDisplayField(ItemFieldDV itemField) {
|
|
displayFields.add(itemField);
|
|
}
|
|
|
|
public void addSearchByField(ItemFieldDV itemField) {
|
|
searchByFields.add(itemField);
|
|
}
|
|
|
|
public void addOrderByField(ItemFieldDV itemField) {
|
|
orderByFields.add(itemField);
|
|
}
|
|
|
|
public List<ItemFieldDV> getDisplayFields() {
|
|
return displayFields;
|
|
}
|
|
|
|
public List<ItemFieldDV> getSearchByFields() {
|
|
return searchByFields;
|
|
}
|
|
|
|
public List<ItemFieldDV> getOrderByFields() {
|
|
return orderByFields;
|
|
}
|
|
|
|
public LinkedHashMap<String, Object> getProjection() {
|
|
return projection;
|
|
}
|
|
|
|
}
|
|
}
|