minor fixes
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134106 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
23c424ccab
commit
1cf1c8a366
|
@ -20,7 +20,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
|
||||
|
|
|
@ -67,7 +67,7 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
// childrenOfA.add(elementW);
|
||||
// childrenOfW.add(new ResourceElementBean(elementW, "File J", false, null, "Folder A:File W: File J"));
|
||||
// listLeft.add(elementA);
|
||||
|
||||
//
|
||||
// String folderId = "e87bfc7d-4fb0-4795-9c79-0c495500ca9c";
|
||||
// ckanServices.getTreeFolder(folderId, new AsyncCallback<ResourceElementBean>() {
|
||||
//
|
||||
|
@ -75,8 +75,7 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
// @Override
|
||||
// public void onSuccess(ResourceElementBean result) {
|
||||
// if(result != null){
|
||||
// List<ResourceElementBean> children = result.getChildren();
|
||||
// RootPanel.get("ckan-metadata-publisher-div").add(new TwinColumnSelectionMainPanel(children));
|
||||
// RootPanel.get("ckan-metadata-publisher-div").add(new TwinColumnSelectionMainPanel(result));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -336,14 +336,14 @@ public class CreateDatasetForm extends Composite{
|
|||
|
||||
if(isWorkspaceRequest){
|
||||
|
||||
// if there are not resources, for now just checked it ( and hide so that the step will be skipped) TODO
|
||||
// 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()){
|
||||
|
||||
alertNoResources.setType(AlertType.WARNING);
|
||||
alertNoResources.setVisible(true);
|
||||
|
||||
}else
|
||||
resourcesTwinPanel = new TwinColumnSelectionMainPanel(bean.getResources());
|
||||
resourcesTwinPanel = new TwinColumnSelectionMainPanel(bean.getResources().get(0));
|
||||
|
||||
}
|
||||
|
||||
|
@ -656,8 +656,9 @@ public class CreateDatasetForm extends Composite{
|
|||
formThirdStep.setVisible(!resourcesPresent);
|
||||
|
||||
// add the resources to the container panel
|
||||
if(workspaceResourcesContainer.getWidget() == null)
|
||||
if(workspaceResourcesContainer.getWidget() == null){
|
||||
workspaceResourcesContainer.add(resourcesTwinPanel);
|
||||
}
|
||||
|
||||
}else{
|
||||
|
||||
|
|
|
@ -302,7 +302,8 @@
|
|||
</b:ControlGroup>
|
||||
|
||||
<g:SimplePanel ui:field="workspaceResourcesContainer"
|
||||
visible="true"></g:SimplePanel>
|
||||
width="100%" visible="true">
|
||||
</g:SimplePanel>
|
||||
|
||||
<b:Button title="Continue" ui:field="continueThirdStep"
|
||||
type="PRIMARY" block="true">Continue</b:Button>
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
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.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Icon;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
/**
|
||||
* Cell that renders left side panel objects
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
|
||||
|
||||
private static final String HTML_FILE = new Icon(IconType.FILE_ALT).toString();
|
||||
private static final String HTML_FOLDER = new Icon(IconType.FOLDER_CLOSE_ALT).toString();
|
||||
private static final Images image = GWT.create(Images.class);
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
|
@ -24,9 +22,19 @@ public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
|
|||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<div style='width:100%; padding:2px'>");
|
||||
sb.appendHtmlConstant(value.isFolder() ? HTML_FOLDER : HTML_FILE);
|
||||
sb.appendHtmlConstant("<span style='margin-left:5px'>");
|
||||
Image file = new Image(image.fileIcon());
|
||||
Image folder = new Image(image.folderIcon());
|
||||
|
||||
file.setWidth("15px");
|
||||
file.setHeight("15px");
|
||||
folder.setWidth("15px");
|
||||
folder.setHeight("15px");
|
||||
|
||||
sb.appendHtmlConstant("<div style='width:100%; min-height:30px; padding-top:5px;'>");
|
||||
sb.appendHtmlConstant("<span style='margin-left:5px;'>");
|
||||
sb.appendHtmlConstant(value.isFolder() ? folder.toString() : file.toString());
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("<span style='margin-left:10px;'>");
|
||||
sb.appendHtmlConstant("<b>");
|
||||
sb.appendEscaped(value.getName());
|
||||
sb.appendHtmlConstant("</b>");
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
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.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Icon;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
/**
|
||||
* Cell that renders right side panel objects
|
||||
|
@ -13,7 +14,7 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|||
*/
|
||||
public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
|
||||
|
||||
private static final String HTML_FILE = new Icon(IconType.FILE_ALT).toString();
|
||||
private static final Images image = GWT.create(Images.class);
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
|
@ -23,14 +24,20 @@ public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
|
|||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<div style='width:100%; padding:2px'>");
|
||||
sb.appendHtmlConstant(HTML_FILE);
|
||||
Image file = new Image(image.fileIcon());
|
||||
|
||||
file.setWidth("15px");
|
||||
file.setHeight("15px");
|
||||
|
||||
sb.appendHtmlConstant("<div style='width:100%; min-height:30px'>");
|
||||
sb.appendHtmlConstant("<span style='margin-left:5px'>");
|
||||
sb.appendHtmlConstant(file.toString());
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("<span style='margin-left:10px'>");
|
||||
sb.appendHtmlConstant("<b>");
|
||||
sb.appendEscaped(value.getFullPath());
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("</div>");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -7,7 +8,10 @@ import java.util.Set;
|
|||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
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.core.client.GWT;
|
||||
|
@ -49,15 +53,32 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
@UiField
|
||||
Button allToLeftButton;
|
||||
@UiField
|
||||
Button goRootButton;
|
||||
@UiField
|
||||
Button goUpButton;
|
||||
@UiField
|
||||
Popover popoverResourceSelection;
|
||||
@UiField
|
||||
Button resourceInfoButton;
|
||||
@UiField
|
||||
Breadcrumbs breadcrumbs;
|
||||
@UiField
|
||||
FluidContainer mainContainerResourcesSelection;
|
||||
// @UiField
|
||||
// Button getResources;
|
||||
|
||||
private static final String PANEL_BORDER_COLOR = "#08c";
|
||||
/**
|
||||
* The breadcrumb subpath with the linked folder
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
private class PathBean{
|
||||
NavLink link;
|
||||
ResourceElementBean resourceFolder;
|
||||
|
||||
PathBean(NavLink link, ResourceElementBean resourceFolder){
|
||||
this.link = link;
|
||||
this.resourceFolder = resourceFolder;
|
||||
}
|
||||
}
|
||||
|
||||
private List<PathBean> pathListBeans = new ArrayList<PathBean>();
|
||||
// private static final String PANEL_BORDER_COLOR = "#08c";
|
||||
private static final String PANEL_HEIGHT = "400px";
|
||||
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel();
|
||||
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel();
|
||||
|
@ -67,10 +88,12 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
private ListDataProvider<ResourceElementBean> dataProviderRight = new ListDataProvider<ResourceElementBean>();
|
||||
private MultiSelectionModel<ResourceElementBean> selectionModelRight;
|
||||
private MultiSelectionModel<ResourceElementBean> selectionModelLeft;
|
||||
private final List<ResourceElementBean> initialElements;
|
||||
private final ResourceElementBean initialBean;
|
||||
private final static HTML aboutHeader = new HTML("<b>Resource Manager</b>");
|
||||
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 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>");
|
||||
|
||||
// private static final int PATH_THRESHOLD = 1; // TODO
|
||||
|
||||
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
|
||||
.create(TwinColumnSelectionMainPanelUiBinder.class);
|
||||
|
@ -79,39 +102,42 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
UiBinder<Widget, TwinColumnSelectionMainPanel> {
|
||||
}
|
||||
|
||||
public TwinColumnSelectionMainPanel(List<ResourceElementBean> elements) {
|
||||
public TwinColumnSelectionMainPanel(ResourceElementBean initialBean) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
|
||||
this.initialElements = elements;
|
||||
this.buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT);
|
||||
this.initialBean = initialBean;
|
||||
|
||||
goRootButton.getElement().getStyle().setPaddingLeft(0, Unit.PX);
|
||||
this.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);
|
||||
prepareHandlers();
|
||||
initLeftSidePanel(elements);
|
||||
initRightSidePanel();
|
||||
resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX);
|
||||
mainContainerResourcesSelection.getElement().getStyle().setPadding(20, Unit.PX);
|
||||
|
||||
prepareHandlers();
|
||||
initLeftSidePanel(initialBean);
|
||||
initRightSidePanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the left side panel
|
||||
*/
|
||||
private void initLeftSidePanel(List<ResourceElementBean> elements) {
|
||||
private void initLeftSidePanel(final ResourceElementBean initialBean) {
|
||||
|
||||
// initialize the left side list
|
||||
ResourceCellLeft cell = new ResourceCellLeft();
|
||||
|
||||
// Set a key provider that provides a unique key for each object.
|
||||
cellListLeft = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER);
|
||||
cellListLeft.setPageSize(elements.size());
|
||||
cellListLeft.setPageSize(initialBean.getChildren().size());
|
||||
cellListLeft.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
|
||||
|
||||
// Add a selection model so we can select cells.
|
||||
|
@ -122,14 +148,40 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
||||
public void onSelectionChange(SelectionChangeEvent event) {
|
||||
Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator();
|
||||
|
||||
while (selectedObjectsIterator.hasNext()) {
|
||||
ResourceElementBean selectedBean = (ResourceElementBean) selectedObjectsIterator.next();
|
||||
if(selectedBean.isFolder()){
|
||||
|
||||
// a single folder selected
|
||||
if(selectionModelLeft.getSelectedSet().size() == 1){
|
||||
|
||||
// update path
|
||||
final NavLink navElem = new NavLink(selectedBean.getName());
|
||||
final PathBean pathBean = new PathBean(navElem, selectedBean);
|
||||
|
||||
navElem.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
removeStartingFromBreadcrumbs(navElem, pathBean);
|
||||
// breadcrumbsUpdater();
|
||||
ResourceElementBean folder = pathBean.resourceFolder;
|
||||
Collections.sort(folder.getChildren());
|
||||
dataProviderLeft.setList(folder.getChildren());
|
||||
dataProviderLeft.refresh();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
pathListBeans.add(pathBean);
|
||||
breadcrumbs.add(navElem);
|
||||
// breadcrumbsUpdater();
|
||||
|
||||
Collections.sort(selectedBean.getChildren());
|
||||
dataProviderLeft.setList(selectedBean.getChildren());
|
||||
dataProviderLeft.refresh();
|
||||
dataProviderLeft.flush();
|
||||
}
|
||||
selectionModelLeft.setSelected(selectedBean, false);
|
||||
}
|
||||
|
@ -140,8 +192,28 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
});
|
||||
|
||||
// set the list into the provider
|
||||
Collections.sort(elements);
|
||||
dataProviderLeft.setList(elements);
|
||||
Collections.sort(this.initialBean.getChildren());
|
||||
dataProviderLeft.setList(this.initialBean.getChildren());
|
||||
|
||||
// add root to breadcrumb
|
||||
final NavLink root = new NavLink(initialBean.getName());
|
||||
final PathBean pathBean = new PathBean(root, initialBean);
|
||||
pathListBeans.add(pathBean);
|
||||
breadcrumbs.add(root);
|
||||
|
||||
root.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
removeStartingFromBreadcrumbs(root, pathBean);
|
||||
// breadcrumbsUpdater();
|
||||
|
||||
// set back the root content list
|
||||
dataProviderLeft.setList(initialBean.getChildren());
|
||||
dataProviderLeft.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
// set the cell list into the provider
|
||||
dataProviderLeft.addDataDisplay(cellListLeft);
|
||||
|
@ -150,12 +222,48 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
showMorePanelLeft.setDisplay(cellListLeft);
|
||||
showMorePanelLeft.setHeight(PANEL_HEIGHT);
|
||||
showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
|
||||
showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
|
||||
showMorePanelLeft.getElement().getStyle().setBorderWidth(1, Unit.PX);
|
||||
// showMorePanelLeft.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
|
||||
|
||||
// add the list to the leftContainerPanel
|
||||
leftContainer.add(showMorePanelLeft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the path
|
||||
* @param navElem
|
||||
* @param pathBean
|
||||
*/
|
||||
public void removeStartingFromBreadcrumbs(NavLink navElem, PathBean pathBean){
|
||||
|
||||
// remove data after
|
||||
Iterator<Widget> iteratorBreadcrumb = breadcrumbs.iterator();
|
||||
Iterator<PathBean> iteratorListPath = pathListBeans.iterator();
|
||||
|
||||
boolean delete = false;
|
||||
while(iteratorBreadcrumb.hasNext()){
|
||||
Widget current = iteratorBreadcrumb.next();
|
||||
|
||||
if(delete)
|
||||
iteratorBreadcrumb.remove();
|
||||
|
||||
if(!delete && navElem.equals(current))
|
||||
delete = true;
|
||||
}
|
||||
|
||||
delete = false;
|
||||
while(iteratorListPath.hasNext()){
|
||||
PathBean current = iteratorListPath.next();
|
||||
|
||||
if(delete)
|
||||
iteratorListPath.remove();
|
||||
|
||||
if(!delete && pathBean.equals(current))
|
||||
delete = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the left side panel
|
||||
*/
|
||||
|
@ -186,7 +294,8 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
showMorePanelRight.setDisplay(cellListRight);
|
||||
showMorePanelRight.setHeight(PANEL_HEIGHT);
|
||||
showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
|
||||
showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
|
||||
showMorePanelRight.getElement().getStyle().setBorderWidth(1, Unit.PX);
|
||||
// showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
|
||||
|
||||
// add the list to the leftContainerPanel
|
||||
rightContainer.add(showMorePanelRight);
|
||||
|
@ -238,77 +347,31 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
*/
|
||||
private void prepareHandlers() {
|
||||
|
||||
goRootButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
dataProviderLeft.setList(initialElements);
|
||||
dataProviderLeft.flush();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
goUpButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
ResourceElementBean firstElemCurrList = dataProviderLeft.getList().get(0);
|
||||
if(firstElemCurrList.getParent() == null){
|
||||
GWT.log("It is the root ...");
|
||||
return;
|
||||
}else{
|
||||
// get the children of the parent and show them
|
||||
GWT.log("Called " + firstElemCurrList.getParent());
|
||||
if(firstElemCurrList.getParent().getParent() == null){
|
||||
// still the root
|
||||
dataProviderLeft.setList(initialElements);
|
||||
}else{
|
||||
dataProviderLeft.setList(firstElemCurrList.getParent().getParent().getChildren());
|
||||
}
|
||||
dataProviderLeft.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
allToRightButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
moveToRight(selectionModelLeft.getSelectedSet());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
toRightButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
moveToRight(selectionModelLeft.getSelectedSet());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
allToLeftButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
moveToLeft(selectionModelRight.getSelectedSet());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
toLeftButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
moveToLeft(selectionModelRight.getSelectedSet());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -367,6 +430,12 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
*/
|
||||
public void freeze() {
|
||||
|
||||
Iterator<Widget> iteratorOverPath = breadcrumbs.iterator();
|
||||
while (iteratorOverPath.hasNext()) {
|
||||
Widget widget = (Widget) iteratorOverPath.next();
|
||||
if(widget instanceof NavLink)
|
||||
((NavLink)widget).setActive(false);
|
||||
}
|
||||
allToRightButton.setEnabled(false);
|
||||
toRightButton.setEnabled(false);
|
||||
allToLeftButton.setEnabled(false);
|
||||
|
@ -378,7 +447,59 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
* @return the resources to save
|
||||
*/
|
||||
public List<ResourceElementBean> getResourcesToPublish(){
|
||||
return dataProviderRight.getList();
|
||||
List<ResourceElementBean> current = dataProviderRight.getList();
|
||||
|
||||
List<ResourceElementBean> toReturn = new ArrayList<ResourceElementBean>();
|
||||
|
||||
for (ResourceElementBean resourceElementBean : current) {
|
||||
resourceElementBean.setName(resourceElementBean.getFullPath());
|
||||
ResourceElementBean beanWithoutChildren = new ResourceElementBean(resourceElementBean);
|
||||
toReturn.add(beanWithoutChildren);
|
||||
}
|
||||
|
||||
GWT.log("List " + toReturn);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
// @UiHandler("getResources")
|
||||
// void getResources(ClickEvent ce){
|
||||
// getResourcesToPublish();
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Short the current path if needed TODO
|
||||
// */
|
||||
// private void breadcrumbsUpdater(){
|
||||
//
|
||||
// // ignore first and last elem
|
||||
// boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD;
|
||||
//
|
||||
// GWT.log("List is " + pathListBeans.toString());
|
||||
//
|
||||
// if(!reduce){
|
||||
// GWT.log("Restore");
|
||||
// for(int i = 1; i < pathListBeans.size(); i++){
|
||||
// PathBean bean = pathListBeans.get(i);
|
||||
// bean.link.setText(bean.resourceFolder.getName());
|
||||
// bean.link.setVisible(true);
|
||||
// }
|
||||
// }else{
|
||||
// for(int i = 1; i < pathListBeans.size(); i++){
|
||||
// PathBean bean = pathListBeans.get(i);
|
||||
//
|
||||
// if(i == (pathListBeans.size() - 1)){
|
||||
// bean.link.setText(bean.resourceFolder.getName());
|
||||
// bean.link.setVisible(true);
|
||||
// }else if(i == (pathListBeans.size() - 2)){
|
||||
// GWT.log("The last to modify ****");
|
||||
// bean.link.setText("...");
|
||||
// bean.link.setVisible(true);
|
||||
// }else{
|
||||
// bean.link.setText(bean.resourceFolder.getName());
|
||||
// bean.link.setVisible(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// GWT.log("Updated list is " + pathListBeans.toString());
|
||||
// }
|
||||
}
|
|
@ -2,42 +2,49 @@
|
|||
<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>
|
||||
.right-vertical-panel {
|
||||
margin-top: 30px;
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<g:SimplePanel width="100%">
|
||||
<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:Button ui:field="resourceInfoButton" type="LINK" icon="INFO_SIGN"
|
||||
size="LARGE"></b:Button>
|
||||
</b:Popover>
|
||||
</g:SimplePanel>
|
||||
<b:FluidContainer>
|
||||
</b:Column>
|
||||
</b:FluidRow>
|
||||
<b:FluidRow>
|
||||
<b:Column size="7">
|
||||
<b:Breadcrumbs ui:field="breadcrumbs" divider=">">
|
||||
</b:Breadcrumbs>
|
||||
</b:Column>
|
||||
</b:FluidRow>
|
||||
<b:FluidRow>
|
||||
<b:Column size="3" ui:field="leftColumn">
|
||||
<b:Button enabled="true" type="LINK" ui:field="goRootButton">Root level</b:Button>
|
||||
<b:Button enabled="true" type="LINK" ui:field="goUpButton">Go up</b:Button>
|
||||
<!-- <b:Button enabled="true" type="LINK" ui:field="goRootButton">Root
|
||||
level</b:Button> -->
|
||||
<!-- <b:Button enabled="true" type="LINK" ui:field="goUpButton">Go up</b:Button> -->
|
||||
<g:VerticalPanel ui:field="leftContainer" width="100%">
|
||||
</g:VerticalPanel>
|
||||
</b:Column>
|
||||
<b:Column size="1" ui:field="centralPanel">
|
||||
<g:VerticalPanel ui:field="buttonsPanel">
|
||||
<b:Button ui:field="allToRightButton" name="toRight"
|
||||
enabled="false" title="Move selected files to right" text=">>" />
|
||||
enabled="false" title="Add selected files" text=">>" />
|
||||
<b:Button ui:field="toRightButton" name="toRight"
|
||||
enabled="false" title="Move selected file to the right" text=">" />
|
||||
enabled="false" title="Add selected file" text=">" />
|
||||
<b:Button ui:field="toLeftButton" name="toLeft" enabled="false"
|
||||
title="Move selected file to the left" text="<" />
|
||||
title="Remove selected file" text="<" />
|
||||
<b:Button ui:field="allToLeftButton" name="toRight"
|
||||
enabled="false" title="Move selected files to left" text="<<" />
|
||||
enabled="false" title="Remove selected files" text="<<" />
|
||||
</g:VerticalPanel>
|
||||
</b:Column>
|
||||
<b:Column size="3" ui:field="rightColumn">
|
||||
<g:VerticalPanel ui:field="rightContainer"
|
||||
styleName="{style.right-vertical-panel}" width="100%"></g:VerticalPanel>
|
||||
<g:VerticalPanel ui:field="rightContainer" width="100%"></g:VerticalPanel>
|
||||
</b:Column>
|
||||
</b:FluidRow>
|
||||
</b:FluidContainer>
|
||||
<!-- <b:Button ui:field="getResources">Get Resources</b:Button> -->
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
|
@ -0,0 +1,13 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.icons;
|
||||
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
|
||||
public interface Images extends ClientBundle {
|
||||
|
||||
@Source("file.png")
|
||||
ImageResource fileIcon();
|
||||
|
||||
@Source("folder.png")
|
||||
ImageResource folderIcon();
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 527 B |
|
@ -32,10 +32,8 @@ public class GcubeDialogExtended extends GCubeDialog {
|
|||
FlexTable captionLayoutTable = new FlexTable();
|
||||
captionLayoutTable.setText(0, 0, captionText);
|
||||
captionLayoutTable.setWidget(0, 3, closeAnchor);
|
||||
captionLayoutTable.getCellFormatter().setHorizontalAlignment(0, 3,
|
||||
HasHorizontalAlignment.ALIGN_RIGHT);
|
||||
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());
|
||||
|
@ -56,13 +54,9 @@ public class GcubeDialogExtended extends GCubeDialog {
|
|||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
hide();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// set the text
|
||||
add(new Paragraph(text));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ 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 = "Folder content will be added as resources of the product";
|
||||
public static final String RESOURCES_INFO_TEXT = "Manage the resources you want to associate to the product.";
|
||||
|
||||
// CUSTOM FIELDS
|
||||
public static final String CUSTOM_FIELDS_INFO_ID_POPUP = "custom-fields-popup-panel-info";
|
||||
|
|
|
@ -66,7 +66,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
||||
instance = DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover, e);
|
||||
logger.warn("Unable to retrieve ckan utils in scope " + scopeInWhichDiscover + ". Error is " + e.toString());
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
@ -366,7 +366,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
// we need to copy such resource in the .catalogue area of the user's ws
|
||||
if(resourcesToAdd != null && !resourcesToAdd.isEmpty()){
|
||||
resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(resourcesToAdd, toCreate.getId(), userName, toCreate);
|
||||
resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(toCreate.getId(), userName, toCreate);
|
||||
}
|
||||
|
||||
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
|
||||
|
@ -580,7 +580,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// @Override
|
||||
// public ResourceElementBean getTreeFolder(String folderId) {
|
||||
//
|
||||
|
@ -598,7 +598,6 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// return toReturn;
|
||||
// }else{
|
||||
// if(session.getUsername().equals(TEST_USER)){
|
||||
// logger.warn("SESSION EXPIRED!");
|
||||
// return null;
|
||||
// }else{
|
||||
// // TODO
|
||||
|
@ -610,7 +609,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
//
|
||||
// /**
|
||||
// * Retrieve the workspace for the development user
|
||||
// * @return
|
||||
|
|
|
@ -64,7 +64,7 @@ public class Utils {
|
|||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Utils.class);
|
||||
private static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
|
||||
private static final String NOTIFICATION_MESSAGE = "Dear members,<br>The product <b></em>PRODUCT_TITLE</em></b> has been just published by <b>USER_FULLNAME</b>.<br>You can find it here: PRODUCT_URL <br>";
|
||||
private static final String NOTIFICATION_MESSAGE = "Dear members,<br>The product PRODUCT_TITLE has been just published by USER_FULLNAME.<br>You can find it here: PRODUCT_URL <br>";
|
||||
private static final String SOCIAL_SERVICE_APPLICATION_TOKEN = "2/tokens/generate-application-token/";
|
||||
private static final String SOCIAL_SERVICE_WRITE_APPLICATION_POST = "2/posts/write-post-app/";
|
||||
private static final String MEDIATYPE_JSON = "application/json";
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -18,25 +19,24 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public class WorkspaceUtils {
|
||||
|
||||
/**
|
||||
* logger
|
||||
*/
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WorkspaceUtils.class);
|
||||
private static final String RESOURCES_NAME_SEPARATOR = "_";
|
||||
|
||||
/**
|
||||
* Copy into the .catalogue area folder the checked resources
|
||||
* @param resourcesToAdd
|
||||
* @param folderId
|
||||
* @param userName
|
||||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
public static List<ResourceBean> copyResourcesToUserCatalogueArea(List<ResourceElementBean> resourcesToAdd, String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
||||
public static List<ResourceBean> copyResourcesToUserCatalogueArea(String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
||||
|
||||
logger.debug("Request to copy onto catalogue area....");
|
||||
List<ResourceBean> resources = new ArrayList<ResourceBean>();
|
||||
WorkspaceItem copiedFolder = null;
|
||||
WorkspaceCatalogue userCatalogue = null;
|
||||
List<ResourceElementBean> resourcesToAdd = bean.getResources();
|
||||
|
||||
// in to the .catalogue area of the user's workspace
|
||||
Workspace ws = HomeLibrary
|
||||
|
@ -58,19 +58,19 @@ public class WorkspaceUtils {
|
|||
((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + System.currentTimeMillis());
|
||||
|
||||
// copy only the selected ones
|
||||
for(ResourceElementBean resourceBeanWrapper : resourcesToAdd){
|
||||
for(ResourceElementBean resource : resourcesToAdd){
|
||||
|
||||
if (resourceBeanWrapper.isToBeAdded()) {
|
||||
if (resource.isToBeAdded()) {
|
||||
|
||||
// ok it is a file, so copy it into the copiedFolder
|
||||
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resourceBeanWrapper.getOriginalIdInWorkspace(), copiedFolder.getId());
|
||||
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resource.getOriginalIdInWorkspace(), copiedFolder.getId());
|
||||
|
||||
// name and description could have been edited
|
||||
copiedFile.setDescription(resourceBeanWrapper.getDescription());
|
||||
copiedFile.setDescription(resource.getDescription());
|
||||
|
||||
resources.add(new ResourceBean(
|
||||
copiedFile.getPublicLink(true),
|
||||
resourceBeanWrapper.getName(),
|
||||
resource.getName(),
|
||||
copiedFile.getDescription(),
|
||||
copiedFile.getId(),
|
||||
userName,
|
||||
|
@ -78,7 +78,7 @@ public class WorkspaceUtils {
|
|||
((FolderItem)copiedFile).getMimeType()));
|
||||
|
||||
// postpone rename operation
|
||||
copiedFile.rename(resourceBeanWrapper.getName() + "_" + System.currentTimeMillis());
|
||||
copiedFile.rename(resource.getName() + "_" + System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ public class WorkspaceUtils {
|
|||
bean.setCustomFields(folderItems);
|
||||
|
||||
// set them into the bean
|
||||
bean.setResources(WorkspaceUtils.getTreeFromFolder(folderId, ws).getChildren());
|
||||
bean.setResources(Arrays.asList(WorkspaceUtils.getTreeFromFolder(folderId, ws)));
|
||||
|
||||
}
|
||||
|
||||
|
@ -131,24 +131,41 @@ public class WorkspaceUtils {
|
|||
|
||||
// start tree construction
|
||||
ResourceElementBean rootElem = new ResourceElementBean();
|
||||
String pathSeparator = ws.getPathSeparator();
|
||||
try{
|
||||
WorkspaceItem initialItemWS = ws.getItem(workspaceFolderId);
|
||||
String fullPathBase = initialItemWS.getPath();
|
||||
// rootElem.setFolder(initialItemWS.isFolder());
|
||||
// rootElem.setFullPath(initialItemWS.getPath().replace(fullPathBase, ""));
|
||||
// rootElem.setParent(null);
|
||||
// rootElem.setName(initialItemWS.getName());
|
||||
// rootElem.setOriginalIdInWorkspace(initialItemWS.getId());
|
||||
// rootElem.setToBeAdded(false);
|
||||
// rootElem.setMimeType(((FolderItem)initialItemWS).getMimeType());
|
||||
// rootElem.setDescription(initialItemWS.getDescription());
|
||||
fullPathBase = fullPathBase.endsWith(ws.getPathSeparator()) ? fullPathBase : fullPathBase + ws.getPathSeparator();
|
||||
rootElem.setFolder(initialItemWS.isFolder());
|
||||
rootElem.setFullPath(initialItemWS.getPath().replace(fullPathBase, ""));
|
||||
rootElem.setParent(null);
|
||||
rootElem.setName(initialItemWS.getName());
|
||||
rootElem.setOriginalIdInWorkspace(initialItemWS.getId());
|
||||
replaceFullPath(rootElem, pathSeparator);
|
||||
// start visiting
|
||||
visit(rootElem, initialItemWS, fullPathBase);
|
||||
return rootElem;
|
||||
visit(rootElem, initialItemWS, fullPathBase, pathSeparator);
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to build the resource tree", e);
|
||||
return null;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -157,18 +174,19 @@ public class WorkspaceUtils {
|
|||
* @param initialItemWS
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
private static void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS, String fullPathBase) throws InternalErrorException {
|
||||
private static void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS, String fullPathBase, String pathSeparator) throws InternalErrorException {
|
||||
List<? extends WorkspaceItem> children = initialItemWS.getChildren();
|
||||
ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
ResourceElementBean elem = new ResourceElementBean();
|
||||
elem.setFolder(workspaceItem.isFolder());
|
||||
elem.setOriginalIdInWorkspace(workspaceItem.getId());
|
||||
elem.setFullPath(workspaceItem.getPath().replace(fullPathBase, "")); // remove this path
|
||||
elem.setFullPath(workspaceItem.getPath().replace(fullPathBase, ""));
|
||||
elem.setParent(rootElem);
|
||||
elem.setName(workspaceItem.getName());
|
||||
replaceFullPath(elem, pathSeparator);
|
||||
childrenInTree.add(elem);
|
||||
visit(elem, workspaceItem, fullPathBase);
|
||||
visit(elem, workspaceItem, fullPathBase, pathSeparator);
|
||||
}
|
||||
rootElem.setChildren(childrenInTree);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,19 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
* @param another
|
||||
*/
|
||||
public ResourceElementBean(ResourceElementBean another) {
|
||||
this.name = another.name;
|
||||
this.originalIdInWorkspace = another.originalIdInWorkspace;
|
||||
this.mimeType = another.mimeType;
|
||||
this.url = another.url;
|
||||
this.description = another.description;
|
||||
this.organizationNameDatasetParent = another.organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
|
@ -193,14 +206,6 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
this.originalIdInWorkspace = originalIdInWorkspace;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "ResourceElementBean [identifier=" + identifier + ", name="
|
||||
// + name + ", movedToRight=" + movedToRight + ", isFolder="
|
||||
// + isFolder + ", fullPath=" + fullPath + "]";
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
boolean toReturn = false;
|
||||
|
@ -213,9 +218,9 @@ public class ResourceElementBean implements Comparable<ResourceElementBean>, Ser
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceElementBean [identifierGWT=" + identifierGWT + ", name="
|
||||
+ name + ", toBeAdded=" + toBeAdded + ", isFolder=" + isFolder
|
||||
+ ", parent=" + parent + ", childrenSize=" + children.size()
|
||||
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
|
||||
|
|
|
@ -1,249 +1,17 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
||||
import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.DataCalogueMetadataFormatReader;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.MetadataType;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataField;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataFormat;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataValidator;
|
||||
import org.gcube.datacatalogue.metadatadiscovery.bean.jaxb.MetadataVocabulary;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.CKANPublisherServicesImpl;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.Utils;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Junit tests class
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class TestClass {
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestClass.class);
|
||||
|
||||
@Test
|
||||
public void testUser() {
|
||||
|
||||
assert(new CKANPublisherServicesImpl().getDevelopmentUser().equals(CKANPublisherServicesImpl.TEST_USER));
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testCopyResources() throws WorkspaceFolderNotFoundException, InternalErrorException, HomeNotFoundException, UserNotFoundException, ItemNotFoundException{
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
|
||||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("costantino.perciante").getWorkspace();
|
||||
|
||||
WorkspaceItem originalFolder = ws.getItem("d3a37eb9-1589-4c95-a9d0-c473a02d4f0f");
|
||||
|
||||
List<? extends WorkspaceItem> children = originalFolder.getChildren();
|
||||
// System.out.println("Folder is " + originalFolder.getName());
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// System.out.println("Child is " + workspaceItem.getName());
|
||||
// }
|
||||
|
||||
// copy to catalogue
|
||||
WorkspaceCatalogue userCatalogue = ws.getCatalogue();
|
||||
|
||||
WorkspaceItem copiedFolder = userCatalogue.addWorkspaceItem(originalFolder.getId(), userCatalogue.getId());
|
||||
System.out.println(copiedFolder.isHidden());
|
||||
// for (WorkspaceItem workspaceItem : children) {
|
||||
// WorkspaceItem copiedChildren = userCatalogue.addWorkspaceItem(workspaceItem.getId(), copiedFolder.getId());
|
||||
// System.out.println("****************************** Copied file has path " + copiedChildren.getPath());
|
||||
// }
|
||||
|
||||
// look at catalogue structure
|
||||
List<WorkspaceItem> catalogueChildrens = ((WorkspaceFolder)userCatalogue).getChildren(true);
|
||||
if(catalogueChildrens.isEmpty())
|
||||
System.out.println("****************************** Catalogue Child list is empty");
|
||||
else for (WorkspaceItem catalogueItem : catalogueChildrens) {
|
||||
System.out.println("****************************** Catalogue Child is " + catalogueItem.getName());
|
||||
if(catalogueItem.isFolder()){
|
||||
WorkspaceFolder catalogueFolder = (WorkspaceFolder) catalogueItem;
|
||||
System.out.println("**************************" + catalogueFolder.getName() + " it is a folder, printing children");
|
||||
List<? extends WorkspaceItem> copiedFolderChildren = catalogueFolder.getChildren(true);
|
||||
for (WorkspaceItem copiedFolderChildrenItem : copiedFolderChildren) {
|
||||
System.out.println("****************************** Child is " + copiedFolderChildrenItem.getName());
|
||||
copiedFolderChildrenItem.getPublicLink(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testTitle(){
|
||||
|
||||
// String regexTitleSubWord = "[^a-zA-Z0-9_.-]";
|
||||
// String title = "this is a test title .";
|
||||
// String[] splittedTitle = title.split(" ");
|
||||
//
|
||||
// for (String word : splittedTitle) {
|
||||
// System.out.println("Word is " + word);
|
||||
// String replaced = word.replaceAll(regexTitleSubWord, "");
|
||||
// System.out.println("Replaced Word is " + replaced);
|
||||
// if(!replaced.equals(word)){
|
||||
// System.out.println("Please note that only alphanumeric characters are allowed for the title");
|
||||
// }
|
||||
// }
|
||||
|
||||
System.out.println("Notification_portlet".replaceAll("[^A-Za-z0-9.-_]", " "));
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void retrieveMetadata(){
|
||||
|
||||
try {
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
|
||||
DataCalogueMetadataFormatReader reader = new DataCalogueMetadataFormatReader();
|
||||
|
||||
for (MetadataType mt : reader.getListOfMetadataTypes()) {
|
||||
|
||||
System.out.println("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + mt.getName());
|
||||
MetadataFormat metadata = reader.getMetadataFormatForMetadataType(mt);
|
||||
|
||||
// we need to wrap the list of metadata
|
||||
List<MetadataFieldWrapper> wrapperList = new ArrayList<MetadataFieldWrapper>();
|
||||
List<MetadataField> toWrap = metadata.getMetadataFields();
|
||||
|
||||
for(MetadataField metadataField: toWrap){
|
||||
|
||||
|
||||
|
||||
MetadataFieldWrapper wrapperObj = new MetadataFieldWrapper();
|
||||
wrapperObj.setDefaultValue(metadataField.getDefaultValue());
|
||||
wrapperObj.setFieldName(metadataField.getFieldName());
|
||||
wrapperObj.setType(DataType.valueOf(metadataField.getDataType().toString()));
|
||||
wrapperObj.setMandatory(metadataField.getMandatory());
|
||||
wrapperObj.setNote(metadataField.getNote());
|
||||
|
||||
MetadataValidator validator = metadataField.getValidator();
|
||||
if(validator != null)
|
||||
wrapperObj.setValidator(validator.getRegularExpression());
|
||||
|
||||
MetadataVocabulary vocabulary = metadataField.getVocabulary();
|
||||
|
||||
if(vocabulary != null){
|
||||
wrapperObj.setVocabulary(vocabulary.getVocabularyFields());
|
||||
wrapperObj.setMultiSelection(vocabulary.isMultiSelection());
|
||||
}
|
||||
|
||||
// add to the list
|
||||
wrapperList.add(wrapperObj);
|
||||
|
||||
}
|
||||
|
||||
// wrap the mt as well
|
||||
MetaDataTypeWrapper typeWrapper = new MetaDataTypeWrapper();
|
||||
typeWrapper.setDescription(mt.getDescription());
|
||||
typeWrapper.setId(mt.getId());
|
||||
typeWrapper.setName(mt.getName());
|
||||
|
||||
}
|
||||
|
||||
System.out.println("List of profiles has been saved into session");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error while retrieving metadata beans " + e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testDataCatalogueManagerApplication(){
|
||||
|
||||
String token = "";
|
||||
String scope = "/gcube/devNext/NextNext";
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
|
||||
Utils.writeProductPost("a great test product",
|
||||
"https://next.d4science.org/group/nextnext/data-catalogue?path=/dataset/test_for_visibility",
|
||||
"Costantino Perciante", Arrays.asList("tag1", "tag2", "tag33"), false);
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void treeVisitorTest() throws Exception{
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
String itemName = "CkanTest1137";
|
||||
String itemId = null;
|
||||
|
||||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("costantino.perciante").getWorkspace();
|
||||
|
||||
List<WorkspaceItem> wsChildren = ws.getRoot().getChildren();
|
||||
|
||||
for (WorkspaceItem workspaceItem : wsChildren) {
|
||||
if(workspaceItem.getName().equals(itemName)){
|
||||
itemId = workspaceItem.getId();
|
||||
logger.debug("Id is " + itemId); //e87bfc7d-4fb0-4795-9c79-0c495500ca9c
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// start tree construction
|
||||
WorkspaceItem initialItemWS = ws.getItem(itemId);
|
||||
ResourceElementBean rootElem = new ResourceElementBean();
|
||||
rootElem.setFolder(initialItemWS.isFolder());
|
||||
rootElem.setFullPath(initialItemWS.getPath());
|
||||
rootElem.setParent(null);
|
||||
rootElem.setName(initialItemWS.getName());
|
||||
rootElem.setOriginalIdInWorkspace(initialItemWS.getId());
|
||||
|
||||
// start visiting
|
||||
visit(rootElem, initialItemWS);
|
||||
|
||||
// print final tree
|
||||
logger.debug("Final tree looks like " + rootElem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive visit of a workspace item
|
||||
* @param rootElem
|
||||
* @param initialItemWS
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
private void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS) throws InternalErrorException {
|
||||
List<? extends WorkspaceItem> children = initialItemWS.getChildren();
|
||||
ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
ResourceElementBean elem = new ResourceElementBean();
|
||||
elem.setFolder(workspaceItem.isFolder());
|
||||
elem.setOriginalIdInWorkspace(workspaceItem.getId());
|
||||
elem.setFullPath(workspaceItem.getPath());
|
||||
elem.setParent(rootElem);
|
||||
elem.setName(workspaceItem.getName());
|
||||
childrenInTree.add(elem);
|
||||
visit(elem, workspaceItem);
|
||||
}
|
||||
rootElem.setChildren(childrenInTree);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue