diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 354d1cb..811d676 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -69,6 +69,9 @@ + + uses + diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java index 410b42a..13ef04b 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryService.java @@ -11,6 +11,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; @@ -112,4 +113,16 @@ public interface GeoportalDataEntryService extends RemoteService { * @throws Exception the exception */ ConcessioneDV getRecord(String itemId, RECORD_TYPE recordType) throws Exception; + + /** + * Update record. + * + * @param itemId the item id + * @param jsonUpdate the json update + * @param recordType the record type + * @return the updated JSON string representing the itemId + * @throws Exception the exception + */ + ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, + GenericDatasetBean gDBean) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java index 1df72e8..60ddcb5 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/GeoportalDataEntryServiceAsync.java @@ -11,6 +11,7 @@ import org.gcube.portlets.user.geoportaldataentry.shared.GeoNaFormDataObject; import org.gcube.portlets.user.geoportaldataentry.shared.GeonaISConfig; import org.gcube.portlets.user.geoportaldataentry.shared.ResultSetPaginatedData; import org.gcube.portlets.user.geoportaldataentry.shared.SortFilter; +import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -67,4 +68,8 @@ public interface GeoportalDataEntryServiceAsync void getRecord(String itemId, RECORD_TYPE recordType, AsyncCallback callback); + + + void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, + GenericDatasetBean gDBean, AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java index 878b145..3c94e7a 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.java @@ -103,7 +103,6 @@ public class EditModeRecord extends Composite { @Override public void onSuccess(FileSetPathsDV fileSetPaths) { UpdateFileset updateFileset = new UpdateFileset(selectedConcessione, recordType, fileSetPaths.getFileSetPaths()); - //updateFileset.setHeight("300px !important"); filesUpdatePanel.add(updateFileset); } }); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java index d6c73a6..b7617f3 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; +import java.util.ArrayList; import java.util.List; import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; @@ -13,8 +14,11 @@ import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataE import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; import org.gcube.portlets.widgets.mpformbuilder.client.ui.metadata.MetaDataFieldSkeleton; +import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.DialogUpload; +import org.gcube.portlets.widgets.mpformbuilder.shared.GenericDatasetBean; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.DataTypeWrapper; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetadataFieldWrapper; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.ControlGroup; @@ -50,8 +54,6 @@ public class UpdateFileset extends Composite { private static final String _FORM_FIELDS_SIZE = "740px"; - private static final String UPLOAD_MISSING_FILE = "You must upload a file"; - private static UpdateFilesetUiBinder uiBinder = GWT.create(UpdateFilesetUiBinder.class); /** @@ -81,9 +83,7 @@ public class UpdateFileset extends Composite { private List listFileSetPaths; - private boolean listBoxPathsPlaceholder = true; - - private String recordId; + private boolean placeholderListBoxPaths = true; private BaseConcessioneDV selectedConcessione; @@ -91,13 +91,13 @@ public class UpdateFileset extends Composite { private RECORD_TYPE recordType; - // private MultipleDilaogUpload mDU; - - private boolean listBoxIndexPlaceholder = true; + private boolean placeholderListBoxIndex = true; private HandlerManager uiBus = new HandlerManager(null); private MetaDataField fieldUploadWidget; + + private Integer pathIndex = null; /** * Instantiates a new update fileset. @@ -123,9 +123,9 @@ public class UpdateFileset extends Composite { GWT.log("Profile type selection changed..."); cgSelectFile.setVisible(false); - if (listBoxPathsPlaceholder) { + if (placeholderListBoxPaths) { listBoxPaths.removeItem(0); // this is the placeholder, removing it once - listBoxPathsPlaceholder = false; + placeholderListBoxPaths = false; } showUploadFileGUI(); } @@ -151,10 +151,27 @@ public class UpdateFileset extends Composite { @Override public void onClick(ClickEvent event) { - if (checkValidUpload() == null) { - Window.alert("I can save..."); + String errorMsg = checkValidUpload(); + if (errorMsg == null) { + List listFilesUploaded = new ArrayList(); + List listMetaDataFieldSkeleton = fieldUploadWidget.getListOfMetadataFields(); + for (MetaDataFieldSkeleton field : listMetaDataFieldSkeleton) { + DialogUpload dUpload = (DialogUpload) field.getHolder(); + // adding it only if exists + if (dUpload.getFileUploadingState() != null) + listFilesUploaded.add(dUpload.getFileUploadingState().getFile()); + } + + GenericDatasetBean gdb = new GenericDatasetBean(); + gdb.setFilesUploaded(listFilesUploaded); + // adding it only if exists + + GWT.log("Section selected: " + listBoxPaths.getSelectedItemText()); + GWT.log("Content index selected: " + pathIndex); + GWT.log("FileUploaded selected: " + gdb.getFilesUploaded()); + } else { - Window.alert("New file not found. " + UPLOAD_MISSING_FILE); + Window.alert(errorMsg); } } @@ -170,15 +187,16 @@ public class UpdateFileset extends Composite { buttonUpdate.setVisible(false); uploadFileContainer.clear(); controlsContent.clear(); - listBoxIndexPlaceholder = true; + placeholderListBoxIndex = true; fieldUploadWidget = null; + pathIndex = null; // listBoxIndex.clear(); cgSelectFile.setVisible(true); - ListBox listBoxIndex = new ListBox(); - listBoxIndex.setWidth(_FORM_FIELDS_SIZE); - listBoxIndex.addItem("Select a content..."); + ListBox listBoxContentIndex = new ListBox(); + listBoxContentIndex.setWidth(_FORM_FIELDS_SIZE); + listBoxContentIndex.addItem("Select a content..."); if (listBoxPaths.getSelectedItemText().contains("abstract_relazione")) { AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo(); @@ -188,7 +206,7 @@ public class UpdateFileset extends Composite { } int posizIndex = 0; - fillListBoxToBeReplaced(listBoxIndex, "abstract_relazione", posizIndex, ar.getTitolo(), + fillListBoxToBeReplaced(listBoxContentIndex, "abstract_relazione", posizIndex, ar.getTitolo(), ar.getListWsContent()); } else if (listBoxPaths.getSelectedItemText().contains("immagini")) { @@ -199,7 +217,7 @@ public class UpdateFileset extends Composite { } int posizIndex = 0; for (UploadedImageDV uploadedImageDV : listImmagini) { - fillListBoxToBeReplaced(listBoxIndex, "immagini", posizIndex, uploadedImageDV.getTitolo(), + fillListBoxToBeReplaced(listBoxContentIndex, "immagini", posizIndex, uploadedImageDV.getTitolo(), uploadedImageDV.getListWsContent()); posizIndex++; } @@ -211,7 +229,7 @@ public class UpdateFileset extends Composite { return; } int posizIndex = 0; - fillListBoxToBeReplaced(listBoxIndex, "relazione", posizIndex, realzione.getTitolo(), + fillListBoxToBeReplaced(listBoxContentIndex, "relazione", posizIndex, realzione.getTitolo(), realzione.getListWsContent()); } else if (listBoxPaths.getSelectedItemText().contains("posizionamentoScavo")) { @@ -221,7 +239,7 @@ public class UpdateFileset extends Composite { return; } int posizIndex = 0; - fillListBoxToBeReplaced(listBoxIndex, "posizionamentoScavo", posizIndex, posiz.getTitolo(), + fillListBoxToBeReplaced(listBoxContentIndex, "posizionamentoScavo", posizIndex, posiz.getTitolo(), posiz.getListWsContent()); } else if (listBoxPaths.getSelectedItemText().contains("piante")) { @@ -232,17 +250,17 @@ public class UpdateFileset extends Composite { } int posizIndex = 0; for (LayerConcessioneDV lcDV : piante) { - fillListBoxToBeReplaced(listBoxIndex, "piante", posizIndex, lcDV.getTitolo(), lcDV.getListWsContent()); + fillListBoxToBeReplaced(listBoxContentIndex, "piante", posizIndex, lcDV.getTitolo(), lcDV.getListWsContent()); posizIndex++; } } - controlsContent.add(listBoxIndex); + controlsContent.add(listBoxContentIndex); } - private void fillListBoxToBeReplaced(ListBox listBoxIndex, String section, int posizIndex, String title, + private void fillListBoxToBeReplaced(ListBox listBoxContentIndex, String section, int posizIndex, String title, List listWSC) { if (listWSC == null || listWSC.isEmpty()) { @@ -250,22 +268,22 @@ public class UpdateFileset extends Composite { return; } - listBoxIndex.addItem(title, posizIndex + ""); + listBoxContentIndex.addItem(title, posizIndex + ""); // adding handler once if (posizIndex == 0) { - listBoxIndex.addChangeHandler(new ChangeHandler() { + listBoxContentIndex.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { - if (listBoxIndexPlaceholder) { - listBoxIndex.removeItem(0); // this is the placeholder, removing it once - listBoxIndexPlaceholder = false; + if (placeholderListBoxIndex) { + listBoxContentIndex.removeItem(0); // this is the placeholder, removing it once + placeholderListBoxIndex = false; } - showFileBrowseInteraction(listWSC); + showFileBrowseInteraction(listBoxContentIndex.getSelectedIndex(), listWSC); } }); } @@ -273,9 +291,10 @@ public class UpdateFileset extends Composite { } - private void showFileBrowseInteraction(List listWSC) { + private void showFileBrowseInteraction(int pathContentIndex, List listWSC) { uploadFileContainer.clear(); - + pathIndex = pathContentIndex; + if (listWSC.size() > 0) { FlexTable table = new FlexTable(); table.addStyleName("table-current-content"); @@ -309,9 +328,9 @@ public class UpdateFileset extends Composite { try { fieldUploadWidget = new MetaDataField(uploadField, uiBus); - //BrowseFilePanel fieldsetContent = new BrowseFilePanel(fieldUploadWidget); + // BrowseFilePanel fieldsetContent = new BrowseFilePanel(fieldUploadWidget); uploadFileContainer.add(fieldUploadWidget); - + buttonUpdate.setVisible(true); } catch (Exception e) { // TODO Auto-generated catch block @@ -327,6 +346,9 @@ public class UpdateFileset extends Composite { */ private String checkValidUpload() { + if (fieldUploadWidget == null) + return "No file uploaded"; + for (MetaDataFieldSkeleton field : fieldUploadWidget.getListOfMetadataFields()) { field.removeError(); 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 72e8e3f..a6be44c 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 @@ -649,6 +649,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); } } + /** * Gets the JSON record. @@ -729,4 +730,87 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen return ConvertToDataViewModel.getFileSetPaths(); } + + /** + * Update record. + * + * @param itemId the item id + * @param jsonUpdate the json update + * @param recordType the record type + * @return the updated JSON string representing the itemId + * @throws Exception the exception + */ + @Override + public ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, GenericDatasetBean gDBean) throws Exception { + LOG.info("updateSectionForRecord called with itemId: " + itemId + ", section: " + section+", pathIndex: " + pathIndex+", gDBean: " + gDBean, ""); + try { + + if (itemId == null) + throw new Exception("Item id is null"); + + if (recordType.equals(RECORD_TYPE.CONCESSIONE)) { + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + MongoServiceUtil serviceUtil = new MongoServiceUtil(); + MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); + + String toEditPath = null; + AddSectionToConcessioneRequest request = null; + + List files = serviceUtil.toTemFiles(gDBean.getFilesUploaded()); + if(files==null || files.isEmpty()) + throw new Exception("Sorry, an error occurred on reading temp files. Refresh and try again"); + + if (section.contains("abstract_relazione")) { + + toEditPath = Paths.ABSTRACT_RELAZIONE; + request = new AddSectionToConcessioneRequest(toEditPath, files); + + } else if (section.contains("immagini")) { + toEditPath = Paths.imgByIndex(pathIndex); + request = new AddSectionToConcessioneRequest(toEditPath, files); + + } else if (section.contains("relazione")) { + toEditPath = Paths.RELAZIONE; + request = new AddSectionToConcessioneRequest(toEditPath, files); + + } else if (section.contains("posizionamentoScavo")) { + toEditPath = Paths.POSIZIONAMENTO; + request = new AddSectionToConcessioneRequest(toEditPath, + files); + + } else if (section.contains("piante")) { + toEditPath = Paths.piantaByIndex(pathIndex); + request = new AddSectionToConcessioneRequest( + toEditPath, files); + } + // Unpublish + System.out.println("Unpublishing "+itemId); + clientMongo.unPublish(itemId); + + // update Fileset + System.out.println("Removing old fileset.. "); + clientMongo.cleanFileSet(itemId,toEditPath); + + System.out.println("Sending new Fileset .."); + + //StorageUtils storage=new StorageUtils(); + // Building TempFile + SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); + LOG.info("Registering FileSet into recordId " + itemId + " with request path: " +toEditPath + " and: " + files.size() + + " file/s"); + Concessione concessione = clientMongo.registerFileSet(itemId,request); + concessione = clientMongo.publish(itemId); + + return ConvertToDataViewModel.toConcessione(concessione); + } + + return null; + + } catch (Exception e) { + LOG.error("Error on updating the project with item id: " + itemId, e); + throw new Exception( + "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); + } + } + }