added the first uploaded image into popup

This commit is contained in:
Francesco Mangiacrapa 2020-11-16 12:09:11 +01:00
parent 2536912982
commit db668a37a8
9 changed files with 264 additions and 31 deletions

26
pom.xml
View File

@ -109,18 +109,18 @@
<artifactId>geo-utility</artifactId>
<version>[1.0.0,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.common</groupId> -->
<!-- <artifactId>authorization-client</artifactId> -->
<!-- <version>[2.0.0, 3.0.0-SNAPSHOT)</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.resources.discovery</groupId> -->
<!-- <artifactId>ic-client</artifactId> -->
<!-- <version>[1.0.0, 2.0.0-SNAPSHOT)</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
@ -203,7 +203,7 @@
<execution>
<goals>
<goal>compile</goal>
<!-- <goal>test</goal> -->
<!-- <goal>test</goal> -->
<!-- <goal>generateAsync</goal> -->
</goals>
</execution>

View File

@ -8,6 +8,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@ -38,4 +39,13 @@ public interface GeoportalDataViewerService extends RemoteService {
GeoNaDataViewerProfile getGeoNaDataViewProfile() throws Exception;
/**
* Gets the uploaded images for id.
*
* @param id the id
* @return the uploaded images for id
* @throws Exception the exception
*/
List<UploadedImageDV> getUploadedImagesForId(String itemType, Long id, int maxImages) throws Exception;
}

View File

@ -8,6 +8,7 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -43,4 +44,6 @@ public interface GeoportalDataViewerServiceAsync {
void getLayerForType(String layerType, AsyncCallback<GeoInformationForWMSRequest> callback);
void getGeoNaDataViewProfile(AsyncCallback<GeoNaDataViewerProfile> callback);
void getUploadedImagesForId(String itemType, Long id, int maxImages, AsyncCallback<List<UploadedImageDV>> callback);
}

View File

@ -13,6 +13,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.events.QueryDataEventHandler;
import org.gcube.portlets.user.geoportaldataviewer.client.events.ShowDetailsEvent;
import org.gcube.portlets.user.geoportaldataviewer.client.gis.OpenLayerOSM;
import org.gcube.portlets.user.geoportaldataviewer.client.util.StringUtil;
import org.gcube.portlets.user.geoportaldataviewer.client.util.URLUtil;
import org.gcube.portlets.user.geoportaldataviewer.shared.GeoNaDataObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.BoundsMap;
@ -22,6 +23,8 @@ import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.GeoInformationForWMSRequest;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wms.ZAxis;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.content.WorkspaceContentDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
@ -153,16 +156,82 @@ public class LayerManager {
//USING ONLY THE FIRST FEATURE IN THE LIST
if(features!=null && features.size()>0) {
feature = features.get(0);
Map<String, List<String>> entries = features.get(0).getMapProperties();
Map<String, List<String>> entries = feature.getMapProperties();
for (String key : entries.keySet()) {
String theValue = entries.get(key).get(0);
if(key.equalsIgnoreCase("nome")) {
flex.setHTML(0, 0, new HTML(entries.get(key).get(0)).toString());
flex.setHTML(0, 0, new HTML(theValue).toString());
}
else if(key.equalsIgnoreCase("descrizione")) {
flex.setText(1, 0, entries.get(key).get(0));
String reducedValue = theValue;
try {
reducedValue = StringUtil.ellipsize(theValue, 300);
GWT.log("reduced: "+reducedValue);
} catch (Exception e) {
GWT.log("error: "+e.getMessage());
}
flex.setText(1, 0, reducedValue);
}else if(key.equalsIgnoreCase("date_scavo")) {
flex.setHTML(2, 0, new HTML("<code>"+entries.get(key).get(0)).toString()+"</code>");
flex.setHTML(2, 0, new HTML("<code>"+theValue).toString()+"</code>");
}
}
/*Scheduler.get().scheduleDeferred(new ScheduledCommand() {
@Override
public void execute() {
List<String> listConcessioni = entries.get("product_id");
if(listConcessioni!=null && listConcessioni.size()>0) {
String concessioneId = listConcessioni.get(0);
try {
Long theConcessioneId = Long.parseLong(concessioneId);
GeoportalDataViewerServiceAsync.Util.getInstance().getUploadedImagesForId("Concessione", theConcessioneId, 1, new AsyncCallback<List<UploadedImageDV>>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(List<UploadedImageDV> result) {
GWT.log("Loaded images: "+result);
for (UploadedImageDV img : result) {
if(img.getListWsContent()!=null) {
WorkspaceContentDV wsContent = img.getListWsContent().get(img.getListWsContent().size()-1);
String theImgHTML = "<img src=\""+wsContent.getLink()+"\"></img>";
GWT.log("theImgHTML: "+theImgHTML);
flex.setHTML(flex.getRowCount()+1, 0, theImgHTML);
}
}
}
});
}catch (Exception e) {
// TODO: handle exception
}
}
}
});*/
if(geoNaDataObject.getMapImages()!=null) {
for (Long key : geoNaDataObject.getMapImages().keySet()) {
List<UploadedImageDV> listUI = geoNaDataObject.getMapImages().get(key);
GWT.log("Adding images: "+listUI);
if(listUI!=null) {
UploadedImageDV img = listUI.get(0);
if(img.getListWsContent()!=null) {
WorkspaceContentDV wsContent = img.getListWsContent().get(img.getListWsContent().size()-1);
String theImgHTML = "<img src=\""+wsContent.getLink()+"\"></img>";
GWT.log("theImgHTML: "+theImgHTML);
flex.setHTML(flex.getRowCount()+1, 0, theImgHTML);
}
}
}
}

View File

@ -0,0 +1,34 @@
/**
*
*/
package org.gcube.portlets.user.geoportaldataviewer.client.util;
/**
* The Class StringUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 16, 2020
*/
public class StringUtil {
/**
* Ellipsize.
*
* @param input the input string that may be subjected to shortening
* @param maxCharacters the maximum characters that must be returned for the input string. Must be at least 3 (that is the ellipses size)
* @return the string
* @throws Exception the exception
*/
public static String ellipsize(String input, int maxCharacters) throws Exception{
if(maxCharacters < 3) {
throw new IllegalArgumentException("maxCharacters must be at least 3 because the ellipsis already take up 3 characters");
}
if (input == null || input.length() < maxCharacters) {
return input;
}
return input.substring(0, maxCharacters)+"...";
}
}

View File

@ -2,6 +2,7 @@ package org.gcube.portlets.user.geoportaldataviewer.server;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -9,6 +10,7 @@ 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;
import org.gcube.application.geoportal.model.content.UploadedImage;
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;
@ -24,6 +26,8 @@ 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.geoportaldataviewer.shared.products.ConcessioneDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.content.WorkspaceContentDV;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
import org.gcube.spatial.data.geoutility.GeoNcWMSMetadataUtility;
import org.gcube.spatial.data.geoutility.bean.LayerStyles;
import org.gcube.spatial.data.geoutility.bean.LayerZAxis;
@ -129,6 +133,23 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
List<FeatureRow> features = FeatureParser.getWFSFeatures(layerObject.getLayerItem(), mapSrsName, selectBBOX, maxWFSFeature);
LOG.debug("For layer name: "+layerObject.getLayerItem().getName() +" got features: "+features);
geoDAO.setFeatures(features);
for (FeatureRow fRow : features) {
if(fRow.getMapProperties()!=null) {
List<String> concessioneIds = fRow.getMapProperties().get("product_id");
if(concessioneIds!=null && concessioneIds.size()>0) {
String cId = concessioneIds.get(0);
try {
long theConcessionID = Long.parseLong(cId);
List<UploadedImageDV> listUI = getUploadedImagesForId("Concessione", theConcessionID, 1);
Map<Long, List<UploadedImageDV>> mapImages = new LinkedHashMap<Long, List<UploadedImageDV>>();
mapImages.put(theConcessionID, listUI);
geoDAO.setMapImages(mapImages);
}catch (Exception e) {
LOG.warn("Error on loading uploaded images for concessione: "+cId, e);
}
}
}
}
geoDAO.setSourceLayerObject(layerObject);
LOG.info("Fo layer name: "+layerObject.getLayerItem().getName() +" got "+features.size()+" feature/s");
listDAO.add(geoDAO);
@ -137,6 +158,74 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
return listDAO;
}
/**
* Gets the uploaded images for id.
*
* @param id the id
* @return the uploaded images for id
* @throws Exception the exception
*/
@Override
public List<UploadedImageDV> getUploadedImagesForId(String itemType, Long id, int maxImages) throws Exception{
LOG.info("getConcessioneForId "+id+ "called");
if(itemType==null)
throw new Exception("Invalid parameter. The itemType is null");
if(id==null)
throw new Exception("Invalid parameter. The Id is null");
List<UploadedImageDV> listUI = null;
try {
LOG.info("Trying to get record for id "+id);
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
AbstractRecordManager<Record> abmRecord = ManagerFactory.getByRecordID(id);
LOG.info("Got record for id "+id);
Record record = abmRecord.getRecord();
Concessione concessione = null;
if (record != null) {
if (itemType.equalsIgnoreCase("Concessione") && record instanceof Concessione) {
concessione = (Concessione) record;
List<UploadedImage> images = concessione.getImmaginiRappresentative();
if (images != null) {
listUI = new ArrayList<UploadedImageDV>();
int max = maxImages < images.size() ? maxImages : images.size();
for (int i = 0; i < max; i++) {
UploadedImageDV ui = ConvertToDataViewModel.toUploadedImage(images.get(i));
listUI.add(ui);
}
}
}
}
return listUI;
}catch (Exception e) {
String erroMsg = UploadedImage.class.getSimpleName() +" not available for "+Concessione.class.getSimpleName() +" with id "+id;
LOG.error(erroMsg,e);
//TODO REMOTE THIS
listUI = new ArrayList<UploadedImageDV>(1);
UploadedImageDV img = new UploadedImageDV();
List<WorkspaceContentDV> listWsContent = new ArrayList<WorkspaceContentDV>();
WorkspaceContentDV wcDV = new WorkspaceContentDV();
wcDV.setLink("https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Tempio_di_Giove_2.jpg/1280px-Tempio_di_Giove_2.jpg");
listWsContent.add(wcDV);
img.setListWsContent(listWsContent);
listUI.add(img);
LOG.warn("DUMMY UploadedImageDVs: "+listUI);
return listUI;
//throw new Exception(erroMsg);
}
}
/**
* Gets the concessione for id.
*
@ -174,6 +263,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
String erroMsg = Concessione.class.getSimpleName() +" with id "+id+" not available";
LOG.error(erroMsg,e);
//TODO REMOVE THIS
Concessione concessione= TestModel.prepareConcessione();
LOG.warn("DUMMY CONCESSIONE: "+concessione);
ConcessioneDV theConcessione = ConvertToDataViewModel.toConcessione(concessione);

View File

@ -2,32 +2,35 @@ package org.gcube.portlets.user.geoportaldataviewer.shared;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.LayerObject;
import org.gcube.portlets.user.geoportaldataviewer.shared.gis.wfs.FeatureRow;
import org.gcube.portlets.user.geoportaldataviewer.shared.products.model.UploadedImageDV;
/**
* The Class GeoNaDataObject.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Nov 13, 2020
* Nov 13, 2020
*/
public class GeoNaDataObject implements Serializable{
public class GeoNaDataObject implements Serializable {
/**
*
*/
private static final long serialVersionUID = 3513120677727206958L;
private List<FeatureRow> features;
private LayerObject sourceLayerObject;
// Map with couple (id concessione, list of uplaoded Images for the concessione)
private Map<Long, List<UploadedImageDV>> mapImages = null;
/**
* Instantiates a new geo na data object.
*/
public GeoNaDataObject(){
public GeoNaDataObject() {
}
/**
@ -66,6 +69,24 @@ public class GeoNaDataObject implements Serializable{
this.sourceLayerObject = sourceLayerObject;
}
/**
* Gets the map images.
*
* @return the map images
*/
public Map<Long, List<UploadedImageDV>> getMapImages() {
return mapImages;
}
/**
* Sets the map images.
*
* @param mapImages the map images
*/
public void setMapImages(Map<Long, List<UploadedImageDV>> mapImages) {
this.mapImages = mapImages;
}
/**
* To string.
*
@ -81,5 +102,5 @@ public class GeoNaDataObject implements Serializable{
builder.append("]");
return builder.toString();
}
}

View File

@ -121,15 +121,10 @@ public class UploadedImageDV extends AssociatedContentDV implements IsSerializab
this.listWsContent = listWsContent;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UploadedImage [didascalia=");
builder.append("UploadedImageDV [didascalia=");
builder.append(didascalia);
builder.append(", format=");
builder.append(format);
@ -137,6 +132,8 @@ public class UploadedImageDV extends AssociatedContentDV implements IsSerializab
builder.append(responsabili);
builder.append(", soggetto=");
builder.append(soggetto);
builder.append(", listWsContent=");
builder.append(listWsContent);
builder.append("]");
return builder.toString();
}

View File

@ -27,9 +27,14 @@
bottom: 12px;
left: -50px;
min-width: 280px;
max-width: 350px;
visibility: hidden;
}
.ol-popup img {
max-width: 100%;
}
.ol-popup:after, .ol-popup:before {
top: 100%;
border: solid transparent;
@ -66,6 +71,10 @@
content: "✖";
}
.data-click-img{
max-width: 395px;
}
.popup-table div:first-child {
font-weight: bold;
}