|
|
|
@ -10,31 +10,43 @@ import java.util.Map;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
|
|
|
|
|
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
|
|
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataViewModel;
|
|
|
|
|
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.MongoServiceCommon;
|
|
|
|
|
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;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.ItemField;
|
|
|
|
|
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;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.SectionView;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.SubDocumentView;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.gis.BoundsMap;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV;
|
|
|
|
|
import org.gcube.application.geoportalcommon.util.URLParserUtil;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.ConcessioniMongoServiceIdentityProxy;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accesspolicy.GeoNACheckAccessPolicy;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaSpatialQueryResult;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
|
|
|
|
@ -44,15 +56,25 @@ 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;
|
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.LayerStyles;
|
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.LayerZAxis;
|
|
|
|
|
import org.gcube.spatial.data.geoutility.bean.WmsParameters;
|
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
import com.google.gson.JsonObject;
|
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
import com.jayway.jsonpath.JsonPath;
|
|
|
|
|
import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
@ -70,6 +92,38 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class ImageDetector {
|
|
|
|
|
|
|
|
|
|
private static String[] getNames(Class<? extends Enum<?>> e) {
|
|
|
|
|
return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<String> listFormatImages;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
|
|
|
|
|
String[] arrayImgs = ImageDetector.getNames(COMMON_IMAGES_FORMAT.class);
|
|
|
|
|
listFormatImages = Arrays.asList(arrayImgs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isImage(String mimeType) {
|
|
|
|
|
if (mimeType == null || mimeType.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
String inputImageFormat = mimeType.replaceAll("image/", "");
|
|
|
|
|
|
|
|
|
|
return listFormatImages.contains(inputImageFormat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the GNA data viewe config profile.
|
|
|
|
|
*
|
|
|
|
@ -221,83 +275,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
return getUploadedImagesForId(this.getThreadLocalRequest(), itemType, itemId, maxImages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the layers for id.
|
|
|
|
|
*
|
|
|
|
|
* @param itemType the item type
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the layers for id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<LayerConcessioneDV> getLayersForId(String itemType, String itemId) throws Exception {
|
|
|
|
|
LOG.info("getLayersForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
|
|
|
|
|
|
|
|
|
|
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<LayerConcessioneDV> listLayers = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
String userName = null;
|
|
|
|
|
try {
|
|
|
|
|
userName = SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.info("User not found in session, the userName for cecking policy will be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemType.equalsIgnoreCase("concessione")) {
|
|
|
|
|
|
|
|
|
|
LOG.info("Trying to get concessione for id " + itemId);
|
|
|
|
|
ConcessioniMongoServiceIdentityProxy cms = new ConcessioniMongoServiceIdentityProxy(
|
|
|
|
|
this.getThreadLocalRequest());
|
|
|
|
|
Concessione concessione = cms.getItemById(itemId);
|
|
|
|
|
|
|
|
|
|
BaseConcessioneDV baseConcessione = ConvertToDataViewModel.toBaseConcessione(concessione);
|
|
|
|
|
if (concessione != null) {
|
|
|
|
|
LOG.info("For id " + itemId + ", got concessione " + concessione.getNome() + " from service");
|
|
|
|
|
listLayers = new ArrayList<LayerConcessioneDV>();
|
|
|
|
|
if (concessione.getPianteFineScavo() != null) {
|
|
|
|
|
|
|
|
|
|
for (LayerConcessione lc : concessione.getPianteFineScavo()) {
|
|
|
|
|
if (GeoNACheckAccessPolicy.isAccessible(lc.getPolicy().name(), userName)) {
|
|
|
|
|
listLayers.add(ConvertToDataViewModel.toLayerConcessione(lc, baseConcessione));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LayerConcessione lcPosizionamento = concessione.getPosizionamentoScavo();
|
|
|
|
|
|
|
|
|
|
if (lcPosizionamento != null) {
|
|
|
|
|
|
|
|
|
|
if (GeoNACheckAccessPolicy.isAccessible(lcPosizionamento.getPolicy().name(), userName)) {
|
|
|
|
|
|
|
|
|
|
LayerConcessioneDV thePosizScavo = ConvertToDataViewModel
|
|
|
|
|
.toLayerConcessione(lcPosizionamento, baseConcessione);
|
|
|
|
|
if (thePosizScavo != null)
|
|
|
|
|
listLayers.add(thePosizScavo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
throw new Exception("Concessione with id '" + itemId + "' not available");
|
|
|
|
|
}
|
|
|
|
|
LOG.info("For id " + itemId + ", returning " + listLayers.size() + " layer/s");
|
|
|
|
|
return listLayers;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String erroMsg = "Layers are not available for " + Concessione.class.getSimpleName() + " with id " + itemId;
|
|
|
|
|
LOG.error(erroMsg, e);
|
|
|
|
|
throw new Exception(erroMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the concessione for id.
|
|
|
|
@ -310,6 +288,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
public ConcessioneDV getConcessioneForId(String mongoId) throws Exception {
|
|
|
|
|
LOG.info("getConcessioneForId " + mongoId + " called");
|
|
|
|
|
|
|
|
|
|
throw new Exception("getConcessioneForId must be removed!");
|
|
|
|
|
/*
|
|
|
|
|
ConcessioneDV concessionDV = null;
|
|
|
|
|
|
|
|
|
|
if (mongoId == null)
|
|
|
|
@ -318,8 +298,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
try {
|
|
|
|
|
LOG.info("Trying to get record for id " + mongoId);
|
|
|
|
|
|
|
|
|
|
ConcessioniMongoServiceIdentityProxy cms = new ConcessioniMongoServiceIdentityProxy(
|
|
|
|
|
this.getThreadLocalRequest());
|
|
|
|
|
GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
|
|
|
|
|
Concessione concessione = cms.getItemById(mongoId);
|
|
|
|
|
|
|
|
|
|
LOG.info("Got concessione for mongoId: " + mongoId);
|
|
|
|
@ -414,7 +393,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
LOG.error(erroMsg, e);
|
|
|
|
|
throw new Exception(erroMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -648,7 +627,9 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
String itemId, Integer maxImages) throws Exception {
|
|
|
|
|
LOG.info("getUploadedImagesForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
|
|
|
|
|
|
|
|
|
|
if (itemType == null)
|
|
|
|
|
throw new Exception("getUploadedImagesForId must be revisited");
|
|
|
|
|
|
|
|
|
|
/*if (itemType == null)
|
|
|
|
|
throw new Exception("Invalid parameter. The itemType is null");
|
|
|
|
|
|
|
|
|
|
if (itemId == null)
|
|
|
|
@ -661,7 +642,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
if (itemType.equalsIgnoreCase("concessione")) {
|
|
|
|
|
|
|
|
|
|
LOG.info("Trying to get concessione for id " + itemId);
|
|
|
|
|
ConcessioniMongoServiceIdentityProxy cms = new ConcessioniMongoServiceIdentityProxy(httpServletRequest);
|
|
|
|
|
GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(httpServletRequest);
|
|
|
|
|
Concessione concessione = cms.getItemById(itemId);
|
|
|
|
|
if (concessione != null) {
|
|
|
|
|
LOG.info("For id " + itemId + ", got concessione " + concessione.getNome() + " from service");
|
|
|
|
@ -687,7 +668,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
+ Concessione.class.getSimpleName() + " with id " + itemId;
|
|
|
|
|
LOG.error(erroMsg, e);
|
|
|
|
|
throw new Exception(erroMsg);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -717,13 +698,51 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<ItemField> listOfFieldsForSearching() throws Exception {
|
|
|
|
|
public List<ItemFieldDV> listOfFieldsForSearching() throws Exception {
|
|
|
|
|
LOG.info("listOfFieldsForSearching called");
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
GNADataViewerConfigProfile profile = getGNADataVieweConfigProfile();
|
|
|
|
|
return profile.getListItemFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* NEW CODE HERE
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the list concessioni.
|
|
|
|
|
*
|
|
|
|
@ -740,18 +759,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|
|
|
|
LOG.info("getListConcessioni called wit start: " + start + ", limit: " + limit + ", filter: " + filter);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// setting identity as D4S User or KC client
|
|
|
|
|
new ConcessioniMongoServiceIdentityProxy(this.getThreadLocalRequest());
|
|
|
|
|
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
MongoServiceCommon serviceCommon = new MongoServiceCommon();
|
|
|
|
|
// TODO MUST BE REPLACED BY COUNT
|
|
|
|
|
List<Concessione> listOfConcessioni = SessionUtil.getListOfConcessioni(getThreadLocalRequest(),
|
|
|
|
|
reloadFromService);
|
|
|
|
|
int listConcessioniSize = listOfConcessioni.size();
|
|
|
|
|
|
|
|
|
|
ResultSetPaginatedData searchedData = serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
|
|
|
|
|
"concessione");
|
|
|
|
|
return searchedData;
|
|
|
|
|
throw new Exception("getListConcessioni must be revisited!!!!");
|
|
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* // setting identity as D4S User or KC client new
|
|
|
|
|
* GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
|
|
|
|
|
* SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
|
|
|
|
|
* MongoServiceCommon serviceCommon = new MongoServiceCommon(); // TODO MUST BE
|
|
|
|
|
* REPLACED BY COUNT List<Concessione> listOfConcessioni =
|
|
|
|
|
* SessionUtil.getListOfConcessioni(getThreadLocalRequest(), reloadFromService);
|
|
|
|
|
* int listConcessioniSize = listOfConcessioni.size();
|
|
|
|
|
*
|
|
|
|
|
* ResultSetPaginatedData searchedData =
|
|
|
|
|
* serviceCommon.queryOnMongo(listConcessioniSize, start, limit, filter,
|
|
|
|
|
* "concessione"); return searchedData;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.error("Error on loading paginated and filtered list of concessioni: ", e);
|
|
|
|
@ -760,4 +783,519 @@ 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) {
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
|
|
|
|
* @param itemType the item type
|
|
|
|
|
* @param itemId the item id
|
|
|
|
|
* @return the layers for id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<LayerConcessioneDV> getLayersForId(String itemType, String itemId) throws Exception {
|
|
|
|
|
LOG.info("getLayersForId [itemId: " + itemId + ", itemType: " + itemType + "] called");
|
|
|
|
|
|
|
|
|
|
throw new Exception("getLayersForId 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<LayerConcessioneDV> listLayers = null;
|
|
|
|
|
*
|
|
|
|
|
* try {
|
|
|
|
|
*
|
|
|
|
|
* SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); String
|
|
|
|
|
* userName = null; try { userName =
|
|
|
|
|
* SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername(); }
|
|
|
|
|
* catch (Exception e) { LOG.
|
|
|
|
|
* info("User not found in session, the userName for cecking policy will be null"
|
|
|
|
|
* ); }
|
|
|
|
|
*
|
|
|
|
|
* if (itemType.equalsIgnoreCase("concessione")) {
|
|
|
|
|
*
|
|
|
|
|
* LOG.info("Trying to get concessione for id " + itemId);
|
|
|
|
|
* GeoportalServiceIdentityProxy cms = new
|
|
|
|
|
* GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); Concessione
|
|
|
|
|
* concessione = cms.getItemById(itemId);
|
|
|
|
|
*
|
|
|
|
|
* BaseConcessioneDV baseConcessione =
|
|
|
|
|
* ConvertToDataViewModel.toBaseConcessione(concessione); if (concessione !=
|
|
|
|
|
* null) { LOG.info("For id " + itemId + ", got concessione " +
|
|
|
|
|
* concessione.getNome() + " from service"); listLayers = new
|
|
|
|
|
* ArrayList<LayerConcessioneDV>(); if (concessione.getPianteFineScavo() !=
|
|
|
|
|
* null) {
|
|
|
|
|
*
|
|
|
|
|
* for (LayerConcessione lc : concessione.getPianteFineScavo()) { if
|
|
|
|
|
* (GeoNACheckAccessPolicy.isAccessible(lc.getPolicy().name(), userName)) {
|
|
|
|
|
* listLayers.add(ConvertToDataViewModel.toLayerConcessione(lc,
|
|
|
|
|
* baseConcessione)); } }
|
|
|
|
|
*
|
|
|
|
|
* LayerConcessione lcPosizionamento = concessione.getPosizionamentoScavo();
|
|
|
|
|
*
|
|
|
|
|
* if (lcPosizionamento != null) {
|
|
|
|
|
*
|
|
|
|
|
* if (GeoNACheckAccessPolicy.isAccessible(lcPosizionamento.getPolicy().name(),
|
|
|
|
|
* userName)) {
|
|
|
|
|
*
|
|
|
|
|
* LayerConcessioneDV thePosizScavo = ConvertToDataViewModel
|
|
|
|
|
* .toLayerConcessione(lcPosizionamento, baseConcessione); if (thePosizScavo !=
|
|
|
|
|
* null) listLayers.add(thePosizScavo); } }
|
|
|
|
|
*
|
|
|
|
|
* }
|
|
|
|
|
*
|
|
|
|
|
* } else throw new Exception("Concessione with id '" + itemId +
|
|
|
|
|
* "' not available"); } LOG.info("For id " + itemId + ", returning " +
|
|
|
|
|
* listLayers.size() + " layer/s"); return listLayers;
|
|
|
|
|
*
|
|
|
|
|
* } catch (Exception e) { String erroMsg = "Layers are not available for " +
|
|
|
|
|
* Concessione.class.getSimpleName() + " with id " + itemId; LOG.error(erroMsg,
|
|
|
|
|
* e); throw new Exception(erroMsg); }
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the project view for id.
|
|
|
|
|
*
|
|
|
|
|
* @param profileID the profile ID
|
|
|
|
|
* @param projectID the project ID
|
|
|
|
|
* @return the project view for id
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ProjectView getProjectViewForId(String profileID, String projectID) throws Exception {
|
|
|
|
|
LOG.info("getProjectForId profileID: " + profileID + ", projectID: " + projectID + "called");
|
|
|
|
|
|
|
|
|
|
if (profileID == null || projectID == null)
|
|
|
|
|
throw new Exception("Invalid parameter. Either profileID or projectID is null");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
String userName = null;
|
|
|
|
|
try {
|
|
|
|
|
userName = SessionUtil.getCurrentUser(this.getThreadLocalRequest()).getUsername();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.info("User not found in session, the userName for cecking policy will be null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("Trying to get project for id " + profileID);
|
|
|
|
|
|
|
|
|
|
GeoportalServiceIdentityProxy cms = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
|
|
|
|
|
ProjectDV theProjectDV = cms.getProjectByID(profileID, projectID);
|
|
|
|
|
|
|
|
|
|
String theWholeProjectAsJSON = theProjectDV.getTheDocument().getDocumentAsJSON();
|
|
|
|
|
|
|
|
|
|
LOG.debug("theProjectDV as JSON: " + theWholeProjectAsJSON);
|
|
|
|
|
LOG.debug("theProjectDV as MAP: " + theProjectDV.getTheDocument().getDocumentAsMap());
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NO UCD defined, applyong default
|
|
|
|
|
if (linkedMap_UCDId_gCubeProfiles.size() == 0) {
|
|
|
|
|
LOG.warn("No " + GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles + " found in the UCD");
|
|
|
|
|
LOG.info("Applying default business logic to display the project");
|
|
|
|
|
SectionView sectionView = new SectionView();
|
|
|
|
|
sectionView.setSectionTitle("Document");
|
|
|
|
|
SubDocumentView subDocumentView = new SubDocumentView();
|
|
|
|
|
subDocumentView.setMetadataAsJSON(theProjectDV.getTheDocument().getDocumentAsJSON());
|
|
|
|
|
sectionView.addSubDocument(subDocumentView);
|
|
|
|
|
projectView.addSectionView(sectionView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<GcubeProfilesMetadataForUCD> listProfilesBean = linkedMap_UCDId_gCubeProfiles.get(profileID);
|
|
|
|
|
|
|
|
|
|
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
|
|
|
|
.jsonProvider(new JsonOrgJsonProvider()).build();
|
|
|
|
|
|
|
|
|
|
// Reading the Project according to list of Profile defined in the UCD
|
|
|
|
|
for (GcubeProfilesMetadataForUCD gcubeProfileMetaForUCD : listProfilesBean) {
|
|
|
|
|
|
|
|
|
|
GcubeProfileDV gcubeProfileDV = gcubeProfileMetaForUCD.getGcubeProfile();
|
|
|
|
|
SectionView sectionView = new SectionView();
|
|
|
|
|
sectionView.setSectionTitle(gcubeProfileDV.getSectionTitle());
|
|
|
|
|
LOG.debug("\n\nThe profile is: " + gcubeProfileDV);
|
|
|
|
|
// Building JSON/section full PATH and section name
|
|
|
|
|
String sectionJSONPath = "";
|
|
|
|
|
String parentPathFromProfile = gcubeProfileDV.getParentName() == null ? ""
|
|
|
|
|
: gcubeProfileDV.getParentName();
|
|
|
|
|
String theSectionName = gcubeProfileDV.getSectionName();
|
|
|
|
|
|
|
|
|
|
if (theSectionName.compareTo(JSON_$_POINTER) == 0
|
|
|
|
|
|| theSectionName.compareTo(JSON_$_POINTER + ".") == 0) {
|
|
|
|
|
sectionJSONPath = JSON_$_POINTER;
|
|
|
|
|
theSectionName = "";
|
|
|
|
|
} else {
|
|
|
|
|
sectionJSONPath = String.format("%s%s",
|
|
|
|
|
parentPathFromProfile.endsWith(".") ? parentPathFromProfile : parentPathFromProfile + ".",
|
|
|
|
|
theSectionName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.debug("The sectionJSONPath is: " + sectionJSONPath);
|
|
|
|
|
|
|
|
|
|
JsonPath theSectionJsonPath = JsonPath.compile(sectionJSONPath);
|
|
|
|
|
Object data = theSectionJsonPath.read(theWholeProjectAsJSON, configuration);
|
|
|
|
|
|
|
|
|
|
LOG.debug("Data is instace of: " + data.getClass());
|
|
|
|
|
LOG.debug("data to string: " + data.toString());
|
|
|
|
|
|
|
|
|
|
// Splitting the General Document in bson.Document according to list of
|
|
|
|
|
// GcubeProfiles
|
|
|
|
|
List<Document> listBSONDocument = new ArrayList<Document>();
|
|
|
|
|
if (data instanceof org.json.JSONObject) {
|
|
|
|
|
String jsonString = data.toString();
|
|
|
|
|
LOG.debug("the JSON to string: " + jsonString);
|
|
|
|
|
Document sectionDoc = Document.parse(jsonString);
|
|
|
|
|
boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath,
|
|
|
|
|
userName);
|
|
|
|
|
if (isAccessibleSection) {
|
|
|
|
|
listBSONDocument.add(sectionDoc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (data instanceof org.json.JSONArray) {
|
|
|
|
|
org.json.JSONArray dataArray = (org.json.JSONArray) data;
|
|
|
|
|
for (int i = 0; i < dataArray.length(); i++) {
|
|
|
|
|
String jsonString = dataArray.get(i).toString();
|
|
|
|
|
LOG.debug("the array " + i + " JSON to string: " + jsonString);
|
|
|
|
|
Document sectionDoc = Document.parse(jsonString);
|
|
|
|
|
boolean isAccessibleSection = isAccessibleSectionAccordingToPolicy(sectionDoc, sectionJSONPath,
|
|
|
|
|
userName);
|
|
|
|
|
if (isAccessibleSection) {
|
|
|
|
|
listBSONDocument.add(sectionDoc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.debug("Result for " + gcubeProfileDV.getSectionName() + " is: " + listBSONDocument);
|
|
|
|
|
List<MetaDataProfileBean> theProfileBeans = gcubeProfileMetaForUCD.getListMetadataProfileBean();
|
|
|
|
|
MetaDataProfileBean theProfileBean = theProfileBeans.get(0);
|
|
|
|
|
|
|
|
|
|
// For each bson.Document creating the SubDocumentView
|
|
|
|
|
for (int i = 0; i < listBSONDocument.size(); i++) {
|
|
|
|
|
Document fromSectionDoc = listBSONDocument.get(i);
|
|
|
|
|
SubDocumentView subDocumentView = new SubDocumentView();
|
|
|
|
|
Document toSectionDoc = new Document();
|
|
|
|
|
// Filling the SubDocumentView metadata with the metadataField.getFieldName()
|
|
|
|
|
// read from the Profile
|
|
|
|
|
for (MetadataFieldWrapper metadataField : theProfileBean.getMetadataFields()) {
|
|
|
|
|
|
|
|
|
|
String theFieldName = metadataField.getFieldId() != null ? metadataField.getFieldId()
|
|
|
|
|
: metadataField.getFieldName();
|
|
|
|
|
LOG.debug("reading theFieldName: " + theFieldName);
|
|
|
|
|
Object theOBJFieldValue = fromSectionDoc.get(theFieldName);
|
|
|
|
|
|
|
|
|
|
// NB: Using ALWAYS THE metadataField.getFieldName() as LABEL
|
|
|
|
|
toSectionDoc = sanitizeDocumentValue(toSectionDoc, metadataField.getFieldName(),
|
|
|
|
|
theOBJFieldValue);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
String subToJSON = toSectionDoc.toJson();
|
|
|
|
|
LOG.debug("theSubSetionDoc is: " + subToJSON);
|
|
|
|
|
subDocumentView.setMetadataAsJSON(toSectionDoc.toJson());
|
|
|
|
|
|
|
|
|
|
// Reading filePaths
|
|
|
|
|
List<FilePathDV> filePaths = gcubeProfileDV.getFilePaths();
|
|
|
|
|
|
|
|
|
|
// READING fileset* field ACCORDING TO filePaths OF THE 'gcubeProfiles' CONFIG
|
|
|
|
|
if (filePaths != null) {
|
|
|
|
|
String fromSectionDocJSON = fromSectionDoc.toJson();
|
|
|
|
|
List<FilesetDV> listFiles = new ArrayList<FilesetDV>();
|
|
|
|
|
List<FilesetDV> listImages = new ArrayList<FilesetDV>();
|
|
|
|
|
for (FilePathDV filePath : filePaths) {
|
|
|
|
|
|
|
|
|
|
String filesetJSONPath = String.format("%s.%s", JSON_$_POINTER, filePath.getFieldName());
|
|
|
|
|
List<Payload> listPayloads = readPayloadsForFileset(filesetJSONPath, fromSectionDocJSON);
|
|
|
|
|
FilesetDV filesetDV = new FilesetDV();
|
|
|
|
|
filesetDV.setName(filePath.getGcubeProfileFieldName());
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
subDocumentView.setListFiles(listFiles);
|
|
|
|
|
subDocumentView.setListImages(listImages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sectionView.addSubDocument(subDocumentView);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
projectView.addSectionView(sectionView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for (SectionView section : projectView.getListSections()) {
|
|
|
|
|
// System.out.println("\n\n###### Section Title: " + section.getSectionTitle() + " ######");
|
|
|
|
|
// int i = 1;
|
|
|
|
|
// for (SubDocumentView subDocument : section.getListSubDocuments()) {
|
|
|
|
|
// System.out.println("## " + SubDocumentView.class.getSimpleName() + " n." + i);
|
|
|
|
|
// System.out.println("***** Metadata");
|
|
|
|
|
// System.out.println(prettyPrintJSON(subDocument.getMetadataAsJSON()));
|
|
|
|
|
// System.out.println("***** Files");
|
|
|
|
|
// if (subDocument.getListFiles() != null) {
|
|
|
|
|
// for (FilesetDV filesetDV : subDocument.getListFiles()) {
|
|
|
|
|
// System.out.println("******* File Fileset name: " + filesetDV.getName());
|
|
|
|
|
// for (PayloadDV payload : filesetDV.getListPayload()) {
|
|
|
|
|
// System.out.println("********* Payload: " + payload);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// System.out.println("***** Images");
|
|
|
|
|
// if (subDocument.getListImages() != null) {
|
|
|
|
|
// for (FilesetDV filesetDV : subDocument.getListImages()) {
|
|
|
|
|
// System.out.println("******* Image Fileset name: " + filesetDV.getName());
|
|
|
|
|
// for (PayloadDV payload : filesetDV.getListPayload()) {
|
|
|
|
|
// System.out.println("********* Payload: " + payload);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// i++;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
return projectView;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String erroMsg = "Error occurred on creating projectView for id: " + projectID;
|
|
|
|
|
LOG.error(erroMsg, e);
|
|
|
|
|
throw new Exception(erroMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Read payloads for fileset.
|
|
|
|
|
*
|
|
|
|
|
* @param filesetJSONPath the fileset JSON path
|
|
|
|
|
* @param sectionJSONDocument the section JSON document
|
|
|
|
|
* @return the list
|
|
|
|
|
*/
|
|
|
|
|
private List<Payload> readPayloadsForFileset(String filesetJSONPath, String sectionJSONDocument) {
|
|
|
|
|
LOG.debug("readPayloadsForFileset called");
|
|
|
|
|
|
|
|
|
|
List<Payload> listPayloads = new ArrayList<Payload>();
|
|
|
|
|
String _payloadsJSONPath = String.format("%s.%s", filesetJSONPath, "_payloads");
|
|
|
|
|
try {
|
|
|
|
|
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
|
|
|
|
.jsonProvider(new JsonOrgJsonProvider()).build();
|
|
|
|
|
|
|
|
|
|
LOG.info("Reading sectionPath at {} into section document {}", _payloadsJSONPath, sectionJSONDocument);
|
|
|
|
|
JsonPath theSectionPolycJsonPath = JsonPath.compile(_payloadsJSONPath);
|
|
|
|
|
Object _payloads = theSectionPolycJsonPath.read(sectionJSONDocument, configuration).toString();
|
|
|
|
|
|
|
|
|
|
if (_payloads instanceof String) {
|
|
|
|
|
String toStringPayloads = (String) _payloads;
|
|
|
|
|
LOG.trace("The _payloads is a String {}", toStringPayloads);
|
|
|
|
|
JSONArray jsonArray = new JSONArray(toStringPayloads);
|
|
|
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
|
|
Payload payloadDV = Serialization.read(jsonArray.getJSONObject(i).toString(), Payload.class);
|
|
|
|
|
listPayloads.add(payloadDV);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("returning list of payloads {}", listPayloads);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.error("Error on reading the JSON Path {} in the doc {} ", _payloadsJSONPath, sectionJSONDocument);
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return listPayloads;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks if is accessible section according to policy.
|
|
|
|
|
*
|
|
|
|
|
* @param section the section
|
|
|
|
|
* @param sectionJSONPath the section JSON path
|
|
|
|
|
* @param myLogin the my login
|
|
|
|
|
* @return true, if is accessible section according to policy
|
|
|
|
|
*/
|
|
|
|
|
private boolean isAccessibleSectionAccordingToPolicy(Document section, String sectionJSONPath, String myLogin) {
|
|
|
|
|
LOG.debug("isAccessibleSectionAccordingToPolicy called");
|
|
|
|
|
boolean isAccessible = true;
|
|
|
|
|
|
|
|
|
|
// Skipping the root, going to check the access_policy of subsections
|
|
|
|
|
if (sectionJSONPath.compareTo(JSON_$_POINTER) != 0) {
|
|
|
|
|
isAccessible = checkAccessPolicy(section.toJson(), myLogin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isAccessible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check access policy.
|
|
|
|
|
*
|
|
|
|
|
* @param sectionDocumentJSON the section document JSON
|
|
|
|
|
* @param myLogin the my login
|
|
|
|
|
* @return true, if successful
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkAccessPolicy(String sectionDocumentJSON, String myLogin) {
|
|
|
|
|
LOG.debug("checkAccessPolicy called");
|
|
|
|
|
// CHECKING THE POLICY
|
|
|
|
|
String accessPolicyPath = JSON_$_POINTER + "._access._policy";
|
|
|
|
|
boolean isAccessible = true;
|
|
|
|
|
try {
|
|
|
|
|
com.jayway.jsonpath.Configuration configuration = com.jayway.jsonpath.Configuration.builder()
|
|
|
|
|
.jsonProvider(new JsonOrgJsonProvider()).build();
|
|
|
|
|
|
|
|
|
|
LOG.info("Reading access policy at {} into section document {}", accessPolicyPath, sectionDocumentJSON);
|
|
|
|
|
JsonPath theSectionPolycJsonPath = JsonPath.compile(accessPolicyPath);
|
|
|
|
|
String _policy = theSectionPolycJsonPath.read(sectionDocumentJSON, configuration).toString();
|
|
|
|
|
LOG.info("The section {} has policy {}", accessPolicyPath, _policy);
|
|
|
|
|
isAccessible = GeportalCheckAccessPolicy.isAccessible(_policy, myLogin);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.error(accessPolicyPath + " not found. Check OK");
|
|
|
|
|
}
|
|
|
|
|
LOG.info("Is the section {} accessible? {}", sectionDocumentJSON, isAccessible);
|
|
|
|
|
return isAccessible;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pretty print JSON.
|
|
|
|
|
*
|
|
|
|
|
* @param jsonString the json string
|
|
|
|
|
* @return the string
|
|
|
|
|
*/
|
|
|
|
|
private String prettyPrintJSON(String jsonString) {
|
|
|
|
|
|
|
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
|
|
JsonObject jsonObject = new JsonParser().parse(jsonString).getAsJsonObject();
|
|
|
|
|
return gson.toJson(jsonObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sanitize document value.
|
|
|
|
|
*
|
|
|
|
|
* @param toDoc the to doc
|
|
|
|
|
* @param fieldLabel the field label
|
|
|
|
|
* @param theObjectFieldValue the the object field value
|
|
|
|
|
* @return the document
|
|
|
|
|
*/
|
|
|
|
|
private Document sanitizeDocumentValue(Document toDoc, String fieldLabel, Object theObjectFieldValue) {
|
|
|
|
|
|
|
|
|
|
if (theObjectFieldValue != null) {
|
|
|
|
|
if (theObjectFieldValue instanceof String) {
|
|
|
|
|
String toString = (String) theObjectFieldValue;
|
|
|
|
|
if (toString != null && !toString.isEmpty()) {
|
|
|
|
|
toDoc.append(fieldLabel, theObjectFieldValue);
|
|
|
|
|
} else {
|
|
|
|
|
LOG.debug("Skipping String field " + fieldLabel + " its value is null or empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (theObjectFieldValue instanceof ArrayList) {
|
|
|
|
|
ArrayList toArrayList = (ArrayList) theObjectFieldValue;
|
|
|
|
|
if (toArrayList != null && !toArrayList.isEmpty()) {
|
|
|
|
|
toDoc.append(fieldLabel, theObjectFieldValue);
|
|
|
|
|
} else {
|
|
|
|
|
LOG.debug("Skipping ArrayList field " + fieldLabel + " its value is null or empty");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
toDoc.append(fieldLabel, theObjectFieldValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
LOG.debug("Skipping field " + fieldLabel + " its value is null or empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return toDoc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|