2020-10-07 17:04:13 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
|
|
|
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2020-10-20 09:58:56 +02:00
|
|
|
import java.util.List;
|
2020-10-20 11:49:23 +02:00
|
|
|
import java.util.Map;
|
2020-10-20 09:58:56 +02:00
|
|
|
|
2020-10-20 11:49:23 +02:00
|
|
|
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.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;
|
2020-10-20 17:43:47 +02:00
|
|
|
import org.gcube.application.geoportal.model.content.WorkspaceContent;
|
2020-10-28 14:49:57 +01:00
|
|
|
import org.gcube.application.geoportal.model.fault.PublishException;
|
|
|
|
import org.gcube.application.geoportal.model.fault.ValidationException;
|
2020-10-30 15:37:08 +01:00
|
|
|
import org.gcube.application.geoportal.utils.Serialization;
|
2020-10-20 11:49:23 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle;
|
2020-10-22 16:50:14 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryService;
|
2020-10-21 16:52:07 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport;
|
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport.STATE;
|
2020-10-20 09:58:56 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject;
|
2020-10-21 15:36:50 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig;
|
2020-10-20 11:49:23 +02:00
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean;
|
|
|
|
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
|
|
|
|
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2020-10-07 17:04:13 +02:00
|
|
|
|
|
|
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The server side implementation of the RPC service.
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("serial")
|
2020-10-22 16:50:14 +02:00
|
|
|
public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implements GeoportalDataEntryService {
|
2020-10-20 11:49:23 +02:00
|
|
|
|
2020-10-21 15:36:50 +02:00
|
|
|
public static final String GEONA_GENERIC_RESOURCE_SECONDARY_TYPE = "GEONA_GENERIC_RESOURCE_SECONDARY_TYPE";
|
2020-10-22 16:50:14 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataEntryServiceImpl.class);
|
2020-10-20 11:49:23 +02:00
|
|
|
|
|
|
|
@Override
|
2020-10-21 16:52:07 +02:00
|
|
|
public CommitReport saveGeonaDataForms(List<GeoNaFormDataObject> listGeonaFormObjects) throws Exception {
|
2020-10-20 11:49:23 +02:00
|
|
|
LOG.info("saveGeonaDataForms called");
|
|
|
|
|
|
|
|
HashMap<ConcessioniFormCardTitle, List<GeoNaFormDataObject>> toMap =
|
|
|
|
new HashMap<ConcessioniFormCardTitle, List<GeoNaFormDataObject>>();
|
|
|
|
|
|
|
|
for (GeoNaFormDataObject geoNaFormDataObject : listGeonaFormObjects) {
|
|
|
|
|
|
|
|
ConcessioniFormCardTitle theType = geoNaFormDataObject.getTheType();
|
|
|
|
|
|
|
|
List<GeoNaFormDataObject> listForm = toMap.get(theType);
|
|
|
|
if (listForm == null) {
|
|
|
|
listForm = new ArrayList<GeoNaFormDataObject>();
|
|
|
|
}
|
|
|
|
|
|
|
|
listForm.add(geoNaFormDataObject);
|
|
|
|
toMap.put(theType, listForm);
|
|
|
|
}
|
|
|
|
if(LOG.isDebugEnabled())
|
|
|
|
prettyPrintClientDataEntryMap(toMap);
|
|
|
|
|
|
|
|
LOG.debug("Built map with form data: "+toMap);
|
2020-10-20 15:25:26 +02:00
|
|
|
|
2020-10-20 11:49:23 +02:00
|
|
|
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
ConcessioneManager manager;
|
|
|
|
try {
|
2020-10-20 11:49:23 +02:00
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
//Saving Data
|
|
|
|
//Informazioni di Progetto
|
|
|
|
List<GeoNaFormDataObject> list = toMap.get(ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO);
|
|
|
|
if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null)
|
|
|
|
throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO.getTitle());
|
|
|
|
|
|
|
|
List<GenericDatasetBean> listGDB = list.get(0).getListGDB();
|
|
|
|
GenericDatasetBean idp = listGDB.get(0);
|
|
|
|
LOG.debug("\n\n");
|
|
|
|
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);
|
2020-10-30 15:37:08 +01:00
|
|
|
|
2020-10-20 11:49:23 +02:00
|
|
|
//saving into back-end
|
2020-10-21 16:16:53 +02:00
|
|
|
manager = ManagerFactory.registerNew(concessione);
|
|
|
|
|
|
|
|
//RELAZIONE_DI_SCAVO
|
|
|
|
list = toMap.get(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO);
|
|
|
|
if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null)
|
|
|
|
throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO.getTitle());
|
|
|
|
|
|
|
|
listGDB = list.get(0).getListGDB();
|
|
|
|
GenericDatasetBean rds = listGDB.get(0);
|
2020-10-20 11:49:23 +02:00
|
|
|
LOG.debug("\n\n");
|
2020-10-21 16:16:53 +02:00
|
|
|
LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO+" building with client obj: "+rds);
|
|
|
|
RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(rds);
|
2020-10-27 11:33:45 +01:00
|
|
|
LOG.debug("Built "+ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO+" as server obj: "+relazioneDiScavo);
|
2020-10-21 16:16:53 +02:00
|
|
|
//Should be only one
|
|
|
|
for (FileUploaded fileUploaded : rds.getFilesUploaded()) {
|
2020-10-20 11:49:23 +02:00
|
|
|
FileInputStream fis = new FileInputStream(fileUploaded.getTempSystemPath());
|
|
|
|
InputStreamDescriptor isd = new InputStreamDescriptor(fis, fileUploaded.getFileName());
|
|
|
|
//saving into back-end
|
2020-10-21 16:16:53 +02:00
|
|
|
manager.setRelazioneScavo(relazioneDiScavo, isd);
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
2020-10-21 16:16:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
//IMMAGINI_RAPPRESENTATIVE
|
|
|
|
list = toMap.get(ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE);
|
|
|
|
if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null)
|
|
|
|
throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.IMMAGINI_RAPPRESENTATIVE.getTitle());
|
|
|
|
|
|
|
|
List<GenericDatasetBean> 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//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)
|
|
|
|
throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.POSIZIONAMENTO_DELL_AREA_DI_INDAGINE.getTitle());
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//PIANTA_DI_FINE_SCAVO
|
|
|
|
list = toMap.get(ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO);
|
|
|
|
if(list==null || list.isEmpty() || list.get(0)==null || list.get(0).getListGDB()==null)
|
|
|
|
throw new Exception("Error: no data found for "+ConcessioniFormCardTitle.PIANTA_DI_FINE_SCAVO.getTitle());
|
|
|
|
|
|
|
|
listGDB = list.get(0).getListGDB();
|
|
|
|
GenericDatasetBean pfs = listGDB.get(0);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}catch (Exception e) {
|
|
|
|
LOG.error("Error on converting form data: ",e);
|
2020-10-30 15:37:08 +01:00
|
|
|
throw new Exception("Error occurred on saving data, try again or contact the support. Error: "+e.getMessage());
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
2020-10-30 15:37:08 +01:00
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
try {
|
2020-10-27 11:33:45 +01:00
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
//If true -> data are published into the SDI
|
2020-10-21 16:52:07 +02:00
|
|
|
Boolean publish=true;
|
2020-10-21 16:16:53 +02:00
|
|
|
Concessione registered=manager.commit(publish);
|
|
|
|
LOG.info("Registered: "+registered);
|
|
|
|
String link = null;
|
|
|
|
try {
|
|
|
|
link = ((WorkspaceContent)registered.getRelazioneScavo().getActualContent().get(0)).getLink();
|
|
|
|
}catch (Exception e) {
|
2020-10-21 16:52:07 +02:00
|
|
|
LOG.warn("Not able to check public link ",e);
|
2020-10-21 16:16:53 +02:00
|
|
|
}
|
2020-10-21 16:52:07 +02:00
|
|
|
|
2020-10-21 16:16:53 +02:00
|
|
|
//String link = "toTest";
|
2020-10-21 16:52:07 +02:00
|
|
|
CommitReport cRep = new CommitReport();
|
|
|
|
cRep.setRecordId(registered.getId());
|
|
|
|
if(link!=null) {
|
|
|
|
cRep.setState(STATE.OK);
|
|
|
|
cRep.setMsg("Project saved successfully");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cRep.setState(STATE.WARN);
|
|
|
|
cRep.setMsg("Project saved with errors");
|
|
|
|
}
|
2020-10-21 16:16:53 +02:00
|
|
|
|
2020-10-21 16:52:07 +02:00
|
|
|
return cRep;
|
2020-10-28 14:49:57 +01:00
|
|
|
}catch (ValidationException e1){
|
|
|
|
LOG.error("Error on validating data: ",e1);
|
2020-10-30 15:37:08 +01:00
|
|
|
throw new Exception("Error on validating data: "+Serialization.prettyPrint(e1.getReport()));
|
2020-10-28 14:49:57 +01:00
|
|
|
}catch (PublishException e2) {
|
|
|
|
LOG.error("Error on publishing data: ",e2);
|
|
|
|
throw new Exception("Error on publishing data: "+e2.getMessage());
|
2020-10-20 17:43:47 +02:00
|
|
|
}catch (Exception e) {
|
2020-10-21 16:16:53 +02:00
|
|
|
LOG.error("Error on commiting data: ",e);
|
2020-10-28 14:49:57 +01:00
|
|
|
throw new Exception("Error occurred on saving data, try again or contact the support. Error: "+e.getMessage());
|
|
|
|
}finally {
|
2020-10-30 15:37:08 +01:00
|
|
|
// if(manager!=null) {
|
|
|
|
// try {
|
|
|
|
// manager.shutdown();
|
|
|
|
// }catch (Exception e) {
|
|
|
|
// //silent
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// }
|
2020-10-20 17:43:47 +02:00
|
|
|
}
|
2020-10-20 11:49:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-21 15:36:50 +02:00
|
|
|
@Override
|
|
|
|
public GeonaISConfig getGeonaInitConfig() {
|
|
|
|
LOG.info("getConfig called");
|
|
|
|
|
|
|
|
String scope = SessionUtil.getCurrentContext(this.getThreadLocalRequest(), false);
|
|
|
|
String theSecondaryType;
|
|
|
|
try {
|
|
|
|
theSecondaryType = this.getServletContext().getInitParameter(GEONA_GENERIC_RESOURCE_SECONDARY_TYPE);
|
|
|
|
} catch (Exception e) {
|
|
|
|
LOG.error("I cannot read the init parameter for: " + GEONA_GENERIC_RESOURCE_SECONDARY_TYPE, e);
|
|
|
|
theSecondaryType = "GeoNaMetadata";
|
|
|
|
}
|
|
|
|
|
2020-11-03 12:14:57 +01:00
|
|
|
// LOG.warn("\n\n\nHARD-CABLING THE SCOPE, PLEASE REMOTE IT!!!!\n\n\n");
|
|
|
|
// scope = "/gcube/devsec/devVRE";
|
2020-10-21 15:36:50 +02:00
|
|
|
|
|
|
|
GeonaISConfig configs = new GeonaISConfig(theSecondaryType, scope);
|
|
|
|
LOG.info("returning config: "+configs);
|
|
|
|
return configs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-20 11:49:23 +02:00
|
|
|
|
|
|
|
private void prettyPrintClientDataEntryMap(HashMap<ConcessioniFormCardTitle, List<GeoNaFormDataObject>> toMap) {
|
|
|
|
|
|
|
|
for (ConcessioniFormCardTitle theType : toMap.keySet()) {
|
2020-10-20 15:25:26 +02:00
|
|
|
LOG.debug("\n\n");
|
|
|
|
LOG.debug(theType.toString());
|
2020-10-20 11:49:23 +02:00
|
|
|
List<GeoNaFormDataObject> list = toMap.get(theType);
|
|
|
|
for (GeoNaFormDataObject geoNaFormDataObject : list) {
|
|
|
|
LOG.debug("\t has "+geoNaFormDataObject.getListGDB().size() +" data bean/s");
|
|
|
|
int i = 0;
|
|
|
|
for (GenericDatasetBean gbd : geoNaFormDataObject.getListGDB()) {
|
|
|
|
LOG.debug("\t "+ ++i +") "+GenericDatasetBean.class.getSimpleName()+" entries:");
|
|
|
|
Map<String, List<String>> map = gbd.getFormDataEntryFields();
|
|
|
|
for (String keyEntry : map.keySet()) {
|
|
|
|
LOG.debug("\t "+keyEntry + ": "+map.get(keyEntry));
|
|
|
|
}
|
|
|
|
for (FileUploaded fup : gbd.getFilesUploaded()) {
|
|
|
|
LOG.debug("\t "+fup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 17:04:13 +02:00
|
|
|
}
|