|
|
|
@ -1,29 +1,20 @@
|
|
|
|
|
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.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
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.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.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.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.shared.GeoNaItemRef;
|
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
|
|
|
|
@ -69,7 +60,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>();
|
|
|
|
@ -82,15 +72,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
prettyPrintClientDataEntryMap(toMap);
|
|
|
|
|
|
|
|
|
|
LOG.debug("Built map with form data: " + toMap);
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true);
|
|
|
|
|
clientMongo = serviceUtil.getInstanceMongoConcessioni();
|
|
|
|
|
|
|
|
|
|
// Saving Data
|
|
|
|
|
// 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);
|
|
|
|
|
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
|
|
|
|
|
c=client.createNew(concessione);
|
|
|
|
|
concessioneService=clientMongo.createNew(concessione);
|
|
|
|
|
mongoId = concessioneService.getMongo_id();
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
LOG.debug("Built " + ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO + " as server obj: " + relazioneDiScavo);
|
|
|
|
|
//Setting Relazione
|
|
|
|
|
c.setRelazioneScavo(relazioneDiScavo);
|
|
|
|
|
// Should be only one
|
|
|
|
|
// Upload file to Concessione Section by Path (e.g. Relazione)
|
|
|
|
|
List<TempFile> files = new ArrayList<TempFile>(rds.getFilesUploaded().size());
|
|
|
|
|
for (FileUploaded fileUploaded : rds.getFilesUploaded()) {
|
|
|
|
|
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
|
|
|
|
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
|
|
|
|
concessioneService.setRelazioneScavo(relazioneDiScavo);
|
|
|
|
|
|
|
|
|
|
// Building TempFile for Relazione
|
|
|
|
|
List<TempFile> files = serviceUtil.toTemFiles(rds.getFilesUploaded());
|
|
|
|
|
// Upload file to Concessione
|
|
|
|
|
if (files!=null && files.size() > 0) {
|
|
|
|
|
// saving into back-end
|
|
|
|
|
|
|
|
|
|
files.add(new TempFile(id, filename))???
|
|
|
|
|
AddSectionToConcessioneRequest request= new AddSectionToConcessioneRequest(Paths.RELAZIONE, files);
|
|
|
|
|
|
|
|
|
|
String mongoId = c.getMongo_id();
|
|
|
|
|
client.setRelazioneScavo(relazioneDiScavo, 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
|
|
|
|
@ -165,15 +151,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
// Building TempFile for Immagini
|
|
|
|
|
files = serviceUtil.toTemFiles(imgRapr.getFilesUploaded());
|
|
|
|
|
// Upload file to Concessione
|
|
|
|
|
if (files!=null && files.size() > 0) {
|
|
|
|
|
// 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
|
|
|
|
|
list = toMap.get(ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE);
|
|
|
|
|
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);
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
// Building TempFile for POSIZIONAMENTO
|
|
|
|
|
files = serviceUtil.toTemFiles(pad.getFilesUploaded());
|
|
|
|
|
// Upload file to Concessione
|
|
|
|
|
if (files!=null && files.size() > 0) {
|
|
|
|
|
// 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
|
|
|
|
@ -209,14 +201,19 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
// Building TempFile for PIANTA_DI_FINE_SCAVO
|
|
|
|
|
files = serviceUtil.toTemFiles(pfs.getFilesUploaded());
|
|
|
|
|
// Upload file to Concessione Section by Path 'Relazione'
|
|
|
|
|
if (files!=null && files.size() > 0) {
|
|
|
|
|
// 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) {
|
|
|
|
|
LOG.error("Error on converting form data: ", e);
|
|
|
|
|
throw new Exception(
|
|
|
|
@ -224,44 +221,45 @@ 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) {
|
|
|
|
|
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(
|
|
|
|
@ -324,6 +322,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<Concessione> concessioni = clientMongo.getList();
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
LOG.info("Returning: " + concessioni);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Pretty print client data entry map.
|
|
|
|
|