resource manager finished

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134111 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-11-13 21:38:27 +00:00
parent 7d029abb19
commit f71602cbdd
15 changed files with 492 additions and 205 deletions

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId> <groupId>org.gcube.portlets.widgets</groupId>
<artifactId>ckan-metadata-publisher-widget</artifactId> <artifactId>ckan-metadata-publisher-widget</artifactId>
<version>1.1.0-SNAPSHOT</version> <version>1.2.0-SNAPSHOT</version>
<name>gCube Ckan metadata publisher widget</name> <name>gCube Ckan metadata publisher widget</name>
<description> <description>

View File

@ -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.CreateDatasetForm;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.MetaDataFieldSkeleton; 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.DataType;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper; 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.github.gwtbootstrap.client.ui.Button;
import com.google.gwt.core.client.EntryPoint; 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.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.Window; 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.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.VerticalPanel;

View File

@ -66,7 +66,7 @@ public interface CKanPublisherService extends RemoteService {
* @return true if it exists, false otherwise * @return true if it exists, false otherwise
*/ */
boolean datasetIdAlreadyExists(String title); boolean datasetIdAlreadyExists(String title);
//
// /** // /**
// * Return a tree object representing the whole folder hierarchy // * Return a tree object representing the whole folder hierarchy
// * @param folderId // * @param folderId

View File

@ -39,7 +39,6 @@ import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.TextArea; import com.github.gwtbootstrap.client.ui.TextArea;
import com.github.gwtbootstrap.client.ui.TextBox; import com.github.gwtbootstrap.client.ui.TextBox;
import com.github.gwtbootstrap.client.ui.constants.AlertType; 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.constants.ControlGroupType;
import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs; import com.github.gwtbootstrap.client.ui.resources.Bootstrap.Tabs;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -336,8 +335,11 @@ public class CreateDatasetForm extends Composite{
if(isWorkspaceRequest){ 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 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.setType(AlertType.WARNING);
alertNoResources.setVisible(true); 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 // we need to show the page to handle resources one by one from the workspace
formFirstStep.setVisible(false); formFirstStep.setVisible(false);
boolean resourcesPresent = receivedBean.getResources() != null && receivedBean.getResources().size() > 0 ? true : false; boolean hideManageResources =
formSecondStep.setVisible(resourcesPresent); receivedBean.getResources() == null ||
formThirdStep.setVisible(!resourcesPresent); 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 // add the resources to the container panel
if(workspaceResourcesContainer.getWidget() == null){ 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 // leave to back button, but remove create and add go to dataset
createButton.removeFromParent(); createButton.removeFromParent();
// set go to dataset as primary
goToDatasetButton.setType(ButtonType.PRIMARY);
}else{ }else{
// remove create button // remove create button

View File

@ -24,7 +24,6 @@ public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
Image file = new Image(image.fileIcon()); Image file = new Image(image.fileIcon());
Image folder = new Image(image.folderIcon()); Image folder = new Image(image.folderIcon());
file.setWidth("15px"); file.setWidth("15px");
file.setHeight("15px"); file.setHeight("15px");
folder.setWidth("15px"); folder.setWidth("15px");
@ -36,10 +35,9 @@ public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
sb.appendHtmlConstant("</span>"); sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("<span style='margin-left:10px;'>"); sb.appendHtmlConstant("<span style='margin-left:10px;'>");
sb.appendHtmlConstant("<b>"); sb.appendHtmlConstant("<b>");
sb.appendEscaped(value.getName()); sb.appendEscaped(value.getEditableName());
sb.appendHtmlConstant("</b>"); sb.appendHtmlConstant("</b>");
sb.appendHtmlConstant("</span>"); sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("</div>"); sb.appendHtmlConstant("</div>");
} }
} }

View File

@ -1,10 +1,14 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection; 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.icons.Images;
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.GcubeDialogExtended;
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
import com.google.gwt.cell.client.AbstractCell; 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.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.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
@ -16,6 +20,10 @@ public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
private static final Images image = GWT.create(Images.class); private static final Images image = GWT.create(Images.class);
public ResourceCellRight() {
super("keydown", "dblclick");
}
@Override @Override
public void render(com.google.gwt.cell.client.Cell.Context context, public void render(com.google.gwt.cell.client.Cell.Context context,
ResourceElementBean value, SafeHtmlBuilder sb) { ResourceElementBean value, SafeHtmlBuilder sb) {
@ -23,9 +31,8 @@ public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
if (value == null || !value.isToBeAdded() || value.isFolder()) { if (value == null || !value.isToBeAdded() || value.isFolder()) {
return; return;
} }
Image file = new Image(image.fileIcon());
Image file = new Image(image.fileIcon());
file.setWidth("15px"); file.setWidth("15px");
file.setHeight("15px"); file.setHeight("15px");
@ -35,9 +42,23 @@ public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
sb.appendHtmlConstant("</span>"); sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("<span style='margin-left:10px'>"); sb.appendHtmlConstant("<span style='margin-left:10px'>");
sb.appendHtmlConstant("<b>"); sb.appendHtmlConstant("<b>");
sb.appendEscaped(value.getFullPath()); sb.appendEscaped(value.getEditableName());
sb.appendHtmlConstant("</b>"); sb.appendHtmlConstant("</b>");
sb.appendHtmlConstant("</span>"); sb.appendHtmlConstant("</span>");
sb.appendHtmlConstant("</div>"); sb.appendHtmlConstant("</div>");
} }
@Override
public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,
Element parent, ResourceElementBean value, NativeEvent event,
ValueUpdater<ResourceElementBean> 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();
}
} }

View File

@ -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<Widget, ResourceInfoForm> {
}
public ResourceInfoForm() {
initWidget(uiBinder.createAndBindUi(this));
}
public ResourceInfoForm(final ResourceElementBean resource, final ValueUpdater<ResourceElementBean> 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);
}
}

View File

@ -0,0 +1,64 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<ui:style>
.legend-style {
width: auto;
padding: 10px;
margin-bottom: 0px;
}
</ui:style>
<g:HTMLPanel>
<b:Form type="VERTICAL">
<!-- <b:Fieldset styleName="{style.fieldset-border-style}"> -->
<b:Legend styleName="{style.legend-style}">
Resource Information
</b:Legend>
<b:Label></b:Label>
<b:ControlGroup ui:field="controlName">
<b:ControlLabel for="name"
title="The name the resource will have on the catalogue">
<b>Name:</b>
</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Resource name" b:id="name"
title="The name the resource will have on the catalogue" ui:field="resourceName" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="path" title="Resource path">
<b>Path:</b>
</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Resource path" b:id="path"
readOnly="true" title="Resource path" ui:field="resourcePath" />
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="description"
title="The description the resource will have on the catalogue">
<b>Description:</b>
</b:ControlLabel>
<b:Controls>
<b:TextArea placeholder="Resource description" b:id="description"
title="The description the resource will have on the catalogue"
ui:field="resourceDescription"></b:TextArea>
</b:Controls>
</b:ControlGroup>
<b:ControlGroup>
<b:ControlLabel for="format" title="The MIME type">
<b>Format:</b>
</b:ControlLabel>
<b:Controls>
<b:TextBox placeholder="Resource format" b:id="format"
title="The MIME type" ui:field="resourceFormat" readOnly="true" />
</b:Controls>
</b:ControlGroup>
<g:HorizontalPanel width="100%" ui:field="commandPanel">
<!-- <b:Button ui:field="cancelButton">Cancel</b:Button> -->
<b:Button ui:field="updateResourceButton" type="PRIMARY">Update</b:Button>
</g:HorizontalPanel>
<!-- </b:Fieldset> -->
</b:Form>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -12,11 +12,9 @@ import com.github.gwtbootstrap.client.ui.Breadcrumbs;
import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.FluidContainer; import com.github.gwtbootstrap.client.ui.FluidContainer;
import com.github.gwtbootstrap.client.ui.NavLink; import com.github.gwtbootstrap.client.ui.NavLink;
import com.github.gwtbootstrap.client.ui.Popover; import com.google.gwt.cell.client.ValueUpdater;
import com.github.gwtbootstrap.client.ui.constants.Placement;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.BorderStyle; 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.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; 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.CellList;
import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy; import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy;
import com.google.gwt.user.client.ui.Composite; 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.VerticalPanel;
import com.google.gwt.user.client.ui.Widget; import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider; import com.google.gwt.view.client.ListDataProvider;
@ -52,10 +49,10 @@ public class TwinColumnSelectionMainPanel extends Composite{
Button toLeftButton; Button toLeftButton;
@UiField @UiField
Button allToLeftButton; Button allToLeftButton;
@UiField // @UiField
Popover popoverResourceSelection; // Popover popoverResourceSelection;
@UiField // @UiField
Button resourceInfoButton; // Button resourceInfoButton;
@UiField @UiField
Breadcrumbs breadcrumbs; Breadcrumbs breadcrumbs;
@UiField @UiField
@ -78,7 +75,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
} }
private List<PathBean> pathListBeans = new ArrayList<PathBean>(); private List<PathBean> pathListBeans = new ArrayList<PathBean>();
// private static final String PANEL_BORDER_COLOR = "#08c"; private static final String PANEL_BORDER_COLOR = "#8899a6";
private static final String PANEL_HEIGHT = "400px"; private static final String PANEL_HEIGHT = "400px";
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel(); private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel();
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel(); private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel();
@ -89,11 +86,11 @@ public class TwinColumnSelectionMainPanel extends Composite{
private MultiSelectionModel<ResourceElementBean> selectionModelRight; private MultiSelectionModel<ResourceElementBean> selectionModelRight;
private MultiSelectionModel<ResourceElementBean> selectionModelLeft; private MultiSelectionModel<ResourceElementBean> selectionModelLeft;
private final ResourceElementBean initialBean; private final ResourceElementBean initialBean;
private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>"); // private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>");
private final static HTML aboutBody = new HTML("<p style='text-align:justify;'>Move the files you want to attach to the product on the right panel below." // private final static HTML aboutBody = new HTML("<p style='text-align:justify;'>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.</p>"); // + " Please consider that any complex hierarchy structure you may have will be flatten.</p>");
// private static final int PATH_THRESHOLD = 1; // TODO // private static final short PATH_THRESHOLD = 1; // TODO
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
.create(TwinColumnSelectionMainPanelUiBinder.class); .create(TwinColumnSelectionMainPanelUiBinder.class);
@ -107,20 +104,19 @@ public class TwinColumnSelectionMainPanel extends Composite{
this.initialBean = initialBean; 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); allToRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX); toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX); allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
buttonsPanel.getElement().setAttribute("align", "center"); buttonsPanel.getElement().setAttribute("align", "center");
// popoverResourceSelection.setPlacement(Placement.LEFT);
popoverResourceSelection.setPlacement(Placement.LEFT); // popoverResourceSelection.setHeading(aboutHeader.getHTML());
popoverResourceSelection.setHeading(aboutHeader.getHTML()); // popoverResourceSelection.setText(aboutBody.getHTML());
popoverResourceSelection.setText(aboutBody.getHTML()); // resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT);
resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT); // resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX);
resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX); mainContainerResourcesSelection.getElement().getStyle().setPadding(10, Unit.PX);
mainContainerResourcesSelection.getElement().getStyle().setPadding(20, Unit.PX);
prepareHandlers(); prepareHandlers();
initLeftSidePanel(initialBean); initLeftSidePanel(initialBean);
@ -146,6 +142,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
// perform an action on selection // perform an action on selection
selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() { selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) { public void onSelectionChange(SelectionChangeEvent event) {
Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator(); Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator();
@ -166,7 +163,8 @@ public class TwinColumnSelectionMainPanel extends Composite{
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
removeStartingFromBreadcrumbs(navElem, pathBean); removeStartingFromBreadcrumbs(navElem, pathBean);
// breadcrumbsUpdater(); GWT.log("Clicked on element " + pathBean.resourceFolder.getName());
//breadcrumbsUpdater();
ResourceElementBean folder = pathBean.resourceFolder; ResourceElementBean folder = pathBean.resourceFolder;
Collections.sort(folder.getChildren()); Collections.sort(folder.getChildren());
dataProviderLeft.setList(folder.getChildren()); dataProviderLeft.setList(folder.getChildren());
@ -177,7 +175,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
pathListBeans.add(pathBean); pathListBeans.add(pathBean);
breadcrumbs.add(navElem); breadcrumbs.add(navElem);
// breadcrumbsUpdater(); //breadcrumbsUpdater();
Collections.sort(selectedBean.getChildren()); Collections.sort(selectedBean.getChildren());
dataProviderLeft.setList(selectedBean.getChildren()); dataProviderLeft.setList(selectedBean.getChildren());
@ -207,7 +205,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
public void onClick(ClickEvent event) { public void onClick(ClickEvent event) {
removeStartingFromBreadcrumbs(root, pathBean); removeStartingFromBreadcrumbs(root, pathBean);
// breadcrumbsUpdater(); //breadcrumbsUpdater();
// set back the root content list // set back the root content list
dataProviderLeft.setList(initialBean.getChildren()); dataProviderLeft.setList(initialBean.getChildren());
@ -222,8 +220,8 @@ public class TwinColumnSelectionMainPanel extends Composite{
showMorePanelLeft.setDisplay(cellListLeft); showMorePanelLeft.setDisplay(cellListLeft);
showMorePanelLeft.setHeight(PANEL_HEIGHT); showMorePanelLeft.setHeight(PANEL_HEIGHT);
showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
showMorePanelLeft.getElement().getStyle().setBorderWidth(1, Unit.PX); showMorePanelLeft.getElement().getStyle().setBorderWidth(2, Unit.PX);
// showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
// add the list to the leftContainerPanel // add the list to the leftContainerPanel
leftContainer.add(showMorePanelLeft); leftContainer.add(showMorePanelLeft);
@ -244,8 +242,10 @@ public class TwinColumnSelectionMainPanel extends Composite{
while(iteratorBreadcrumb.hasNext()){ while(iteratorBreadcrumb.hasNext()){
Widget current = iteratorBreadcrumb.next(); Widget current = iteratorBreadcrumb.next();
if(delete) if(delete){
current.removeFromParent();
iteratorBreadcrumb.remove(); iteratorBreadcrumb.remove();
}
if(!delete && navElem.equals(current)) if(!delete && navElem.equals(current))
delete = true; delete = true;
@ -275,6 +275,16 @@ public class TwinColumnSelectionMainPanel extends Composite{
// Set a key provider that provides a unique key for each object. // Set a key provider that provides a unique key for each object.
cellListRight = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER); cellListRight = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER);
cellListRight.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE); cellListRight.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
cellListRight.setValueUpdater(new ValueUpdater<ResourceElementBean>() {
@Override
public void update(ResourceElementBean value) {
// just redraw the list
cellListRight.redraw();
}
});
// Add a selection model so we can select cells. // Add a selection model so we can select cells.
selectionModelRight = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER); selectionModelRight = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
@ -294,8 +304,8 @@ public class TwinColumnSelectionMainPanel extends Composite{
showMorePanelRight.setDisplay(cellListRight); showMorePanelRight.setDisplay(cellListRight);
showMorePanelRight.setHeight(PANEL_HEIGHT); showMorePanelRight.setHeight(PANEL_HEIGHT);
showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
showMorePanelRight.getElement().getStyle().setBorderWidth(1, Unit.PX); showMorePanelRight.getElement().getStyle().setBorderWidth(2, Unit.PX);
// showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR); showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
// add the list to the leftContainerPanel // add the list to the leftContainerPanel
rightContainer.add(showMorePanelRight); rightContainer.add(showMorePanelRight);
@ -450,14 +460,13 @@ public class TwinColumnSelectionMainPanel extends Composite{
List<ResourceElementBean> current = dataProviderRight.getList(); List<ResourceElementBean> current = dataProviderRight.getList();
List<ResourceElementBean> toReturn = new ArrayList<ResourceElementBean>(); List<ResourceElementBean> toReturn = new ArrayList<ResourceElementBean>();
for (ResourceElementBean resourceElementBean : current) { for (ResourceElementBean resource : current) {
if(resourceElementBean.isToBeAdded()){ // be sure ... if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ...
resourceElementBean.setName(resourceElementBean.getFullPath()); ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource);
ResourceElementBean beanWithoutChildren = new ResourceElementBean(resourceElementBean); beanWithoutChildren.setName(resource.getEditableName());
toReturn.add(beanWithoutChildren); toReturn.add(beanWithoutChildren);
} }
} }
return toReturn; return toReturn;
} }
@ -465,21 +474,24 @@ public class TwinColumnSelectionMainPanel extends Composite{
// void getResources(ClickEvent ce){ // void getResources(ClickEvent ce){
// getResourcesToPublish(); // getResourcesToPublish();
// } // }
//
// /** // /**
// * Short the current path if needed TODO // * Short the current path if needed
// */ // */
// private void breadcrumbsUpdater(){ // private void breadcrumbsUpdater(){
// //
// // ignore first and last elem // // ignore first and last elem
// boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD; // 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){ // if(!reduce){
// GWT.log("Restore"); // GWT.log("Restore");
// for(int i = 1; i < pathListBeans.size(); i++){ // for(int i = 0; i < pathListBeans.size(); i++){
// PathBean bean = pathListBeans.get(i); // PathBean bean = pathListBeans.get(i);
// GWT.log("Elem is " + bean.resourceFolder);
// bean.link.setText(bean.resourceFolder.getName()); // bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true); // bean.link.setVisible(true);
// } // }
@ -491,7 +503,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
// bean.link.setText(bean.resourceFolder.getName()); // bean.link.setText(bean.resourceFolder.getName());
// bean.link.setVisible(true); // bean.link.setVisible(true);
// }else if(i == (pathListBeans.size() - 2)){ // }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.setText("...");
// bean.link.setVisible(true); // bean.link.setVisible(true);
// }else{ // }else{

View File

@ -1,27 +1,29 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> 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">
<ui:style> <ui:style>
</ui:style> </ui:style>
<g:HTMLPanel> <g:HTMLPanel>
<b:FluidContainer ui:field="mainContainerResourcesSelection"> <b:FluidContainer ui:field="mainContainerResourcesSelection">
<!-- <b:FluidRow> -->
<!-- <b:Column offset="6" size="1"> -->
<!-- <b:Popover ui:field="popoverResourceSelection" html="true"> -->
<!-- <b:Button ui:field="resourceInfoButton" type="LINK" icon="INFO_SIGN" -->
<!-- size="LARGE"></b:Button> -->
<!-- </b:Popover> -->
<!-- </b:Column> -->
<!-- </b:FluidRow> -->
<b:FluidRow> <b:FluidRow>
<b:Column offset="6" size="1"> <b:Column size="9">
<b:Popover ui:field="popoverResourceSelection" html="true"> <b:Breadcrumbs ui:field="breadcrumbs" divider=">"
<b:Button ui:field="resourceInfoButton" type="LINK" icon="INFO_SIGN" title="Current path">
size="LARGE"></b:Button>
</b:Popover>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="7">
<b:Breadcrumbs ui:field="breadcrumbs" divider=">">
</b:Breadcrumbs> </b:Breadcrumbs>
</b:Column> </b:Column>
</b:FluidRow> </b:FluidRow>
<b:FluidRow> <b:FluidRow>
<b:Column size="3" ui:field="leftColumn"> <b:Column size="4" ui:field="leftColumn">
<!-- <b:Button enabled="true" type="LINK" ui:field="goRootButton">Root <!-- <b:Button enabled="true" type="LINK" ui:field="goRootButton">Root
level</b:Button> --> level</b:Button> -->
<!-- <b:Button enabled="true" type="LINK" ui:field="goUpButton">Go up</b:Button> --> <!-- <b:Button enabled="true" type="LINK" ui:field="goUpButton">Go up</b:Button> -->
@ -40,9 +42,12 @@
enabled="false" title="Remove selected files" text="&lt;&lt;" /> enabled="false" title="Remove selected files" text="&lt;&lt;" />
</g:VerticalPanel> </g:VerticalPanel>
</b:Column> </b:Column>
<b:Column size="3" ui:field="rightColumn"> <b:Column size="4" ui:field="rightColumn">
<g:VerticalPanel ui:field="rightContainer" width="100%"></g:VerticalPanel> <g:VerticalPanel ui:field="rightContainer" width="100%"></g:VerticalPanel>
</b:Column> </b:Column>
<!-- <b:Column size="2"> -->
<!-- <m:ResourceInfoForm ui:field="resourceInfoForm"></m:ResourceInfoForm> -->
<!-- </b:Column> -->
</b:FluidRow> </b:FluidRow>
</b:FluidContainer> </b:FluidContainer>
<!-- <b:Button ui:field="getResources">Get Resources</b:Button> --> <!-- <b:Button ui:field="getResources">Get Resources</b:Button> -->

View File

@ -1,6 +1,7 @@
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils; package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils;
import org.gcube.portlets.user.gcubewidgets.client.popup.GCubeDialog; 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.github.gwtbootstrap.client.ui.Paragraph;
import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Element;
@ -19,6 +20,11 @@ import com.google.gwt.user.client.ui.HasHorizontalAlignment;
*/ */
public class GcubeDialogExtended extends GCubeDialog { public class GcubeDialogExtended extends GCubeDialog {
/**
* For simple information
* @param captionText
* @param text
*/
public GcubeDialogExtended(String captionText, String text){ public GcubeDialogExtended(String captionText, String text){
// add custom style // add custom style
@ -59,4 +65,47 @@ public class GcubeDialogExtended extends GCubeDialog {
}); });
add(new Paragraph(text)); 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);
}
} }

View File

@ -29,7 +29,7 @@ public class InfoIconsLabels {
+ "product and by means of them it can be retrieved. A tag can contain only alphanumeric characters. " + "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." + "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\"."; + "Examples of good tags: \"This is a sample tag\", \"tagY\". Example of bad tag: \"c\".";
// LICENSES // LICENSES
public static final String LICENSES_INFO_ID_POPUP = "licenses-popup-panel-info"; public static final String LICENSES_INFO_ID_POPUP = "licenses-popup-panel-info";
public static final String LICENSES_INFO_CAPTION = "Licenses"; public static final String LICENSES_INFO_CAPTION = "Licenses";
@ -67,19 +67,20 @@ public class InfoIconsLabels {
// RESOURCES // RESOURCES
public static final String RESOURCES_INFO_ID_POPUP = "resouces-popup-panel-info"; 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_CAPTION = "Manage resource products";
public static final String RESOURCES_INFO_TEXT = "Manage the resources you want to associate to the product."; 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 // CUSTOM FIELDS
public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info"; 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_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."; 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 // TITLE
public static final String TITLE_INFO_ID_POPUP = "title-popup-panel-info"; 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_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"; public static final String TITLE_INFO_CAPTION = "Product Title";
/** /**
* Prepare the popover and the gcube popup panel for information. * Prepare the popover and the gcube popup panel for information.
* @param text * @param text
@ -140,7 +141,7 @@ public class InfoIconsLabels {
}); });
} }
/** /**
* Check if an element of such type is actually a widget * Check if an element of such type is actually a widget
* @param element * @param element
@ -162,7 +163,7 @@ public class InfoIconsLabels {
} }
return null; return null;
} }
/** /**
* Close any dialog box opened * Close any dialog box opened
*/ */

View File

@ -93,7 +93,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
*/ */
public String getDevelopmentUser() { public String getDevelopmentUser() {
String user = TEST_USER; String user = TEST_USER;
// user = "costantino.perciante"; user = "costantino.perciante";
return user; return user;
} }
@ -113,17 +113,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
ASLSession aslSession = getASLSession(); ASLSession aslSession = getASLSession();
String username = aslSession.getUsername(); String username = aslSession.getUsername();
logger.debug("User in session is " + username);
// 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
if(username.equals(TEST_USER)){ if(username.equals(TEST_USER)){
logger.warn("Session expired, returning null token"); logger.warn("Session expired, returning null token");
@ -131,7 +121,11 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}else{ }else{
try{ 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){ if(httpSession.getAttribute(keyPerScope) != null){
token = (String)httpSession.getAttribute(keyPerScope); token = (String)httpSession.getAttribute(keyPerScope);
logger.debug("Found ckan token into session"); 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"); logger.debug("Request for user " + username + " organizations list");
List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>(); List<OrganizationBean> orgsName = new ArrayList<OrganizationBean>();
// get http session
HttpSession httpSession = getThreadLocalRequest().getSession(); HttpSession httpSession = getThreadLocalRequest().getSession();
// get key
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope); String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scope);
if(httpSession.getAttribute(keyPerScope) != null){ if(httpSession.getAttribute(keyPerScope) != null){
@ -213,35 +204,40 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String username = session.getUsername(); String username = session.getUsername();
// get http session if(username.equals(TEST_USER)){
HttpSession httpSession = getThreadLocalRequest().getSession();
String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
logger.info("Request for CKAN licenses for scope " + scope); logger.warn("Session expired, returning null token");
return null;
// get key per scope }else{
String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
LicensesBean licensesBean = null; // get http session
if(httpSession.getAttribute(keyPerScope) != null){ HttpSession httpSession = getThreadLocalRequest().getSession();
licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope); String scope = (String)httpSession.getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
logger.debug("List of licenses was into session"); logger.info("Request for CKAN licenses for scope " + scope);
} String keyPerScope = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_LICENSES_KEY, scope);
else{
List<CkanLicense> titlesLicenses = getCatalogue(scope).getLicenses(); LicensesBean licensesBean = null;
List<String> titles = new ArrayList<String>(); if(httpSession.getAttribute(keyPerScope) != null){
List<String> urls = new ArrayList<String>(); licensesBean = (LicensesBean)httpSession.getAttribute(keyPerScope);
for (CkanLicense license : titlesLicenses) { logger.info("List of licenses was into session");
titles.add(license.getTitle()); }
String url = (license.getUrl() != null && !license.getUrl().isEmpty()) ? license.getUrl() : ""; else{
urls.add(url); List<CkanLicense> titlesLicenses = getCatalogue(scope).getLicenses();
List<String> titles = new ArrayList<String>();
List<String> urls = new ArrayList<String>();
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 @Override
@ -254,11 +250,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
logger.info("DatasetBean request for " + folderId + " and " + userName); 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()){ if(isWithinPortal()){
try{ try{
@ -268,9 +259,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
return null; 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 logger.debug("Request dataset metadata bean for folder with id " + folderId
+ " whose owner is " + userName); + " whose owner is " + userName);
// get usermanager (liferay)
UserManager liferUserManager = new LiferayUserManager(); UserManager liferUserManager = new LiferayUserManager();
GCubeUser userOwner = liferUserManager.getUserByUsername(userName); GCubeUser userOwner = liferUserManager.getUserByUsername(userName);
@ -290,9 +286,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
// if the request comes from the workspace // if the request comes from the workspace
if(folderId != null && !folderId.isEmpty()){ if(folderId != null && !folderId.isEmpty()){
WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean);
} }
}catch(Exception e){ }catch(Exception e){
@ -301,7 +295,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}else{ }else{
try{ try{
bean = new DatasetMetadataBean(); bean = new DatasetMetadataBean();
bean.setId(folderId); bean.setId(folderId);
bean.setDescription("This is a fantastic description"); bean.setDescription("This is a fantastic description");
@ -317,11 +310,8 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
bean.setOwnerIdentifier(userName); bean.setOwnerIdentifier(userName);
if(folderId != null && !folderId.isEmpty()){ if(folderId != null && !folderId.isEmpty()){
WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean); WorkspaceUtils.handleWorkspaceResources(folderId, userName, bean);
} }
}catch(Exception e){ }catch(Exception e){
logger.error("Error while building bean into dev mode", 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 // check if session expired
if(userName.equals(TEST_USER)){ if(userName.equals(TEST_USER)){
logger.debug("SESSION EXPIRED"); logger.warn("SESSION EXPIRED");
return null; return null;
} }
@ -379,7 +369,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if(datasetId != null){ if(datasetId != null){
logger.debug("Dataset created!"); logger.info("Dataset created!");
toCreate.setId(datasetId); toCreate.setId(datasetId);
// retrieve the url // retrieve the url
@ -427,7 +417,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
@Override @Override
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) { public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) {
ASLSession session = getASLSession(); ASLSession session = getASLSession();
String username = session.getUsername(); String username = session.getUsername();
@ -442,13 +431,10 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
}else{ }else{
if(username.equals(TEST_USER)){ if(username.equals(TEST_USER)){
logger.warn("SESSION EXPIRED!");
logger.warn("SESSION EXPIRED! ");
return null; return null;
}else{ }else{
try{ try{
ResourceBean resourceBean = new ResourceBean( ResourceBean resourceBean = new ResourceBean(
resource.getUrl(), resource.getUrl(),
resource.getName(), resource.getName(),
@ -501,7 +487,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
deleted = getCatalogue(scope). deleted = getCatalogue(scope).
deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), getUserCKanTokenFromSession(scope)); deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), getUserCKanTokenFromSession(scope));
if(deleted){ if(deleted){
logger.debug("Resource described by " + resource + " deleted"); logger.info("Resource described by " + resource + " deleted");
}else }else
logger.error("Resource described by " + resource + " NOT deleted"); logger.error("Resource described by " + resource + " NOT deleted");
}catch(Exception e){ }catch(Exception e){
@ -516,7 +502,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
public List<MetaDataProfileBean> getProfiles(String orgName) { public List<MetaDataProfileBean> getProfiles(String orgName) {
logger.debug("Requested profiles for products into orgName " + orgName); logger.debug("Requested profiles for products into orgName " + orgName);
List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>(); List<MetaDataProfileBean> toReturn = new ArrayList<MetaDataProfileBean>();
try{ try{
String evaluatedScope = getScopeFromOrgName(orgName); String evaluatedScope = getScopeFromOrgName(orgName);
@ -534,17 +519,13 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
if(title == null || title.isEmpty()) if(title == null || title.isEmpty())
return true; // it's an error somehow return true; // it's an error somehow
try{ try{
String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL); String scope = (String)getThreadLocalRequest().getSession().getAttribute(SessionCatalogueAttributes.SCOPE_CLIENT_PORTLET_URL);
String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title); String idFromTitle = org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(title);
return getCatalogue(scope).existProductWithNameOrId(idFromTitle); return getCatalogue(scope).existProductWithNameOrId(idFromTitle);
}catch(Exception e){ }catch(Exception e){
logger.error("Unable to check if such a dataset id already exists", e); logger.error("Unable to check if such a dataset id already exists", e);
} }
return false; return false;
} }
@ -555,7 +536,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
private String getScopeFromOrgName(String orgName){ private String getScopeFromOrgName(String orgName){
logger.debug("Request for scope related to orgName " + orgName + "[ map that will be used is " + mapOrganizationScope.toString() + " ]"); logger.debug("Request for scope related to orgName " + orgName + "[ map that will be used is " + mapOrganizationScope.toString() + " ]");
if(orgName == null || orgName.isEmpty()) if(orgName == null || orgName.isEmpty())
throw new IllegalArgumentException("orgName cannot be empty or null!"); throw new IllegalArgumentException("orgName cannot be empty or null!");
@ -565,22 +545,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
toReturn = mapOrganizationScope.get(orgName); toReturn = mapOrganizationScope.get(orgName);
else{ else{
try{ try{
String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName); String evaluatedScope = Utils.retrieveScopeFromOrganizationName(orgName);
mapOrganizationScope.put(orgName, evaluatedScope); mapOrganizationScope.put(orgName, evaluatedScope);
toReturn = evaluatedScope; toReturn = evaluatedScope;
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e); logger.error("Failed to retrieve scope from OrgName for organization " + orgName, e);
} }
} }
logger.debug("Returning scope " + toReturn); logger.debug("Returning scope " + toReturn);
return toReturn; return toReturn;
} }
//
// @Override // @Override
// public ResourceElementBean getTreeFolder(String folderId) { // public ResourceElementBean getTreeFolder(String folderId) {
// //

View File

@ -55,13 +55,16 @@ public class WorkspaceUtils {
copiedFolder.setDescription(bean.getDescription()); copiedFolder.setDescription(bean.getDescription());
// change name of the copied folder to match the title (append the timestamp to avoid ties) // 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 // copy only the selected ones
for(ResourceElementBean resource : resourcesToAdd){ for(ResourceElementBean resource : resourcesToAdd){
if (resource.isToBeAdded()) { if (resource.isToBeAdded()) {
logger.debug("Resource to add is " + resource);
// ok it is a file, so copy it into the copiedFolder // ok it is a file, so copy it into the copiedFolder
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId()); WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId());
@ -74,15 +77,13 @@ public class WorkspaceUtils {
copiedFile.getDescription(), copiedFile.getDescription(),
copiedFile.getId(), copiedFile.getId(),
userName, userName,
null, // to be set null, // dataset id, to be set
((FolderItem)copiedFile).getMimeType())); ((FolderItem)copiedFile).getMimeType()));
// postpone rename operation // postpone rename operation
copiedFile.rename(resource.getName() + "_" + System.currentTimeMillis()); copiedFile.rename(resource.getName() + "_" + referenceTime);
} }
} }
// return
return resources; return resources;
} }
@ -128,22 +129,23 @@ public class WorkspaceUtils {
* @throws Exception * @throws Exception
*/ */
public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace ws) throws Exception{ public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace ws) throws Exception{
// start tree construction
ResourceElementBean rootElem = new ResourceElementBean(); ResourceElementBean rootElem = new ResourceElementBean();
String pathSeparator = ws.getPathSeparator(); String pathSeparator = ws.getPathSeparator();
try{ try{
WorkspaceItem initialItemWS = ws.getItem(workspaceFolderId); WorkspaceItem initialItem = ws.getItem(workspaceFolderId);
String fullPathBase = initialItemWS.getPath(); String fullPathBase = initialItem.getPath();
fullPathBase = fullPathBase.endsWith(ws.getPathSeparator()) ? fullPathBase : fullPathBase + ws.getPathSeparator(); fullPathBase = fullPathBase.endsWith(ws.getPathSeparator()) ? fullPathBase : fullPathBase + ws.getPathSeparator();
rootElem.setFolder(initialItemWS.isFolder()); rootElem.setFolder(initialItem.isFolder());
rootElem.setFullPath(initialItemWS.getPath().replace(fullPathBase, "")); rootElem.setFullPath(initialItem.getPath().replace(fullPathBase, ""));
rootElem.setParent(null); rootElem.setParent(null);
rootElem.setName(initialItemWS.getName()); rootElem.setName(initialItem.getName());
rootElem.setOriginalIdInWorkspace(initialItemWS.getId()); rootElem.setOriginalIdInWorkspace(initialItem.getId());
replaceFullPath(rootElem, pathSeparator); rootElem.setDescription(initialItem.getDescription());
// start visiting extractEditableNameFromPath(rootElem, pathSeparator);
visit(rootElem, initialItemWS, fullPathBase, pathSeparator);
// recursive visiting
if(initialItem.isFolder())
visit(rootElem, initialItem, fullPathBase, pathSeparator);
}catch(Exception e){ }catch(Exception e){
logger.error("Failed to build the resource tree", e); logger.error("Failed to build the resource tree", e);
return null; return null;
@ -151,44 +153,47 @@ public class WorkspaceUtils {
return rootElem; 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 * Recursive visit of a workspace item
* @param rootElem * @param rootElem
* @param initialItemWS * @param initialItemWS
* @throws InternalErrorException * @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<? extends WorkspaceItem> children = initialItemWS.getChildren(); List<? extends WorkspaceItem> children = initialItemWS.getChildren();
ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size()); ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size());
for (WorkspaceItem workspaceItem : children) { for (WorkspaceItem item : children) {
ResourceElementBean elem = new ResourceElementBean(); ResourceElementBean elem = new ResourceElementBean();
elem.setFolder(workspaceItem.isFolder()); elem.setFolder(item.isFolder());
elem.setOriginalIdInWorkspace(workspaceItem.getId()); elem.setOriginalIdInWorkspace(item.getId());
elem.setFullPath(workspaceItem.getPath().replace(fullPathBase, "")); elem.setFullPath(item.getPath().replace(fullPathBase, ""));
elem.setParent(rootElem); elem.setParent(parent);
elem.setName(workspaceItem.getName()); elem.setName(item.getName());
replaceFullPath(elem, pathSeparator); elem.setDescription(item.getDescription());
extractEditableNameFromPath(elem, pathSeparator);
childrenInTree.add(elem); 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);
} }
} }

View File

@ -15,16 +15,17 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
private static final long serialVersionUID = -1230871392599580669L; private static final long serialVersionUID = -1230871392599580669L;
private int identifierGWT; private int identifierGWT;
private String name; private String name;
private String editableName;
private boolean toBeAdded; private boolean toBeAdded;
private boolean isFolder; private boolean isFolder;
private ResourceElementBean parent;
private List<ResourceElementBean> children;
private String fullPath; private String fullPath;
private String originalIdInWorkspace; private String originalIdInWorkspace;
private String mimeType; private String mimeType;
private String url; private String url;
private String description; private String description;
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
private ResourceElementBean parent;
private List<ResourceElementBean> children;
// to generate the identifiers // to generate the identifiers
private static int nextId = 0; private static int nextId = 0;
@ -45,6 +46,9 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
*/ */
public ResourceElementBean(ResourceElementBean another) { public ResourceElementBean(ResourceElementBean another) {
this.name = another.name; this.name = another.name;
this.toBeAdded = another.toBeAdded;
this.fullPath = another.fullPath;
this.editableName = another.editableName;
this.originalIdInWorkspace = another.originalIdInWorkspace; this.originalIdInWorkspace = another.originalIdInWorkspace;
this.mimeType = another.mimeType; this.mimeType = another.mimeType;
this.url = another.url; this.url = another.url;
@ -206,6 +210,14 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
this.originalIdInWorkspace = originalIdInWorkspace; this.originalIdInWorkspace = originalIdInWorkspace;
} }
public String getEditableName() {
return editableName;
}
public void setEditableName(String newName) {
this.editableName = newName;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
boolean toReturn = false; boolean toReturn = false;
@ -216,21 +228,22 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
return toReturn; 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 @Override
public int compareTo(ResourceElementBean o) { public int compareTo(ResourceElementBean o) {
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath); int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
return toReturn; 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()) + "]";
}
} }