merged with branch Feature #20435

This commit is contained in:
Francesco Mangiacrapa 2021-07-23 17:40:50 +02:00
parent c511cbd163
commit 7f8e9da1e2
8 changed files with 342 additions and 128 deletions

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/home/francesco-mangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-1.3.0-SNAPSHOT
lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-1.3.0-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -1,37 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="geoportal-data-entry-app-1.3.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="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="metadata-profile-form-builder-widget-1.0.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/metadata-profile-form-builder-widget/metadata-profile-form-builder-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="geoportal-data-entry-app"/>
<property name="java-output-path" value="/geoportal-data-entry-app/target/geoportal-data-entry-app-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</wb-module>
</project-modules>

View File

@ -4,11 +4,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v1.3.0-SNAPSHOT] - 2021-07-22
## [v1.3.0-SNAPSHOT] - 2021-07-21
#### Enhancements
[#20435] Client integration with MongoConcessioni
Moved to maven-portal-bom 3.6.3
## [v1.2.0] - 2020-12-18
#### Enhancements

View File

@ -122,8 +122,8 @@
</dependency>
<dependency>
<groupId>org.gcube.application</groupId>
<artifactId>geoportal-logic</artifactId>
<version>[1.0.8, 2.0.0-SNAPSHOT)</version>
<artifactId>geoportal-client</artifactId>
<version>[1.0.0, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
<exclusions>
<exclusion>

View File

@ -8,11 +8,11 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportal.model.AccessPolicy;
import org.gcube.application.geoportal.model.concessioni.Concessione;
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
import org.gcube.application.geoportal.model.concessioni.RelazioneScavo;
import org.gcube.application.geoportal.model.content.UploadedImage;
import org.gcube.application.geoportal.common.model.legacy.AccessPolicy;
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.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp;
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;

View File

@ -1,20 +1,19 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.application.geoportal.managers.ConcessioneManager;
import org.gcube.application.geoportal.managers.ManagerFactory;
import org.gcube.application.geoportal.model.InputStreamDescriptor;
import org.gcube.application.geoportal.model.Record;
import org.gcube.application.geoportal.model.concessioni.Concessione;
import org.gcube.application.geoportal.model.concessioni.LayerConcessione;
import org.gcube.application.geoportal.model.concessioni.RelazioneScavo;
import org.gcube.application.geoportal.model.content.UploadedImage;
import org.gcube.application.geoportal.model.report.PublicationReport;
import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.legacy.Concessione.Paths;
import org.gcube.application.geoportal.common.model.legacy.LayerConcessione;
import org.gcube.application.geoportal.common.model.legacy.RelazioneScavo;
import org.gcube.application.geoportal.common.model.legacy.UploadedImage;
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
import org.gcube.application.geoportal.common.rest.AddSectionToConcessioneRequest;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportalcommon.GeoportalCommon;
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
@ -60,7 +59,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
ConcessioniFormCardTitle theType = geoNaFormDataObject.getTheType();
List<GeoNaFormDataObject> listForm = toMap.get(theType);
if (listForm == null) {
listForm = new ArrayList<GeoNaFormDataObject>();
@ -73,13 +71,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
prettyPrintClientDataEntryMap(toMap);
LOG.debug("Built map with form data: " + toMap);
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
ConcessioneManager manager;
Concessione concessioneNew;
String mongoId = null;
ServiceUtil serviceUtil = new ServiceUtil();
MongoConcessioni clientMongo = null;
try {
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
clientMongo = serviceUtil.getInstanceMongoConcessioni();
// Saving Data
// Informazioni di Progetto
List<GeoNaFormDataObject> list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO);
@ -94,9 +97,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
LOG.debug("Built " + ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
// saving into back-end
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
manager = ManagerFactory.registerNew(concessione);
//Register New Concessione
concessioneNew=clientMongo.createNew(concessione);
// ABSTRACT_RELAZIONE_DI_SCAVO
list = toMap.get(ConcessioniFormCardTitle.ABSTRACT_RELAZIONE_DI_SCAVO);
@ -122,13 +125,10 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " building with client obj: " + rds);
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(abstractRelazioneDiScavo, rds);
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
// Should be only one
for (FileUploaded fileUploaded : rds.getFilesUploaded()) {
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
// saving into back-end
manager.setRelazioneScavo(relazioneDiScavo, isd);
}
//Setting Relazione
concessioneNew.setRelazioneScavo(relazioneDiScavo);
// IMMAGINI_RAPPRESENTATIVE
list = toMap.get(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE);
@ -137,20 +137,23 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
"Error: no data found for " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getTitle());
List<GenericDatasetBean> imgRaprsLst = list.get(0).getListGDB();
List<UploadedImage> immaginiRappresentativeService = null;
if(imgRaprsLst.size()>0) {
immaginiRappresentativeService = new ArrayList<UploadedImage>(imgRaprsLst.size());
for (GenericDatasetBean imgRapr : imgRaprsLst) {
LOG.debug("\n\n");
LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " building with client obj: " + imgRapr);
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
LOG.debug("Built " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
for (FileUploaded fileUploaded : imgRapr.getFilesUploaded()) {
LOG.debug("Adding uploaded file: " + fileUploaded.getFileName() + " to " + img);
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
// saving into back-end
manager.addImmagineRappresentativa(img, isd);
immaginiRappresentativeService.add(img);
}
}
//Setting Immagini Rappresentative
if(immaginiRappresentativeService!=null) {
concessioneNew.setImmaginiRappresentative(immaginiRappresentativeService);
}
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
list = toMap.get(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
@ -159,18 +162,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
listGDB = list.get(0).getListGDB();
GenericDatasetBean pad = listGDB.get(0);
LayerConcessione layerPad = null;
if(pad!=null) {
LOG.debug("\n\n");
LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
+ pad);
LayerConcessione layerPad = ConvertToServiceModel.toLayerConcessione(pad);
layerPad = ConvertToServiceModel.toLayerConcessione(pad);
LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
+ layerPad);
for (FileUploaded fileUploaded : pad.getFilesUploaded()) {
LOG.debug("Adding uploaded file: " + fileUploaded.getFileName() + " to " + layerPad);
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
// saving into back-end
manager.setPosizionamento(layerPad, isd);
}
//Setting Posizionamento Di Scavo
if(layerPad!=null) {
concessioneNew.setPosizionamentoScavo(layerPad);
}
// PIANTA_DI_FINE_SCAVO
@ -180,20 +184,91 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
"Error: no data found for " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getTitle());
listGDB = list.get(0).getListGDB();
List<GenericDatasetBean> listPfs = listGDB;
//Managing N:N
for (GenericDatasetBean pfs : listGDB) {
List<LayerConcessione> pianteFineScavo = null;
if(listPfs.size()>0) {
pianteFineScavo = new ArrayList<LayerConcessione>(listPfs.size());
for (GenericDatasetBean pfs : listPfs) {
LOG.debug("\n\n");
LOG.debug(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
LOG.debug("Built " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " as server obj: " + layerPfs);
for (FileUploaded fileUploaded : pfs.getFilesUploaded()) {
LOG.debug("Adding uploaded file: " + fileUploaded.getFileName() + " to " + layerPfs);
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
pianteFineScavo.add(layerPfs);
}
}
//Setting Piante fine Scavo
if(pianteFineScavo!=null) {
concessioneNew.setPianteFineScavo(pianteFineScavo);
}
//Registering Meta
clientMongo.replace(concessioneNew);
mongoId = concessioneNew.getMongo_id();
LOG.info("Registered the meta. Called mongo.replace for: "+concessioneNew);
//UPLOADING FILES
LOG.info("Now uploading the files...");
// Building TempFile for Relazione
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
// Upload file to Concessione. Should be one file.
if (files!=null && files.size() > 0) {
// saving into back-end
manager.addPiantaFineScavo(layerPfs, isd);
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
clientMongo.registerFile(mongoId, request);
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.RELAZIONE + "with "+files.size()+" file/s");
}
//IMMAGINI RAPPRESENTATIVE
for (int i=0; i<imgRaprsLst.size(); i++) {
LOG.debug("\n\n");
GenericDatasetBean imgRapr = imgRaprsLst.get(i);
// Building TempFile for Immagini
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
// Upload file to Concessione. The size is always 1 so it is consistent with the 'for' index
if (files!=null && files.size() > 0) {
// saving into back-end
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.imgByIndex(i), files);
clientMongo.registerFile(mongoId, request);
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.IMMAGINI + "with "+files.size()+" file/s");
}
}
//POSIZIONAMENTO
// Building TempFile for POSIZIONAMENTO
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
// Upload file to Concessione
if (files!=null && files.size() > 0) {
// saving into back-end
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.POSIZIONAMENTO, files);
clientMongo.registerFile(mongoId, request);
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.POSIZIONAMENTO + "with "+files.size()+" file/s");
}
//PIANTE FINE SCAVO
if(listPfs.size()>0) {
for (int i=0; i<listPfs.size(); i++) {
// Building TempFile for PIANTA_DI_FINE_SCAVO
GenericDatasetBean pfs = listPfs.get(i);
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
// Upload file to Concessione Section by Path 'Relazione'
if (files!=null && files.size() > 0) {
// saving into back-end
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.piantaByIndex(i), files);
clientMongo.registerFile(mongoId, request);
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.PIANTE + "with "+files.size()+" file/s");
}
}
}
} catch (Exception e) {
LOG.error("Error on converting form data: ", e);
throw new Exception(
@ -202,19 +277,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
try {
// If true -> data are published into the SDI
Boolean publish = true;
PublicationReport report = manager.commitSafely(publish);
LOG.info("PublicationReport: " + report);
Record registered = report.getTheRecord();
// String link = "toTest";
Concessione concessione;
if(clientMongo!=null && mongoId!=null) {
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
concessione = clientMongo.publish(mongoId);
//server report
ValidationReport report = concessione.getReport();
LOG.info("ValidationReport: " + report);
//to client
CommitReport cRep = new CommitReport();
if(registered!=null)
cRep.setRecordId(registered.getId());
cRep.setReport(report.prettyPrint());
cRep.setRecordId(concessione.getId());
String theJSON = serviceUtil.toJSON(report);
cRep.setReport(theJSON);
switch (report.getStatus()) {
case PASSED:
@ -239,6 +313,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
}
return cRep;
}else
throw new Exception("MongoId or Client not found");
} catch (Exception e) {
LOG.error("Error on commiting data: ", e);
throw new Exception(
@ -302,6 +379,28 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
return item;
}
/**
* Gets the links for.
*
* @param itemId the item id
* @param recordType the record type
* @return the links for
* @throws Exception the exception
*/
//@Override
public void getListConcessioni(Integer startIdx, Integer limit) throws Exception {
LOG.info("getListConcessioni called");
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
ServiceUtil serviceUtil = new ServiceUtil();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni();
Iterable<Concessione> concessioni = clientMongo.getList();
//TODO
LOG.info("Returning: " + concessioni);
}
/**
* Pretty print client data entry map.
*

View File

@ -0,0 +1,110 @@
package org.gcube.portlets.user.geoportaldataentry.server;
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
import org.gcube.application.geoportal.common.rest.TempFile;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class ServiceUtil.
*
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
*
* Jan 28, 2021
*/
public class ServiceUtil {
private static Logger LOG = LoggerFactory.getLogger(ServiceUtil.class);
/**
* Gets the instance mongo concessioni.
*
* @return the instance mongo concessioni
*/
public MongoConcessioni getInstanceMongoConcessioni() {
return mongoConcessioni().build();
}
/**
* Creates the temp file on storage.
*
* @param is the is
* @param fileName the file name
* @return the temp file
*/
public TempFile createTempFileOnStorage(InputStream is, String fileName) {
LOG.debug("createTempFileOnStorage called");
StorageUtils storage = new StorageUtils();
TempFile toUpload = null;
try {
LOG.info("calling putOntoStorage the stream with the fileName: " + fileName);
toUpload = storage.putOntoStorage(is, fileName);
} catch (RemoteBackendException | FileNotFoundException e) {
LOG.error("Error when uploading stream on Storage: ", e);
}
return toUpload;
}
/**
* To tem files.
*
* @param listFileUploaded the list file uploaded
* @return the list
*/
public List<TempFile> toTemFiles(List<FileUploaded> listFileUploaded) {
LOG.debug("toTemFiles called");
if (listFileUploaded == null || listFileUploaded.isEmpty())
return null;
// Building TempFile
List<TempFile> files = new ArrayList<TempFile>(listFileUploaded.size());
for (FileUploaded fileUploaded : listFileUploaded) {
FileInputStream fis;
try {
fis = new FileInputStream(fileUploaded.getTempSystemPath());
// Creating TempFile
TempFile storageTempFile = createTempFileOnStorage(fis, fileUploaded.getFileName());
files.add(storageTempFile);
} catch (FileNotFoundException e) {
LOG.error("Error on loading temp file with path: " + fileUploaded.getTempSystemPath(), e);
}
}
return files;
}
/**
* To JSON.
*
* @param <T> the generic type
* @param report the report
* @return the string
*/
public String toJSON(Object theObj) {
LOG.debug("toJSON called");
try {
if(theObj instanceof Serializable) {
return org.gcube.application.geoportal.client.utils.Serialization.write(theObj);
}
throw new Exception("The input object is not serializable");
} catch (Exception e) {
LOG.warn("Error on deserializing: ", e);
return null;
}
}
}

View File

@ -5,6 +5,7 @@ package org.gcube.portlets.user.geoportaldataentry.server;
import javax.servlet.http.HttpServletRequest;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.vomanagement.usermanagement.GroupManager;
@ -67,21 +68,28 @@ public class SessionUtil {
* Retrieve the current scope by using the portal manager.
*
* @param request the request
* @param setInThread the set in thread
* @param setContextsInThread set the scope and the security token into current thread
* @return a GcubeUser object
*/
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
public static String getCurrentContext(HttpServletRequest request, boolean setContextsInThread){
if(request == null)
throw new IllegalArgumentException("HttpServletRequest is null!");
PortalContext pContext = PortalContext.getConfiguration();
String context = pContext.getCurrentScope(request);
LOG.debug("Returning context " + context);
if(context != null && setInThread)
if(setContextsInThread) {
GCubeUser user = getCurrentUser(request);
String token = pContext.getCurrentUserToken(context, user.getUsername());
if(context!=null)
ScopeProvider.instance.set(context);
if(token!=null)
SecurityTokenProvider.instance.set(token);
}
return context;
}