merged
parent
1f741268fb
commit
be42e8ad2f
@ -0,0 +1,7 @@
|
||||
<root>
|
||||
<facet id="jst.jaxrs">
|
||||
<node name="libprov">
|
||||
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
|
||||
</node>
|
||||
</facet>
|
||||
</root>
|
@ -1,46 +0,0 @@
|
||||
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.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 Images image = GWT.create(Images.class);
|
||||
private static final String tipFile = "Hold down the Control (ctrl) or Command button to select multiple options";
|
||||
private static final String tipFolder = "Click on the folder to navigate it";
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
ResourceElementBean value, SafeHtmlBuilder sb) {
|
||||
|
||||
if (value == null || value.isToBeAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Image file = new Image(image.fileIcon());
|
||||
Image folder = new Image(image.folderIcon());
|
||||
file.setWidth("15px");
|
||||
file.setHeight("15px");
|
||||
folder.setWidth("15px");
|
||||
folder.setHeight("15px");
|
||||
|
||||
String whichTip = value.isFolder() ? tipFolder : tipFile;
|
||||
sb.appendHtmlConstant("<div title='" + value.getName() + "( " + whichTip + " )" + "' style='overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis;max-width:240px; 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>");
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("</div>");
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
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.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.cell.client.ValueUpdater;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NativeEvent;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
|
||||
/**
|
||||
* Cell that renders right side panel objects
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
|
||||
|
||||
private static final Images image = GWT.create(Images.class);
|
||||
private static final String tip = "Hold down the Control (CTRL) or Command button to select multiple options. Double click to access "
|
||||
+ "this resource information";
|
||||
|
||||
public ResourceCellRight() {
|
||||
super("keydown", "dblclick");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
ResourceElementBean value, SafeHtmlBuilder sb) {
|
||||
|
||||
if (value == null || !value.isToBeAdded() || value.isFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Image file = new Image(image.fileIcon());
|
||||
file.setWidth("15px");
|
||||
file.setHeight("15px");
|
||||
|
||||
sb.appendHtmlConstant("<div title='" + value.getName() + "( " + tip + " )" + "' style='overflow-x:hidden;white-space:nowrap;text-overflow:ellipsis;max-width:240px; min-height:30px; padding-top:5px;'>");
|
||||
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.getEditableName());
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendHtmlConstant("</span>");
|
||||
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 || TwinColumnSelectionMainPanel.isFroozen())
|
||||
return;
|
||||
super.onBrowserEvent(context, parent, value, event, valueUpdater);
|
||||
ResourceInfoForm info = new ResourceInfoForm(value, valueUpdater);
|
||||
if(TwinColumnSelectionMainPanel.detailContainer.getWidget() != null)
|
||||
TwinColumnSelectionMainPanel.detailContainer.clear();
|
||||
TwinColumnSelectionMainPanel.detailContainer.add(info);
|
||||
TwinColumnSelectionMainPanel.detailContainer.setVisible(true);
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
<!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: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 0px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.panel-style {
|
||||
padding: 5px;
|
||||
border: 1px solid #bbb;
|
||||
border-radius: 5px;
|
||||
height: 400px;
|
||||
width: 95%;
|
||||
}
|
||||
|
||||
.labels-style {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.controls-style {
|
||||
margin-left: 10px !important;
|
||||
}
|
||||
|
||||
.control-group {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel styleName="{style.panel-style}">
|
||||
<b:Form type="VERTICAL" width="100%">
|
||||
<!-- <b:Fieldset styleName="{style.fieldset-border-style}"> -->
|
||||
<b:Legend styleName="{style.legend-style}">
|
||||
<b>Resource Information</b>
|
||||
<b:Button ui:field="closeButton" type="LINK" title="Close details"></b:Button>
|
||||
</b:Legend>
|
||||
<b:ControlGroup ui:field="controlName" styleName="{style.control-group}">
|
||||
<b:ControlLabel for="name" styleName="{style.labels-style}"
|
||||
title="The name the resource will have on the catalogue">
|
||||
<b>Name:</b>
|
||||
</b:ControlLabel>
|
||||
<b:Controls styleName="{style.controls-style}">
|
||||
<b:TextBox placeholder="Resource name" b:id="name"
|
||||
enabled="true" title="The name the resource will have on the catalogue"
|
||||
ui:field="resourceName" />
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
<b:ControlGroup styleName="{style.control-group}">
|
||||
<b:ControlLabel for="path" title="Resource path"
|
||||
styleName="{style.labels-style}">
|
||||
<b>Path:</b>
|
||||
</b:ControlLabel>
|
||||
<b:Controls styleName="{style.controls-style}">
|
||||
<b:TextBox placeholder="Resource path" b:id="path"
|
||||
readOnly="true" title="Resource path" ui:field="resourcePath" />
|
||||
</b:Controls>
|
||||
</b:ControlGroup>
|
||||
<b:ControlGroup styleName="{style.control-group}">
|
||||
<b:ControlLabel for="description" styleName="{style.labels-style}"
|
||||
title="The description the resource will have on the catalogue">
|
||||
<b>Description:</b>
|
||||
</b:ControlLabel>
|
||||
<b:Controls styleName="{style.controls-style}">
|
||||
<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 styleName="{style.control-group}">
|
||||
<b:ControlLabel for="format" styleName="{style.labels-style}"
|
||||
title="The MIME type">
|
||||
<b>Format:</b>
|
||||
</b:ControlLabel>
|
||||
<b:Controls styleName="{style.controls-style}">
|
||||
<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>
|
@ -1,101 +0,0 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import com.google.gwt.event.dom.client.ScrollEvent;
|
||||
import com.google.gwt.event.dom.client.ScrollHandler;
|
||||
import com.google.gwt.user.cellview.client.AbstractPager;
|
||||
import com.google.gwt.user.client.ui.ScrollPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwt.view.client.HasRows;
|
||||
|
||||
/**
|
||||
* Basically a scroll panel
|
||||
* Partially changed from the code at http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellList
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ShowMorePagerPanel extends AbstractPager{
|
||||
|
||||
/**
|
||||
* The default increment size.
|
||||
*/
|
||||
public static final int DEFAULT_INCREMENT = 10;
|
||||
|
||||
/**
|
||||
* The increment size.
|
||||
*/
|
||||
private int incrementSize = DEFAULT_INCREMENT;
|
||||
|
||||
/**
|
||||
* The last scroll position.
|
||||
*/
|
||||
private int lastScrollPos = 0;
|
||||
|
||||
/**
|
||||
* The scrollable panel.
|
||||
*/
|
||||
private final ScrollPanel scrollable = new ScrollPanel();
|
||||
|
||||
/**
|
||||
* Construct a new {@link ShowMorePagerPanel}.
|
||||
*/
|
||||
public ShowMorePagerPanel() {
|
||||
initWidget(scrollable);
|
||||
|
||||
// Do not let the scrollable take tab focus.
|
||||
scrollable.getElement().setTabIndex(-1);
|
||||
|
||||
// Handle scroll events.
|
||||
scrollable.addScrollHandler(new ScrollHandler() {
|
||||
public void onScroll(ScrollEvent event) {
|
||||
// If scrolling up, ignore the event.
|
||||
int oldScrollPos = lastScrollPos;
|
||||
lastScrollPos = scrollable.getVerticalScrollPosition();
|
||||
if (oldScrollPos >= lastScrollPos) {
|
||||
return;
|
||||
}
|
||||
|
||||
HasRows display = getDisplay();
|
||||
if (display == null) {
|
||||
return;
|
||||
}
|
||||
int maxScrollTop = scrollable.getWidget().getOffsetHeight()
|
||||
- scrollable.getOffsetHeight();
|
||||
if (lastScrollPos >= maxScrollTop) {
|
||||
// We are near the end, so increase the page size.
|
||||
int newPageSize = Math.min(
|
||||
display.getVisibleRange().getLength() + incrementSize,
|
||||
display.getRowCount());
|
||||
display.setVisibleRange(0, newPageSize);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of rows by which the range is increased when the scrollbar
|
||||
* reaches the bottom.
|
||||
* @return the increment size
|
||||
*/
|
||||
public int getIncrementSize() {
|
||||
return incrementSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplay(HasRows display) {
|
||||
assert display instanceof Widget : "display must extend Widget";
|
||||
scrollable.setWidget((Widget) display);
|
||||
super.setDisplay(display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of rows by which the range is increased when the scrollbar
|
||||
* reaches the bottom.
|
||||
* @param incrementSize the incremental number of rows
|
||||
*/
|
||||
public void setIncrementSize(int incrementSize) {
|
||||
this.incrementSize = incrementSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRangeOrRowCountChanged() {
|
||||
}
|
||||
}
|
@ -1,571 +0,0 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
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.google.gwt.cell.client.ValueUpdater;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.Style.BorderStyle;
|
||||
import com.google.gwt.dom.client.Style.FontWeight;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.cellview.client.CellList;
|
||||
import com.google.gwt.user.cellview.client.HasKeyboardPagingPolicy.KeyboardPagingPolicy;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.SimplePanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.google.gwt.view.client.ListDataProvider;
|
||||
import com.google.gwt.view.client.MultiSelectionModel;
|
||||
import com.google.gwt.view.client.SelectionChangeEvent;
|
||||
|
||||
/**
|
||||
* The twin column panels for selection of the files to attach to the catalague product.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR
|
||||
*/
|
||||
public class TwinColumnSelectionMainPanel extends Composite{
|
||||
|
||||
@UiField
|
||||
VerticalPanel leftContainer;
|
||||
@UiField
|
||||
VerticalPanel rightContainer;
|
||||
@UiField
|
||||
VerticalPanel buttonsPanel;
|
||||
@UiField
|
||||
Button allToRightButton;
|
||||
@UiField
|
||||
Button toRightButton;
|
||||
@UiField
|
||||
Button toLeftButton;
|
||||
@UiField
|
||||
Button allToLeftButton;
|
||||
// @UiField
|
||||
// Popover popoverResourceSelection;
|
||||
// @UiField
|
||||
// Button resourceInfoButton;
|
||||
@UiField
|
||||
Breadcrumbs breadcrumbs;
|
||||
@UiField
|
||||
FluidContainer mainContainerResourcesSelection;
|
||||
// @UiField
|
||||
// Button getResources;
|
||||
@UiField
|
||||
public static SimplePanel detailContainer;
|
||||
|
||||
/**
|
||||
* 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 static boolean frozen = false;
|
||||
private List<PathBean> pathListBeans = new ArrayList<PathBean>();
|
||||
private static final String PANEL_BORDER_COLOR = "#8899a6";
|
||||
private static final String PANEL_HEIGHT = "400px";
|
||||
private ShowMorePagerPanel showMorePanelLeft = new ShowMorePagerPanel();
|
||||
private ShowMorePagerPanel showMorePanelRight = new ShowMorePagerPanel();
|
||||
private CellList<ResourceElementBean> cellListLeft;
|
||||
private CellList<ResourceElementBean> cellListRight;
|
||||
private ListDataProvider<ResourceElementBean> dataProviderLeft = new ListDataProvider<ResourceElementBean>();
|
||||
private ListDataProvider<ResourceElementBean> dataProviderRight = new ListDataProvider<ResourceElementBean>();
|
||||
private MultiSelectionModel<ResourceElementBean> selectionModelRight;
|
||||
private MultiSelectionModel<ResourceElementBean> selectionModelLeft;
|
||||
private final ResourceElementBean initialBean;
|
||||
// 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."
|
||||
// + " Please consider that any complex hierarchy structure you may have will be flatten.</p>");
|
||||
|
||||
// private static final short PATH_THRESHOLD = 1; // TODO
|
||||
|
||||
private static TwinColumnSelectionMainPanelUiBinder uiBinder = GWT
|
||||
.create(TwinColumnSelectionMainPanelUiBinder.class);
|
||||
|
||||
interface TwinColumnSelectionMainPanelUiBinder extends
|
||||
UiBinder<Widget, TwinColumnSelectionMainPanel> {
|
||||
}
|
||||
|
||||
public TwinColumnSelectionMainPanel(ResourceElementBean initialBean) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
frozen = false;
|
||||
|
||||
GWT.log(initialBean.toString());
|
||||
|
||||
this.initialBean = initialBean;
|
||||
|
||||
buttonsPanel.getElement().getStyle().setMarginTop(50, Unit.PCT);
|
||||
allToRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
|
||||
toRightButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
|
||||
toLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
|
||||
allToLeftButton.getElement().getStyle().setMarginBottom(4, Unit.PX);
|
||||
|
||||
buttonsPanel.getElement().setAttribute("align", "center");
|
||||
// popoverResourceSelection.setPlacement(Placement.LEFT);
|
||||
// popoverResourceSelection.setHeading(aboutHeader.getHTML());
|
||||
// popoverResourceSelection.setText(aboutBody.getHTML());
|
||||
// resourceInfoButton.getElement().getStyle().setFloat(Float.RIGHT);
|
||||
// resourceInfoButton.getElement().getStyle().setPaddingRight(0, Unit.PX);
|
||||
mainContainerResourcesSelection.getElement().getStyle().setPadding(10, Unit.PX);
|
||||
|
||||
breadcrumbs.getElement().getStyle().setBackgroundColor("white");
|
||||
breadcrumbs.getElement().getStyle().setFontWeight(FontWeight.BOLD);
|
||||
breadcrumbs.getElement().getStyle().setMarginLeft(0, Unit.PX);
|
||||
mainContainerResourcesSelection.getElement().getStyle().setMarginLeft(10, Unit.PX);
|
||||
mainContainerResourcesSelection.getElement().getStyle().setMarginBottom(20, Unit.PX);
|
||||
mainContainerResourcesSelection.getElement().getStyle().setMarginTop(0, Unit.PX);
|
||||
|
||||
prepareHandlers();
|
||||
initLeftSidePanel(initialBean);
|
||||
initRightSidePanel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the left side panel
|
||||
*/
|
||||
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.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
|
||||
|
||||
// set page size
|
||||
int size = initialBean.isFolder() ? initialBean.getChildren().size() : 1;
|
||||
cellListLeft.setPageSize(size);
|
||||
|
||||
// Add a selection model so we can select cells.
|
||||
selectionModelLeft = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
|
||||
cellListLeft.setSelectionModel(selectionModelLeft);
|
||||
|
||||
// perform an action on selection
|
||||
selectionModelLeft.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
||||
|
||||
public void onSelectionChange(SelectionChangeEvent event) {
|
||||
|
||||
if(frozen)
|
||||
return;
|
||||
|
||||
Iterator<ResourceElementBean> selectedObjectsIterator = selectionModelLeft.getSelectedSet().iterator();
|
||||
|
||||
while (selectedObjectsIterator.hasNext()) {
|
||||
ResourceElementBean selectedBean = selectedObjectsIterator.next();
|
||||
if(selectedBean.isFolder()){
|
||||
|
||||
// a single folder selected
|
||||
if(selectionModelLeft.getSelectedSet().size() == 1){
|
||||
|
||||
// update path
|
||||
final NavLink navElem = new NavLink(selectedBean.getName());
|
||||
navElem.getElement().getStyle().setFontWeight(FontWeight.BOLD);
|
||||
final PathBean pathBean = new PathBean(navElem, selectedBean);
|
||||
|
||||
navElem.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
removeStartingFromBreadcrumbs(navElem, pathBean);
|
||||
GWT.log("Clicked on element " + pathBean.resourceFolder.getName());
|
||||
//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());
|
||||
GWT.log("Children " + selectedBean.getChildren());
|
||||
dataProviderLeft.setList(selectedBean.getChildren());
|
||||
cellListLeft.setPageSize(selectedBean.getChildren().size());
|
||||
dataProviderLeft.refresh();
|
||||
}
|
||||
selectionModelLeft.setSelected(selectedBean, false);
|
||||
}
|
||||
}
|
||||
// enable the buttons that allows to move the objects to the right
|
||||
enableMoveToRightButtons(selectionModelLeft.getSelectedSet());
|
||||
}
|
||||
});
|
||||
|
||||
// set the list into the provider
|
||||
if(initialBean.isFolder()){
|
||||
Collections.sort(this.initialBean.getChildren());
|
||||
dataProviderLeft.setList(this.initialBean.getChildren());
|
||||
}else
|
||||
dataProviderLeft.setList(Arrays.asList(this.initialBean));
|
||||
|
||||
// add root to breadcrumb
|
||||
final NavLink root = new NavLink(initialBean.getName());
|
||||
final PathBean pathBean = new PathBean(root, initialBean);
|
||||
root.getElement().getStyle().setFontWeight(FontWeight.BOLD);
|
||||
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());
|
||||
cellListLeft.setPageSize(initialBean.getChildren().size());
|
||||
dataProviderLeft.refresh();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// set the cell list into the provider
|
||||
dataProviderLeft.addDataDisplay(cellListLeft);
|
||||
|
||||
// manage showMorePanelLeft
|
||||
showMorePanelLeft.setDisplay(cellListLeft);
|
||||
showMorePanelLeft.setHeight(PANEL_HEIGHT);
|
||||
showMorePanelLeft.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
|
||||
showMorePanelLeft.getElement().getStyle().setBorderWidth(2, 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){
|
||||
current.removeFromParent();
|
||||
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
|
||||
*/
|
||||
private void initRightSidePanel() {
|
||||
|
||||
// initialize the left side list
|
||||
ResourceCellRight cell = new ResourceCellRight();
|
||||
|
||||
// Set a key provider that provides a unique key for each object.
|
||||
cellListRight = new CellList<ResourceElementBean>(cell, ResourceElementBean.KEY_PROVIDER);
|
||||
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.
|
||||
selectionModelRight = new MultiSelectionModel<ResourceElementBean>(ResourceElementBean.KEY_PROVIDER);
|
||||
cellListRight.setSelectionModel(selectionModelRight);
|
||||
|
||||
// perform an action on selection
|
||||
selectionModelRight.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
|
||||
public void onSelectionChange(SelectionChangeEvent event) {
|
||||
|
||||
if(frozen)
|
||||
return;
|
||||
|
||||
enableMoveToLeftButtons(selectionModelRight.getSelectedSet());
|
||||
}
|
||||
});
|
||||
|
||||
// set the cell list into the provider
|
||||
dataProviderRight.addDataDisplay(cellListRight);
|
||||
|
||||
// manage showMorePanelRight
|
||||
showMorePanelRight.setDisplay(cellListRight);
|
||||
showMorePanelRight.setHeight(PANEL_HEIGHT);
|
||||
showMorePanelRight.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
|
||||
showMorePanelRight.getElement().getStyle().setBorderWidth(2, Unit.PX);
|
||||
showMorePanelRight.getElement().getStyle().setBorderColor(PANEL_BORDER_COLOR);
|
||||
|
||||
// add the list to the leftContainerPanel
|
||||
rightContainer.add(showMorePanelRight);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable the buttons to move objects from left to right properly.
|
||||
* @param setselectedItemsLeft
|
||||
*/
|
||||
private void enableMoveToRightButtons(Set<ResourceElementBean> setselectedItemsLeft){
|
||||
|
||||
if(setselectedItemsLeft == null || setselectedItemsLeft.isEmpty()){
|
||||
allToRightButton.setEnabled(false);
|
||||
toRightButton.setEnabled(false);
|
||||
}
|
||||
else if(setselectedItemsLeft.size() > 1){
|
||||
allToRightButton.setEnabled(true);
|
||||
toRightButton.setEnabled(false);
|
||||
}
|
||||
else{
|
||||
allToRightButton.setEnabled(false);
|
||||
toRightButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable the buttons to move objects from right to left properly.
|
||||
* @param setselectedItemsRight
|
||||
*/
|
||||
private void enableMoveToLeftButtons(Set<ResourceElementBean> setselectedItemsRight){
|
||||
|
||||
if(setselectedItemsRight == null || setselectedItemsRight.isEmpty()){
|
||||
allToLeftButton.setEnabled(false);
|
||||
allToLeftButton.setEnabled(false);
|
||||
}
|
||||
else if(setselectedItemsRight.size() > 1){
|
||||
allToLeftButton.setEnabled(true);
|
||||
toLeftButton.setEnabled(false);
|
||||
}
|
||||
else{
|
||||
allToLeftButton.setEnabled(false);
|
||||
toLeftButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the buttons' handlers
|
||||
*/
|
||||
private void prepareHandlers() {
|
||||
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to right elements
|
||||
* @param set the elements to move
|
||||
*/
|
||||
private void moveToRight(Set<ResourceElementBean> setSelected){
|
||||
|
||||
if(setSelected == null || setSelected.isEmpty())
|
||||
return;
|
||||
|
||||
Iterator<ResourceElementBean> iterator = setSelected.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ResourceElementBean resourceElementBean = iterator
|
||||
.next();
|
||||
resourceElementBean.setToBeAdded(true);
|
||||
|
||||
int indexRight = dataProviderRight.getList().indexOf(resourceElementBean);
|
||||
if(indexRight >= 0)
|
||||
dataProviderRight.getList().set(indexRight, resourceElementBean);
|
||||
else{
|
||||
dataProviderRight.getList().add(resourceElementBean);
|
||||
Collections.sort(dataProviderRight.getList());
|
||||
dataProviderRight.refresh();
|
||||
}
|
||||
|
||||
int indexLeft = dataProviderLeft.getList().indexOf(resourceElementBean);
|
||||
dataProviderLeft.getList().set(indexLeft, resourceElementBean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to left elements
|
||||
* @param setSelected the elements to move
|
||||
*/
|
||||
private void moveToLeft(Set<ResourceElementBean> setSelected){
|
||||
|
||||
if(setSelected == null || setSelected.isEmpty())
|
||||
return;
|
||||
|
||||
Iterator<ResourceElementBean> iterator = setSelected.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ResourceElementBean resourceElementBean = iterator.next();
|
||||
resourceElementBean.setToBeAdded(false);
|
||||
}
|
||||
|
||||
Collections.sort(dataProviderLeft.getList());
|
||||
dataProviderLeft.refresh();
|
||||
dataProviderRight.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze the panel
|
||||
*/
|
||||
public void freeze() {
|
||||
|
||||
frozen = true;
|
||||
|
||||
Iterator<Widget> iteratorOverPath = breadcrumbs.iterator();
|
||||
while (iteratorOverPath.hasNext()) {
|
||||
Widget widget = iteratorOverPath.next();
|
||||
if(widget instanceof NavLink)
|
||||
((NavLink)widget).setActive(false);
|
||||
}
|
||||
|
||||
allToRightButton.setEnabled(false);
|
||||
toRightButton.setEnabled(false);
|
||||
allToLeftButton.setEnabled(false);
|
||||
toLeftButton.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root parent with the children as files to save
|
||||
* @return the resources to save
|
||||
*/
|
||||
public ResourceElementBean getResourcesToPublish(){
|
||||
|
||||
List<ResourceElementBean> current = dataProviderRight.getList();
|
||||
|
||||
ResourceElementBean toReturn = new ResourceElementBean();
|
||||
List<ResourceElementBean> children = new ArrayList<ResourceElementBean>();
|
||||
|
||||
for (ResourceElementBean resource : current) {
|
||||
if(resource.isToBeAdded() && !resource.isFolder()){ // be sure ...
|
||||
ResourceElementBean beanWithoutChildren = new ResourceElementBean(resource);
|
||||
beanWithoutChildren.setName(resource.getEditableName());
|
||||
children.add(beanWithoutChildren);
|
||||
}
|
||||
}
|
||||
|
||||
toReturn.setChildren(children);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the freezed
|
||||
*/
|
||||
public static boolean isFroozen() {
|
||||
|
||||
return frozen;
|
||||
}
|
||||
|
||||
// @UiHandler("getResources")
|
||||
// void getResources(ClickEvent ce){
|
||||
// getResourcesToPublish();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Short the current path if needed
|
||||
// */
|
||||
// private void breadcrumbsUpdater(){
|
||||
//
|
||||
// // ignore first and last elem
|
||||
// boolean reduce = (pathListBeans.size() - 2) > PATH_THRESHOLD;
|
||||
//
|
||||
// GWT.log("Is to reduce? " + reduce);
|
||||
//
|
||||
// GWT.log("Full size is " + pathListBeans.size());
|
||||
//
|
||||
// if(!reduce){
|
||||
// GWT.log("Restore");
|
||||
// for(int i = 0; i < pathListBeans.size(); i++){
|
||||
// PathBean bean = pathListBeans.get(i);
|
||||
// GWT.log("Elem is " + bean.resourceFolder);
|
||||
// bean.link.setText(bean.resourceFolder.getName());
|
||||
// bean.link.setVisible(true);
|
||||
// }
|
||||
// }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.resourceFolder.getName());
|
||||
// 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());
|
||||
// }
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<!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"
|
||||
xmlns:m="urn:import:org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection">
|
||||
<ui:style>
|
||||
|
||||
</ui:style>
|
||||
<g:HTMLPanel>
|
||||
<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:Column size="11">
|
||||
<b:Breadcrumbs ui:field="breadcrumbs" divider=">"
|
||||
title="Current path">
|
||||
</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> -->
|
||||
<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="Add selected files" text=">>" />
|
||||
<b:Button ui:field="toRightButton" name="toRight"
|
||||
enabled="false" title="Add selected file" text=">" />
|
||||
<b:Button ui:field="toLeftButton" name="toLeft" enabled="false"
|
||||
title="Remove selected file" text="<" />
|
||||
<b:Button ui:field="allToLeftButton" name="toRight"
|
||||
enabled="false" title="Remove selected files" text="<<" />
|
||||
</g:VerticalPanel>
|
||||
</b:Column>
|
||||
<b:Column size="3" ui:field="rightColumn">
|
||||
<g:VerticalPanel ui:field="rightContainer" width="100%"></g:VerticalPanel>
|
||||
</b:Column>
|
||||
<b:Column size="3" ui:field="detailColumn">
|
||||
<g:SimplePanel ui:field="detailContainer" width="100%"></g:SimplePanel>
|
||||
</b:Column>
|
||||
<!-- <b:Column size="2"> -->
|
||||
<!-- <m:ResourceInfoForm ui:field="resourceInfoForm"></m:ResourceInfoForm> -->
|
||||
<!-- </b:Column> -->
|
||||
</b:FluidRow>
|
||||
</b:FluidContainer>
|
||||
<!-- <b:Button ui:field="getResources">Get Resources</b:Button> -->
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@ -0,0 +1,154 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
|
||||
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.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
* The Class WizardCreator.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 15, 2021
|
||||
*/
|
||||
public class WizardCreator extends Composite {
|
||||
|
||||
/** The ui binder. */
|
||||
private static WizardCreatorUiBinder uiBinder = GWT.create(WizardCreatorUiBinder.class);
|
||||
|
||||
/**
|
||||
* The Interface WizardCreatorUiBinder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 15, 2021
|
||||
*/
|
||||
interface WizardCreatorUiBinder extends UiBinder<Widget, WizardCreator> {
|
||||
}
|
||||
|
||||
/** The title of steps. */
|
||||
private List<String> titleOfSteps;
|
||||
|
||||
/** The html steps. */
|
||||
private List<HTML> htmlSteps;
|
||||
|
||||
/** The wizard container. */
|
||||
@UiField
|
||||
HTMLPanel theWizardContainer;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new wizard creator.
|
||||
*
|
||||
* @param titleOfSteps the title of steps
|
||||
*/
|
||||
public WizardCreator(List<String> titleOfSteps) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
this.titleOfSteps = titleOfSteps;
|
||||
createSteps();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the steps.
|
||||
*/
|
||||
private void createSteps() {
|
||||
|
||||
if(titleOfSteps==null)
|
||||
return;
|
||||
|
||||
int i = 1;
|
||||
htmlSteps = new ArrayList<>(titleOfSteps.size());
|
||||
for (String step : titleOfSteps) {
|
||||
HTML toHML = createStep(i, step);
|
||||
htmlSteps.add(toHML);
|
||||
theWizardContainer.add(toHML);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
activeStep(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Active step.
|
||||
*
|
||||
* @param stepNumber the step number
|
||||
*/
|
||||
public void activeStep(int stepNumber) {
|
||||
disableAllBadge();
|
||||
|
||||
int index = stepNumber-1;
|
||||
if(index>=0) {
|
||||
HTML html = htmlSteps.get(index);
|
||||
html.getElement().addClassName("current");
|
||||
// NodeList<Element> spans = html.getElement().getElementsByTagName("span");
|
||||
// if(spans!=null && spans.getLength()>0) {
|
||||
// Element el = spans.getItem(0);
|
||||
// el.addClassName("badge-inverse");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void disableAllBadge() {
|
||||
for (HTML html : htmlSteps) {
|
||||
html.getElement().removeClassName("current");
|
||||
// NodeList<Element> spans = html.getElement().getElementsByTagName("span");
|
||||
// if(spans!=null && spans.getLength()>0) {
|
||||
// Element el = spans.getItem(0);
|
||||
// el.removeClassName("badge-inverse");
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates the step.
|
||||
*
|
||||
* @param stepNumber the step number
|
||||
* @param stepTitle the step title
|
||||
* @return the string
|
||||
*/
|
||||
private HTML createStep(int stepNumber, String stepTitle) {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("<span class=\"badge-wiz\">");
|
||||
builder.append(stepNumber+".");
|
||||
builder.append("</span>");
|
||||
builder.append(" "+stepTitle);
|
||||
|
||||
|
||||
return new HTML(builder.toString());
|
||||
|
||||
}
|
||||
|
||||
public static class HTMLNoDiv extends HTML{
|
||||
|
||||
public static HTML noDiv(String theHtml) {
|
||||
HTML html = new HTML() {
|
||||
|
||||
};
|
||||
|
||||
html.setHTML(theHtml);
|
||||
return html;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
<!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">
|
||||
|
||||
<g:HTMLPanel addStyleNames="wizard-creator"
|
||||
ui:field="theWizardContainer">
|
||||
</g:HTMLPanel>
|
||||
|
||||
</ui:UiBinder>
|
@ -0,0 +1,59 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
/**
|
||||
* The Class RemovePublishingResourceEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 9, 2021
|
||||
*/
|
||||
public class RemovePublishingResourceEvent extends GwtEvent<RemovePublishingResourceEventHandler> {
|
||||
|
||||
/** The type. */
|
||||
public static Type<RemovePublishingResourceEventHandler> TYPE = new Type<RemovePublishingResourceEventHandler>();
|
||||
|
||||
/** The resource. */
|
||||
private ResourceElementBean resource;
|
||||
|
||||
/**
|
||||
* Instantiates a new removes the publishing resource event.
|
||||
*
|
||||
* @param resource the resource
|
||||
*/
|
||||
public RemovePublishingResourceEvent(ResourceElementBean resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resource.
|
||||
*
|
||||
* @return the resource
|
||||
*/
|
||||
public ResourceElementBean getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated type.
|
||||
*
|
||||
* @return the associated type
|
||||
*/
|
||||
@Override
|
||||
public Type<RemovePublishingResourceEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(RemovePublishingResourceEventHandler handler) {
|
||||
handler.onRemoveResource(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
// TODO: Auto-generated Javadoc
|
||||
/**
|
||||
* The Interface RemovePublishingResourceEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 9, 2021
|
||||
*/
|
||||
public interface RemovePublishingResourceEventHandler extends EventHandler {
|
||||
|
||||
/**
|
||||
* On remove resource.
|
||||
*
|
||||
* @param removeResourceEvent the remove resource event
|
||||
*/
|
||||
void onRemoveResource(RemovePublishingResourceEvent removeResourceEvent);
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
<!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: 100%;
|
||||
padding: 10px;
|
||||
margin-bottom: 0px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.panel-style {
|
||||
padding: 5px;
|
||||
border: 1px solid #bbb;
|
||||
border-radius: 5px;
|
||||
height: 320px;
|
||||
width: 700px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.labels-style {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.controls-style {
|
||||
margin-left: 10px !important;
|
||||
}
|
||||
|
||||
.control-group {
|
||||
margin-bottom: 0px !important;
|
||||
}
|
||||
|
||||
.custom-input input {
|
||||
width: 350px;
|
||||
}
|
||||
|
||||
.custom-input textarea {
|
||||
width: 355px;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel addStyleNames="{style.panel-style}">
|
||||
<b:Form type="HORIZONTAL" width="100%">
|
||||
<b:Fieldset addStyleNames="{style.custom-input}">
|
||||
<b:Legend addStyleNames="{style.legend-style}">
|
||||
<b>Resource Information</b>
|
||||
<b:Button ui:field="closeButton" type="LINK"
|
||||
title="Close details"></b:Button>
|
||||
</b:Legend>
|
||||
<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"
|
||||
enabled="true"
|
||||
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="Type here the 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 visible="false">
|
||||
<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>
|
@ -0,0 +1,305 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
import org.gcube.portlets.widgets.wsexplorer.client.explore.WorkspaceResourcesEnhancedExplorerPanel;
|
||||
import org.gcube.portlets.widgets.wsexplorer.client.notification.WorkspaceExplorerSelectNotification.WorskpaceExplorerSelectNotificationListener;
|
||||
import org.gcube.portlets.widgets.wsexplorer.client.view.grid.ItemsTable.DISPLAY_FIELD;
|
||||
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.AccordionGroup;
|
||||
import com.github.gwtbootstrap.client.ui.Alert;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.Label;
|
||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||
import com.github.gwtbootstrap.client.ui.constants.LabelType;
|
||||
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.event.shared.HandlerManager;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
* The Class SelectResourceByWEMainPanel.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 5, 2021
|
||||
*/
|
||||
public class SelectResourceByWEMainPanel extends Composite {
|
||||
|
||||
/** The ui binder. */
|
||||
private static SelectResourceByWEMainPanelUiBinder uiBinder = GWT.create(SelectResourceByWEMainPanelUiBinder.class);
|
||||
|
||||
private static boolean frozen = false;
|
||||
|
||||
private final ResourceElementBean initialBean;
|
||||
|
||||
@UiField
|
||||
VerticalPanel wsContainer;
|
||||
|
||||
@UiField
|
||||
FlowPanel selectResourcesContainer;
|
||||
|
||||
@UiField
|
||||
Alert showAlert;
|
||||
|
||||
@UiField
|
||||
Button buttSelectResource;
|
||||
|
||||
@UiField
|
||||
AccordionGroup buttPickResources;
|
||||
|
||||
@UiField
|
||||
HTMLPanel containerPickResources;
|
||||
|
||||
@UiField
|
||||
Label labelNothing;
|
||||
|
||||
private Item selectedWEItem;
|
||||
|
||||
public final static HandlerManager eventBus = new HandlerManager(null);
|
||||
|
||||
private Map<String, SelectedResourceWidget> mapSelectedResources = new HashMap<String, SelectedResourceWidget>();
|
||||
|
||||
/**
|
||||
* The Interface SelectResourceByWEMainPanelUiBinder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 5, 2021
|
||||
*/
|
||||
interface SelectResourceByWEMainPanelUiBinder extends UiBinder<Widget, SelectResourceByWEMainPanel> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new select resource by WE main panel.
|
||||
*/
|
||||
public SelectResourceByWEMainPanel(ResourceElementBean initialBean) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
SelectResourceByWEMainPanel.frozen = false;
|
||||
this.initialBean = initialBean;
|
||||
this.labelNothing.setType(LabelType.INFO);
|
||||
|
||||
try {
|
||||
|
||||
String wsFolderId = null;
|
||||
|
||||
//remove this?
|
||||
if(initialBean.isFolder()) {
|
||||
wsFolderId = initialBean.getOriginalIdInWorkspace();
|
||||
}else {
|
||||
//is file
|
||||
if(initialBean.getParent()!=null) {
|
||||
wsFolderId = initialBean.getParent().getOriginalIdInWorkspace();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//wsFolderId = initialBean.getRootIdInWorkspace()!=null?initialBean.getRootIdInWorkspace():wsFolderId;
|
||||
|
||||
//loads the WE only if the root is not null
|
||||
if(wsFolderId!=null) {
|
||||
|
||||
DISPLAY_FIELD[] displayFields = new DISPLAY_FIELD[] { DISPLAY_FIELD.ICON, DISPLAY_FIELD.NAME,
|
||||
DISPLAY_FIELD.OWNER, DISPLAY_FIELD.CREATION_DATE};
|
||||
|
||||
WorkspaceResourcesEnhancedExplorerPanel workspaceExplorerPanel = new WorkspaceResourcesEnhancedExplorerPanel(wsFolderId,false,null, null,false,null,displayFields);
|
||||
WorskpaceExplorerSelectNotificationListener wsResourceExplorerListener = new WorskpaceExplorerSelectNotificationListener() {
|
||||
|
||||
@Override
|
||||
public void onSelectedItem(Item item) {
|
||||
GWT.log("Listener Selected Item " + item);
|
||||
selectedWEItem = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailed(Throwable throwable) {
|
||||
// Log.error(throwable.getLocalizedMessage());
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAborted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotValidSelection() {
|
||||
selectedWEItem = null;
|
||||
}
|
||||
};
|
||||
|
||||
workspaceExplorerPanel.addWorkspaceExplorerSelectNotificationListener(wsResourceExplorerListener);
|
||||
wsContainer.add(workspaceExplorerPanel);
|
||||
}else {
|
||||
containerPickResources.setVisible(false);
|
||||
}
|
||||
|
||||
// if(rootName!=null) {
|
||||
// buttPickResources.setHeading("Add files from "+rootName);
|
||||
// }
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!initialBean.isFolder()) {
|
||||
addSelectResource(initialBean.getOriginalIdInWorkspace(), initialBean.getName(),initialBean.getFullPath(), initialBean.isFolder());
|
||||
}
|
||||
|
||||
addHandlers();
|
||||
|
||||
}
|
||||
|
||||
private void addHandlers() {
|
||||
|
||||
buttSelectResource.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
if(selectedWEItem!=null && !selectedWEItem.isFolder()) {
|
||||
addSelectResource(selectedWEItem.getId(), selectedWEItem.getName(), selectedWEItem.getPath(), selectedWEItem.isFolder());
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
eventBus.addHandler(RemovePublishingResourceEvent.TYPE, new RemovePublishingResourceEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onRemoveResource(RemovePublishingResourceEvent removeResourceEvent) {
|
||||
if(removeResourceEvent.getResource()!=null) {
|
||||
removePublishingResource(removeResourceEvent.getResource());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void removePublishingResource(ResourceElementBean resource) {
|
||||
|
||||
SelectedResourceWidget theRW = mapSelectedResources.get(resource.getOriginalIdInWorkspace());
|
||||
if(theRW!=null) {
|
||||
selectResourcesContainer.remove(theRW);
|
||||
mapSelectedResources.remove(resource.getOriginalIdInWorkspace());
|
||||
}
|
||||
|
||||
showNothingResourceSelected();
|
||||
}
|
||||
|
||||
public void addSelectResource(String wsItemId, String name, String path, boolean isFolder) {
|
||||
|
||||
SelectedResourceWidget selWidg = mapSelectedResources.get(wsItemId);
|
||||
if (selWidg != null) {
|
||||
showAlertMsg(AlertType.WARNING,"Item '" + name + "' already selected",true);
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceElementBean rb = new ResourceElementBean();
|
||||
rb.setOriginalIdInWorkspace(wsItemId);
|
||||
rb.setName(name);
|
||||
rb.setFullPath(path);
|
||||
rb.setEditableName(name);
|
||||
rb.setFolder(isFolder);
|
||||
selWidg = new SelectedResourceWidget(rb);
|
||||
|
||||
mapSelectedResources.put(wsItemId, selWidg);
|
||||
selectResourcesContainer.add(selWidg);
|
||||
|
||||
showNothingResourceSelected();
|
||||
|
||||
}
|
||||
|
||||
private void showNothingResourceSelected() {
|
||||
if(mapSelectedResources.size()==0) {
|
||||
labelNothing.setVisible(true);
|
||||
}else
|
||||
labelNothing.setVisible(false);
|
||||
}
|
||||
|
||||
private void showAlertMsg(AlertType type, String txt, boolean autoHide) {
|
||||
showAlert.setType(type);
|
||||
showAlert.setText(txt);
|
||||
showAlert.setVisible(true);
|
||||
showAlert.setClose(true);
|
||||
if(autoHide) {
|
||||
Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
showAlert.setVisible(false);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
timer.schedule(5000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void freeze() {
|
||||
|
||||
GWT.log("called freeze into selected resources");
|
||||
frozen = true;
|
||||
selectResourcesContainer.getElement().setAttribute("disabled", "disabled");
|
||||
containerPickResources.getElement().setAttribute("disabled", "disabled");
|
||||
//buttPickResources.getElement().getStyle().setProperty("pointer-events","none");
|
||||
buttSelectResource.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the root parent with the children as files to save
|
||||
* @return the resources to save
|
||||
*/
|
||||
public ResourceElementBean getResourcesToPublish(){
|
||||
|
||||
ResourceElementBean toReturn = new ResourceElementBean();
|
||||
List<ResourceElementBean> children = new ArrayList<ResourceElementBean>();
|
||||
|
||||
for (String wsItemId : mapSelectedResources.keySet()) {
|
||||
SelectedResourceWidget selecWC = mapSelectedResources.get(wsItemId);
|
||||
ResourceElementBean theResource = selecWC.getResourceBean();
|
||||
theResource.setToBeAdded(true);
|
||||
|
||||
if(!theResource.isFolder()){ // be sure ...
|
||||
children.add(theResource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
toReturn.setToPublish(children);
|
||||
GWT.log("resources to publish are: "+toReturn.getToPublish());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the freezed
|
||||
*/
|
||||
public static boolean isFroozen() {
|
||||
|
||||
return frozen;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<!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>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.custom-header {
|
||||
margin: 0 !important;
|
||||
font-size: 18px !important;
|
||||
color: #222 !important;
|
||||
}
|
||||
|
||||
.max-height-250 {
|
||||
max-height: 250px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.margin-top-10 {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.margin-top-30 {
|
||||
margin-top: 30px;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel width="100%">
|
||||
|
||||
<g:HTMLPanel>
|
||||
<b:Heading size="1" addStyleNames="{style.custom-header}">Selected Items</b:Heading>
|
||||
<b:Alert ui:field="showAlert" visible="false"></b:Alert>
|
||||
<g:FlowPanel ui:field="selectResourcesContainer"
|
||||
width="100%">
|
||||
<b:Label ui:field="labelNothing">no file selected</b:Label>
|
||||
</g:FlowPanel>
|
||||
</g:HTMLPanel>
|
||||
|
||||
<g:HTMLPanel ui:field="containerPickResources"
|
||||
addStyleNames="{style.margin-top-30}">
|
||||
<b:AccordionGroup ui:field="buttPickResources"
|
||||
heading="Add files from..." defaultOpen="false"
|
||||
addStyleNames="accordion-no-border-inner">
|
||||
<b:FluidRow addStyleNames="{style.max-height-250}">
|
||||
<g:VerticalPanel ui:field="wsContainer">
|
||||
</g:VerticalPanel>
|
||||
</b:FluidRow>
|
||||
<b:Button ui:field="buttSelectResource"
|
||||
addStyleNames="{style.margin-top-10}">Select</b:Button>
|
||||
</b:AccordionGroup>
|
||||
</g:HTMLPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@ -0,0 +1,133 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.workspace;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
||||
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.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
/**
|
||||
* The Class SelectResourceWidget.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 12, 2021
|
||||
*/
|
||||
public class SelectedResourceWidget extends Composite {
|
||||
|
||||
/** The ui binder. */
|
||||
private static SelectedResourceWidgetUiBinder uiBinder = GWT.create(SelectedResourceWidgetUiBinder.class);
|
||||
|
||||
/**
|
||||
* The Interface SelectResourceWidgetUiBinder.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||
*
|
||||
* Mar 12, 2021
|
||||
*/
|
||||
interface SelectedResourceWidgetUiBinder extends UiBinder<Widget, SelectedResourceWidget> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new select resource widget.
|
||||
*/
|
||||
public SelectedResourceWidget() {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
}
|
||||
|
||||
/** The button delete. */
|
||||
@UiField
|
||||
Button buttonDelete;
|
||||
|
||||
/** The button edit. */
|
||||
@UiField
|
||||
Button buttonEdit;
|
||||
|
||||
/** The field name. */
|
||||
@UiField
|
||||
Label fieldName;
|
||||
|
||||
@UiField
|
||||
Label fieldDescription;
|
||||
|
||||
/** The edit panel. */
|
||||
@UiField
|
||||
HTMLPanel editPanel;
|
||||
|
||||
/** The resource bean. */
|
||||
private ResourceElementBean resourceBean;
|
||||
|
||||
/**
|
||||
* Instantiates a new select resource widget.
|
||||
*
|
||||
* @param rb the rb
|
||||
*/
|
||||
public SelectedResourceWidget(ResourceElementBean rb) {
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
buttonEdit.setType(ButtonType.LINK);
|
||||
buttonDelete.setType(ButtonType.LINK);
|
||||
this.resourceBean = rb;
|
||||
updateFields();
|
||||
addHandlers();
|
||||
|
||||
}
|
||||
|
||||
private void updateFields() {
|
||||
this.fieldName.setText(resourceBean.getEditableName());
|
||||
|
||||
if(resourceBean.getDescription()!=null && !resourceBean.getDescription().isEmpty()) {
|
||||
this.fieldDescription.setVisible(true);
|
||||
this.fieldDescription.setText(resourceBean.getDescription());
|
||||
}else
|
||||
this.fieldDescription.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the handlers.
|
||||
*/
|
||||
private void addHandlers() {
|
||||
|
||||
buttonEdit.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
editPanel.clear();
|
||||
ResourceInfoForm resourceInformationInfo = new ResourceInfoForm(resourceBean) {
|
||||
protected void onUnload() {
|
||||
super.onUnload();
|
||||
updateFields();
|
||||
};
|
||||
};
|
||||
editPanel.add(resourceInformationInfo);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
buttonDelete.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
SelectResourceByWEMainPanel.eventBus.fireEvent(new RemovePublishingResourceEvent(resourceBean));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the resource bean.
|
||||
*
|
||||
* @return the resource bean
|
||||
*/
|
||||
public ResourceElementBean getResourceBean() {
|
||||
return resourceBean;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
<!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>
|
||||
.important {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.selected-resources {
|
||||
|
||||
}
|
||||
|
||||
.selected-resources td {
|
||||
vertical-align: middle !important;
|
||||
}
|
||||
|
||||
.margin-bottom-8 {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.descr-text {
|
||||
font-style: italic;
|
||||
padding-left: 105px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.title-text {
|
||||
font-weight: bold;
|
||||
font-size: 14px;
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
color: #222;
|
||||
}
|
||||
|
||||
.icon-my-style {
|
||||
font-size: 1.2em;
|
||||
margin-right: 10px;
|
||||
margin-left: 10px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel addStyleNames="{style.margin-bottom-8}">
|
||||
<g:FlowPanel addStyleNames="{style.selected-resources}">
|
||||
<!-- <b:Icon type="PUSHPIN" addStyleNames="{style.icon-my-style}"></b:Icon> -->
|
||||
<b:Button ui:field="buttonEdit" icon="PENCIL"
|
||||
title="Edit the resource information" />
|
||||
<b:Button ui:field="buttonDelete" icon="TRASH"
|
||||
title="Remove this resource" />
|
||||
<g:Label ui:field="fieldName"
|
||||
addStyleNames="{style.title-text}"></g:Label>
|
||||
<g:Label ui:field="fieldDescription" visible="false"
|
||||
addStyleNames="{style.descr-text}"></g:Label>
|
||||
</g:FlowPanel>
|
||||
<g:HTMLPanel ui:field="editPanel"></g:HTMLPanel>
|
||||
</g:HTMLPanel>
|
||||
</ui:UiBinder>
|
@ -1,160 +1,161 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.common.portal.mailing.EmailNotification;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
|
||||
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
||||
|
||||
/**
|
||||
* Associate the dataset to a group and send notifications to group's admins.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class AssociationToGroupAndNotifyThread extends Thread {
|
||||
|
||||
//private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupAndNotifyThread.class);
|
||||
private static final Log logger = LogFactoryUtil.getLog(AssociationToGroupAndNotifyThread.class);
|
||||
private static final String PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT = "Item $TITLE added to group $GROUP";
|
||||
private static final String PRODUCT_ASSOCIATED_TO_GROUP_BODY = "Dear user,<br> a new item named '<b>$TITLE</b>' has been "
|
||||
+ "just published by $USER_FULLNAME in <b>$GROUP</b> .<br>"
|
||||
+ "You can find it here $DATASET_URL";
|
||||
|
||||
private String groupTitle;
|
||||
private String datasetId;
|
||||
private String username;
|
||||
private String datasetTitle;
|
||||
private String userFullName;
|
||||
private DataCatalogue catalogue;
|
||||
// private String organization;
|
||||
private List<OrganizationBean> groups;
|
||||
private HttpServletRequest request;
|
||||
private String datasetUrl;
|
||||
private List<OrganizationBean> groupsForceCreation;
|
||||
|
||||
/**
|
||||
* @param list
|
||||
* @param groupTitle
|
||||
* @param datasetId
|
||||
* @param username
|
||||
* @param catalogue
|
||||
*/
|
||||
public AssociationToGroupAndNotifyThread(List<OrganizationBean> groups, List<OrganizationBean> groupsForceCreation, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName,
|
||||
String username, DataCatalogue catalogue, String organization, HttpServletRequest request) {
|
||||
this.request = request;
|
||||
this.groups = groups == null ? new ArrayList<OrganizationBean>() : groups;
|
||||
this.groupsForceCreation = groupsForceCreation;
|
||||
this.groupTitle = groupTitle;
|
||||
this.datasetId = datasetId;
|
||||
this.username = username;
|
||||
this.catalogue = catalogue;
|
||||
// this.organization = organization;
|
||||
this.datasetTitle = datasetTitle;
|
||||
this.userFullName = userFullName;
|
||||
this.datasetUrl = datasetUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
|
||||
|
||||
// force creation of groups if needed
|
||||
if(groupsForceCreation != null){
|
||||
logger.info("Groups that must be created before association are " + groupsForceCreation);
|
||||
for (OrganizationBean groupToForce : groupsForceCreation) {
|
||||
try{
|
||||
CkanGroup group = catalogue.createGroup(groupToForce.getName(), groupToForce.getTitle(), "");
|
||||
if(group == null)
|
||||
logger.error("Unable to retrieve or create group with name " + groupToForce);
|
||||
else
|
||||
groups.add(new OrganizationBean(group.getTitle(), group.getName(), false, groupToForce.isPropagateUp()));
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to check if a group with this info " + groupToForce + " already exists or can be created");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
logger.info("Other groups to which the product should be associate are " + groups);
|
||||
|
||||
if(groups != null)
|
||||
for (OrganizationBean groupBean : groups) {
|
||||
boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getName(), datasetId, catalogue.getApiKeyFromUsername(username), groupBean.isPropagateUp());
|
||||
logger.info("Was product put into group" + groupBean.getTitle() + "? " + putIntoGroup);
|
||||
if(putIntoGroup)
|
||||
notifyGroupAdmins(catalogue, groupBean.getName() ,groupBean.getTitle(), username);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a notification to the group admin(s) about the just added product
|
||||
* @param username
|
||||
* @param groupTitle
|
||||
* @param catalogue
|
||||
*/
|
||||
private void notifyGroupAdmins(DataCatalogue catalogue, String groupName, String groupTitle, String username){
|
||||
|
||||
// get the groups admin
|
||||
Map<RolesCkanGroupOrOrg, List<String>> userAndRoles = catalogue.getRolesAndUsersGroup(groupName);
|
||||
|
||||
if(userAndRoles.containsKey(RolesCkanGroupOrOrg.ADMIN)){
|
||||
|
||||
List<String> admins = userAndRoles.get(RolesCkanGroupOrOrg.ADMIN);
|
||||
List<String> adminsEmails = new ArrayList<String>();
|
||||
|
||||
for(int i = 0; i < admins.size(); i++){
|
||||
String convertedName = CatalogueUtilMethods.fromCKanUsernameToUsername(admins.get(i));
|
||||
admins.set(i, convertedName);
|
||||
}
|
||||
|
||||
// remove the same user who published the product if he/she is an admin of the group
|
||||
int indexOfUser = admins.indexOf(username);
|
||||
if(indexOfUser >= 0)
|
||||
admins.remove(indexOfUser);
|
||||
|
||||
// further cleaning of the list (for users that are only in ckan... sysadmin for example)
|
||||
UserManager um = new LiferayUserManager();
|
||||
Iterator<String> adminIt = admins.iterator();
|
||||
|
||||
while (adminIt.hasNext()) {
|
||||
String admin = (String) adminIt.next();
|
||||
try{
|
||||
adminsEmails.add(um.getUserByUsername(admin).getEmail());
|
||||
}catch(Exception e){
|
||||
logger.error("User with username " + admin + " doesn't exist in Liferay");
|
||||
adminIt.remove();
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("The list of admins for group " + groupTitle + " is " + admins);
|
||||
|
||||
if(admins.isEmpty())
|
||||
return;
|
||||
|
||||
// send the email
|
||||
EmailNotification mailToSend = new EmailNotification(
|
||||
adminsEmails,
|
||||
PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle),
|
||||
PRODUCT_ASSOCIATED_TO_GROUP_BODY.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle).replace("$USER_FULLNAME", userFullName).replace("$DATASET_URL", datasetUrl),
|
||||
request);
|
||||
mailToSend.sendEmail();
|
||||
|
||||
}else
|
||||
logger.warn("It seems there is no user with role Admin in group " + groupTitle);
|
||||
}
|
||||
}
|
||||
//package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Iterator;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//
|
||||
//import org.gcube.common.portal.mailing.EmailNotification;
|
||||
//import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||
//import org.gcube.datacatalogue.ckanutillibrary.server.utils.CatalogueUtilMethods;
|
||||
//import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg;
|
||||
//import org.gcube.datacatalogue.ckanutillibrary.shared.jackan.model.CkanGroup;
|
||||
//import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
//import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
//import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
//
|
||||
//import com.liferay.portal.kernel.log.Log;
|
||||
//import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
//
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Associate the dataset to a group and send notifications to group's admins.
|
||||
// * @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
// */
|
||||
//public class AssociationToGroupAndNotifyThread extends Thread {
|
||||
//
|
||||
// //private static final Logger logger = LoggerFactory.getLogger(AssociationToGroupAndNotifyThread.class);
|
||||
// private static final Log logger = LogFactoryUtil.getLog(AssociationToGroupAndNotifyThread.class);
|
||||
// private static final String PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT = "Item $TITLE added to group $GROUP";
|
||||
// private static final String PRODUCT_ASSOCIATED_TO_GROUP_BODY = "Dear user,<br> a new item named '<b>$TITLE</b>' has been "
|
||||
// + "just published by $USER_FULLNAME in <b>$GROUP</b> .<br>"
|
||||
// + "You can find it here $DATASET_URL";
|
||||
//
|
||||
// private String groupTitle;
|
||||
// private String datasetId;
|
||||
// private String username;
|
||||
// private String datasetTitle;
|
||||
// private String userFullName;
|
||||
// private DataCatalogue catalogue;
|
||||
// // private String organization;
|
||||
// private List<OrganizationBean> groups;
|
||||
// private HttpServletRequest request;
|
||||
// private String datasetUrl;
|
||||
// private List<OrganizationBean> groupsForceCreation;
|
||||
//
|
||||
// /**
|
||||
// * @param list
|
||||
// * @param groupTitle
|
||||
// * @param datasetId
|
||||
// * @param username
|
||||
// * @param catalogue
|
||||
// */
|
||||
// public AssociationToGroupAndNotifyThread(List<OrganizationBean> groups, List<OrganizationBean> groupsForceCreation, String groupTitle, String datasetUrl, String datasetId, String datasetTitle, String userFullName,
|
||||
// String username, DataCatalogue catalogue, String organization, HttpServletRequest request) {
|
||||
// this.request = request;
|
||||
// this.groups = groups == null ? new ArrayList<OrganizationBean>() : groups;
|
||||
// this.groupsForceCreation = groupsForceCreation;
|
||||
// this.groupTitle = groupTitle;
|
||||
// this.datasetId = datasetId;
|
||||
// this.username = username;
|
||||
// this.catalogue = catalogue;
|
||||
// // this.organization = organization;
|
||||
// this.datasetTitle = datasetTitle;
|
||||
// this.userFullName = userFullName;
|
||||
// this.datasetUrl = datasetUrl;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// logger.info("Association thread started to put the dataset with id = "+ datasetId + " into group with title " + groupTitle + " for user " + username);
|
||||
//
|
||||
// // force creation of groups if needed
|
||||
// if(groupsForceCreation != null){
|
||||
// logger.info("Groups that must be created before association are " + groupsForceCreation);
|
||||
// for (OrganizationBean groupToForce : groupsForceCreation) {
|
||||
// try{
|
||||
// CkanGroup group = catalogue.createGroup(groupToForce.getName(), groupToForce.getTitle(), "");
|
||||
// if(group == null)
|
||||
// logger.error("Unable to retrieve or create group with name " + groupToForce);
|
||||
// else
|
||||
// groups.add(new OrganizationBean(group.getTitle(), group.getName(), false, groupToForce.isPropagateUp()));
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to check if a group with this info " + groupToForce + " already exists or can be created");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// logger.info("Other groups to which the product should be associate are " + groups);
|
||||
//
|
||||
// if(groups != null)
|
||||
// for (OrganizationBean groupBean : groups) {
|
||||
// boolean putIntoGroup = catalogue.assignDatasetToGroup(groupBean.getName(), datasetId, groupBean.isPropagateUp());
|
||||
// logger.info("Was product put into group" + groupBean.getTitle() + "? " + putIntoGroup);
|
||||
// if(putIntoGroup)
|
||||
// notifyGroupAdmins(catalogue, groupBean.getName() ,groupBean.getTitle(), username);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Send a notification to the group admin(s) about the just added product
|
||||
// * @param username
|
||||
// * @param groupTitle
|
||||
// * @param catalogue
|
||||
// */
|
||||
// private void notifyGroupAdmins(DataCatalogue catalogue, String groupName, String groupTitle, String username){
|
||||
//
|
||||
// // get the groups admin
|
||||
// Map<RolesCkanGroupOrOrg, List<String>> userAndRoles = catalogue.getRolesAndUsersGroup(groupName);
|
||||
//
|
||||
// if(userAndRoles.containsKey(RolesCkanGroupOrOrg.ADMIN)){
|
||||
//
|
||||
// List<String> admins = userAndRoles.get(RolesCkanGroupOrOrg.ADMIN);
|
||||
// List<String> adminsEmails = new ArrayList<String>();
|
||||
//
|
||||
// for(int i = 0; i < admins.size(); i++){
|
||||
// String convertedName = CatalogueUtilMethods.fromCKanUsernameToUsername(admins.get(i));
|
||||
// admins.set(i, convertedName);
|
||||
// }
|
||||
//
|
||||
// // remove the same user who published the product if he/she is an admin of the group
|
||||
// int indexOfUser = admins.indexOf(username);
|
||||
// if(indexOfUser >= 0)
|
||||
// admins.remove(indexOfUser);
|
||||
//
|
||||
// // further cleaning of the list (for users that are only in ckan... sysadmin for example)
|
||||
// UserManager um = new LiferayUserManager();
|
||||
// Iterator<String> adminIt = admins.iterator();
|
||||
//
|
||||
// while (adminIt.hasNext()) {
|
||||
// String admin = (String) adminIt.next();
|
||||
// try{
|
||||
// adminsEmails.add(um.getUserByUsername(admin).getEmail());
|
||||
// }catch(Exception e){
|
||||
// logger.error("User with username " + admin + " doesn't exist in Liferay");
|
||||
// adminIt.remove();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// logger.info("The list of admins for group " + groupTitle + " is " + admins);
|
||||
//
|
||||
// if(admins.isEmpty())
|
||||
// return;
|
||||
//
|
||||
// // send the email
|
||||
// EmailNotification mailToSend = new EmailNotification(
|
||||
// adminsEmails,
|
||||
// PRODUCT_ASSOCIATED_TO_GROUP_SUBJECT.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle),
|
||||
// PRODUCT_ASSOCIATED_TO_GROUP_BODY.replace("$TITLE", datasetTitle).replace("$GROUP", groupTitle).replace("$USER_FULLNAME", userFullName).replace("$DATASET_URL", datasetUrl),
|
||||
// request);
|
||||
// mailToSend.sendEmail();
|
||||
//
|
||||
// }else
|
||||
// logger.warn("It seems there is no user with role Admin in group " + groupTitle);
|
||||
// }
|
||||
//}
|
||||
|
@ -1,325 +1,322 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.Header;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpEntity;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.HttpResponse;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.ClientProtocolException;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.client.methods.HttpPost;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.entity.StringEntity;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.CloseableHttpClient;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.impl.client.HttpClientBuilder;
|
||||
import eu.trentorise.opendata.jackan.internal.org.apache.http.util.EntityUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Let the Product Catalogue Manager write a post in a VRE and alert there is a new product
|
||||
* @author Costantino Perciante at ISTI-CNR
|
||||
* (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class WritePostCatalogueManagerThread extends Thread {
|
||||
|
||||
public static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
|
||||
private static final String NOTIFICATION_MESSAGE = "Dear members,\n$USER_FULLNAME just published the item '$PRODUCT_TITLE'.\nYou can find it at: $PRODUCT_URL\n";
|
||||
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";
|
||||
private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class);
|
||||
private String username;
|
||||
private String scope;
|
||||
private String productTitle;
|
||||
private String productUrl;
|
||||
private boolean enableNotification;
|
||||
private List<String> hashtags;
|
||||
private String userFullName;
|
||||
private String userCurrentUrl;
|
||||
|
||||
/**
|
||||
* @param token
|
||||
* @param scope
|
||||
* @param productTitle
|
||||
* @param productUrl
|
||||
* @param enableNotification
|
||||
* @param hashtags
|
||||
* @param userFullName
|
||||
*/
|
||||
public WritePostCatalogueManagerThread(
|
||||
String username, String scope,
|
||||
String productTitle, String productUrl, boolean enableNotification,
|
||||
List<String> hashtags, String userFullName, String userCurrentUrl) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.scope = scope;
|
||||
this.productTitle = productTitle;
|
||||
this.productUrl = productUrl;
|
||||
this.enableNotification = enableNotification;
|
||||
this.hashtags = hashtags;
|
||||
this.userFullName = userFullName;
|
||||
this.userCurrentUrl = userCurrentUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try{
|
||||
// evaluate user's token for this scope
|
||||
String token = GenericUtils.tryGetElseCreateToken(username, scope);
|
||||
|
||||
if(token == null){
|
||||
logger.warn("Unable to proceed, user's token is not available");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Started request to write application post "
|
||||
+ "for new product created. Scope is " + scope + " and "
|
||||
+ "token is " + token.substring(0, 10) + "****************");
|
||||
|
||||
// set token and scope
|
||||
ScopeProvider.instance.set(scope);
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
|
||||
//see Feature #17577
|
||||
/*final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
||||
|
||||
userFullName = "<a class=\"link\" href=\"" + profilePageURL + "?"+
|
||||
Base64.getEncoder().encodeToString(GCubeSocialNetworking.USER_PROFILE_OID.getBytes())+"="+
|
||||
Base64.getEncoder().encodeToString(username.getBytes())+"\">"+userFullName+
|
||||
"</a> ";
|
||||
*/
|
||||
|
||||
userFullName = "@"+username;
|
||||
|
||||
// write
|
||||
writeProductPost(
|
||||
productTitle,
|
||||
productUrl,
|
||||
userFullName,
|
||||
hashtags,
|
||||
enableNotification
|
||||
);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to write the post because of the following error ", e);
|
||||
}finally{
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public static String extractOrgFriendlyURL(String portalURL) {
|
||||
String groupRegEx = "/group/";
|
||||
if (portalURL.contains(groupRegEx)) {
|
||||
String[] splits = portalURL.split(groupRegEx);
|
||||
String friendlyURL = splits[1];
|
||||
if (friendlyURL.contains("/")) {
|
||||
friendlyURL = friendlyURL.split("/")[0];
|
||||
} else {
|
||||
friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0];
|
||||
}
|
||||
return "/"+friendlyURL;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send notification to vre members about the created product by writing a post.
|
||||
* @param productName the title of the product
|
||||
* @param productUrl the url of the product
|
||||
* @param hashtags a list of product's hashtags
|
||||
*/
|
||||
private static void writeProductPost(String productName, String productUrl, String userFullname, List<String> hashtags, boolean enablePostNotification){
|
||||
|
||||
// discover service endpoint for the social networking library
|
||||
String currentScope = ScopeProvider.instance.get();
|
||||
String tokenUser = SecurityTokenProvider.instance.get();
|
||||
|
||||
logger.info("Current scope for writeProductPost is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************");
|
||||
String basePath = new GCoreEndPointReaderSocial(currentScope).getBasePath();
|
||||
|
||||
if(basePath == null){
|
||||
|
||||
logger.error("Unable to write a post because there is no social networking service available");
|
||||
|
||||
}else{
|
||||
|
||||
// check base path form
|
||||
basePath = basePath.endsWith("/") ? basePath : basePath + "/";
|
||||
|
||||
try(CloseableHttpClient client = HttpClientBuilder.create().build();){
|
||||
|
||||
String pathTokenApp = basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser;
|
||||
String tokenApp = requireAppToken(client, pathTokenApp);
|
||||
if(tokenApp != null){
|
||||
String pathWritePost = basePath + SOCIAL_SERVICE_WRITE_APPLICATION_POST + "?gcube-token=" + tokenApp;
|
||||
writePost(client, pathWritePost, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to create a post", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Require the application token
|
||||
* @param tokenUser
|
||||
* @param basePath
|
||||
* @param client
|
||||
* @return
|
||||
*/
|
||||
private static String requireAppToken(CloseableHttpClient client, String path){
|
||||
|
||||
String token = null;
|
||||
try{
|
||||
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER);
|
||||
HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||
|
||||
int statusTokenGenerate = response.getStatusLine().getStatusCode();
|
||||
|
||||
if(statusTokenGenerate == HttpURLConnection.HTTP_CREATED){
|
||||
|
||||
// extract token
|
||||
JSONObject obj = getJSONObject(response);
|
||||
if(((Boolean) obj.get("success")))
|
||||
token = (String)obj.get("result");
|
||||
else
|
||||
return null;
|
||||
|
||||
}else if(statusTokenGenerate == HttpURLConnection.HTTP_MOVED_TEMP
|
||||
|| statusTokenGenerate == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| statusTokenGenerate == HttpURLConnection.HTTP_SEE_OTHER){
|
||||
|
||||
// re-execute
|
||||
Header[] locations = response.getHeaders("Location");
|
||||
Header lastLocation = locations[locations.length - 1];
|
||||
String realLocation = lastLocation.getValue();
|
||||
logger.debug("New location is " + realLocation);
|
||||
token = requireAppToken(client, realLocation);
|
||||
|
||||
}else
|
||||
return null;
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to retrieve application token", e);
|
||||
}
|
||||
|
||||
logger.info("Returning app token " + (token != null ? token.substring(0, 10) + "*************************" : null));
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write post request
|
||||
* @param client
|
||||
* @param applicationToken
|
||||
* @param productName
|
||||
* @param productUrl
|
||||
* @param userFullname
|
||||
* @param hashtags
|
||||
*/
|
||||
private static void writePost(CloseableHttpClient client, String path, String productName, String productUrl, String userFullname, List<String> hashtags,
|
||||
boolean enablePostNotification) {
|
||||
|
||||
try{
|
||||
|
||||
// replace
|
||||
String message = NOTIFICATION_MESSAGE.replace("$PRODUCT_TITLE", productName).replace("$PRODUCT_URL", productUrl).replace("$USER_FULLNAME", userFullname);
|
||||
|
||||
if(hashtags != null && !hashtags.isEmpty())
|
||||
for (String hashtag : hashtags) {
|
||||
String modifiedHashtag = hashtag.replaceAll(" ", "_").replace("_+", "_");
|
||||
if(modifiedHashtag.endsWith("_"))
|
||||
modifiedHashtag = modifiedHashtag.substring(0, modifiedHashtag.length() - 1);
|
||||
message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't
|
||||
}
|
||||
|
||||
JSONObject request = new JSONObject();
|
||||
request.put("text", message);
|
||||
request.put("enable_notification", enablePostNotification);
|
||||
logger.info("The post that is going to be written is ->\n" + request.toJSONString());
|
||||
HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||
int statusWritePost = response.getStatusLine().getStatusCode();
|
||||
|
||||
if(statusWritePost == HttpURLConnection.HTTP_CREATED){
|
||||
|
||||
// extract token
|
||||
JSONObject obj = getJSONObject(response);
|
||||
if(((Boolean) obj.get("success")))
|
||||
logger.info("Post written");
|
||||
else
|
||||
logger.info("Failed to write the post " + obj.get("message"));
|
||||
|
||||
}else if(statusWritePost == HttpURLConnection.HTTP_MOVED_TEMP
|
||||
|| statusWritePost == HttpURLConnection.HTTP_MOVED_PERM
|
||||
|| statusWritePost == HttpURLConnection.HTTP_SEE_OTHER){
|
||||
|
||||
// re-execute
|
||||
Header[] locations = response.getHeaders("Location");
|
||||
Header lastLocation = locations[locations.length - 1];
|
||||
String realLocation = lastLocation.getValue();
|
||||
logger.debug("New location is " + realLocation);
|
||||
writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
||||
|
||||
}else
|
||||
throw new RuntimeException("Failed to write the post ");
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to write the post ", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the json response to a map
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
private static JSONObject getJSONObject(HttpResponse response){
|
||||
|
||||
JSONObject toReturn = null;
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
try {
|
||||
String jsonString = EntityUtils.toString(response.getEntity());
|
||||
JSONParser parser = new JSONParser();
|
||||
toReturn = (JSONObject)parser.parse(jsonString);
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to read json object", e);
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("Returning " + toReturn.toJSONString());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an http request post request with json entity
|
||||
* @throws IOException
|
||||
* @throws ClientProtocolException
|
||||
*/
|
||||
private static HttpResponse performRequest(CloseableHttpClient client, String path, String entity) throws ClientProtocolException, IOException{
|
||||
|
||||
HttpPost request = new HttpPost(path);
|
||||
StringEntity stringEntity = new StringEntity(entity);
|
||||
stringEntity.setContentType(MEDIATYPE_JSON);
|
||||
request.setEntity(stringEntity);
|
||||
return client.execute(request);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//package org.gcube.portlets.widgets.ckandatapublisherwidget.server.threads;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.net.HttpURLConnection;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.apache.http.HttpEntity;
|
||||
//import org.apache.http.HttpResponse;
|
||||
//import org.apache.http.client.ClientProtocolException;
|
||||
//import org.apache.http.client.methods.HttpPost;
|
||||
//import org.apache.http.entity.StringEntity;
|
||||
//import org.apache.http.impl.client.CloseableHttpClient;
|
||||
//import org.apache.http.impl.client.HttpClientBuilder;
|
||||
//import org.apache.http.util.EntityUtils;
|
||||
//import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
//import org.gcube.common.scope.api.ScopeProvider;
|
||||
//import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GCoreEndPointReaderSocial;
|
||||
//import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.GenericUtils;
|
||||
//
|
||||
//import com.google.gwt.json.client.JSONParser;
|
||||
//import com.liferay.portal.kernel.log.Log;
|
||||
//import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * Let the Product Catalogue Manager write a post in a VRE and alert there is a new product
|
||||
// * @author Costantino Perciante at ISTI-CNR
|
||||
// * (costantino.perciante@isti.cnr.it)
|
||||
// */
|
||||
//public class WritePostCatalogueManagerThread extends Thread {
|
||||
//
|
||||
// public static final String APPLICATION_ID_CATALOGUE_MANAGER = "org.gcube.datacatalogue.ProductCatalogue";
|
||||
// private static final String NOTIFICATION_MESSAGE = "Dear members,\n$USER_FULLNAME just published the item '$PRODUCT_TITLE'.\nYou can find it at: $PRODUCT_URL\n";
|
||||
// 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";
|
||||
// private static final Log logger = LogFactoryUtil.getLog(WritePostCatalogueManagerThread.class);
|
||||
// private String username;
|
||||
// private String scope;
|
||||
// private String productTitle;
|
||||
// private String productUrl;
|
||||
// private boolean enableNotification;
|
||||
// private List<String> hashtags;
|
||||
// private String userFullName;
|
||||
// private String userCurrentUrl;
|
||||
//
|
||||
// /**
|
||||
// * @param token
|
||||
// * @param scope
|
||||
// * @param productTitle
|
||||
// * @param productUrl
|
||||
// * @param enableNotification
|
||||
// * @param hashtags
|
||||
// * @param userFullName
|
||||
// */
|
||||
// public WritePostCatalogueManagerThread(
|
||||
// String username, String scope,
|
||||
// String productTitle, String productUrl, boolean enableNotification,
|
||||
// List<String> hashtags, String userFullName, String userCurrentUrl) {
|
||||
// super();
|
||||
// this.username = username;
|
||||
// this.scope = scope;
|
||||
// this.productTitle = productTitle;
|
||||
// this.productUrl = productUrl;
|
||||
// this.enableNotification = enableNotification;
|
||||
// this.hashtags = hashtags;
|
||||
// this.userFullName = userFullName;
|
||||
// this.userCurrentUrl = userCurrentUrl;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
//
|
||||
// try{
|
||||
// // evaluate user's token for this scope
|
||||
// String token = GenericUtils.tryGetElseCreateToken(username, scope);
|
||||
//
|
||||
// if(token == null){
|
||||
// logger.warn("Unable to proceed, user's token is not available");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// logger.info("Started request to write application post "
|
||||
// + "for new product created. Scope is " + scope + " and "
|
||||
// + "token is " + token.substring(0, 10) + "****************");
|
||||
//
|
||||
// // set token and scope
|
||||
// ScopeProvider.instance.set(scope);
|
||||
// SecurityTokenProvider.instance.set(token);
|
||||
//
|
||||
// //see Feature #17577
|
||||
// /*final String profilePageURL = GCubePortalConstants.PREFIX_GROUP_URL + extractOrgFriendlyURL(userCurrentUrl) + GCubePortalConstants.USER_PROFILE_FRIENDLY_URL;
|
||||
//
|
||||
// userFullName = "<a class=\"link\" href=\"" + profilePageURL + "?"+
|
||||
// Base64.getEncoder().encodeToString(GCubeSocialNetworking.USER_PROFILE_OID.getBytes())+"="+
|
||||
// Base64.getEncoder().encodeToString(username.getBytes())+"\">"+userFullName+
|
||||
// "</a> ";
|
||||
// */
|
||||
//
|
||||
// userFullName = "@"+username;
|
||||
//
|
||||
// // write
|
||||
// writeProductPost(
|
||||
// productTitle,
|
||||
// productUrl,
|
||||
// userFullName,
|
||||
// hashtags,
|
||||
// enableNotification
|
||||
// );
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to write the post because of the following error ", e);
|
||||
// }finally{
|
||||
// SecurityTokenProvider.instance.reset();
|
||||
// ScopeProvider.instance.reset();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static String extractOrgFriendlyURL(String portalURL) {
|
||||
// String groupRegEx = "/group/";
|
||||
// if (portalURL.contains(groupRegEx)) {
|
||||
// String[] splits = portalURL.split(groupRegEx);
|
||||
// String friendlyURL = splits[1];
|
||||
// if (friendlyURL.contains("/")) {
|
||||
// friendlyURL = friendlyURL.split("/")[0];
|
||||
// } else {
|
||||
// friendlyURL = friendlyURL.split("\\?")[0].split("\\#")[0];
|
||||
// }
|
||||
// return "/"+friendlyURL;
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Send notification to vre members about the created product by writing a post.
|
||||
// * @param productName the title of the product
|
||||
// * @param productUrl the url of the product
|
||||
// * @param hashtags a list of product's hashtags
|
||||
// */
|
||||
// private static void writeProductPost(String productName, String productUrl, String userFullname, List<String> hashtags, boolean enablePostNotification){
|
||||
//
|
||||
// // discover service endpoint for the social networking library
|
||||
// String currentScope = ScopeProvider.instance.get();
|
||||
// String tokenUser = SecurityTokenProvider.instance.get();
|
||||
//
|
||||
// logger.info("Current scope for writeProductPost is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************");
|
||||
// String basePath = new GCoreEndPointReaderSocial(currentScope).getBasePath();
|
||||
//
|
||||
// if(basePath == null){
|
||||
//
|
||||
// logger.error("Unable to write a post because there is no social networking service available");
|
||||
//
|
||||
// }else{
|
||||
//
|
||||
// // check base path form
|
||||
// basePath = basePath.endsWith("/") ? basePath : basePath + "/";
|
||||
//
|
||||
// try(CloseableHttpClient client = HttpClientBuilder.create().build();){
|
||||
//
|
||||
// String pathTokenApp = basePath + SOCIAL_SERVICE_APPLICATION_TOKEN + "?gcube-token=" + tokenUser;
|
||||
// String tokenApp = requireAppToken(client, pathTokenApp);
|
||||
// if(tokenApp != null){
|
||||
// String pathWritePost = basePath + SOCIAL_SERVICE_WRITE_APPLICATION_POST + "?gcube-token=" + tokenApp;
|
||||
// writePost(client, pathWritePost, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
||||
// }
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to create a post", e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Require the application token
|
||||
// * @param tokenUser
|
||||
// * @param basePath
|
||||
// * @param client
|
||||
// * @return
|
||||
// */
|
||||
// private static String requireAppToken(CloseableHttpClient client, String path){
|
||||
//
|
||||
// String token = null;
|
||||
// try{
|
||||
//
|
||||
// JSONObject request = new JSONObject();
|
||||
// request.put("app_id", APPLICATION_ID_CATALOGUE_MANAGER);
|
||||
// HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||
//
|
||||
// int statusTokenGenerate = response.getStatusLine().getStatusCode();
|
||||
//
|
||||
// if(statusTokenGenerate == HttpURLConnection.HTTP_CREATED){
|
||||
//
|
||||
// // extract token
|
||||
// JSONObject obj = getJSONObject(response);
|
||||
// if(((Boolean) obj.get("success")))
|
||||
// token = (String)obj.get("result");
|
||||
// else
|
||||
// return null;
|
||||
//
|
||||
// }else if(statusTokenGenerate == HttpURLConnection.HTTP_MOVED_TEMP
|
||||
// || statusTokenGenerate == HttpURLConnection.HTTP_MOVED_PERM
|
||||
// || statusTokenGenerate == HttpURLConnection.HTTP_SEE_OTHER){
|
||||
//
|
||||
// // re-execute
|
||||
// Header[] locations = response.getHeaders("Location");
|
||||
// Header lastLocation = locations[locations.length - 1];
|
||||
// String realLocation = lastLocation.getValue();
|
||||
// logger.debug("New location is " + realLocation);
|
||||
// token = requireAppToken(client, realLocation);
|
||||
//
|
||||
// }else
|
||||
// return null;
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to retrieve application token", e);
|
||||
// }
|
||||
//
|
||||
// logger.info("Returning app token " + (token != null ? token.substring(0, 10) + "*************************" : null));
|
||||
// return token;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Write post request
|
||||
// * @param client
|
||||
// * @param applicationToken
|
||||
// * @param productName
|
||||
// * @param productUrl
|
||||
// * @param userFullname
|
||||
// * @param hashtags
|
||||
// */
|
||||
// private static void writePost(CloseableHttpClient client, String path, String productName, String productUrl, String userFullname, List<String> hashtags,
|
||||
// boolean enablePostNotification) {
|
||||
//
|
||||
// try{
|
||||
//
|
||||
// // replace
|
||||
// String message = NOTIFICATION_MESSAGE.replace("$PRODUCT_TITLE", productName).replace("$PRODUCT_URL", productUrl).replace("$USER_FULLNAME", userFullname);
|
||||
//
|
||||
// if(hashtags != null && !hashtags.isEmpty())
|
||||
// for (String hashtag : hashtags) {
|
||||
// String modifiedHashtag = hashtag.replaceAll(" ", "_").replace("_+", "_");
|
||||
// if(modifiedHashtag.endsWith("_"))
|
||||
// modifiedHashtag = modifiedHashtag.substring(0, modifiedHashtag.length() - 1);
|
||||
// message += " #" + modifiedHashtag; // ckan accepts tag with empty spaces, we don't
|
||||
// }
|
||||
//
|
||||
// JSONObject request = new JSONObject();
|
||||
// request.put("text", message);
|
||||
// request.put("enable_notification", enablePostNotification);
|
||||
// logger.info("The post that is going to be written is ->\n" + request.toJSONString());
|
||||
// HttpResponse response = performRequest(client, path, request.toJSONString());
|
||||
// int statusWritePost = response.getStatusLine().getStatusCode();
|
||||
//
|
||||
// if(statusWritePost == HttpURLConnection.HTTP_CREATED){
|
||||
//
|
||||
// // extract token
|
||||
// JSONObject obj = getJSONObject(response);
|
||||
// if(((Boolean) obj.get("success")))
|
||||
// logger.info("Post written");
|
||||
// else
|
||||
// logger.info("Failed to write the post " + obj.get("message"));
|
||||
//
|
||||
// }else if(statusWritePost == HttpURLConnection.HTTP_MOVED_TEMP
|
||||
// || statusWritePost == HttpURLConnection.HTTP_MOVED_PERM
|
||||
// || statusWritePost == HttpURLConnection.HTTP_SEE_OTHER){
|
||||
//
|
||||
// // re-execute
|
||||
// Header[] locations = response.getHeaders("Location");
|
||||
// Header lastLocation = locations[locations.length - 1];
|
||||
// String realLocation = lastLocation.getValue();
|
||||
// logger.debug("New location is " + realLocation);
|
||||
// writePost(client, realLocation, productName, productUrl, userFullname, hashtags, enablePostNotification);
|
||||
//
|
||||
// }else
|
||||
// throw new RuntimeException("Failed to write the post ");
|
||||
//
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to write the post ", e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Convert the json response to a map
|
||||
// * @param response
|
||||
// * @return
|
||||
// */
|
||||
// private static JSONObject getJSONObject(HttpResponse response){
|
||||
//
|
||||
// JSONObject toReturn = null;
|
||||
// HttpEntity entity = response.getEntity();
|
||||
//
|
||||
// if (entity != null) {
|
||||
// try {
|
||||
// String jsonString = EntityUtils.toString(response.getEntity());
|
||||
// JSONParser parser = new JSONParser();
|
||||
// toReturn = (JSONObject)parser.parse(jsonString);
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to read json object", e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// logger.debug("Returning " + toReturn.toJSONString());
|
||||
// return toReturn;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Perform an http request post request with json entity
|
||||
// * @throws IOException
|
||||
// * @throws ClientProtocolException
|
||||
// */
|
||||
// private static HttpResponse performRequest(CloseableHttpClient client, String path, String entity) throws ClientProtocolException, IOException{
|
||||
//
|
||||
// HttpPost request = new HttpPost(path);
|
||||
// StringEntity stringEntity = new StringEntity(entity);
|
||||
// stringEntity.setContentType(MEDIATYPE_JSON);
|
||||
// request.setEntity(stringEntity);
|
||||
// return client.execute(request);
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
@ -0,0 +1,107 @@
|
||||
package org.gcube.portlets.widgets.ckandatapublisherwidget;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehubwrapper.server.StorageHubWrapper;
|
||||
import org.gcube.datacatalogue.utillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.WorkspaceUtils;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* The Class TestDataCatalogueLib.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR Pisa (Italy)
|
||||
* Jun 1, 2020
|
||||
*/
|
||||
public class TestPublishingWidget {
|
||||
|
||||
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(TestPublishingWidget.class);
|
||||
|
||||
private String scope = "/gcube";
|
||||
//private String testUser = "costantino_perciante";
|
||||
private String testUser = "francesco.mangiacrapa";
|
||||
private String authorizationToken = "";
|
||||
|
||||
/**
|
||||
* Before.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Before
|
||||
public void before() throws Exception{
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory test.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
//@Test
|
||||
public void factoryTest() throws Exception{
|
||||
|
||||
DataCatalogueFactory factory = DataCatalogueFactory.getFactory();
|
||||
|
||||
while(true){
|
||||
factory.getUtilsPerScope(scope);
|
||||
Thread.sleep(60* 1000 * 3);
|
||||
factory.getUtilsPerScope(scope);
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Thread.sleep(1000);
|
||||
factory.getUtilsPerScope(scope);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void getDatasetBeanTest() throws Exception{
|
||||
ScopeProvider.instance.set(scope);
|
||||
String userName = testUser;
|
||||
String token = authorizationToken;
|
||||
|
||||
String folderId = "6399daa7-2173-4314-b4f7-2afa24eae8f8";
|
||||
DatasetBean bean;
|
||||
try{
|
||||
bean = new DatasetBean();
|
||||
bean.setId(folderId);
|
||||
bean.setDescription("This is a fantastic description");
|
||||
bean.setVersion(1);
|
||||
String onlyAlphanumeric = "test-creation-blablabla".replaceAll("[^A-Za-z0-9]", "");
|
||||
bean.setTitle(onlyAlphanumeric + Calendar.getInstance().getTimeInMillis());
|
||||
bean.setAuthorName("Francesco");
|
||||
bean.setAuthorSurname("Mangiacrapa");
|
||||
bean.setAuthorEmail("francesco.mangiacrapa@isti.cnr.it");
|
||||
bean.setMaintainer("Francesco Mangiacrapa");
|
||||
bean.setMaintainerEmail("francesco.mangiacrapa@isti.cnr.it");
|
||||
|
||||
//UPDATED By Francesco
|
||||
String vreName = scope.substring(scope.lastIndexOf("/")+1,scope.length());
|
||||
LOG.debug("In dev mode using the scope: "+scope+" and VRE name: "+vreName);
|
||||
bean.setOrganizationList(Arrays.asList(new OrganizationBean(vreName, vreName.toLowerCase(), true)));
|
||||
|
||||
bean.setOwnerIdentifier(userName);
|
||||
|
||||
if(folderId != null && !folderId.isEmpty()){
|
||||
StorageHubWrapper storageHubWrapper = new StorageHubWrapper(scope, token, false, false, true);
|
||||
WorkspaceUtils.toWorkspaceResource(folderId, userName, bean, storageHubWrapper.getWorkspace());
|
||||
}
|
||||
}catch(Exception e){
|
||||
LOG.error("Error while building bean into dev mode", e);
|
||||
throw new Exception("Error while retrieving basic information " + e.getMessage());
|
||||
}
|
||||
|
||||
LOG.info("Got dataset: "+bean);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
/devsec.gcubekey
|
||||
/gcube.gcubekey
|
||||
/log4j.properties
|
Loading…
Reference in New Issue