From e54ba3b0b6d8734df5f6bcfab1af70d3a822fb5c Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Wed, 21 Oct 2020 16:16:53 +0200 Subject: [PATCH] Added try catches to manage errors on publishing --- .../client/GeoPortalDataEntryApp.java | 11 +- .../client/ui/GeonaDataEntryMainForm.java | 8 + .../server/GreetingServiceImpl.java | 228 ++++++++++-------- 3 files changed, 138 insertions(+), 109 deletions(-) diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java index 3ab7e7b..c7c90a8 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoPortalDataEntryApp.java @@ -194,6 +194,8 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onSave(SaveGeonaDataFormsEvent saveGeonaDataFormsEvent) { + geoNaMainForm.enableButtonSave(false); + if(saveGeonaDataFormsEvent.getListGeonaDataForms()!=null) { final Modal modal = new Modal(true); @@ -206,29 +208,32 @@ public class GeoPortalDataEntryApp implements EntryPoint { @Override public void onFailure(Throwable caught) { - modal.remove(loader); + modal.clear(); Alert alert = new Alert(caught.getMessage()); alert.setType(AlertType.ERROR); alert.setClose(false); modal.add(alert); modal.setCloseVisible(true); //resetUI(); + geoNaMainForm.enableButtonSave(true); } @Override public void onSuccess(String result) { - modal.remove(loader); + modal.clear(); Alert alert = new Alert(result); alert.setType(AlertType.INFO); alert.setClose(false); modal.add(alert); modal.setCloseVisible(true); //resetUI(); + geoNaMainForm.enableButtonSave(true); } }); modal.show(); - } + }else + geoNaMainForm.enableButtonSave(true); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java index 4ef2610..986f2e9 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/GeonaDataEntryMainForm.java @@ -12,6 +12,7 @@ import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetada import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.github.gwtbootstrap.client.ui.AlertBlock; +import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Tab; import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.constants.AlertType; @@ -44,6 +45,9 @@ public class GeonaDataEntryMainForm extends Composite { @UiField AlertBlock alertFormAction; + @UiField + Button buttonSave; + private LinkedHashMap mapForms = new LinkedHashMap(); private List listTabs = new ArrayList(); @@ -152,6 +156,10 @@ public class GeonaDataEntryMainForm extends Composite { } } + public void enableButtonSave(boolean enabled) { + buttonSave.setEnabled(enabled); + } + /** * Sets the ative after. diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java index 2d16bbd..420f923 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/GreetingServiceImpl.java @@ -61,122 +61,138 @@ public class GreetingServiceImpl extends RemoteServiceServlet implements Greetin GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest()); - //Saving Data - //Informazioni di Progetto - List 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()); + ConcessioneManager manager; + try { - List 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); - //saving into back-end - ConcessioneManager 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); - LOG.debug("\n\n"); - LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO+" building with client obj: "+rds); - RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(rds); - LOG.debug("Built "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO+" 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); - } - - - //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 imgRaprsLst = list.get(0).getListGDB(); - for (GenericDatasetBean imgRapr : imgRaprsLst) { + //Saving Data + //Informazioni di Progetto + List 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 listGDB = list.get(0).getListGDB(); + GenericDatasetBean idp = listGDB.get(0); 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); + 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 + 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); + LOG.debug("\n\n"); + LOG.debug(ConcessioniFormCardTitle.RELAZIONE_DI_SCAVO+" building with client obj: "+rds); + RelazioneScavo relazioneDiScavo = ConvertToServiceModel.toRelazioneScavo(rds); + LOG.debug("Built "+ConcessioniFormCardTitle.INFORMAZIONI_DI_PROGETTO+" 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.addImmagineRappresentativa(img,isd); + manager.setRelazioneScavo(relazioneDiScavo, isd); + } + + + //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 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); } - } - - //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); - } - - //If true -> data are published into the SDI - Boolean publish=false; - - /*Chiedo al manager di salvare il progetto, causando : - *scrittura sul WS - *pubblicazione sull'SDI (boolean publish) - *scrittura sul DB di applicazione sia dei meta che dei vari link */ - Concessione registered=manager.commit(publish); - - LOG.info("Registered: "+registered); - String link = null; - try { - link = ((WorkspaceContent)registered.getRelazioneScavo().getActualContent().get(0)).getLink(); }catch (Exception e) { - // TODO: handle exception + LOG.error("Error on converting form data: ",e); + throw new Exception("Error occurred on saving data, try again or contact the support"); + } + + try { + + //If true -> data are published into the SDI + Boolean publish=false; + + /*Chiedo al manager di salvare il progetto, causando : + *scrittura sul WS + *pubblicazione sull'SDI (boolean publish) + *scrittura sul DB di applicazione sia dei meta che dei vari link */ + Concessione registered=manager.commit(publish); + + LOG.info("Registered: "+registered); + String link = null; + try { + link = ((WorkspaceContent)registered.getRelazioneScavo().getActualContent().get(0)).getLink(); + }catch (Exception e) { + // TODO: handle exception + } + + //String link = "toTest"; + + if(link!=null) + return "Project saved successfully"; + else + return "Project saved with errors"; + + }catch (Exception e) { + LOG.error("Error on commiting data: ",e); + throw new Exception("Error occurred on saving data, try again or contact the support"); } - //String link = "toTest"; - if(link!=null) - return "Project saved successfully"; - else - return "Project saved with errors"; } @Override