2020-10-23 18:18:06 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
|
2020-11-13 16:37:34 +01:00
|
|
|
import java.util.ArrayList;
|
2020-10-27 16:04:34 +01:00
|
|
|
import java.util.HashMap;
|
2020-10-29 15:18:14 +01:00
|
|
|
import java.util.List;
|
2020-10-27 16:04:34 +01:00
|
|
|
import java.util.Map;
|
|
|
|
|
2020-11-02 13:05:53 +01:00
|
|
|
import org.gcube.application.geoportal.managers.AbstractRecordManager;
|
|
|
|
import org.gcube.application.geoportal.managers.ManagerFactory;
|
|
|
|
import org.gcube.application.geoportal.model.Record;
|
|
|
|
import org.gcube.application.geoportal.model.concessioni.Concessione;
|
2020-10-26 12:24:23 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService;
|
2020-10-29 15:18:14 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser;
|
2020-10-27 16:04:34 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator;
|
2020-11-03 18:04:47 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
2020-11-12 11:39:52 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.URLParserUtil;
|
2020-10-29 15:18:14 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject;
|
2020-11-12 18:25:24 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataViewerProfile;
|
2020-10-29 15:18:14 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
2020-11-13 16:37:34 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
|
2020-11-03 13:09:08 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.Styles;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis;
|
2020-11-02 18:18:03 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
|
2020-10-27 16:04:34 +01:00
|
|
|
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;
|
2020-11-11 15:53:04 +01:00
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
2020-10-27 16:04:34 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2020-10-23 18:18:06 +02:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
2020-11-12 18:25:24 +01:00
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
|
|
|
*
|
|
|
|
* Nov 12, 2020
|
2020-10-23 18:18:06 +02:00
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2020-10-26 12:24:23 +01:00
|
|
|
public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements
|
|
|
|
GeoportalDataViewerService {
|
2020-10-27 16:04:34 +01:00
|
|
|
|
2020-11-02 18:18:03 +01:00
|
|
|
public static final String PRODUCT_ID = "product_id";
|
2020-10-27 16:04:34 +01:00
|
|
|
/** The Constant LOG. */
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class);
|
2020-10-23 18:18:06 +02:00
|
|
|
|
2020-11-12 18:25:24 +01:00
|
|
|
/**
|
|
|
|
* Parses the wms request.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @param layerName the layer name
|
|
|
|
* @return the geo information for WMS request
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-10-27 16:04:34 +01:00
|
|
|
@Override
|
2020-10-27 16:41:30 +01:00
|
|
|
public GeoInformationForWMSRequest parseWmsRequest(String wmsRequest, String layerName) throws Exception {
|
2020-10-27 16:04:34 +01:00
|
|
|
return loadGeoInfoForWmsRequest(wmsRequest, layerName);
|
|
|
|
}
|
|
|
|
|
2020-11-12 18:25:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load geo info for wms request.
|
2020-10-27 16:04:34 +01:00
|
|
|
*
|
2020-11-12 18:25:24 +01:00
|
|
|
* @param wmsLink the wms link
|
2020-10-27 16:04:34 +01:00
|
|
|
* @param layerName the layer name
|
2020-11-12 18:25:24 +01:00
|
|
|
* @return the geo information for WMS request
|
2020-10-27 16:04:34 +01:00
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-11-12 18:25:24 +01:00
|
|
|
public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsLink, String layerName) throws Exception{
|
2020-10-27 16:04:34 +01:00
|
|
|
try {
|
2020-11-12 18:25:24 +01:00
|
|
|
WMSUrlValidator validator = new WMSUrlValidator(wmsLink, layerName);
|
2020-10-27 16:04:34 +01:00
|
|
|
String wmsServiceHost = validator.getWmsServiceHost();
|
|
|
|
String validWMSRequest = validator.parseWMSRequest(true, true);
|
|
|
|
layerName = validator.getLayerName();
|
|
|
|
String versionWms = validator.getValueOfParsedWMSParameter(WmsParameters.VERSION);
|
|
|
|
String crs = validator.getValueOfParsedWMSParameter(WmsParameters.CRS);
|
|
|
|
//
|
|
|
|
HashMap<String, String> mapWmsNotStandard = new HashMap<String, String>();
|
|
|
|
|
|
|
|
if(validator.getMapWmsNoStandardParams()!=null){
|
|
|
|
mapWmsNotStandard.putAll(validator.getMapWmsNoStandardParams());
|
|
|
|
}
|
|
|
|
//
|
|
|
|
GeoNcWMSMetadataUtility geoGS = new GeoNcWMSMetadataUtility(validWMSRequest, 4000);
|
|
|
|
//STYLES
|
|
|
|
LayerStyles layerStyle = geoGS.loadStyles();
|
|
|
|
Map<String,String> mapNcWmsStyles = layerStyle.getMapNcWmsStyles()==null?new HashMap<String, String>(1):layerStyle.getMapNcWmsStyles();
|
|
|
|
mapWmsNotStandard.putAll(mapNcWmsStyles);
|
|
|
|
//MAP STYLES INTO GWT-SERIALIZABLE OBJECT
|
|
|
|
Styles styles = new Styles(layerStyle.getGeoStyles(), layerStyle.getMapNcWmsStyles(), layerStyle.isNcWms());
|
|
|
|
//ZAxis
|
|
|
|
LayerZAxis layerZAxis = geoGS.loadZAxis();
|
|
|
|
//MAP ZAXIS INTO GWT-SERIALIZABLE OBJECT
|
|
|
|
ZAxis zAxis = layerZAxis!=null?new ZAxis(layerZAxis.getUnits(), layerZAxis.isPositive(), layerZAxis.getValues()):null;
|
|
|
|
|
|
|
|
return new GeoInformationForWMSRequest(wmsServiceHost, validWMSRequest, layerName, versionWms, crs, mapWmsNotStandard, styles, styles.isNcWms(), zAxis);
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
String msg = "An error occurred during wms request validation for layer: "+layerName;
|
|
|
|
LOG.error(msg,e);
|
|
|
|
throw new Exception(msg);
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 16:37:34 +01:00
|
|
|
|
2020-11-12 18:25:24 +01:00
|
|
|
/**
|
|
|
|
* Gets the data result.
|
|
|
|
*
|
2020-11-13 16:37:34 +01:00
|
|
|
* @param layerObjects the layer objects
|
2020-11-12 18:25:24 +01:00
|
|
|
* @param mapSrsName the map srs name
|
|
|
|
* @param selectBBOX the select BBOX
|
|
|
|
* @param maxWFSFeature the max WFS feature
|
|
|
|
* @param zoomLevel the zoom level
|
|
|
|
* @return the data result
|
|
|
|
*/
|
2020-10-29 15:18:14 +01:00
|
|
|
@Override
|
2020-11-13 16:37:34 +01:00
|
|
|
public List<GeoNaDataObject> getDataResult(List<LayerObject> layerObjects, String mapSrsName, BoundsMap selectBBOX,
|
2020-11-02 18:18:03 +01:00
|
|
|
int maxWFSFeature, double zoomLevel) {
|
2020-10-29 15:18:14 +01:00
|
|
|
LOG.info("getDataResult called");
|
2020-11-13 16:37:34 +01:00
|
|
|
|
|
|
|
List<GeoNaDataObject> listDAO = new ArrayList<GeoNaDataObject>(layerObjects.size());
|
|
|
|
|
|
|
|
for (LayerObject layerObject : layerObjects) {
|
|
|
|
GeoNaDataObject geoDAO = new GeoNaDataObject();
|
|
|
|
List<FeatureRow> features = FeatureParser.getWFSFeatures(layerObject.getLayerItem(), mapSrsName, selectBBOX, maxWFSFeature);
|
|
|
|
LOG.debug("For layer name: "+layerObject.getLayerItem().getName() +" got features: "+features);
|
|
|
|
geoDAO.setFeatures(features);
|
|
|
|
geoDAO.setSourceLayerObject(layerObject);
|
|
|
|
LOG.info("Fo layer name: "+layerObject.getLayerItem().getName() +" got "+features.size()+" feature/s");
|
|
|
|
listDAO.add(geoDAO);
|
|
|
|
}
|
|
|
|
LOG.info("returning "+listDAO+" geona data objects");
|
|
|
|
return listDAO;
|
2020-10-29 15:18:14 +01:00
|
|
|
}
|
2020-11-02 13:05:53 +01:00
|
|
|
|
2020-11-12 18:25:24 +01:00
|
|
|
/**
|
|
|
|
* Gets the concessione for id.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @return the concessione for id
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-11-03 13:09:08 +01:00
|
|
|
@Override
|
|
|
|
public ConcessioneDV getConcessioneForId(Long id) throws Exception{
|
2020-11-03 18:04:47 +01:00
|
|
|
LOG.info("getConcessioneForId "+id+ "called");
|
2020-11-02 13:05:53 +01:00
|
|
|
|
2020-11-04 16:00:13 +01:00
|
|
|
ConcessioneDV concessionDV = null;
|
2020-11-03 18:04:47 +01:00
|
|
|
|
2020-11-02 13:05:53 +01:00
|
|
|
if(id==null)
|
|
|
|
throw new Exception("Invalid parameter. The Id is null");
|
|
|
|
|
|
|
|
try {
|
2020-11-03 18:04:47 +01:00
|
|
|
LOG.info("Trying to get record for id "+id);
|
2020-11-10 16:46:28 +01:00
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
2020-11-02 13:05:53 +01:00
|
|
|
AbstractRecordManager<Record> abmRecord = ManagerFactory.getByRecordID(id);
|
2020-11-03 18:04:47 +01:00
|
|
|
LOG.info("Got record for id "+id);
|
2020-11-02 13:05:53 +01:00
|
|
|
Record record = abmRecord.getRecord();
|
|
|
|
Concessione concessione = null;
|
|
|
|
if(record !=null && record instanceof Concessione) {
|
|
|
|
concessione = (Concessione) record;
|
2020-11-04 16:00:13 +01:00
|
|
|
concessionDV = ConvertToDataViewModel.toConcessione(concessione);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(concessionDV==null)
|
|
|
|
throw new Exception("Concessione not retrieved");
|
2020-11-02 13:05:53 +01:00
|
|
|
|
2020-11-04 16:00:13 +01:00
|
|
|
return concessionDV;
|
2020-11-02 13:05:53 +01:00
|
|
|
|
|
|
|
}catch (Exception e) {
|
2020-11-02 18:18:03 +01:00
|
|
|
String erroMsg = Concessione.class.getSimpleName() +" with id "+id+" not available";
|
|
|
|
LOG.error(erroMsg,e);
|
2020-11-04 16:00:13 +01:00
|
|
|
|
|
|
|
Concessione concessione= TestModel.prepareConcessione();
|
|
|
|
LOG.warn("DUMMY CONCESSIONE: "+concessione);
|
|
|
|
ConcessioneDV theConcessione = ConvertToDataViewModel.toConcessione(concessione);
|
|
|
|
LOG.warn("RETURNING DUMMY CONCESSIONE: "+theConcessione+"!!!!!\n\n\n\n");
|
|
|
|
return theConcessione;
|
|
|
|
|
|
|
|
//throw new Exception(erroMsg);
|
2020-11-02 13:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-11-11 15:53:04 +01:00
|
|
|
|
|
|
|
|
2020-11-12 11:39:52 +01:00
|
|
|
/**
|
|
|
|
* Gets the parameters from URL.
|
|
|
|
*
|
|
|
|
* @param theURL the the URL
|
|
|
|
* @param parameters the parameters
|
|
|
|
* @return a map with couple (paramKey, paramValue)
|
|
|
|
*/
|
|
|
|
|
|
|
|
public Map<String, String> getParametersFromURL(String theURL, List<String> parameters) {
|
|
|
|
|
|
|
|
if (theURL == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (parameters == null || parameters.size() == 0)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Map<String, String> hashParameters = new HashMap<String, String>(parameters.size());
|
|
|
|
for (String paramKey : parameters) {
|
|
|
|
String paramValue = URLParserUtil.extractValueOfParameterFromURL(paramKey, theURL);
|
|
|
|
hashParameters.put(paramKey, paramValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hashParameters;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-11 15:53:04 +01:00
|
|
|
/**
|
|
|
|
* Gets the my login.
|
|
|
|
*
|
|
|
|
* @return the my login
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getMyLogin(){
|
|
|
|
try {
|
|
|
|
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
if(user==null)
|
|
|
|
return null;
|
|
|
|
return user.getUsername();
|
|
|
|
}catch (Exception e) {
|
|
|
|
LOG.warn("Error on getting the login, am I out of portal? Returning null");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 18:25:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the layer for type.
|
|
|
|
*
|
|
|
|
* @param layerType the layer type
|
|
|
|
* @return the layer for type
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public GeoInformationForWMSRequest getLayerForType(String layerType) throws Exception{
|
|
|
|
LOG.info("Called getLayerForType for:"+layerType);
|
|
|
|
|
|
|
|
if(layerType==null || layerType.isEmpty())
|
|
|
|
throw new Exception("The input parameter layerType is null or empty");
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app");
|
|
|
|
GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure();
|
|
|
|
LOG.info("Read profile: "+profile);
|
|
|
|
|
|
|
|
String lowerLayerType = layerType.toLowerCase();
|
|
|
|
LOG.info("Reading map layers for type:"+lowerLayerType);
|
|
|
|
LayerItem layer = profile.getMapLayers().get(lowerLayerType);
|
|
|
|
|
|
|
|
if(layer==null || layer.getWmsLink()==null)
|
|
|
|
throw new Exception("The layer type "+lowerLayerType+" has not been found. Please check your input parameter");
|
|
|
|
|
|
|
|
if(layer.getWmsLink()==null)
|
|
|
|
throw new Exception("The layer type "+lowerLayerType+" has not a WMS Link associated. Please check your input parameter");
|
|
|
|
|
|
|
|
|
|
|
|
return parseWmsRequest(layer.getWmsLink(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-11-13 16:37:34 +01:00
|
|
|
/**
|
|
|
|
* Gets the geo na data view profile.
|
|
|
|
*
|
|
|
|
* @return the geo na data view profile
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2020-11-12 18:25:24 +01:00
|
|
|
@Override
|
|
|
|
public GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception{
|
|
|
|
LOG.info("Called getAvailableLayers");
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
GeoNaDataViewerProfileReader gdvp = new GeoNaDataViewerProfileReader("geoportal-data-viewer-app");
|
|
|
|
GeoNaDataViewerProfile profile = gdvp.readProfileFromInfrastrucure();
|
|
|
|
LOG.info("Returning profile: "+profile);
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:18:14 +01:00
|
|
|
|
2020-10-23 18:18:06 +02:00
|
|
|
}
|