integrated Base Maps into GNABaseMaps Runtime Resource

This commit is contained in:
Francesco Mangiacrapa 2021-11-18 15:55:05 +01:00
parent bba75e70b8
commit bb64769b51
9 changed files with 229 additions and 36 deletions

View File

@ -1,31 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="geoportal-data-viewer-app-2.1.0-SNAPSHOT">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<property name="context-root" value="geoportal-data-viewer-app"/>
</wb-module>
</project-modules>

View File

@ -42,6 +42,8 @@ import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerManager;
@ -95,7 +97,7 @@ public class GeoportalDataViewer implements EntryPoint {
int attempt = 0;
private LoaderIcon loaderApp = new LoaderIcon("Loading application....");
//private LoaderIcon loaderApp = new LoaderIcon("Loading application....");
private HTML attributionDiv = new HTML();
@ -106,7 +108,10 @@ public class GeoportalDataViewer implements EntryPoint {
*/
public void onModuleLoad() {
loaderApp.getElement().getStyle().setZIndex(100);
// Style style = loaderApp.getElement().getStyle();
// style.setZIndex(300);
// style.setMarginTop(50,Unit.PX);
// style.setMarginLeft(50, Unit.PX);
paramWmsRequest = Window.Location.getParameter(GeoportalDataViewerConstants.GET_WMS_PARAMETER);
paramGeonaItemType = Window.Location.getParameter(GeoportalDataViewerConstants.GET_GEONA_ITEM_TYPE);
@ -117,7 +122,7 @@ public class GeoportalDataViewer implements EntryPoint {
GWT.log(GeoportalDataViewerConstants.GET_GEONA_ITEM_ID + " = " + paramGeonaItemID);
GWT.log(GeoportalDataViewerConstants.GET_LAYER_TITLE + " = " + paramLayerTitle);
RootPanel.get(APP_DIV).add(loaderApp);
//RootPanel.get(APP_DIV).add(loaderApp);
mainPanel = new GeonaDataViewMainPanel(applicationBus, getClientHeight());
RootPanel.get(APP_DIV).add(mainPanel);
@ -132,13 +137,13 @@ public class GeoportalDataViewer implements EntryPoint {
@Override
public void onFailure(Throwable caught) {
RootPanel.get(APP_DIV).remove(loaderApp);
//RootPanel.get(APP_DIV).remove(loaderApp);
Window.alert("Error occurred on instancing the GeoPortale Viewer. Please, contact the support");
}
@Override
public void onSuccess(List<BaseMapLayer> listBaseMapLayers) {
RootPanel.get(APP_DIV).remove(loaderApp);
//RootPanel.get(APP_DIV).remove(loaderApp);
GeoportalDataViewer.listBaseMapLayers = listBaseMapLayers;
//now the map is loaded and I'm sure that I can load the GeonaDataViewer Profile
loadGeonaDataViewerProfile();

View File

@ -0,0 +1,111 @@
package org.gcube.portlets.user.geoportaldataviewer.server;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.gcube.common.encryption.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer.OL_BASE_MAP;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class GNABaseMapsResourceReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Nov 18, 2021
*/
public class GNABaseMapsResourceReader {
private static Logger LOG = LoggerFactory.getLogger(GNABaseMapsResourceReader.class);
private static final String SE_PROFILE_NAME = "GNABaseMaps";
private static final String SE_CATEGORY_NAME = "Application";
/**
* Gets the list base maps.
*
* @return the list base maps
* @throws Exception the exception
*/
public static List<BaseMapLayer> getListBaseMaps() throws Exception {
List<BaseMapLayer> lstBaseMaps = new ArrayList<BaseMapLayer>();
LOG.info("Searching SE in the scope: " + ScopeProvider.instance.get() + " with profile name: " + SE_PROFILE_NAME
+ " and category name: " + SE_CATEGORY_NAME);
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '" + SE_PROFILE_NAME + "'");
query.addCondition("$resource/Profile/Category/text() eq '" + SE_CATEGORY_NAME + "'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if (resources.size() > 0)
LOG.info("The query returned " + resources.size() + " ServiceEndpoint/s");
else
throw new RuntimeException("ServiceEndpoint not found. Searching for profile name: " + SE_PROFILE_NAME
+ " and category name: " + SE_CATEGORY_NAME + "in the scope: " + ScopeProvider.instance.get());
ServiceEndpoint se = resources.get(0);
Collection<AccessPoint> theAccessPoints = se.profile().accessPoints().asCollection();
for (AccessPoint accessPoint : theAccessPoints) {
BaseMapLayer bml = new BaseMapLayer();
bml.setName(accessPoint.name());
bml.setAttribution(accessPoint.description());
String url = accessPoint.address();
String apiTokenName = accessPoint.username();
String apiTokenPwd = accessPoint.password();
LOG.debug("Found API_TOKEN name: " + apiTokenName + ", encrypted token: " + apiTokenPwd);
// decrypting the pwd
try {
if (isValorized(apiTokenPwd)) {
apiTokenPwd = StringEncrypter.getEncrypter().decrypt(apiTokenPwd);
LOG.debug("Token decrypted is: " + apiTokenPwd.substring(0, apiTokenPwd.length() / 2)
+ "_MASKED_TOKEN_");
}
} catch (Exception e) {
throw new RuntimeException("Error on decrypting the pwd: ", e);
}
if (isValorized(apiTokenName) && isValorized(apiTokenPwd)) {
url = String.format("%s?%s=%s", url, apiTokenName, apiTokenPwd);
}
bml.setUrl(url);
// SETTING MAP TYPE
String urlLower = bml.getUrl().toLowerCase();
if (urlLower.contains("mapbox")) {
bml.setType(OL_BASE_MAP.MAPBOX);
} else if (urlLower.contains("openstreetmap")) {
bml.setType(OL_BASE_MAP.OSM);
} else
bml.setType(OL_BASE_MAP.OTHER);
lstBaseMaps.add(bml);
}
LOG.debug("Read base maps: "+lstBaseMaps);
LOG.info("Returning " + lstBaseMaps.size() + " base maps");
return lstBaseMaps;
}
private static boolean isValorized(String value) {
if (value != null && !value.isEmpty()) {
return true;
}
return false;
}
}

View File

@ -322,8 +322,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
if (layerPosizionamento != null) {
if (!GeoNACheckAccessPolicy.isAccessible(layerPosizionamento.getPolicy(), userName)) {
concessionDV.setPosizionamentoScavo(null);
} else {
LOG.info("Posizionamento di Scavo is not accessible by current user");
LOG.info("Posizionamento di Scavo is not accessible by current user: "+userName);
}
}
@ -333,6 +332,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
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);
@ -342,6 +343,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
if (abstractRS != null) {
if (!GeoNACheckAccessPolicy.isAccessible(abstractRS.getPolicy(), userName)) {
concessionDV.setAbstractRelazioneScavo(null);
LOG.info("Abstract relazione is not accessible by current user: "+userName);
}
}
@ -349,6 +351,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
if (relazioneScavo != null) {
if (!GeoNACheckAccessPolicy.isAccessible(relazioneScavo.getPolicy(), userName)) {
concessionDV.setRelazioneScavo(null);
LOG.info("Relazione scavo is not accessible by current user: "+userName);
}
}
@ -361,6 +364,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
if (GeoNACheckAccessPolicy.isAccessible(uploadedImageDV.getPolicy(), userName)) {
accessibleListImages.add(uploadedImageDV);
}else {
LOG.info("Immagine "+uploadedImageDV.getTitolo()+" is not accessible by current user: "+userName);
}
}
@ -664,24 +669,28 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
@Override
public List<BaseMapLayer> getListBaseLayers() {
LOG.info("getListBaseLayers called");
List<BaseMapLayer> listBL = new ArrayList<BaseMapLayer>();
// OSM
String attribution = "© <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>";
BaseMapLayer baseLayer = new BaseMapLayer("Open Street Map", "https://tile.openstreetmap.org/{z}/{x}/{y}.png", attribution,
BaseMapLayer.OL_BASE_MAP.OSM);
listBL.add(baseLayer);
//Setting scope in the cuurent thread
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
listBL = SessionUtil.getGNABaseMaps(this.getThreadLocalRequest());
// MAPBOX
attribution = "© <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> © <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>";
baseLayer = new BaseMapLayer("MapBox Satellite",
"https://{a-d}.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZDRzY2llbmNlIiwiYSI6ImNpcW1nZjE4MDAwMXNod25rdHJsemRoNTQifQ.YPNkNLb8EzjThpvJl1tg4w",
attribution, BaseMapLayer.OL_BASE_MAP.MAPBOX);
listBL.add(baseLayer);
LOG.info("getListBaseLayers returning "+listBL.size() +" base maps");
//
// String attribution;
// BaseMapLayer baseLayer;
// // OSM
// attribution = "© <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>";
// baseLayer = new BaseMapLayer("Open Street Map", "https://tile.openstreetmap.org/{z}/{x}/{y}.png", attribution,
// BaseMapLayer.OL_BASE_MAP.OSM);
// listBL.add(baseLayer);
// // MAPBOX
// attribution = "© <a href='https://www.mapbox.com/about/maps/'>Mapbox</a> © <a href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a> <a href='https://www.mapbox.com/map-feedback/' target='_blank'>Improve this map</a>";
// baseLayer = new BaseMapLayer("MapBox Satellite",
// "https://{a-d}.tiles.mapbox.com/v4/mapbox.satellite/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZDRzY2llbmNlIiwiYSI6ImNpcW1nZjE4MDAwMXNod25rdHJsemRoNTQifQ.YPNkNLb8EzjThpvJl1tg4w",
// attribution, BaseMapLayer.OL_BASE_MAP.MAPBOX);
//
// listBL.add(baseLayer);
return listBL;

View File

@ -17,7 +17,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class IAMClientCredentialsReader.
* The Class GNABaseMapsResourceReader.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*

View File

@ -3,12 +3,16 @@
*/
package org.gcube.portlets.user.geoportaldataviewer.server.util;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
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.shared.gis.BaseMapLayer;
import org.gcube.portlets.user.urlshortener.UrlShortener;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
@ -34,6 +38,7 @@ public class SessionUtil {
private static Logger LOG = LoggerFactory.getLogger(SessionUtil.class);
private static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE";
private static final String LIST_BASE_MAPS_LAYERS = "LIST_BASE_MAPS_LAYERS";
/**
* Checks if is into portal.
@ -168,4 +173,28 @@ public class SessionUtil {
return shortener;
}
/**
* Gets the GNA base maps.
*
* @param httpServletRequest the http servlet request
* @return the GNA base maps
*/
public static List<BaseMapLayer> getGNABaseMaps(HttpServletRequest httpServletRequest) {
HttpSession session = httpServletRequest.getSession();
List<BaseMapLayer> lstBML = null;
try {
lstBML = (List<BaseMapLayer>) session.getAttribute(LIST_BASE_MAPS_LAYERS);
if (lstBML == null) {
GNABaseMapsResourceReader gnaBMRR = new GNABaseMapsResourceReader();
lstBML = gnaBMRR.getListBaseMaps();
session.setAttribute(LIST_BASE_MAPS_LAYERS, lstBML);
}
} catch (Exception e) {
LOG.warn("Error occurred reading the base maps by " + GNABaseMapsResourceReader.class.getSimpleName(), e);
}
return lstBML;
}
}

View File

@ -434,7 +434,7 @@ body {
.base-internal-layers-maplink .btn-link {
/*border: 1px solid #eee;*/
border: 1px solid #005580;
border: 2px solid rgba(255,255,255,.4);
/*background-color: #fcfcfc;*/
margin: 1px;
}

View File

@ -31,7 +31,7 @@
<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>
<title>GNA Data Viewer Application</title>
<!-- -->
<!-- This script loads your compiled module. -->

View File

@ -0,0 +1,29 @@
package org.gcube.portlets.user.geoportaldataviewer;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.geoportaldataviewer.server.GNABaseMapsResourceReader;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BaseMapLayer;
import org.junit.Test;
public class GNABaseMaps {
private static final String SCOPE = "/gcube/devsec/devVRE";
@Test
public void readBaseMaps() {
System.out.println("called readBaseMaps test");
ScopeProvider.instance.set(SCOPE);
GNABaseMapsResourceReader gnaBaseMapsR = new GNABaseMapsResourceReader();
List<BaseMapLayer> lstBML = null;
try {
lstBML = gnaBaseMapsR.getListBaseMaps();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Read base map layers: " + lstBML);
}
}