Initial porting to MongoConcessioni and geoportal-client
This commit is contained in:
parent
9c787071c3
commit
b1696fd356
|
@ -1,12 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/geoportal-data-entry-app-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
<classpathentry kind="src" output="target/geoportal-data-entry-app-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry excluding="**" kind="src" output="target/geoportal-data-entry-app-1.2.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
<classpathentry excluding="**" kind="src" output="target/geoportal-data-entry-app-1.3.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
@ -35,5 +35,5 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/geoportal-data-entry-app-1.2.0-SNAPSHOT/WEB-INF/classes"/>
|
<classpathentry kind="output" path="target/geoportal-data-entry-app-1.3.0-SNAPSHOT/WEB-INF/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
jarsExcludedFromWebInfLib=
|
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
|
warSrcDir=src/main/webapp
|
||||||
warSrcDirIsOutput=false
|
warSrcDirIsOutput=false
|
||||||
|
|
|
@ -1,29 +1,20 @@
|
||||||
package org.gcube.portlets.user.geoportaldataentry.server;
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
||||||
|
|
||||||
import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||||
import org.gcube.application.geoportal.common.model.legacy.Concessione;
|
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.Concessione.Paths;
|
||||||
import org.gcube.application.geoportal.common.model.legacy.InputStreamDescriptor;
|
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.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.AddSectionToConcessioneRequest;
|
||||||
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
|
import org.gcube.application.geoportal.common.rest.MongoConcessioni;
|
||||||
import org.gcube.application.geoportal.common.rest.TempFile;
|
import org.gcube.application.geoportal.common.rest.TempFile;
|
||||||
//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.geoportalcommon.GeoportalCommon;
|
import org.gcube.application.geoportalcommon.GeoportalCommon;
|
||||||
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
import org.gcube.application.geoportalcommon.shared.GeoNaItemRef;
|
||||||
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
|
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
|
||||||
|
@ -69,7 +60,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
|
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
|
||||||
|
|
||||||
ConcessioniFormCardTitle theType = geoNaFormDataObject.getTheType();
|
ConcessioniFormCardTitle theType = geoNaFormDataObject.getTheType();
|
||||||
|
|
||||||
List<GeoNaFormDataObject> listForm = toMap.get(theType);
|
List<GeoNaFormDataObject> listForm = toMap.get(theType);
|
||||||
if (listForm == null) {
|
if (listForm == null) {
|
||||||
listForm = new ArrayList<GeoNaFormDataObject>();
|
listForm = new ArrayList<GeoNaFormDataObject>();
|
||||||
|
@ -82,15 +72,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
prettyPrintClientDataEntryMap(toMap);
|
prettyPrintClientDataEntryMap(toMap);
|
||||||
|
|
||||||
LOG.debug("Built map with form data: " + toMap);
|
LOG.debug("Built map with form data: " + toMap);
|
||||||
|
|
||||||
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
||||||
|
|
||||||
Concessione c;
|
Concessione concessioneService = null;
|
||||||
|
String mongoId = null;
|
||||||
|
ServiceUtil serviceUtil = new ServiceUtil();
|
||||||
|
MongoConcessioni clientMongo = null;
|
||||||
|
|
||||||
MongoConcessioni client = mongoConcessioni().build();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
||||||
|
clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
||||||
|
|
||||||
// Saving Data
|
// Saving Data
|
||||||
// Informazioni di Progetto
|
// Informazioni di Progetto
|
||||||
List<GeoNaFormDataObject> list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO);
|
List<GeoNaFormDataObject> list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO);
|
||||||
|
@ -105,12 +98,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
|
Concessione concessione = ConvertToServiceModel.toConcessione(idp, user);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO + " as server obj: " + concessione);
|
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
|
//Register New Concessione
|
||||||
c=client.createNew(concessione);
|
concessioneService=clientMongo.createNew(concessione);
|
||||||
|
mongoId = concessioneService.getMongo_id();
|
||||||
|
|
||||||
// ABSTRACT_RELAZIONE_DI_SCAVO
|
// ABSTRACT_RELAZIONE_DI_SCAVO
|
||||||
list = toMap.get(ConcessioniFormCardTitle.ABSTRACT_RELAZIONE_DI_SCAVO);
|
list = toMap.get(ConcessioniFormCardTitle.ABSTRACT_RELAZIONE_DI_SCAVO);
|
||||||
|
@ -137,20 +127,16 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(abstractRelazioneDiScavo, rds);
|
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(abstractRelazioneDiScavo, rds);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
|
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
|
||||||
//Setting Relazione
|
//Setting Relazione
|
||||||
c.setRelazioneScavo(relazioneDiScavo);
|
concessioneService.setRelazioneScavo(relazioneDiScavo);
|
||||||
// Should be only one
|
|
||||||
// Upload file to Concessione Section by Path (e.g. Relazione)
|
// Building TempFile for Relazione
|
||||||
List<TempFile> files = new ArrayList<TempFile>(rds.getFilesUploaded().size());
|
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
|
||||||
for (FileUploaded fileUploaded : rds.getFilesUploaded()) {
|
// Upload file to Concessione
|
||||||
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
if (files!=null && files.size() > 0) {
|
||||||
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
|
||||||
// saving into back-end
|
// saving into back-end
|
||||||
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
|
||||||
files.add(new TempFile(id, filename))???
|
clientMongo.registerFile(mongoId, request);
|
||||||
AddSectionToConcessioneRequest request= new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.RELAZIONE + "with "+files.size()+" file/s");
|
||||||
|
|
||||||
String mongoId = c.getMongo_id();
|
|
||||||
client.setRelazioneScavo(relazioneDiScavo, isd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IMMAGINI_RAPPRESENTATIVE
|
// IMMAGINI_RAPPRESENTATIVE
|
||||||
|
@ -165,15 +151,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " building with client obj: " + imgRapr);
|
LOG.debug(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " building with client obj: " + imgRapr);
|
||||||
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
|
UploadedImage img = ConvertToServiceModel.toImmaginiRappresentative(imgRapr);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
|
LOG.debug("Built " + ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE + " as server obj: " + img);
|
||||||
for (FileUploaded fileUploaded : imgRapr.getFilesUploaded()) {
|
|
||||||
LOG.debug("Adding uploaded file: " + fileUploaded.getFileName() + " to " + img);
|
// Building TempFile for Immagini
|
||||||
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
|
||||||
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
// Upload file to Concessione
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
// saving into back-end
|
// saving into back-end
|
||||||
manager.addImmagineRappresentativa(img, isd);
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.IMMAGINI, files);
|
||||||
|
clientMongo.registerFile(mongoId, request);
|
||||||
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.IMMAGINI + "with "+files.size()+" file/s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
|
// POSIZIONAMENTO_DELL_AREA_DI_INDAGINE
|
||||||
list = toMap.get(ConcessioniFormCardTitle.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)
|
if (list == null || list.isEmpty() || list.get(0) == null || list.get(0).getListGDB() == null)
|
||||||
|
@ -188,12 +177,15 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LayerConcessione layerPad = ConvertToServiceModel.toLayerConcessione(pad);
|
LayerConcessione layerPad = ConvertToServiceModel.toLayerConcessione(pad);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
|
LOG.debug("Built " + ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE + " as server obj: "
|
||||||
+ layerPad);
|
+ layerPad);
|
||||||
for (FileUploaded fileUploaded : pad.getFilesUploaded()) {
|
|
||||||
LOG.debug("Adding uploaded file: " + fileUploaded.getFileName() + " to " + layerPad);
|
// Building TempFile for POSIZIONAMENTO
|
||||||
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
|
||||||
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
// Upload file to Concessione
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
// saving into back-end
|
// saving into back-end
|
||||||
manager.setPosizionamento(layerPad, isd);
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
// PIANTA_DI_FINE_SCAVO
|
// PIANTA_DI_FINE_SCAVO
|
||||||
|
@ -209,14 +201,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.debug(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
|
LOG.debug(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " building with client obj: " + pfs);
|
||||||
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
|
LayerConcessione layerPfs = ConvertToServiceModel.toLayerConcessione(pfs);
|
||||||
LOG.debug("Built " + ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO + " as server obj: " + layerPfs);
|
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);
|
// Building TempFile for PIANTA_DI_FINE_SCAVO
|
||||||
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
|
||||||
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
// Upload file to Concessione Section by Path 'Relazione'
|
||||||
|
if (files!=null && files.size() > 0) {
|
||||||
// saving into back-end
|
// saving into back-end
|
||||||
manager.addPiantaFineScavo(layerPfs, isd);
|
AddSectionToConcessioneRequest request = new AddSectionToConcessioneRequest(Paths.PIANTE, files);
|
||||||
|
clientMongo.registerFile(mongoId, request);
|
||||||
|
LOG.info("Registered the mongoId "+mongoId+" request " + Paths.PIANTE + "with "+files.size()+" file/s");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error on converting form data: ", e);
|
LOG.error("Error on converting form data: ", e);
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -224,44 +221,45 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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)
|
Concessione concessione;
|
||||||
cRep.setRecordId(registered.getId());
|
if(clientMongo!=null && mongoId!=null) {
|
||||||
|
concessione = clientMongo.publish(mongoId);
|
||||||
cRep.setReport(report.prettyPrint());
|
//server report
|
||||||
|
ValidationReport report = concessione.getReport();
|
||||||
switch (report.getStatus()) {
|
LOG.info("ValidationReport: " + report);
|
||||||
case PASSED:
|
//to client
|
||||||
cRep.setState(STATE.OK);
|
CommitReport cRep = new CommitReport();
|
||||||
if(cRep.getRecordId()==null) {
|
cRep.setRecordId(concessione.getId());
|
||||||
LOG.error("The record id is null!!!");
|
String theJSON = serviceUtil.toJSON(report);
|
||||||
throw new Exception("Invalid record id");
|
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:
|
return cRep;
|
||||||
cRep.setState(STATE.WARN);
|
}else
|
||||||
cRep.setMsg(report.getWarningMessages().toString());
|
throw new Exception("MongoId or Client not found");
|
||||||
break;
|
|
||||||
case ERROR:
|
|
||||||
cRep.setState(STATE.ERROR);
|
|
||||||
cRep.setMsg(report.getErrorMessages().toString());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
cRep.setState(STATE.UNKNOWN);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cRep;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Error on commiting data: ", e);
|
LOG.error("Error on commiting data: ", e);
|
||||||
throw new Exception(
|
throw new Exception(
|
||||||
|
@ -324,6 +322,28 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
LOG.info("Returning: " + item);
|
LOG.info("Returning: " + item);
|
||||||
return 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<Concessione> concessioni = clientMongo.getList();
|
||||||
|
|
||||||
|
//TODO
|
||||||
|
LOG.info("Returning: " + concessioni);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pretty print client data entry map.
|
* Pretty print client data entry map.
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
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.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.application.geoportal.common.model.legacy.report.ValidationReport;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue