diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index a3150e8..21392b8 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,9 @@ - + + + + + @@ -82,7 +86,11 @@ - + + + + + @@ -165,7 +173,11 @@ - + + + + + @@ -248,7 +260,11 @@ - + + + + + @@ -331,7 +347,11 @@ - + + + + + @@ -366,7 +386,20 @@ - + + uses + + + uses + + + uses + + + + + + @@ -449,7 +482,11 @@ - + + + + + @@ -532,7 +569,11 @@ - + + + + + @@ -615,7 +656,11 @@ - + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index f477d17..f26c19a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - [#24166] Implemented the Update facility - [#24244] Integrated with the geoportal-data-mapper library -## [v3.1.0-SNAPSHOT] - 2023-02-09 +## [v3.1.0] - 2023-03-06 #### Enhancements 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 d4bfdc6..0a92dee 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 @@ -18,12 +18,15 @@ import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV; import org.gcube.application.geoportalcommon.shared.geoportal.WORKFLOW_PHASE; import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.FilesetDV; +import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleInformationDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.application.geoportaldatamapper.shared.MetaDataProfileBeanExt; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.ACTION_PERFORMED_ON_ITEM; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalClientCaches.CacheSearchingFilterParametersFromConfig; import org.gcube.portlets.user.geoportaldataentry.client.events.ClickItemEvent; @@ -72,6 +75,8 @@ import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilde import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; +import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadedRemote; import com.github.gwtbootstrap.client.ui.Alert; import com.github.gwtbootstrap.client.ui.Button; @@ -382,8 +387,8 @@ public class GeoPortalDataEntryApp implements EntryPoint { } - private void createNewDataEntyFor(String profileID, HandlerDeclarationDV handlerDeclarationDV, - List listGPs) { + private void createNewDataEntyFor(String profileID, + HandlerDeclarationDV handlerDeclarationDV, List listGPs) { dataEntryProjectCreated = true; mainTabPanel.setLoaderVisible("Loading...", true); // orderedCards.clear(); @@ -412,10 +417,18 @@ public class GeoPortalDataEntryApp implements EntryPoint { final int order = i; GWT.log("calling getProfilesInTheScope for secondaryType: " + gcubeProfile.getGcubeSecondaryType() + ", name: " + gcubeProfile.getGcubeName()); + MetadataProfileFormBuilderServiceAsync.Util.getInstance().getProfilesInTheScopeForName( geoportalISConfigs.getScope(), gcubeProfile.getGcubeSecondaryType(), gcubeProfile.getGcubeName(), new AsyncCallback>() { + @Override + public void onFailure(Throwable caught) { + mainTabPanel.setLoaderVisible("Loading...", false); + Window.alert(caught.getMessage()); + + } + @Override public void onSuccess(List result) { @@ -446,12 +459,7 @@ public class GeoPortalDataEntryApp implements EntryPoint { // orderedCards.addAll(new ArrayList(gnaCardsModels)); buildNewCards(profileID, handlerDeclarationDV.getItemType(), listGNAFormCardModel); } - } - @Override - public void onFailure(Throwable caught) { - mainTabPanel.setLoaderVisible("Loading...", false); - Window.alert(caught.getMessage()); } }); @@ -1528,14 +1536,14 @@ public class GeoPortalDataEntryApp implements EntryPoint { int width = Window.getClientWidth() * 70 / 100; modal3.setWidth(width); modal3.setHeight(height + "px"); - - - //#24569 + + // #24569 boolean isNotInDRAFT = false; if (resultDocumentDV.getLifecycleInfo() != null) { String phase = resultDocumentDV.getLifecycleInfo().getPhase(); - // IF the project is not in DRAFT phase, showing an alert and no Update Mode will + // IF the project is not in DRAFT phase, showing an alert and no Update Mode + // will // be activated if (phase != null && phase.compareToIgnoreCase(WORKFLOW_PHASE.DRAFT.getLabel()) != 0) { @@ -1559,19 +1567,18 @@ public class GeoPortalDataEntryApp implements EntryPoint { UpdateRecord ur = new UpdateRecord(appManagerBus, resultDocumentDV.getProfileID(), resultDocumentDV.getId()); - - if(isNotInDRAFT) { + + if (isNotInDRAFT) { ur.noUpdateMode(); } - modal3.add(ur); modal3.show(); break; } case CREATE_RELATION: { - //#24571 + // #24571 boolean isNotInDRAFT = false; if (resultDocumentDV.getLifecycleInfo() != null) { @@ -1588,8 +1595,8 @@ public class GeoPortalDataEntryApp implements EntryPoint { isNotInDRAFT = true; } } - - //Allowing the Create Relation only in DRAFT phase + + // Allowing the Create Relation only in DRAFT phase if (!isNotInDRAFT) { mainTabPanel.showCreateRelationPanel(true, resultDocumentDV); } @@ -1818,8 +1825,9 @@ public class GeoPortalDataEntryApp implements EntryPoint { * @param appManagerBus the app manager bus * @return the geo na form card model */ - public static GeoNaFormCardModel buildNewFormCardModelFromProfile(GcubeProfileDV gcubeProfile, int order, - MetaDataProfileBean metaDataProfileBean, OPERATION operation, HandlerManager appManagerBus) { + public static GeoNaFormCardModel buildNewFormCardModelFromProfile( + GcubeProfileDV gcubeProfile, int order, T metaDataProfileBean, OPERATION operation, + HandlerManager appManagerBus) { // Managing Forms Repeatability int minOccurs = gcubeProfile.getMinOccurs(); @@ -1831,13 +1839,50 @@ public class GeoPortalDataEntryApp implements EntryPoint { ProjectFormCard cct = new ProjectFormCard(gcubeProfile.getSectionName(), gcubeProfile.getSectionTitle(), order, maxOccurs > 1, minOccurs, maxOccurs); + List fileset = null; + if (metaDataProfileBean instanceof MetaDataProfileBeanExt) { + MetaDataProfileBeanExt metaDataProfileBeanExt = (MetaDataProfileBeanExt) metaDataProfileBean; + fileset = metaDataProfileBeanExt.getListFileset(); + } + GeoNaFormCardModel geoNaFormCardModel = new GeoNaFormCardModel(metaDataProfileBean, null, cct, gcubeProfile); - CreateMetadataForm baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), - appManagerBus, operation); + CreateMetadataForm baseForm = null; + if (fileset == null) { + GWT.log("Instancing CreateMetadataForm without files"); + baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), appManagerBus, + operation); + } else { + GWT.log("Instancing CreateMetadataForm with files"); + List files = toListFileUploadedRemote(fileset); + baseForm = new CreateMetadataForm(Arrays.asList(geoNaFormCardModel.getMetadataProfileBean()), appManagerBus, + operation, files); + } + geoNaFormCardModel.setMetadataForm(baseForm); return geoNaFormCardModel; } + public static List toListFileUploadedRemote(List fileset) { + + if (fileset == null || fileset.size() == 0) + return null; + + List fileUploaded = new ArrayList(); + + FilesetDV listFiles = fileset.get(0); + + for (PayloadDV payload : listFiles.getListPayload()) { + FileUploadedRemote fu = new FileUploadedRemote(); + fu.setFileName(payload.getName()); + fu.setUrl(payload.getLink()); + fu.setMimeType(payload.getMimetype()); + fileUploaded.add(fu); + } + + return fileUploaded; + + } + } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/card/GeoNaFormCardModel.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/card/GeoNaFormCardModel.java index d6c55d4..4de4e16 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/card/GeoNaFormCardModel.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/card/GeoNaFormCardModel.java @@ -5,9 +5,9 @@ import org.gcube.portlets.user.geoportaldataentry.client.ProjectFormCard; import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm; import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean; -public class GeoNaFormCardModel { +public class GeoNaFormCardModel { - private MetaDataProfileBean metadataProfileBean; + private T metadataProfileBean; private CreateMetadataForm metadataForm; private ProjectFormCard formCard; // matching with metadata profile private GcubeProfileDV gcubeProfile; @@ -16,8 +16,8 @@ public class GeoNaFormCardModel { } - public GeoNaFormCardModel(MetaDataProfileBean metadataProfileBean, CreateMetadataForm metadataForm, - ProjectFormCard formCard, GcubeProfileDV gcubeProfile) { + public GeoNaFormCardModel(T metadataProfileBean, CreateMetadataForm metadataForm, ProjectFormCard formCard, + GcubeProfileDV gcubeProfile) { super(); this.metadataProfileBean = metadataProfileBean; this.metadataForm = metadataForm; @@ -25,11 +25,11 @@ public class GeoNaFormCardModel { this.gcubeProfile = gcubeProfile; } - public MetaDataProfileBean getMetadataProfileBean() { + public T getMetadataProfileBean() { return metadataProfileBean; } - public void setMetadataProfileBean(MetaDataProfileBean metadataProfileBean) { + public void setMetadataProfileBean(T metadataProfileBean) { this.metadataProfileBean = metadataProfileBean; } 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 9b6173d..6629ed1 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,550 +1,550 @@ -//package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; -// -//import java.util.ArrayList; -//import java.util.Collection; -//import java.util.HashMap; -//import java.util.List; -//import java.util.Map; -// -//import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; -//import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; -//import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; -//import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV; -//import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; -//import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV; -//import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; -//import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; -//import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; -//import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.ModalConfirm; -//import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil; -//import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; -//import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; -//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; -//import com.github.gwtbootstrap.client.ui.Controls; -//import com.github.gwtbootstrap.client.ui.Label; -//import com.github.gwtbootstrap.client.ui.ListBox; -//import com.github.gwtbootstrap.client.ui.constants.IconType; -//import com.github.gwtbootstrap.client.ui.constants.LabelType; -//import com.google.gwt.core.client.GWT; -//import com.google.gwt.dom.client.Document; -//import com.google.gwt.dom.client.Style.Unit; -//import com.google.gwt.event.dom.client.ChangeEvent; -//import com.google.gwt.event.dom.client.ChangeHandler; -//import com.google.gwt.event.dom.client.ClickEvent; -//import com.google.gwt.event.dom.client.ClickHandler; -//import com.google.gwt.event.dom.client.DomEvent; -//import com.google.gwt.event.shared.HandlerManager; -//import com.google.gwt.uibinder.client.UiBinder; -//import com.google.gwt.uibinder.client.UiField; -//import com.google.gwt.user.client.Window; -//import com.google.gwt.user.client.rpc.AsyncCallback; -//import com.google.gwt.user.client.ui.Composite; -//import com.google.gwt.user.client.ui.FlexTable; -//import com.google.gwt.user.client.ui.HTML; -//import com.google.gwt.user.client.ui.HTMLPanel; -//import com.google.gwt.user.client.ui.Widget; -// -///** -// * The Class UpdateFileset. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Sep 27, 2021 -// */ -//public class UpdateFileset extends Composite { -// -// private static final String SECTION_PIANTE = "piante"; -// -// private static final String SECTION_POSIZIONAMENTO_SCAVO = "posizionamentoScavo"; -// -// private static final String SECTION_RELAZIONE = "relazione"; -// -// private static final String SECTION_IMMAGINI = "immagini"; -// -// private static final String SECTION_ABSTRACT_RELAZIONE = "abstract_relazione"; -// -// private static final String _FORM_WIDTH_FIELDS_SIZE = "730px"; -// -// private static UpdateFilesetUiBinder uiBinder = GWT.create(UpdateFilesetUiBinder.class); -// -// /** -// * The Interface UpdateFilesetUiBinder. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Sep 27, 2021 -// */ -// interface UpdateFilesetUiBinder extends UiBinder { -// } -// -// @UiField -// ListBox listBoxPaths; -// -// @UiField -// ControlGroup cgSelectFile; -// -// @UiField -// Controls controlsContent; -// -// @UiField -// HTMLPanel uploadFileContainer; -// -// @UiField -// Button buttonUpdate; -// -// private List listFileSetPaths; -// -// private boolean placeholderListBoxPaths = true; -// -// private BaseConcessioneDV selectedConcessione; -// -// private ConcessioneDV fullConcessione; -// -// private boolean placeholderListBoxIndex = true; -// -// private HandlerManager uiBus = new HandlerManager(null); -// -// private MetaDataField fieldUploadWidget; -// -// private Integer pathIndex = null; -// -// private Map mapForCCUploading = null; -// -// private Map> mapWSContentListBox = null; -// -// private HandlerManager editorManagerBus; -// -// private String profileID; -// -// -// /** -// * Instantiates a new update fileset. -// * -// * @param editorManagerBus the editor manager bus -// * @param selectedConcessione the selected concessione -// * @param recordType the record type -// * @param listFileSetPaths the list file set paths -// */ -// public UpdateFileset(HandlerManager editorManagerBus, BaseConcessioneDV selectedConcessione, String profileID, List listFileSetPaths) { -// initWidget(uiBinder.createAndBindUi(this)); -// this.editorManagerBus = editorManagerBus; -// this.selectedConcessione = selectedConcessione; -// this.profileID = profileID; -// this.listFileSetPaths = listFileSetPaths; -// listBoxPaths.addItem("Select a section..."); -// for (String path : listFileSetPaths) { -// listBoxPaths.addItem(path); -// } -// listBoxPaths.setWidth(_FORM_WIDTH_FIELDS_SIZE); -// -// // add handler on select -// listBoxPaths.addChangeHandler(new ChangeHandler() { -// -// @Override -// public void onChange(ChangeEvent event) { -// GWT.log("Profile type selection changed..."); -// cgSelectFile.setVisible(false); -// -// if (placeholderListBoxPaths) { -// listBoxPaths.removeItem(0); // this is the placeholder, removing it once -// placeholderListBoxPaths = false; -// } -// showUploadFileGUI(); -// } -// -// }); -// -// -// Window.alert("This part must be revisited"); -// -//// GeoPortalDataEntryApp.geoportalDataEntryService.getRecord(selectedConcessione.getItemId(), recordType, -//// new AsyncCallback() { -//// -//// @Override -//// public void onSuccess(ConcessioneDV theRecord) { -//// fullConcessione = theRecord; -//// } -//// -//// @Override -//// public void onFailure(Throwable caught) { -//// Window.alert(caught.getMessage()); -//// } -//// }); -// -// buttonUpdate.addClickHandler(new ClickHandler() { -// -// @Override -// public void onClick(ClickEvent event) { -// -// 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()); -// -// List listCurrentContent = new ArrayList(); -// if (mapForCCUploading != null) { -// Collection currentContent = mapForCCUploading.values(); -// if (currentContent != null) -// listCurrentContent.addAll(currentContent); -// } -// -// String htmlMsg = "Going to update the section " + listBoxPaths.getSelectedItemText() + ":"; -// htmlMsg += "
    "; -// htmlMsg += "
  • keeping " + listCurrentContent.size() + " current file/s
  • "; -// htmlMsg += "
  • uploading " + listFilesUploaded.size() + " new file/s
  • "; -// htmlMsg += "
"; -// htmlMsg += "
"; -// htmlMsg += "This operation cannot be undone. Would you like to proceed?"; -// -// GWT.log(htmlMsg); -// -// final ModalConfirm dialogConfirm = new ModalConfirm(null, "Update Confirm?", htmlMsg); -// dialogConfirm.getElement().getStyle().setZIndex(100000); -// dialogConfirm.getYesButton().addClickHandler(new ClickHandler() { -// -// @Override -// public void onClick(ClickEvent event) { -// dialogConfirm.hide(); -// buttonUpdate.setEnabled(false); -// -// final DialogInform dialogInf = new DialogInform(null, "Updating Project...", ""); -// dialogInf.setZIndex(100000); -// dialogInf.showLoader("Updating file/s for project: "+fullConcessione.getNome()); -// //dialogInf.setWidth("400px"); -// -// GeoportalDataEntryServiceAsync.Util.getInstance().updateSectionForRecord( -// fullConcessione.getItemId(), fullConcessione.getRecordType(), -// listBoxPaths.getSelectedItemText(), pathIndex, listCurrentContent, gdb, -// new AsyncCallback() { -// -// @Override -// public void onFailure(Throwable caught) { -// dialogInf.hideLoader(); -// dialogInf.setMsg( -// "Sorry error occurred during project update. Error reported: " -// + caught.getMessage()); -// buttonUpdate.setEnabled(true); -// showUploadFileGUI(); -// -// } -// -// @Override -// public void onSuccess(ConcessioneDV result) { -// dialogInf.hideLoader(); -// dialogInf.setText("Project updated!"); -// dialogInf.setMsg(result.getNome() + " updated correclty"); -// dialogInf.center(); -// fullConcessione = result; -// GWT.log("new concessione: "+fullConcessione); -// buttonUpdate.setEnabled(true); -// showUploadFileGUI(); -// -// Window.alert("updateSectionForRecord must be revisited"); -// -// /* -// editorManagerBus.fireEvent( -// new OperationPerformedOnItemEvent(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); -// -// */ -// -// } -// }); -// dialogInf.center(); -// } -// }); -// dialogConfirm.show(); -// -// } else { -// Window.alert(errorMsg); -// } -// -// } -// }); -// -// } -// -// /** -// * Show upload file GUI. -// */ -// private void showUploadFileGUI() { -// uploadFileContainer.setVisible(true); -// buttonUpdate.setVisible(false); -// uploadFileContainer.clear(); -// controlsContent.clear(); -// placeholderListBoxIndex = true; -// fieldUploadWidget = null; -// pathIndex = null; -// mapForCCUploading = null; -// mapWSContentListBox = null; -// -//// listBoxIndex.clear(); -// cgSelectFile.setVisible(true); -// -// ListBox listBoxContentIndex = new ListBox(); -// listBoxContentIndex.setWidth(_FORM_WIDTH_FIELDS_SIZE); -// listBoxContentIndex.addItem("Select a content..."); -// String section = null; -// Integer posizIndex = 0; -// if (listBoxPaths.getSelectedItemText().contains(SECTION_ABSTRACT_RELAZIONE)) { -// section = SECTION_ABSTRACT_RELAZIONE; -// AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo(); -// -// if (ar == null) { -// showMessage(SECTION_ABSTRACT_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); -//// pathIndex = 0; -//// showNewFileUpload(); -// return; -// } -// -// fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, ar.getTitolo(), -// ar.getListWsContent()); -// -// } else if (listBoxPaths.getSelectedItemText().contains(SECTION_IMMAGINI)) { -// section = SECTION_IMMAGINI; -// List listImmagini = fullConcessione.getImmaginiRappresentative(); -// if (listImmagini == null || listImmagini.isEmpty()) { -// showMessage(SECTION_IMMAGINI + " NOT AVAILABLE", LabelType.WARNING); -//// pathIndex = 0; -//// showNewFileUpload(); -// return; -// } -// -// for (UploadedImageDV uploadedImageDV : listImmagini) { -// fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, StringUtil.ellipsize(uploadedImageDV.getDidascalia(),30), -// uploadedImageDV.getListWsContent()); -// posizIndex++; -// } -// -// } else if (listBoxPaths.getSelectedItemText().contains(SECTION_RELAZIONE)) { -// section = SECTION_RELAZIONE; -// RelazioneScavoDV relazioneScavo = fullConcessione.getRelazioneScavo(); -// if (relazioneScavo == null) { -// showMessage(SECTION_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); -//// pathIndex = 0; -//// showNewFileUpload(); -// return; -// } -// -// fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, relazioneScavo.getTitolo(), -// relazioneScavo.getListWsContent()); -// -// } else if (listBoxPaths.getSelectedItemText().contains(SECTION_POSIZIONAMENTO_SCAVO)) { -// section = SECTION_POSIZIONAMENTO_SCAVO; -// LayerConcessioneDV posiz = fullConcessione.getPosizionamentoScavo(); -// if (posiz == null) { -// showMessage(SECTION_POSIZIONAMENTO_SCAVO + " NOT AVAILABLE", LabelType.WARNING); -//// pathIndex = 0; -//// showNewFileUpload(); -// return; -// } -// -// fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, posiz.getTitolo(), -// posiz.getListWsContent()); -// -// } else if (listBoxPaths.getSelectedItemText().contains(SECTION_PIANTE)) { -// section = SECTION_PIANTE; -// List piante = fullConcessione.getPianteFineScavo(); -// if (piante == null || piante.isEmpty()) { -// showMessage(SECTION_PIANTE + " NOT AVAILABLE", LabelType.WARNING); -//// pathIndex = 0; -//// showNewFileUpload(); -// return; -// } -// -// for (LayerConcessioneDV lcDV : piante) { -// fillListBoxToBeReplaced(listBoxContentIndex, SECTION_PIANTE, posizIndex, lcDV.getTitolo(), -// lcDV.getListWsContent()); -// posizIndex++; -// } -// -// } -// -// controlsContent.add(listBoxContentIndex); -// -// if (listBoxContentIndex.getItemCount() == 2) { -// // listBoxContentIndex.setSelectedIndex(1); -// listBoxContentIndex.setSelectedValue(listBoxContentIndex.getItemText(1)); -// -// DomEvent.fireNativeEvent(Document.get().createChangeEvent(), listBoxContentIndex); -// } -// -// } -// -// private void fillListBoxToBeReplaced(ListBox listBoxContentIndex, String section, int posizIndex, String title, -// List listWSC) { -// GWT.log("fillListBoxToBeReplaced called, posizIndex: "+posizIndex+", listWSC: "+listWSC); -// -// if(mapWSContentListBox==null) { -// mapWSContentListBox = new HashMap>(); -// } -// -// listBoxContentIndex.addItem(title, posizIndex + ""); -// mapWSContentListBox.put(posizIndex, listWSC); -// -// // adding handler once -// if (posizIndex == 0) { -// -// listBoxContentIndex.addChangeHandler(new ChangeHandler() { -// -// @Override -// public void onChange(ChangeEvent event) { -// GWT.log("listBoxContentIndex changed, value: "+listBoxContentIndex.getSelectedValue()); -// -// if (placeholderListBoxIndex) { -// listBoxContentIndex.removeItem(0); // this is the placeholder, removing it once -// placeholderListBoxIndex = false; -// } -// int selectedIndex = listBoxContentIndex.getSelectedIndex(); -// GWT.log("selected index: "+selectedIndex); -// List theListWC = mapWSContentListBox.get(selectedIndex); -// -// if (theListWC == null || theListWC.isEmpty()) { -// uploadFileContainer.clear(); -// showMessage(section + " does not contain file!", LabelType.WARNING); -// pathIndex = posizIndex; -// showNewFileUpload(); -// return; -// } -// -// showFileBrowseInteraction(selectedIndex, mapWSContentListBox.get(selectedIndex)); -// } -// }); -// } -//// -// -// } -// -// private void showFileBrowseInteraction(int pathContentIndex, List listWSC) { -// uploadFileContainer.clear(); -// pathIndex = pathContentIndex; -// GWT.log("showing pathContentIndex: "+pathContentIndex); -// GWT.log("showing ws content: "+listWSC); -// -// // map for current content uploading -// mapForCCUploading = new HashMap(listWSC.size()); -// int index = 0; -// for (WorkspaceContentDV workspaceContentDV : listWSC) { -// workspaceContentDV.setCliendId(index); -// mapForCCUploading.put(index, workspaceContentDV); -// index++; -// } -// -// if (listWSC.size() > 0) { -// FlexTable table = new FlexTable(); -// table.addStyleName("table-current-content"); -// table.setHTML(0, 0, "Current content:"); -// table.setHTML(1, 0, "Filename"); -// table.setHTML(1, 1, "MimeType"); -// table.setHTML(1, 2, "Link"); -// -// int i = 2; -// for (final WorkspaceContentDV wsContent : listWSC) { -// table.setHTML(i, 0, wsContent.getName()); -// table.setHTML(i, 1, wsContent.getMimetype()); -// String link = "View"; -// table.setHTML(i, 2, link); -// -// final int rowIndexToRem = i; -// Button buttonRemoveFile = new Button(); -// buttonRemoveFile.setIcon(IconType.TRASH); -// buttonRemoveFile.setTitle("Remove this file"); -// buttonRemoveFile.addClickHandler(new ClickHandler() { +package org.gcube.portlets.user.geoportaldataentry.client.ui.edit; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.gcube.application.geoportalcommon.shared.products.BaseConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; +import org.gcube.application.geoportalcommon.shared.products.model.AbstractRelazioneScavoDV; +import org.gcube.application.geoportalcommon.shared.products.model.LayerConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScavoDV; +import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; +import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.ModalConfirm; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.StringUtil; +import org.gcube.portlets.widgets.mpformbuilder.client.form.MetaDataField; +import org.gcube.portlets.widgets.mpformbuilder.client.form.generic.CreateMetadataForm.OPERATION; +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; +import com.github.gwtbootstrap.client.ui.Controls; +import com.github.gwtbootstrap.client.ui.Label; +import com.github.gwtbootstrap.client.ui.ListBox; +import com.github.gwtbootstrap.client.ui.constants.IconType; +import com.github.gwtbootstrap.client.ui.constants.LabelType; +import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ChangeEvent; +import com.google.gwt.event.dom.client.ChangeHandler; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.dom.client.DomEvent; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class UpdateFileset. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 27, 2021 + */ +public class UpdateFileset extends Composite { + + private static final String SECTION_PIANTE = "piante"; + + private static final String SECTION_POSIZIONAMENTO_SCAVO = "posizionamentoScavo"; + + private static final String SECTION_RELAZIONE = "relazione"; + + private static final String SECTION_IMMAGINI = "immagini"; + + private static final String SECTION_ABSTRACT_RELAZIONE = "abstract_relazione"; + + private static final String _FORM_WIDTH_FIELDS_SIZE = "730px"; + + private static UpdateFilesetUiBinder uiBinder = GWT.create(UpdateFilesetUiBinder.class); + + /** + * The Interface UpdateFilesetUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Sep 27, 2021 + */ + interface UpdateFilesetUiBinder extends UiBinder { + } + + @UiField + ListBox listBoxPaths; + + @UiField + ControlGroup cgSelectFile; + + @UiField + Controls controlsContent; + + @UiField + HTMLPanel uploadFileContainer; + + @UiField + Button buttonUpdate; + + private List listFileSetPaths; + + private boolean placeholderListBoxPaths = true; + + private BaseConcessioneDV selectedConcessione; + + private ConcessioneDV fullConcessione; + + private boolean placeholderListBoxIndex = true; + + private HandlerManager uiBus = new HandlerManager(null); + + private MetaDataField fieldUploadWidget; + + private Integer pathIndex = null; + + private Map mapForCCUploading = null; + + private Map> mapWSContentListBox = null; + + private HandlerManager editorManagerBus; + + private String profileID; + + + /** + * Instantiates a new update fileset. + * + * @param editorManagerBus the editor manager bus + * @param selectedConcessione the selected concessione + * @param recordType the record type + * @param listFileSetPaths the list file set paths + */ + public UpdateFileset(HandlerManager editorManagerBus, BaseConcessioneDV selectedConcessione, String profileID, List listFileSetPaths) { + initWidget(uiBinder.createAndBindUi(this)); + this.editorManagerBus = editorManagerBus; + this.selectedConcessione = selectedConcessione; + this.profileID = profileID; + this.listFileSetPaths = listFileSetPaths; + listBoxPaths.addItem("Select a section..."); + for (String path : listFileSetPaths) { + listBoxPaths.addItem(path); + } + listBoxPaths.setWidth(_FORM_WIDTH_FIELDS_SIZE); + + // add handler on select + listBoxPaths.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + GWT.log("Profile type selection changed..."); + cgSelectFile.setVisible(false); + + if (placeholderListBoxPaths) { + listBoxPaths.removeItem(0); // this is the placeholder, removing it once + placeholderListBoxPaths = false; + } + showUploadFileGUI(); + } + + }); + + + Window.alert("This part must be revisited"); + +// GeoPortalDataEntryApp.geoportalDataEntryService.getRecord(selectedConcessione.getItemId(), recordType, +// new AsyncCallback() { // // @Override -// public void onClick(ClickEvent event) { -// mapForCCUploading.remove(wsContent.getCliendId()); -// table.getRowFormatter().getElement(rowIndexToRem).setAttribute("hidden", "hidden"); +// public void onSuccess(ConcessioneDV theRecord) { +// fullConcessione = theRecord; +// } +// +// @Override +// public void onFailure(Throwable caught) { +// Window.alert(caught.getMessage()); // } // }); -// table.setWidget(i, 3, buttonRemoveFile); -// i++; -// } -// -// uploadFileContainer.add(table); -// } -// -// showNewFileUpload(); -// } -// -// -// private void showNewFileUpload() { + + buttonUpdate.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + 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()); + + List listCurrentContent = new ArrayList(); + if (mapForCCUploading != null) { + Collection currentContent = mapForCCUploading.values(); + if (currentContent != null) + listCurrentContent.addAll(currentContent); + } + + String htmlMsg = "Going to update the section " + listBoxPaths.getSelectedItemText() + ":"; + htmlMsg += "
    "; + htmlMsg += "
  • keeping " + listCurrentContent.size() + " current file/s
  • "; + htmlMsg += "
  • uploading " + listFilesUploaded.size() + " new file/s
  • "; + htmlMsg += "
"; + htmlMsg += "
"; + htmlMsg += "This operation cannot be undone. Would you like to proceed?"; + + GWT.log(htmlMsg); + + final ModalConfirm dialogConfirm = new ModalConfirm(null, "Update Confirm?", htmlMsg); + dialogConfirm.getElement().getStyle().setZIndex(100000); + dialogConfirm.getYesButton().addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + dialogConfirm.hide(); + buttonUpdate.setEnabled(false); + + final DialogInform dialogInf = new DialogInform(null, "Updating Project...", ""); + dialogInf.setZIndex(100000); + dialogInf.showLoader("Updating file/s for project: "+fullConcessione.getNome()); + //dialogInf.setWidth("400px"); + + GeoportalDataEntryServiceAsync.Util.getInstance().updateSectionForRecord( + fullConcessione.getItemId(), fullConcessione.getRecordType(), + listBoxPaths.getSelectedItemText(), pathIndex, listCurrentContent, gdb, + new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + dialogInf.hideLoader(); + dialogInf.setMsg( + "Sorry error occurred during project update. Error reported: " + + caught.getMessage()); + buttonUpdate.setEnabled(true); + showUploadFileGUI(); + + } + + @Override + public void onSuccess(ConcessioneDV result) { + dialogInf.hideLoader(); + dialogInf.setText("Project updated!"); + dialogInf.setMsg(result.getNome() + " updated correclty"); + dialogInf.center(); + fullConcessione = result; + GWT.log("new concessione: "+fullConcessione); + buttonUpdate.setEnabled(true); + showUploadFileGUI(); + + Window.alert("updateSectionForRecord must be revisited"); + + /* + editorManagerBus.fireEvent( + new OperationPerformedOnItemEvent(Arrays.asList(fullConcessione), ACTION_PERFORMED_ON_ITEM.UPDATED_PROJECT)); + + */ + + } + }); + dialogInf.center(); + } + }); + dialogConfirm.show(); + + } else { + Window.alert(errorMsg); + } + + } + }); + + } + + /** + * Show upload file GUI. + */ + private void showUploadFileGUI() { + uploadFileContainer.setVisible(true); + buttonUpdate.setVisible(false); + uploadFileContainer.clear(); + controlsContent.clear(); + placeholderListBoxIndex = true; + fieldUploadWidget = null; + pathIndex = null; + mapForCCUploading = null; + mapWSContentListBox = null; + +// listBoxIndex.clear(); + cgSelectFile.setVisible(true); + + ListBox listBoxContentIndex = new ListBox(); + listBoxContentIndex.setWidth(_FORM_WIDTH_FIELDS_SIZE); + listBoxContentIndex.addItem("Select a content..."); + String section = null; + Integer posizIndex = 0; + if (listBoxPaths.getSelectedItemText().contains(SECTION_ABSTRACT_RELAZIONE)) { + section = SECTION_ABSTRACT_RELAZIONE; + AbstractRelazioneScavoDV ar = fullConcessione.getAbstractRelazioneScavo(); + + if (ar == null) { + showMessage(SECTION_ABSTRACT_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); +// pathIndex = 0; +// showNewFileUpload(); + return; + } + + fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, ar.getTitolo(), + ar.getListWsContent()); + + } else if (listBoxPaths.getSelectedItemText().contains(SECTION_IMMAGINI)) { + section = SECTION_IMMAGINI; + List listImmagini = fullConcessione.getImmaginiRappresentative(); + if (listImmagini == null || listImmagini.isEmpty()) { + showMessage(SECTION_IMMAGINI + " NOT AVAILABLE", LabelType.WARNING); +// pathIndex = 0; +// showNewFileUpload(); + return; + } + + for (UploadedImageDV uploadedImageDV : listImmagini) { + fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, StringUtil.ellipsize(uploadedImageDV.getDidascalia(),30), + uploadedImageDV.getListWsContent()); + posizIndex++; + } + + } else if (listBoxPaths.getSelectedItemText().contains(SECTION_RELAZIONE)) { + section = SECTION_RELAZIONE; + RelazioneScavoDV relazioneScavo = fullConcessione.getRelazioneScavo(); + if (relazioneScavo == null) { + showMessage(SECTION_RELAZIONE + " NOT AVAILABLE", LabelType.WARNING); +// pathIndex = 0; +// showNewFileUpload(); + return; + } + + fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, relazioneScavo.getTitolo(), + relazioneScavo.getListWsContent()); + + } else if (listBoxPaths.getSelectedItemText().contains(SECTION_POSIZIONAMENTO_SCAVO)) { + section = SECTION_POSIZIONAMENTO_SCAVO; + LayerConcessioneDV posiz = fullConcessione.getPosizionamentoScavo(); + if (posiz == null) { + showMessage(SECTION_POSIZIONAMENTO_SCAVO + " NOT AVAILABLE", LabelType.WARNING); +// pathIndex = 0; +// showNewFileUpload(); + return; + } + + fillListBoxToBeReplaced(listBoxContentIndex, section, posizIndex, posiz.getTitolo(), + posiz.getListWsContent()); + + } else if (listBoxPaths.getSelectedItemText().contains(SECTION_PIANTE)) { + section = SECTION_PIANTE; + List piante = fullConcessione.getPianteFineScavo(); + if (piante == null || piante.isEmpty()) { + showMessage(SECTION_PIANTE + " NOT AVAILABLE", LabelType.WARNING); +// pathIndex = 0; +// showNewFileUpload(); + return; + } + + for (LayerConcessioneDV lcDV : piante) { + fillListBoxToBeReplaced(listBoxContentIndex, SECTION_PIANTE, posizIndex, lcDV.getTitolo(), + lcDV.getListWsContent()); + posizIndex++; + } + + } + + controlsContent.add(listBoxContentIndex); + + if (listBoxContentIndex.getItemCount() == 2) { + // listBoxContentIndex.setSelectedIndex(1); + listBoxContentIndex.setSelectedValue(listBoxContentIndex.getItemText(1)); + + DomEvent.fireNativeEvent(Document.get().createChangeEvent(), listBoxContentIndex); + } + + } + + private void fillListBoxToBeReplaced(ListBox listBoxContentIndex, String section, int posizIndex, String title, + List listWSC) { + GWT.log("fillListBoxToBeReplaced called, posizIndex: "+posizIndex+", listWSC: "+listWSC); + + if(mapWSContentListBox==null) { + mapWSContentListBox = new HashMap>(); + } + + listBoxContentIndex.addItem(title, posizIndex + ""); + mapWSContentListBox.put(posizIndex, listWSC); + + // adding handler once + if (posizIndex == 0) { + + listBoxContentIndex.addChangeHandler(new ChangeHandler() { + + @Override + public void onChange(ChangeEvent event) { + GWT.log("listBoxContentIndex changed, value: "+listBoxContentIndex.getSelectedValue()); + + if (placeholderListBoxIndex) { + listBoxContentIndex.removeItem(0); // this is the placeholder, removing it once + placeholderListBoxIndex = false; + } + int selectedIndex = listBoxContentIndex.getSelectedIndex(); + GWT.log("selected index: "+selectedIndex); + List theListWC = mapWSContentListBox.get(selectedIndex); + + if (theListWC == null || theListWC.isEmpty()) { + uploadFileContainer.clear(); + showMessage(section + " does not contain file!", LabelType.WARNING); + pathIndex = posizIndex; + showNewFileUpload(); + return; + } + + showFileBrowseInteraction(selectedIndex, mapWSContentListBox.get(selectedIndex)); + } + }); + } // -// HTML label = new HTML(); -// label.getElement().getStyle().setMarginTop(10, Unit.PX); -// label.getElement().getStyle().setMarginBottom(10, Unit.PX); -// label.setHTML("Add new file/s:"); -// uploadFileContainer.add(label); -// // mDU = new MultipleDilaogUpload(); -// -// MetadataFieldWrapper uploadField = new MetadataFieldWrapper(); -// uploadField.setFieldName("File"); -// uploadField.setMandatory(false); -// uploadField.setType(DataTypeWrapper.File); -// uploadField.setMaxOccurs(1000); -// -// try { -// fieldUploadWidget = new MetaDataField(uploadField, uiBus, OPERATION.NEW); -// uploadFileContainer.add(fieldUploadWidget); -// -// buttonUpdate.setVisible(true); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// } -// -// /** -// * Test if profile data are valid. -// * -// * @return the string -// */ -// private String checkValidUpload() { -// -// if (fieldUploadWidget == null) -// return "No file uploaded"; -// -// for (MetaDataFieldSkeleton field : fieldUploadWidget.getListOfMetadataFields()) { -// -// field.removeError(); -// -// String error = field.isFieldValueValid(); -// if (error != null) { -// field.showError(); -// String errorMsg = field.getFieldNameOriginal() + " is not valid. Suggestion: " + error; -// return errorMsg; -// } -// } -// -// return null; -// } -// -// private void showMessage(String txt, LabelType type) { -// Label l = new Label(); -// l.setType(type); -// l.setText(txt); -// uploadFileContainer.add(l); -// } -// -//} + + } + + private void showFileBrowseInteraction(int pathContentIndex, List listWSC) { + uploadFileContainer.clear(); + pathIndex = pathContentIndex; + GWT.log("showing pathContentIndex: "+pathContentIndex); + GWT.log("showing ws content: "+listWSC); + + // map for current content uploading + mapForCCUploading = new HashMap(listWSC.size()); + int index = 0; + for (WorkspaceContentDV workspaceContentDV : listWSC) { + workspaceContentDV.setCliendId(index); + mapForCCUploading.put(index, workspaceContentDV); + index++; + } + + if (listWSC.size() > 0) { + FlexTable table = new FlexTable(); + table.addStyleName("table-current-content"); + table.setHTML(0, 0, "Current content:"); + table.setHTML(1, 0, "Filename"); + table.setHTML(1, 1, "MimeType"); + table.setHTML(1, 2, "Link"); + + int i = 2; + for (final WorkspaceContentDV wsContent : listWSC) { + table.setHTML(i, 0, wsContent.getName()); + table.setHTML(i, 1, wsContent.getMimetype()); + String link = "View"; + table.setHTML(i, 2, link); + + final int rowIndexToRem = i; + Button buttonRemoveFile = new Button(); + buttonRemoveFile.setIcon(IconType.TRASH); + buttonRemoveFile.setTitle("Remove this file"); + buttonRemoveFile.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + mapForCCUploading.remove(wsContent.getCliendId()); + table.getRowFormatter().getElement(rowIndexToRem).setAttribute("hidden", "hidden"); + } + }); + table.setWidget(i, 3, buttonRemoveFile); + i++; + } + + uploadFileContainer.add(table); + } + + showNewFileUpload(); + } + + + private void showNewFileUpload() { + + HTML label = new HTML(); + label.getElement().getStyle().setMarginTop(10, Unit.PX); + label.getElement().getStyle().setMarginBottom(10, Unit.PX); + label.setHTML("Add new file/s:"); + uploadFileContainer.add(label); + // mDU = new MultipleDilaogUpload(); + + MetadataFieldWrapper uploadField = new MetadataFieldWrapper(); + uploadField.setFieldName("File"); + uploadField.setMandatory(false); + uploadField.setType(DataTypeWrapper.File); + uploadField.setMaxOccurs(1000); + + try { + fieldUploadWidget = new MetaDataField(uploadField, uiBus, OPERATION.NEW); + uploadFileContainer.add(fieldUploadWidget); + + buttonUpdate.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Test if profile data are valid. + * + * @return the string + */ + private String checkValidUpload() { + + if (fieldUploadWidget == null) + return "No file uploaded"; + + for (MetaDataFieldSkeleton field : fieldUploadWidget.getListOfMetadataFields()) { + + field.removeError(); + + String error = field.isFieldValueValid(); + if (error != null) { + field.showError(); + String errorMsg = field.getFieldNameOriginal() + " is not valid. Suggestion: " + error; + return errorMsg; + } + } + + return null; + } + + private void showMessage(String txt, LabelType type) { + Label l = new Label(); + l.setType(type); + l.setText(txt); + uploadFileContainer.add(l); + } + +} diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.ui.xml index a5df4fd..5f27e0d 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/UpdateFileset.ui.xml @@ -1,4 +1,4 @@ - \ No newline at end of file + \ No newline at end of file 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 4de9d4c..a4cbe68 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 @@ -22,7 +22,6 @@ import org.bson.Document; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.document.access.Access; -import org.gcube.application.geoportal.common.model.document.access.AccessPolicy; import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation; import org.gcube.application.geoportal.common.model.rest.TempFile; import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition; @@ -81,8 +80,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.spi.json.JsonOrgJsonProvider; /** * The server side implementation of the RPC service. @@ -1197,9 +1194,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen for (String keyEntry : map.keySet()) { LOG.debug("\t " + keyEntry + ": " + map.get(keyEntry)); } - for (FileUploaded fup : gbd.getFilesUploaded()) { - LOG.debug("\t " + fup); - } +// for (FileUploaded fup : gbd.getFilesUploaded()) { +// LOG.debug("\t " + fup); +// } } } }