diff --git a/pom.xml b/pom.xml index 866d2bc..d2354e2 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.gcube.portlets.widgets ckan-metadata-publisher-widget - 1.1.0-SNAPSHOT + 1.2.0-SNAPSHOT gCube Ckan metadata publisher widget diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java index ecc445e..94a3eba 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanMetadataPublisher.java @@ -5,8 +5,10 @@ import java.util.List; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.MetaDataFieldSkeleton; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import com.github.gwtbootstrap.client.ui.Button; import com.google.gwt.core.client.EntryPoint; @@ -15,6 +17,7 @@ import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java index a48eaa1..4d669c4 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/CKanPublisherService.java @@ -66,7 +66,7 @@ public interface CKanPublisherService extends RemoteService { * @return true if it exists, false otherwise */ boolean datasetIdAlreadyExists(String title); - // + // /** // * Return a tree object representing the whole folder hierarchy // * @param folderId diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java index 4080423..3ade183 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java @@ -39,7 +39,6 @@ import com.github.gwtbootstrap.client.ui.TabPanel; import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.constants.AlertType; -import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.google.gwt.core.client.GWT; @@ -336,8 +335,11 @@ public class CreateDatasetForm extends Composite{ if(isWorkspaceRequest){ + boolean showAlertMissingResources = bean.getResources() == null || bean.getResources().isEmpty() || bean.getResources().get(0).getChildren() == null || + bean.getResources().get(0).getChildren().isEmpty(); + // if there are not resources, for now just checked it ( and hide so that the step will be skipped) - if(bean.getResources() == null || bean.getResources().isEmpty()){ + if(showAlertMissingResources){ alertNoResources.setType(AlertType.WARNING); alertNoResources.setVisible(true); @@ -651,9 +653,13 @@ public class CreateDatasetForm extends Composite{ // we need to show the page to handle resources one by one from the workspace formFirstStep.setVisible(false); - boolean resourcesPresent = receivedBean.getResources() != null && receivedBean.getResources().size() > 0 ? true : false; - formSecondStep.setVisible(resourcesPresent); - formThirdStep.setVisible(!resourcesPresent); + boolean hideManageResources = + receivedBean.getResources() == null || + receivedBean.getResources().isEmpty() || + receivedBean.getResources().get(0).getChildren() == null || + receivedBean.getResources().get(0).getChildren().isEmpty(); + formSecondStep.setVisible(!hideManageResources); + formThirdStep.setVisible(hideManageResources); // add the resources to the container panel if(workspaceResourcesContainer.getWidget() == null){ @@ -825,9 +831,6 @@ public class CreateDatasetForm extends Composite{ // leave to back button, but remove create and add go to dataset createButton.removeFromParent(); - // set go to dataset as primary - goToDatasetButton.setType(ButtonType.PRIMARY); - }else{ // remove create button diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java index 442ee51..5d93450 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellLeft.java @@ -24,7 +24,6 @@ public class ResourceCellLeft extends AbstractCell{ Image file = new Image(image.fileIcon()); Image folder = new Image(image.folderIcon()); - file.setWidth("15px"); file.setHeight("15px"); folder.setWidth("15px"); @@ -36,10 +35,9 @@ public class ResourceCellLeft extends AbstractCell{ sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); - sb.appendEscaped(value.getName()); + sb.appendEscaped(value.getEditableName()); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); } - } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java index 007e033..5c41151 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceCellRight.java @@ -1,10 +1,14 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons.Images; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import com.google.gwt.cell.client.AbstractCell; +import com.google.gwt.cell.client.ValueUpdater; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.ui.Image; @@ -16,6 +20,10 @@ public class ResourceCellRight extends AbstractCell{ private static final Images image = GWT.create(Images.class); + public ResourceCellRight() { + super("keydown", "dblclick"); + } + @Override public void render(com.google.gwt.cell.client.Cell.Context context, ResourceElementBean value, SafeHtmlBuilder sb) { @@ -23,9 +31,8 @@ public class ResourceCellRight extends AbstractCell{ if (value == null || !value.isToBeAdded() || value.isFolder()) { return; } - - Image file = new Image(image.fileIcon()); + Image file = new Image(image.fileIcon()); file.setWidth("15px"); file.setHeight("15px"); @@ -35,9 +42,23 @@ public class ResourceCellRight extends AbstractCell{ sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); - sb.appendEscaped(value.getFullPath()); + sb.appendEscaped(value.getEditableName()); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); sb.appendHtmlConstant(""); } + + @Override + public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, + Element parent, ResourceElementBean value, NativeEvent event, + ValueUpdater valueUpdater) { + if(value == null) + return; + + super.onBrowserEvent(context, parent, value, event, valueUpdater); + ResourceInfoForm info = new ResourceInfoForm(value, valueUpdater); + GcubeDialogExtended panel = new GcubeDialogExtended(info); + panel.setPopupPosition(parent.getAbsoluteLeft(), parent.getAbsoluteTop()); + panel.show(); + } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java new file mode 100644 index 0000000..43c4c7c --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.java @@ -0,0 +1,138 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; + +import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; + +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.ControlGroup; +import com.github.gwtbootstrap.client.ui.TextArea; +import com.github.gwtbootstrap.client.ui.TextBox; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.google.gwt.cell.client.ValueUpdater; +import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.HasHorizontalAlignment; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Widget; + +/** + * A resource information form panel + * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it) + */ +public class ResourceInfoForm extends Composite{ + + @UiField + TextBox resourceName; + @UiField + TextBox resourcePath; + @UiField + TextBox resourceFormat; + @UiField + TextArea resourceDescription; + @UiField + Button updateResourceButton; + // @UiField + // Button cancelButton; + @UiField + HorizontalPanel commandPanel; + @UiField + ControlGroup controlName; + + private ResourceElementBean resourceBean; + + private static ResourceInfoFormUiBinder uiBinder = GWT + .create(ResourceInfoFormUiBinder.class); + + interface ResourceInfoFormUiBinder extends + UiBinder { + } + + public ResourceInfoForm() { + initWidget(uiBinder.createAndBindUi(this)); + } + + public ResourceInfoForm(final ResourceElementBean resource, final ValueUpdater valueUpdater) { + initWidget(uiBinder.createAndBindUi(this)); + this.resourceBean = resource; + this.resourceDescription.setText(resource.getDescription()); + this.resourceFormat.setText(resource.getMimeType() == null? "Unavailable" : resource.getMimeType()); + this.resourceName.setText(resource.getName()); + this.resourcePath.setText(resource.getFullPath()); + commandPanel.setCellHorizontalAlignment(updateResourceButton, HasHorizontalAlignment.ALIGN_RIGHT); + + // handlers + // cancelButton.addClickHandler(new ClickHandler() { + // + // @Override + // public void onClick(ClickEvent event) { + // + // + // + // } + // }); + updateResourceButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + removeError(controlName); + + // check description + resourceBean.setDescription(resourceDescription.getText()); + + // check name + String newName = resourceName.getText(); + if(newName == null || newName.isEmpty()){ + showError(controlName); + }else + resourceBean.setEditableName(newName); + + valueUpdater.update(resourceBean); + } + }); + } + + public String getResourceName() { + return resourceName.getText(); + } + + public void setResourceName(String resourceName) { + this.resourceName.setText(resourceName); + } + + public String getResourcePath() { + return resourcePath.getText(); + } + + public void setResourcePath(String resourcePath) { + this.resourcePath.setText(resourcePath); + } + + public String getResourceFormat() { + return resourceFormat.getText(); + } + + public void setResourceFormat(String resourceFormat) { + this.resourceFormat.setText(resourceFormat); + } + + public String getResourceDescription() { + return resourceDescription.getText(); + } + + public void setResourceDescription(String resourceDescription) { + this.resourceDescription.setText(resourceDescription); + } + + public void removeError(ControlGroup control) { + control.setType(ControlGroupType.NONE); + } + + public void showError(ControlGroup control) { + control.setType(ControlGroupType.ERROR); + } + +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml new file mode 100644 index 0000000..e3f3135 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/ResourceInfoForm.ui.xml @@ -0,0 +1,64 @@ + + + + .legend-style { + width: auto; + padding: 10px; + margin-bottom: 0px; + } + + + + + + Resource Information + + + + + Name: + + + + + + + + Path: + + + + + + + + Description: + + + + + + + + Format: + + + + + + + + Update + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java index 43ee298..6d8c121 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.java @@ -12,11 +12,9 @@ import com.github.gwtbootstrap.client.ui.Breadcrumbs; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.FluidContainer; import com.github.gwtbootstrap.client.ui.NavLink; -import com.github.gwtbootstrap.client.ui.Popover; -import com.github.gwtbootstrap.client.ui.constants.Placement; +import com.google.gwt.cell.client.ValueUpdater; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Style.BorderStyle; -import com.google.gwt.dom.client.Style.Float; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -25,7 +23,6 @@ import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.cellview.client.CellList; import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy; import com.google.gwt.user.client.ui.Composite; -import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; import com.google.gwt.view.client.ListDataProvider; @@ -52,10 +49,10 @@ public class TwinColumnSelectionMainPanel extends Composite{ Button toLeftButton; @UiField Button allToLeftButton; - @UiField - Popover popoverResourceSelection; - @UiField - Button resourceInfoButton; + // @UiField + // Popover popoverResourceSelection; + // @UiField + // Button resourceInfoButton; @UiField Breadcrumbs breadcrumbs; @UiField @@ -78,7 +75,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ } private List pathListBeans = new ArrayList(); - // private static final String PANEL_BORDER_COLOR = "#08c"; + private static final String PANEL_BORDER_COLOR = "#8899a6"; private static final String PANEL_HEIGHT = "400px"; private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel(); private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel(); @@ -89,11 +86,11 @@ public class TwinColumnSelectionMainPanel extends Composite{ private MultiSelectionModel selectionModelRight; private MultiSelectionModel selectionModelLeft; private final ResourceElementBean initialBean; - private final static HTML aboutHeader = new HTML("Resource Manager"); - private final static HTML aboutBody = new HTML("

Move the files you want to attach to the product on the right panel below." - + " Please consider that any complex hierarchy structure you may have will be flatten.

"); + // private final static HTML aboutHeader = new HTML("Resource Manager"); + // private final static HTML aboutBody = new HTML("

Move the files you want to attach to the product on the right panel below." + // + " Please consider that any complex hierarchy structure you may have will be flatten.

"); - // private static final int PATH_THRESHOLD = 1; // TODO + // private static final short PATH_THRESHOLD = 1; // TODO private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT .create(TwinColumnSelectionMainPanelUiBinder.class); @@ -107,20 +104,19 @@ public class TwinColumnSelectionMainPanel extends Composite{ this.initialBean = initialBean; - this.buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT); + buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT); allToRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX); toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX); toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); buttonsPanel.getElement().setAttribute("align", "center"); - - popoverResourceSelection.setPlacement(Placement.LEFT); - popoverResourceSelection.setHeading(aboutHeader.getHTML()); - popoverResourceSelection.setText(aboutBody.getHTML()); - resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT); - resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX); - mainContainerResourcesSelection.getElement().getStyle().setPadding(20, Unit.PX); + // popoverResourceSelection.setPlacement(Placement.LEFT); + // popoverResourceSelection.setHeading(aboutHeader.getHTML()); + // popoverResourceSelection.setText(aboutBody.getHTML()); + // resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT); + // resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX); + mainContainerResourcesSelection.getElement().getStyle().setPadding(10, Unit.PX); prepareHandlers(); initLeftSidePanel(initialBean); @@ -146,6 +142,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ // perform an action on selection selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { + public void onSelectionChange(SelectionChangeEvent event) { Iterator selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator(); @@ -166,7 +163,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ public void onClick(ClickEvent event) { removeStartingFromBreadcrumbs(navElem, pathBean); - // breadcrumbsUpdater(); + GWT.log("Clicked on element " + pathBean.resourceFolder.getName()); + //breadcrumbsUpdater(); ResourceElementBean folder = pathBean.resourceFolder; Collections.sort(folder.getChildren()); dataProviderLeft.setList(folder.getChildren()); @@ -177,7 +175,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ pathListBeans.add(pathBean); breadcrumbs.add(navElem); - // breadcrumbsUpdater(); + //breadcrumbsUpdater(); Collections.sort(selectedBean.getChildren()); dataProviderLeft.setList(selectedBean.getChildren()); @@ -207,7 +205,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ public void onClick(ClickEvent event) { removeStartingFromBreadcrumbs(root, pathBean); - // breadcrumbsUpdater(); + //breadcrumbsUpdater(); // set back the root content list dataProviderLeft.setList(initialBean.getChildren()); @@ -222,8 +220,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ showMorePanelLeft.setDisplay(cellListLeft); showMorePanelLeft.setHeight(PANEL_HEIGHT); showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); - showMorePanelLeft.getElement().getStyle().setBorderWidth(1, Unit.PX); - // showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); + showMorePanelLeft.getElement().getStyle().setBorderWidth(2, Unit.PX); + showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); // add the list to the leftContainerPanel leftContainer.add(showMorePanelLeft); @@ -244,8 +242,10 @@ public class TwinColumnSelectionMainPanel extends Composite{ while(iteratorBreadcrumb.hasNext()){ Widget current = iteratorBreadcrumb.next(); - if(delete) + if(delete){ + current.removeFromParent(); iteratorBreadcrumb.remove(); + } if(!delete && navElem.equals(current)) delete = true; @@ -275,6 +275,16 @@ public class TwinColumnSelectionMainPanel extends Composite{ // Set a key provider that provides a unique key for each object. cellListRight = new CellList(cell, ResourceElementBean.KEY_PROVIDER); cellListRight.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); + cellListRight.setValueUpdater(new ValueUpdater() { + + @Override + public void update(ResourceElementBean value) { + + // just redraw the list + cellListRight.redraw(); + + } + }); // Add a selection model so we can select cells. selectionModelRight = new MultiSelectionModel(ResourceElementBean.KEY_PROVIDER); @@ -294,8 +304,8 @@ public class TwinColumnSelectionMainPanel extends Composite{ showMorePanelRight.setDisplay(cellListRight); showMorePanelRight.setHeight(PANEL_HEIGHT); showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); - showMorePanelRight.getElement().getStyle().setBorderWidth(1, Unit.PX); - // showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); + showMorePanelRight.getElement().getStyle().setBorderWidth(2, Unit.PX); + showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); // add the list to the leftContainerPanel rightContainer.add(showMorePanelRight); @@ -450,14 +460,13 @@ public class TwinColumnSelectionMainPanel extends Composite{ List current = dataProviderRight.getList(); List toReturn = new ArrayList(); - for (ResourceElementBean resourceElementBean : current) { - if(resourceElementBean.isToBeAdded()){ // be sure ... - resourceElementBean.setName(resourceElementBean.getFullPath()); - ResourceElementBean beanWithoutChildren = new ResourceElementBean(resourceElementBean); + for (ResourceElementBean resource : current) { + if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ... + ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource); + beanWithoutChildren.setName(resource.getEditableName()); toReturn.add(beanWithoutChildren); } } - return toReturn; } @@ -465,21 +474,24 @@ public class TwinColumnSelectionMainPanel extends Composite{ // void getResources(ClickEvent ce){ // getResourcesToPublish(); // } - + // // /** - // * Short the current path if needed TODO + // * Short the current path if needed // */ // private void breadcrumbsUpdater(){ // // // ignore first and last elem // boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD; // - // GWT.log("List is " + pathListBeans.toString()); + // GWT.log("Is to reduce? " + reduce); + // + // GWT.log("Full size is " + pathListBeans.size()); // // if(!reduce){ // GWT.log("Restore"); - // for(int i = 1; i < pathListBeans.size(); i++){ + // for(int i = 0; i < pathListBeans.size(); i++){ // PathBean bean = pathListBeans.get(i); + // GWT.log("Elem is " + bean.resourceFolder); // bean.link.setText(bean.resourceFolder.getName()); // bean.link.setVisible(true); // } @@ -491,7 +503,7 @@ public class TwinColumnSelectionMainPanel extends Composite{ // bean.link.setText(bean.resourceFolder.getName()); // bean.link.setVisible(true); // }else if(i == (pathListBeans.size() - 2)){ - // GWT.log("The last to modify ****"); + // GWT.log("The last to modify ****" + bean.resourceFolder.getName()); // bean.link.setText("..."); // bean.link.setVisible(true); // }else{ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml index 31b92b3..a016c82 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/TwinColumnSelection/TwinColumnSelectionMainPanel.ui.xml @@ -1,27 +1,29 @@ + xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" + xmlns:m="urn:import:org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection"> + + + + + + + + - - - - - - - - - + + - + @@ -40,9 +42,12 @@ enabled="false" title="Remove selected files" text="<<" /> - + + + + diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java index 5876113..4627f1a 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/GcubeDialogExtended.java @@ -1,6 +1,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; +import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.ResourceInfoForm; import com.github.gwtbootstrap.client.ui.Paragraph; import com.google.gwt.dom.client.Element; @@ -19,6 +20,11 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment; */ public class GcubeDialogExtended extends GCubeDialog { + /** + * For simple information + * @param captionText + * @param text + */ public GcubeDialogExtended(String captionText, String text){ // add custom style @@ -59,4 +65,47 @@ public class GcubeDialogExtended extends GCubeDialog { }); add(new Paragraph(text)); } + + /** + * For simple information + * @param captionText + * @param text + */ + public GcubeDialogExtended(ResourceInfoForm form){ + + // add custom style + addStyleName("metadata-popup-panel"); + + // create an anchor to close the dialogbox + final Anchor closeAnchor = new Anchor("x"); + closeAnchor.setTitle("Close"); + + // create a panel that will be put into the caption + FlexTable captionLayoutTable = new FlexTable(); + captionLayoutTable.setText(0, 0, "About Resource"); + captionLayoutTable.setWidget(0, 3, closeAnchor); + captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_RIGHT); + captionLayoutTable.setWidth("100%"); + HTML caption = (HTML) getCaption(); + caption.getElement().getStyle().setCursor(Cursor.MOVE); + caption.getElement().appendChild(captionLayoutTable.getElement()); + caption.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + EventTarget target = event.getNativeEvent().getEventTarget(); + Element targetElement = (Element) target.cast(); + if (targetElement == closeAnchor.getElement()) { + closeAnchor.fireEvent(event); + } + } + }); + closeAnchor.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + hide(); + } + }); + add(form); + } + } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java index c2ae00a..b67127d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/utils/InfoIconsLabels.java @@ -29,7 +29,7 @@ public class InfoIconsLabels { + "product and by means of them it can be retrieved. A tag can contain only alphanumeric characters. " + "If the tag is composed by a single word it must have a size of at least two characters." + "Examples of good tags: \"This is a sample tag\", \"tagY\". Example of bad tag: \"c\"."; - + // LICENSES public static final String LICENSES_INFO_ID_POPUP = "licenses-popup-panel-info"; public static final String LICENSES_INFO_CAPTION = "Licenses"; @@ -67,19 +67,20 @@ public class InfoIconsLabels { // RESOURCES public static final String RESOURCES_INFO_ID_POPUP = "resouces-popup-panel-info"; - public static final String RESOURCES_INFO_CAPTION = "Product Resources"; - public static final String RESOURCES_INFO_TEXT = "Manage the resources you want to associate to the product."; - + public static final String RESOURCES_INFO_CAPTION = "Manage resource products"; + public static final String RESOURCES_INFO_TEXT = "Move the files you want to attach to the product on the right panel below. Double click on the item for changing resource's name or description." + + " Please consider that any complex hierarchy structure you may have will be flatten."; + // CUSTOM FIELDS public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info"; public static final String CUSTOM_FIELDS_INFO_CAPTION = "Product Custom Fields"; public static final String CUSTOM_FIELDS_INFO_TEXT = "Custom fields are customable metadata that will be added to the product. You have to choose a unique key for the field and a value for this. You can remove them at any time until you create the product."; - + // TITLE public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info"; public static final String TITLE_INFO_TEXT = "Product Title must contain only alphanumer characters, dots, underscore or hyphen minus. No others symbols are allowed."; public static final String TITLE_INFO_CAPTION = "Product Title"; - + /** * Prepare the popover and the gcube popup panel for information. * @param text @@ -140,7 +141,7 @@ public class InfoIconsLabels { }); } - + /** * Check if an element of such type is actually a widget * @param element @@ -162,7 +163,7 @@ public class InfoIconsLabels { } return null; } - + /** * Close any dialog box opened */ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index f439dfd..cec163f 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -93,7 +93,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C */ public String getDevelopmentUser() { String user = TEST_USER; - // user = "costantino.perciante"; + user = "costantino.perciante"; return user; } @@ -113,17 +113,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession aslSession = getASLSession(); String username = aslSession.getUsername(); - - // store info in the http session - HttpSession httpSession = getThreadLocalRequest().getSession(); - - // check the scope we need to discover - String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope(); - - // get the key per scope - String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_TOKEN_KEY, scopeInWhichDiscover); - - // check if session expired + logger.debug("User in session is " + username); if(username.equals(TEST_USER)){ logger.warn("Session expired, returning null token"); @@ -131,7 +121,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C }else{ try{ - logger.debug("User in session is " + username); + + HttpSession httpSession = getThreadLocalRequest().getSession(); + String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getASLSession().getScope(); + String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_TOKEN_KEY, scopeInWhichDiscover); + if(httpSession.getAttribute(keyPerScope) != null){ token = (String)httpSession.getAttribute(keyPerScope); logger.debug("Found ckan token into session"); @@ -161,10 +155,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.debug("Request for user " + username + " organizations list"); List orgsName = new ArrayList(); - // get http session HttpSession httpSession = getThreadLocalRequest().getSession(); - - // get key String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); if(httpSession.getAttribute(keyPerScope) != null){ @@ -213,35 +204,40 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession session = getASLSession(); String username = session.getUsername(); - // get http session - HttpSession httpSession = getThreadLocalRequest().getSession(); - String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + if(username.equals(TEST_USER)){ - logger.info("Request for CKAN licenses for scope " + scope); + logger.warn("Session expired, returning null token"); + return null; - // get key per scope - String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); + }else{ - LicensesBean licensesBean = null; - if(httpSession.getAttribute(keyPerScope) != null){ - licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope); - logger.debug("List of licenses was into session"); - } - else{ - List titlesLicenses = getCatalogue(scope).getLicenses(); - List titles = new ArrayList(); - List urls = new ArrayList(); - for (CkanLicense license : titlesLicenses) { - titles.add(license.getTitle()); - String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : ""; - urls.add(url); + // get http session + HttpSession httpSession = getThreadLocalRequest().getSession(); + String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + logger.info("Request for CKAN licenses for scope " + scope); + String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope); + + LicensesBean licensesBean = null; + if(httpSession.getAttribute(keyPerScope) != null){ + licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope); + logger.info("List of licenses was into session"); + } + else{ + List titlesLicenses = getCatalogue(scope).getLicenses(); + List titles = new ArrayList(); + List urls = new ArrayList(); + for (CkanLicense license : titlesLicenses) { + titles.add(license.getTitle()); + String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : ""; + urls.add(url); + } + licensesBean = new LicensesBean(titles, urls); + httpSession.setAttribute(keyPerScope, licensesBean); + logger.info("List of licenses has been saved into session"); } - licensesBean = new LicensesBean(titles, urls); - httpSession.setAttribute(keyPerScope, licensesBean); - logger.debug("List of licenses has been saved into session"); - } - return licensesBean; + return licensesBean; + } } @Override @@ -254,11 +250,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C logger.info("DatasetBean request for " + folderId + " and " + userName); - HttpSession httpSession = this.getThreadLocalRequest().getSession(); - String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); - - logger.debug("Scope recovered from session is " + scope); - if(isWithinPortal()){ try{ @@ -268,9 +259,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C return null; } + HttpSession httpSession = this.getThreadLocalRequest().getSession(); + String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); + + logger.debug("Scope recovered from session is " + scope); + logger.debug("Request dataset metadata bean for folder with id " + folderId + " whose owner is " + userName); - // get usermanager (liferay) + UserManager liferUserManager = new LiferayUserManager(); GCubeUser userOwner = liferUserManager.getUserByUsername(userName); @@ -290,9 +286,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // if the request comes from the workspace if(folderId != null && !folderId.isEmpty()){ - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); - } }catch(Exception e){ @@ -301,7 +295,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C }else{ try{ - bean = new DatasetMetadataBean(); bean.setId(folderId); bean.setDescription("This is a fantastic description"); @@ -317,11 +310,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C bean.setOwnerIdentifier(userName); if(folderId != null && !folderId.isEmpty()){ - WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); - } - }catch(Exception e){ logger.error("Error while building bean into dev mode", e); } @@ -342,7 +332,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // check if session expired if(userName.equals(TEST_USER)){ - logger.debug("SESSION EXPIRED"); + logger.warn("SESSION EXPIRED"); return null; } @@ -379,7 +369,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C if(datasetId != null){ - logger.debug("Dataset created!"); + logger.info("Dataset created!"); toCreate.setId(datasetId); // retrieve the url @@ -427,7 +417,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C @Override public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) { - ASLSession session = getASLSession(); String username = session.getUsername(); @@ -442,13 +431,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C }else{ if(username.equals(TEST_USER)){ - - logger.warn("SESSION EXPIRED! "); + logger.warn("SESSION EXPIRED!"); return null; - }else{ try{ - ResourceBean resourceBean = new ResourceBean( resource.getUrl(), resource.getName(), @@ -501,7 +487,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C deleted = getCatalogue(scope). deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), getUserCKanTokenFromSession(scope)); if(deleted){ - logger.debug("Resource described by " + resource + " deleted"); + logger.info("Resource described by " + resource + " deleted"); }else logger.error("Resource described by " + resource + " NOT deleted"); }catch(Exception e){ @@ -516,7 +502,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C public List getProfiles(String orgName) { logger.debug("Requested profiles for products into orgName " + orgName); - List toReturn = new ArrayList(); try{ String evaluatedScope = getScopeFromOrgName(orgName); @@ -534,17 +519,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C if(title == null || title.isEmpty()) return true; // it's an error somehow - try{ - String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title); return getCatalogue(scope).existProductWithNameOrId(idFromTitle); - }catch(Exception e){ logger.error("Unable to check if such a dataset id already exists", e); } - return false; } @@ -555,7 +536,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C private String getScopeFromOrgName(String orgName){ logger.debug("Request for scope related to orgName " + orgName + "[ map that will be used is " + mapOrganizationScope.toString() + " ]"); - if(orgName == null || orgName.isEmpty()) throw new IllegalArgumentException("orgName cannot be empty or null!"); @@ -565,22 +545,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C toReturn = mapOrganizationScope.get(orgName); else{ try{ - String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName); mapOrganizationScope.put(orgName, evaluatedScope); toReturn = evaluatedScope; - }catch(Exception e){ logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e); } } - - logger.debug("Returning scope " + toReturn); return toReturn; - } - // + // @Override // public ResourceElementBean getTreeFolder(String folderId) { // diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java index b21bf5c..57aa4bb 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/WorkspaceUtils.java @@ -55,13 +55,16 @@ public class WorkspaceUtils { copiedFolder.setDescription(bean.getDescription()); // change name of the copied folder to match the title (append the timestamp to avoid ties) - ((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + System.currentTimeMillis()); + long referenceTime = System.currentTimeMillis(); + ((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + referenceTime); // copy only the selected ones for(ResourceElementBean resource : resourcesToAdd){ if (resource.isToBeAdded()) { + logger.debug("Resource to add is " + resource); + // ok it is a file, so copy it into the copiedFolder WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId()); @@ -74,15 +77,13 @@ public class WorkspaceUtils { copiedFile.getDescription(), copiedFile.getId(), userName, - null, // to be set + null, // dataset id, to be set ((FolderItem)copiedFile).getMimeType())); // postpone rename operation - copiedFile.rename(resource.getName() + "_" + System.currentTimeMillis()); + copiedFile.rename(resource.getName() + "_" + referenceTime); } } - - // return return resources; } @@ -128,22 +129,23 @@ public class WorkspaceUtils { * @throws Exception */ public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace ws) throws Exception{ - - // start tree construction ResourceElementBean rootElem = new ResourceElementBean(); String pathSeparator = ws.getPathSeparator(); try{ - WorkspaceItem initialItemWS = ws.getItem(workspaceFolderId); - String fullPathBase = initialItemWS.getPath(); + WorkspaceItem initialItem = ws.getItem(workspaceFolderId); + String fullPathBase = initialItem.getPath(); fullPathBase = fullPathBase.endsWith(ws.getPathSeparator()) ? fullPathBase : fullPathBase + ws.getPathSeparator(); - rootElem.setFolder(initialItemWS.isFolder()); - rootElem.setFullPath(initialItemWS.getPath().replace(fullPathBase, "")); + rootElem.setFolder(initialItem.isFolder()); + rootElem.setFullPath(initialItem.getPath().replace(fullPathBase, "")); rootElem.setParent(null); - rootElem.setName(initialItemWS.getName()); - rootElem.setOriginalIdInWorkspace(initialItemWS.getId()); - replaceFullPath(rootElem, pathSeparator); - // start visiting - visit(rootElem, initialItemWS, fullPathBase, pathSeparator); + rootElem.setName(initialItem.getName()); + rootElem.setOriginalIdInWorkspace(initialItem.getId()); + rootElem.setDescription(initialItem.getDescription()); + extractEditableNameFromPath(rootElem, pathSeparator); + + // recursive visiting + if(initialItem.isFolder()) + visit(rootElem, initialItem, fullPathBase, pathSeparator); }catch(Exception e){ logger.error("Failed to build the resource tree", e); return null; @@ -151,44 +153,47 @@ public class WorkspaceUtils { return rootElem; } - /** - * Replaces the "/" char with a custom one - * @param rootElem - * @param pathSeparatorInWs - */ - private static void replaceFullPath(ResourceElementBean rootElem, String pathSeparatorInWs) { - - if(rootElem == null) - return; - - String elemName = rootElem.getName(); - int lastIndex = rootElem.getFullPath().lastIndexOf(elemName); - String fullPath = rootElem.getFullPath().substring(0, lastIndex); - fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; - rootElem.setFullPath(fullPath); - } - /** * Recursive visit of a workspace item * @param rootElem * @param initialItemWS * @throws InternalErrorException */ - private static void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS, String fullPathBase, String pathSeparator) throws InternalErrorException { + private static void visit(ResourceElementBean parent, WorkspaceItem initialItemWS, String fullPathBase, String pathSeparator) throws InternalErrorException { List children = initialItemWS.getChildren(); ArrayList childrenInTree = new ArrayList(children.size()); - for (WorkspaceItem workspaceItem : children) { + for (WorkspaceItem item : children) { ResourceElementBean elem = new ResourceElementBean(); - elem.setFolder(workspaceItem.isFolder()); - elem.setOriginalIdInWorkspace(workspaceItem.getId()); - elem.setFullPath(workspaceItem.getPath().replace(fullPathBase, "")); - elem.setParent(rootElem); - elem.setName(workspaceItem.getName()); - replaceFullPath(elem, pathSeparator); + elem.setFolder(item.isFolder()); + elem.setOriginalIdInWorkspace(item.getId()); + elem.setFullPath(item.getPath().replace(fullPathBase, "")); + elem.setParent(parent); + elem.setName(item.getName()); + elem.setDescription(item.getDescription()); + extractEditableNameFromPath(elem, pathSeparator); childrenInTree.add(elem); - visit(elem, workspaceItem, fullPathBase, pathSeparator); + if(item.isFolder()) + visit(elem, item, fullPathBase, pathSeparator); } - rootElem.setChildren(childrenInTree); + // add these list as child of the rootElem + parent.setChildren(childrenInTree); + } + + /** + * Replaces the "/" char with a custom one + * @param rootElem + * @param pathSeparatorInWs + */ + private static void extractEditableNameFromPath(ResourceElementBean rootElem, String pathSeparatorInWs) { + + if(rootElem == null) + return; + + String elemName = rootElem.getName(); + int lastIndex = rootElem.getFullPath().lastIndexOf(elemName); + String fullPath = rootElem.getFullPath().substring(0, lastIndex); + fullPath = fullPath.replaceAll(pathSeparatorInWs, RESOURCES_NAME_SEPARATOR) + elemName; + rootElem.setEditableName(fullPath); } } diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java index f13c257..e722094 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/shared/ResourceElementBean.java @@ -15,16 +15,17 @@ public class ResourceElementBean implements Comparable, Ser private static final long serialVersionUID = -1230871392599580669L; private int identifierGWT; private String name; + private String editableName; private boolean toBeAdded; private boolean isFolder; - private ResourceElementBean parent; - private List children; private String fullPath; private String originalIdInWorkspace; private String mimeType; private String url; private String description; private String organizationNameDatasetParent; // the organization name in which the parent dataset was created + private ResourceElementBean parent; + private List children; // to generate the identifiers private static int nextId = 0; @@ -45,6 +46,9 @@ public class ResourceElementBean implements Comparable, Ser */ public ResourceElementBean(ResourceElementBean another) { this.name = another.name; + this.toBeAdded = another.toBeAdded; + this.fullPath = another.fullPath; + this.editableName = another.editableName; this.originalIdInWorkspace = another.originalIdInWorkspace; this.mimeType = another.mimeType; this.url = another.url; @@ -206,6 +210,14 @@ public class ResourceElementBean implements Comparable, Ser this.originalIdInWorkspace = originalIdInWorkspace; } + public String getEditableName() { + return editableName; + } + + public void setEditableName(String newName) { + this.editableName = newName; + } + @Override public boolean equals(Object o) { boolean toReturn = false; @@ -216,21 +228,22 @@ public class ResourceElementBean implements Comparable, Ser return toReturn; } - @Override - public String toString() { - return "ResourceElementBean [identifierGWT=" + identifierGWT - + ", name=" + name + ", toBeAdded=" + toBeAdded + ", isFolder=" - + isFolder + ", parent=" + parent + ", children number=" + (children == null ? 0 : children.size()) - + ", fullPath=" + fullPath + ", originalIdInWorkspace=" - + originalIdInWorkspace + ", mimeType=" + mimeType + ", url=" - + url + ", description=" + description - + ", organizationNameDatasetParent=" - + organizationNameDatasetParent + "]"; - } - @Override public int compareTo(ResourceElementBean o) { int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath); return toReturn; } + + @Override + public String toString() { + return "ResourceElementBean [identifierGWT=" + identifierGWT + + ", name=" + name + ", editableName=" + editableName + + ", toBeAdded=" + toBeAdded + ", isFolder=" + isFolder + + ", fullPath=" + fullPath + ", originalIdInWorkspace=" + + originalIdInWorkspace + ", mimeType=" + mimeType + ", url=" + + url + ", description=" + description + + ", organizationNameDatasetParent=" + + organizationNameDatasetParent + ", parent=" + parent + + ", children number=" + (children == null ? 0 : children.size()) + "]"; + } }