diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 811d676..27a98b3 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,5 +1,6 @@ - + + @@ -13,7 +14,8 @@ - + + @@ -27,7 +29,8 @@ - + + @@ -41,7 +44,8 @@ - + + @@ -55,7 +59,8 @@ - + + @@ -72,7 +77,8 @@ uses - + + @@ -86,7 +92,8 @@ - + + @@ -100,7 +107,8 @@ - + + @@ -114,7 +122,8 @@ - + + 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 13ef04b..e85bd00 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 @@ -4,6 +4,7 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; @@ -124,5 +125,6 @@ public interface GeoportalDataEntryService extends RemoteService { * @throws Exception the exception */ ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, - GenericDatasetBean gDBean) throws Exception; + List keepCurrentContent, 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 60ddcb5..0dc4486 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 @@ -4,6 +4,7 @@ import java.util.List; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.shared.CommitReport; @@ -71,5 +72,6 @@ public interface GeoportalDataEntryServiceAsync void updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, - GenericDatasetBean gDBean, AsyncCallback callback); + List keepCurrentContent, GenericDatasetBean gDBean, + AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.ui.xml b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.ui.xml index c9d898c..d85b3d7 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.ui.xml +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/edit/EditModeRecord.ui.xml @@ -54,7 +54,7 @@ addStyleNames="{style.button-save-style}" ui:field="buttonJSONUpdate">UPDATE - Manage the file/s You can choose a section (e.g. "piante") and 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 2f75123..17dd804 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,6 +1,7 @@ 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; @@ -14,6 +15,9 @@ import org.gcube.application.geoportalcommon.shared.products.model.RelazioneScav import org.gcube.application.geoportalcommon.shared.products.model.UploadedImageDV; import org.gcube.portlets.user.geoportaldataentry.client.ConstantsGeoPortalDataEntryApp.RECORD_TYPE; import org.gcube.portlets.user.geoportaldataentry.client.GeoPortalDataEntryApp; +import org.gcube.portlets.user.geoportaldataentry.client.GeoportalDataEntryServiceAsync; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogConfirm; +import org.gcube.portlets.user.geoportaldataentry.client.ui.utils.DialogInform; 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; @@ -30,11 +34,13 @@ 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; @@ -103,6 +109,7 @@ public class UpdateFileset extends Composite { private Integer pathIndex = null; private Map mapForCCUploading = null; + /** * Instantiates a new update fileset. @@ -175,6 +182,71 @@ public class UpdateFileset extends Composite { 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 DialogConfirm dialogConfirm = new DialogConfirm(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"); + dialogInf.center(); + + 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; + buttonUpdate.setEnabled(true); + showUploadFileGUI(); + + } + }); + dialogInf.center(); + } + }); + dialogConfirm.center(); + } else { Window.alert(errorMsg); } @@ -264,11 +336,12 @@ public class UpdateFileset extends Composite { } controlsContent.add(listBoxContentIndex); - - - if(listBoxContentIndex.getItemCount()==1) { - listBoxContentIndex.setSelectedIndex(0); - listBoxContentIndex.setSelectedValue(listBoxContentIndex.getItemText(0)); + + if (listBoxContentIndex.getItemCount() == 2) { + // listBoxContentIndex.setSelectedIndex(1); + listBoxContentIndex.setSelectedValue(listBoxContentIndex.getItemText(1)); + + DomEvent.fireNativeEvent(Document.get().createChangeEvent(), listBoxContentIndex); } } @@ -360,7 +433,7 @@ public class UpdateFileset extends Composite { MetadataFieldWrapper uploadField = new MetadataFieldWrapper(); uploadField.setFieldName("File"); - uploadField.setMandatory(true); + uploadField.setMandatory(false); uploadField.setType(DataTypeWrapper.File); uploadField.setMaxOccurs(1000); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogConfirm.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogConfirm.java index d3e856f..69edbde 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogConfirm.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogConfirm.java @@ -3,9 +3,6 @@ */ package org.gcube.portlets.user.geoportaldataentry.client.ui.utils; - - - import org.gcube.portlets.user.geoportaldataentry.client.resource.Images; import com.google.gwt.dom.client.Style.Unit; @@ -22,12 +19,10 @@ import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; - /** * The Class DialogConfirm. * - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Feb 19, 2015 + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Feb 19, 2015 */ public class DialogConfirm extends DialogBox implements ClickHandler { @@ -37,15 +32,16 @@ public class DialogConfirm extends DialogBox implements ClickHandler { private ImageResource loading = Images.ICONS.loading(); private HorizontalPanel hpButtons = new HorizontalPanel(); private Button noButton; + /** * Instantiates a new dialog confirm. * - * @param img the img + * @param img the img * @param caption the caption - * @param text the text + * @param text the text */ public DialogConfirm(Image img, String caption, String text) { - //getElement().setClassName("gwt-DialogBoxNew"); + // getElement().setClassName("gwt-DialogBoxNew"); dock.setSpacing(4); dock.setWidth("100%"); setText(caption); @@ -81,7 +77,6 @@ public class DialogConfirm extends DialogBox implements ClickHandler { dock.add(vpContainer, DockPanel.CENTER); setWidget(dock); -// add(dock); } /* @@ -101,10 +96,11 @@ public class DialogConfirm extends DialogBox implements ClickHandler { * * @param message the message */ - public void loader(String message){ - try{ + public void loader(String message) { + try { dock.remove(hpButtons); - }catch(Exception e){} + } catch (Exception e) { + } vpContainer.clear(); HorizontalPanel hpMask = new HorizontalPanel(); hpMask.add(new Image(loading)); diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogInform.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogInform.java new file mode 100644 index 0000000..87cfb6c --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/client/ui/utils/DialogInform.java @@ -0,0 +1,172 @@ +/** + * + */ +package org.gcube.portlets.user.geoportaldataentry.client.ui.utils; + +import org.gcube.portlets.user.geoportaldataentry.client.resource.Images; + +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.resources.client.ImageResource; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.DockPanel; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * The Class DialogInform. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Oct 5, 2021 + */ +public class DialogInform extends DialogBox implements ClickHandler { + + private DockPanel dock = new DockPanel(); + private Button okButton; + private VerticalPanel vpContainer = new VerticalPanel(); + private ImageResource loading = Images.ICONS.loading(); + private HorizontalPanel hpButtons = new HorizontalPanel(); + private HorizontalPanel hpMask = new HorizontalPanel(); + private DialogInform instance = this; + + /** + * Instantiates a new dialog inform. + * + * @param img the img + * @param caption the caption + * @param msg the msg + */ + public DialogInform(Image img, String caption, String msg) { + // getElement().setClassName("gwt-DialogBoxNew"); + dock.setSpacing(4); + dock.setWidth("100%"); + setText(caption); +// setHeading(caption); + + okButton = new Button("OK"); + + vpContainer.getElement().getStyle().setMargin(20.0, Unit.PX); + vpContainer.add(new HTML(msg)); + hpButtons = new HorizontalPanel(); + hpButtons.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); +// hpButtons.getElement().getStyle().setMarginTop(20.0, Unit.PX); + hpButtons.setSpacing(3); + okButton.getElement().getStyle().setMarginRight(20.0, Unit.PX); + hpButtons.add(okButton); + + okButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + instance.hide(); + } + }); + + dock.add(hpButtons, DockPanel.SOUTH); + dock.setCellHorizontalAlignment(hpButtons, DockPanel.ALIGN_CENTER); + + if (img != null) + dock.add(img, DockPanel.WEST); + + vpContainer.add(hpMask); + dock.add(vpContainer, DockPanel.CENTER); + setWidget(dock); + } + + /** + * Sets the msg. + * + * @param msg the new msg + */ + public void setMsg(String msg) { + vpContainer.clear(); + vpContainer.add(new HTML(msg)); + hpButtons.setVisible(true); + } + + /** + * On click. + * + * @param event the event + */ + /* + * (non-Javadoc) + * + * @see + * com.google.gwt.event.dom.client.ClickHandler#onClick(com.google.gwt.event + * .dom.client.ClickEvent) + */ + @Override + public void onClick(ClickEvent event) { +// hide(); + } + + /** + * Hide loader. + */ + public void hideLoader() { + hpMask.clear(); + hpButtons.setVisible(true); + } + + /** + * Loader. + * + * @param message the message + */ + public void showLoader(String message) { + try { + hpButtons.setVisible(false); + } catch (Exception e) { + } + hpMask.clear(); + hpMask.add(new Image(loading)); + HTML html = new HTML(message); + html.getElement().getStyle().setMarginLeft(5, Unit.PX); + hpMask.add(html); + } + + /** + * Adds the to center panel. + * + * @param w the w + */ + public void addToCenterPanel(Widget w) { + vpContainer.add(w); + } + + /** + * Gets the dock. + * + * @return the dock + */ + public DockPanel getDock() { + return dock; + } + + /** + * Gets the yes button. + * + * @return the yes button + */ + public Button getOKButton() { + return okButton; + } + + /** + * Sets the z index. + * + * @param value the new z index + */ + public void setZIndex(int value) { + this.getElement().getStyle().setZIndex(value); + } + +} \ 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 a6be44c..030ad2c 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,6 +22,7 @@ import org.gcube.application.geoportalcommon.GeoportalCommon; import org.gcube.application.geoportalcommon.shared.GeoNaDataViewerProfile; import org.gcube.application.geoportalcommon.shared.GeoNaItemRef; 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.ValidationReportDV; import org.gcube.application.geoportalcommon.shared.products.paths.FileSetPathsDV; import org.gcube.portlets.user.geoportaldataentry.client.ConcessioniFormCardTitle; @@ -649,7 +650,6 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on updating the project with id: " + itemId + ". Error: " + e.getMessage()); } } - /** * Gets the JSON record. @@ -674,7 +674,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Concessione concessione = clientMongo.getById(itemId); return serviceUtil.toJSON(concessione); } - + return null; } catch (Exception e) { @@ -683,12 +683,11 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen "Error occurred on reading the JSON project with id: " + itemId + ". Error: " + e.getMessage()); } } - /** * Gets the record. * - * @param itemId the item id + * @param itemId the item id * @param recordType the record type * @return the record * @throws Exception the exception @@ -708,7 +707,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen Concessione concessione = clientMongo.getById(itemId); return ConvertToDataViewModel.toConcessione(concessione); } - + return null; } catch (Exception e) { @@ -730,78 +729,101 @@ 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 + * @param itemId the item id + * @param recordType the record type + * @param section the section + * @param pathIndex the path index + * @param keepCurrentContent the keep current content + * @param gDBean the g D bean * @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, ""); + public ConcessioneDV updateSectionForRecord(String itemId, String recordType, String section, int pathIndex, + List keepCurrentContent, 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)) { + if (recordType.equalsIgnoreCase(RECORD_TYPE.CONCESSIONE.name())) { SessionUtil.getCurrentContext(this.getThreadLocalRequest(), true); MongoServiceUtil serviceUtil = new MongoServiceUtil(); MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - + String toEditPath = null; AddSectionToConcessioneRequest request = null; + List files = new ArrayList(); - 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"); - + // Managing files already present as current content and kept by user + List keepFiles = serviceUtil.toTemFilesFromWSC(keepCurrentContent); + if (keepFiles != null) { + files.addAll(keepFiles); + LOG.debug(keepFiles.size() +" current corrent file/s has/have been added to list of files"); + } + + // Managing new files uploaded by user + List newFiles = serviceUtil.toTemFiles(gDBean.getFilesUploaded()); + if (newFiles != null) { + files.addAll(newFiles); + LOG.debug(newFiles.size() +" new file/s has/have been added to list of files"); + } + +// 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); + request = new AddSectionToConcessioneRequest(toEditPath, files); } else if (section.contains("piante")) { toEditPath = Paths.piantaByIndex(pathIndex); - request = new AddSectionToConcessioneRequest( - toEditPath, files); + request = new AddSectionToConcessioneRequest(toEditPath, files); } - // Unpublish - System.out.println("Unpublishing "+itemId); - clientMongo.unPublish(itemId); + // Unpublish + LOG.info("Unpublishing " + itemId); + clientMongo.unPublish(itemId); - // update Fileset - System.out.println("Removing old fileset.. "); - clientMongo.cleanFileSet(itemId,toEditPath); + // update Fileset + LOG.info("Removing old fileset.. "); + Concessione concessione = 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); + LOG.debug("Sending new Fileset .."); + if(files.size()>0) { + // 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 = clientMongo.registerFileSet(itemId, request); + }else { + LOG.info("Fileset is empty, skipping registerFileSet"); + } + + LOG.info("Publishings itemId: "+itemId); concessione = clientMongo.publish(itemId); - - return ConvertToDataViewModel.toConcessione(concessione); + + LOG.trace("returning concessione: "+concessione); + return ConvertToDataViewModel.toConcessione(concessione); } return null; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java index 5cb11c9..42bad84 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataentry/server/MongoServiceUtil.java @@ -4,7 +4,9 @@ import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mon import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -14,18 +16,18 @@ import org.gcube.application.geoportal.common.rest.MongoConcessioni; import org.gcube.application.geoportal.common.rest.TempFile; import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; +import org.gcube.application.geoportalcommon.shared.products.content.WorkspaceContentDV; import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException; import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * The Class MongoServiceUtil. * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Sep 16, 2021 + * Sep 16, 2021 */ public class MongoServiceUtil { @@ -87,6 +89,33 @@ public class MongoServiceUtil { return files; } + /** + * To tem files from WSC. + * + * @param listFiles the list files + * @return the list + */ + public List toTemFilesFromWSC(List listFiles) { + LOG.debug("toTemFilesFromWSC called"); + if (listFiles == null || listFiles.isEmpty()) + return null; + + // Building TempFile + List files = new ArrayList(listFiles.size()); + for (WorkspaceContentDV fileUploaded : listFiles) { + InputStream is; + try { + is = new URL(fileUploaded.getLink()).openStream(); + // Creating TempFile + TempFile storageTempFile = createTempFileOnStorage(is, fileUploaded.getName()); + files.add(storageTempFile); + } catch (IOException e) { + LOG.error("Error on creating temp file from URL: " + fileUploaded.getLink(), e); + } + } + return files; + } + /** * To JSON. * @@ -98,7 +127,7 @@ public class MongoServiceUtil { try { // if (theObj instanceof Serializable) { - return org.gcube.application.geoportal.client.utils.Serialization.write(theObj); + return org.gcube.application.geoportal.client.utils.Serialization.write(theObj); // } // throw new Exception("The input object is not serializable"); @@ -141,7 +170,7 @@ public class MongoServiceUtil { * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Sep 16, 2021 + * Sep 16, 2021 */ public static class ConcessioneDVValidationReportStatusComparator implements Comparator {