2020-10-23 18:18:06 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer.server;
|
|
|
|
|
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-11-03 18:04:47 +01:00
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
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-10-29 15:18:14 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
|
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerItem;
|
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;
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
@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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load geo info for wms request.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @param layerName the layer name
|
|
|
|
* @return the gis viewer wms valid parameters
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
|
|
|
public static GeoInformationForWMSRequest loadGeoInfoForWmsRequest(String wmsRequest, String layerName) throws Exception{
|
|
|
|
try {
|
|
|
|
WMSUrlValidator validator = new WMSUrlValidator(wmsRequest, layerName);
|
|
|
|
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-10-29 15:18:14 +01:00
|
|
|
|
2020-11-02 18:18:03 +01:00
|
|
|
/*
|
|
|
|
* (non-Javadoc)
|
|
|
|
*
|
|
|
|
* @see
|
|
|
|
* org.gcube.portlets.user.gisviewer.client.GisViewerService#getDataResult(java.
|
|
|
|
* util.List, java.lang.String, int)
|
2020-10-29 15:18:14 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2020-11-02 18:18:03 +01:00
|
|
|
public List<GeoNaDataObject> getDataResult(List<LayerItem> layerItems, String mapSrsName, BoundsMap selectBBOX,
|
|
|
|
int maxWFSFeature, double zoomLevel) {
|
2020-10-29 15:18:14 +01:00
|
|
|
LOG.info("getDataResult called");
|
2020-10-29 17:57:29 +01:00
|
|
|
List<GeoNaDataObject> result = FeatureParser.getDataResults(layerItems, mapSrsName, selectBBOX, maxWFSFeature);
|
2020-11-02 18:18:03 +01:00
|
|
|
|
2020-11-03 13:09:08 +01:00
|
|
|
/*for (GeoNaDataObject geoNaDataObject : result) {
|
2020-11-02 18:18:03 +01:00
|
|
|
List<FeatureRow> features = geoNaDataObject.getFeatures();
|
|
|
|
for (FeatureRow feature : features) {
|
|
|
|
List<String> theProductIds = feature.getMapProperties().get(PRODUCT_ID);
|
|
|
|
try {
|
|
|
|
if (theProductIds != null && theProductIds.size() > 0) {
|
|
|
|
String theProductID = theProductIds.get(0);
|
|
|
|
LOG.info("Found: "+PRODUCT_ID + " loading "+ConcessioneDV.class.getSimpleName());
|
|
|
|
long productID = Long.parseLong(theProductID);
|
|
|
|
ConcessioneDV concessioneDV = getConcessioneForId(productID);
|
|
|
|
geoNaDataObject.setConcessioneDV(concessioneDV);
|
|
|
|
LOG.debug("Added "+ConcessioneDV.class.getSimpleName()+" as "+concessioneDV);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("Error:", e);
|
|
|
|
}
|
|
|
|
}
|
2020-11-03 13:09:08 +01:00
|
|
|
}*/
|
2020-10-29 15:18:14 +01:00
|
|
|
return result;
|
|
|
|
}
|
2020-11-02 13:05:53 +01:00
|
|
|
|
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-03 18:04:47 +01:00
|
|
|
if(!SessionUtil.isIntoPortal()) {
|
|
|
|
LOG.warn("OUT OF PORTAL setting HARD-CODED SCOPE");
|
|
|
|
String scope = "/gcube/devNext/NextNext";
|
|
|
|
LOG.warn("SCOPE is: "+scope);
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
}
|
|
|
|
|
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-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-02 18:18:03 +01:00
|
|
|
return ConvertToDataViewModel.toConcessione(concessione);
|
2020-11-02 13:05:53 +01:00
|
|
|
}else
|
2020-11-02 18:18:03 +01:00
|
|
|
throw new Exception("No Concessione with id '"+id+"' is available");
|
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);
|
|
|
|
throw new Exception(erroMsg);
|
2020-11-02 13:05:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-10-29 15:18:14 +01:00
|
|
|
|
2020-10-23 18:18:06 +02:00
|
|
|
}
|