diff --git a/.classpath b/.classpath
index aa74380..60e5a76 100644
--- a/.classpath
+++ b/.classpath
@@ -1,12 +1,12 @@
-
+
-
+
@@ -35,5 +35,5 @@
-
+
diff --git a/.settings/com.gwtplugins.gdt.eclipse.core.prefs b/.settings/com.gwtplugins.gdt.eclipse.core.prefs
index 149db97..2b6aaa6 100644
--- a/.settings/com.gwtplugins.gdt.eclipse.core.prefs
+++ b/.settings/com.gwtplugins.gdt.eclipse.core.prefs
@@ -1,5 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
-lastWarOutDir=/home/francescomangiacrapa/git/geoportal-data-entry-app/target/geoportal-data-entry-app-1.2.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
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index a6e9c94..d76c958 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -1,10 +1,19 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
index 1727216..7812414 100644
--- a/.settings/org.eclipse.wst.common.project.facet.core.xml
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 703fa54..a427f70 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@
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
+
+#### Enhancements
+
+[#20435] Client integration with MongoConcessioni
+Moved to maven-portal-bom 3.6.3
+
## [v1.2.0] - 2020-12-18
diff --git a/pom.xml b/pom.xml
index 2aa82a1..d9fc82d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,7 +14,7 @@
org.gcube.portlets.user
geoportal-data-entry-app
war
- 1.2.0
+ 1.3.0-SNAPSHOT
GeoPortal Data Entry App
The GeoPortal Data Entry App is an application to build the web forms for data entries needed to GeoNa project
@@ -51,7 +51,7 @@
org.gcube.distribution
maven-portal-bom
- 3.6.0
+ 3.6.3-SNAPSHOT
pom
import
@@ -122,8 +122,8 @@
org.gcube.application
- geoportal-logic
- [1.0.8, 2.0.0-SNAPSHOT)
+ geoportal-client
+ [1.0.0, 2.0.0-SNAPSHOT)
compile
@@ -227,6 +227,10 @@
org.apache.maven.plugins
maven-compiler-plugin
+
+
+ ${maven.compiler.target}
+
diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java
index 61bca5b..55e6846 100644
--- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java
+++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ConvertToServiceModel.java
@@ -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;
diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java
index 152bc50..6a140c1 100644
--- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java
+++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GeoportalDataEntryServiceImpl.java
@@ -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 listForm = toMap.get(theType);
if (listForm == null) {
listForm = new ArrayList();
@@ -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 list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO);
@@ -93,11 +96,11 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.debug(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " building with client obj: " + idp);
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);
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
@@ -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 imgRaprsLst = list.get(0).getListGDB();
- 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);
+ List immaginiRappresentativeService = null;
+ if(imgRaprsLst.size()>0) {
+ immaginiRappresentativeService = new ArrayList(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);
+ 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);
- LOG.debug("\n\n");
- LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
- + pad);
- LayerConcessione 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);
+ LayerConcessione layerPad = null;
+ if(pad!=null) {
+ LOG.debug("\n\n");
+ LOG.debug(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " building with client obj: "
+ + pad);
+ layerPad = ConvertToServiceModel.toLayerConcessione(pad);
+ LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
+ + layerPad);
+ }
+
+ //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 listPfs = listGDB;
//Managing N:N
- for (GenericDatasetBean pfs : listGDB) {
- 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());
- // saving into back-end
- manager.addPiantaFineScavo(layerPfs, isd);
+ List pianteFineScavo = null;
+ if(listPfs.size()>0) {
+ pianteFineScavo = new ArrayList(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);
+ 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 files = serviceUtil.toTemFiles(rds.getFilesUploaded());
+ // Upload file to Concessione. Should be one file.
+ if (files!=null && files.size() > 0) {
+ // saving into back-end
+ 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 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 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(
@@ -201,44 +276,46 @@ 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";
- CommitReport cRep = new CommitReport();
- if(registered!=null)
- cRep.setRecordId(registered.getId());
-
- cRep.setReport(report.prettyPrint());
-
- switch (report.getStatus()) {
- case PASSED:
- cRep.setState(STATE.OK);
- if(cRep.getRecordId()==null) {
- LOG.error("The record id is null!!!");
- throw new Exception("Invalid record id");
+ 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();
+ cRep.setRecordId(concessione.getId());
+ String theJSON = serviceUtil.toJSON(report);
+ cRep.setReport(theJSON);
+
+ switch (report.getStatus()) {
+ case PASSED:
+ cRep.setState(STATE.OK);
+ if(cRep.getRecordId()==null) {
+ LOG.error("The record id is null!!!");
+ throw new Exception("Invalid record id");
+ }
+ break;
+ case WARNING:
+ cRep.setState(STATE.WARN);
+ cRep.setMsg(report.getWarningMessages().toString());
+ break;
+ case ERROR:
+ cRep.setState(STATE.ERROR);
+ cRep.setMsg(report.getErrorMessages().toString());
+ break;
+
+ default:
+ cRep.setState(STATE.UNKNOWN);
+ break;
}
- break;
- case WARNING:
- cRep.setState(STATE.WARN);
- cRep.setMsg(report.getWarningMessages().toString());
- break;
- case ERROR:
- cRep.setState(STATE.ERROR);
- cRep.setMsg(report.getErrorMessages().toString());
- break;
-
- default:
- cRep.setState(STATE.UNKNOWN);
- break;
- }
+
+ return cRep;
+ }else
+ throw new Exception("MongoId or Client not found");
- return cRep;
} catch (Exception e) {
LOG.error("Error on commiting data: ", e);
throw new Exception(
@@ -301,6 +378,28 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.info("Returning: " + item);
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 concessioni = clientMongo.getList();
+
+ //TODO
+ LOG.info("Returning: " + concessioni);
+ }
+
/**
* Pretty print client data entry map.
diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java
new file mode 100644
index 0000000..3160e6b
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/ServiceUtil.java
@@ -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 toTemFiles(List listFileUploaded) {
+ LOG.debug("toTemFiles called");
+ if (listFileUploaded == null || listFileUploaded.isEmpty())
+ return null;
+
+ // Building TempFile
+ List files = new ArrayList(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 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;
+ }
+ }
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java
index d92dcbc..5b3dc08 100644
--- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java
+++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/SessionUtil.java
@@ -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,20 +68,27 @@ 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)
- ScopeProvider.instance.set(context);
+
+ 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;
}