The widget with the new file picker is almost finished. Tests will follow
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/ckan-metadata-publisher-widget@134000 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7e492c87d1
commit
78c831b980
2
pom.xml
2
pom.xml
|
@ -60,6 +60,7 @@
|
|||
<artifactId>xercesImpl</artifactId>
|
||||
<version>2.9.1</version>
|
||||
<scope>provided</scope>
|
||||
<!-- put at provided for deploying -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
|
@ -269,4 +270,5 @@
|
|||
</plugins>
|
||||
</build>
|
||||
|
||||
<packaging>war</packaging>
|
||||
</project>
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.CreateDatasetForm;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.MetaDataFieldSkeleton;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||
|
||||
|
@ -26,6 +25,9 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
|
||||
private HandlerManager eventBus = new HandlerManager(null);
|
||||
|
||||
// Create a remote service proxy to talk to the server-side ckan service.
|
||||
public static final CKanPublisherServiceAsync ckanServices = GWT.create(CKanPublisherService.class);
|
||||
|
||||
/**
|
||||
* This is the entry point method.
|
||||
*/
|
||||
|
@ -41,7 +43,50 @@ public class CKanMetadataPublisher implements EntryPoint {
|
|||
@SuppressWarnings("unused")
|
||||
private void testSelectionPanel() {
|
||||
|
||||
RootPanel.get("ckan-metadata-publisher-div").add(new TwinColumnSelectionMainPanel());
|
||||
// List<ResourceElementBean> listLeft = new ArrayList<ResourceElementBean>();
|
||||
// listLeft.add(new ResourceElementBean(null, "File A", false, null, "File A"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File B", false, null, "File B"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File C", false, null, "File C"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File D", false, null, "File D"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File E", false, null, "File E"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File F", false, null, "File F"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File G", false, null, "File G"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File H", false, null, "File H"));
|
||||
// listLeft.add(new ResourceElementBean(null, "File I", false, null, "File I"));
|
||||
//
|
||||
// // test with folder and childs
|
||||
// ArrayList<ResourceElementBean> childrenOfA = new ArrayList<ResourceElementBean>();
|
||||
// ArrayList<ResourceElementBean> childrenOfW = new ArrayList<ResourceElementBean>();
|
||||
//
|
||||
// ResourceElementBean elementA = new ResourceElementBean(null, "Folder A", true, childrenOfA, "Folder A");
|
||||
// childrenOfA.add(new ResourceElementBean(elementA, "File X", false, null, "Folder A:File X"));
|
||||
// childrenOfA.add(new ResourceElementBean(elementA, "File Y", false, null, "Folder A:File Y"));
|
||||
// childrenOfA.add(new ResourceElementBean(elementA, "File Z", false, null, "Folder A:File Z"));
|
||||
// childrenOfA.add(new ResourceElementBean(elementA, "File V", false, null, "Folder A:File V"));
|
||||
// ResourceElementBean elementW = new ResourceElementBean(elementA, "Folder W", true, childrenOfW, "Folder A:File W");
|
||||
// childrenOfA.add(elementW);
|
||||
// childrenOfW.add(new ResourceElementBean(elementW, "File J", false, null, "Folder A:File W: File J"));
|
||||
// listLeft.add(elementA);
|
||||
|
||||
// String folderId = "e87bfc7d-4fb0-4795-9c79-0c495500ca9c";
|
||||
// ckanServices.getTreeFolder(folderId, new AsyncCallback<ResourceElementBean>() {
|
||||
//
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(ResourceElementBean result) {
|
||||
// if(result != null){
|
||||
// List<ResourceElementBean> children = result.getChildren();
|
||||
// RootPanel.get("ckan-metadata-publisher-div").add(new TwinColumnSelectionMainPanel(children));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
//
|
||||
// Window.alert("Failed to retrieve ResourceElementBean");
|
||||
//
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
|
@ -17,48 +17,48 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
*/
|
||||
@RemoteServiceRelativePath("ckanservices")
|
||||
public interface CKanPublisherService extends RemoteService {
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the list of licenses to show to the user.
|
||||
* @return a LicenseBean on success, <b>null</b> on error.
|
||||
*/
|
||||
LicensesBean getLicenses();
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve the list of profiles for a given organization name .
|
||||
* @return a List<MetaDataProfileBean> on success, <b>null</b> on error.
|
||||
*/
|
||||
List<MetaDataProfileBean> getProfiles(String orgName);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve a partially filled bean given a folder id and its owner.
|
||||
* @param folderId
|
||||
* @return @return a DatasetMetadataBean on success, <b>null</b> on error.
|
||||
*/
|
||||
DatasetMetadataBean getDatasetBean(String folderId);
|
||||
|
||||
|
||||
/**
|
||||
* Try to create such dataset starting from the information contained into the toCreate bean.
|
||||
* @param toCreate
|
||||
* @return the sent bean filled with the needed information
|
||||
*/
|
||||
DatasetMetadataBean createCKanDataset(DatasetMetadataBean toCreate);
|
||||
|
||||
|
||||
/**
|
||||
* Add this resource to the dataset whose id is datasetId
|
||||
* @param resource
|
||||
* @param datasetId
|
||||
*/
|
||||
ResourceBeanWrapper addResourceToDataset(ResourceBeanWrapper resource, String datasetId);
|
||||
|
||||
ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId);
|
||||
|
||||
/**
|
||||
* Delete this resource from the dataset with id datasetId
|
||||
* @param resource
|
||||
* @param datasetId
|
||||
* @return <b>true</b> on success, false otherwise
|
||||
*/
|
||||
boolean deleteResourceFromDataset(ResourceBeanWrapper resource);
|
||||
|
||||
boolean deleteResourceFromDataset(ResourceElementBean resource);
|
||||
|
||||
/**
|
||||
* Given the title the user wants to give to the new product to create, a check is performed
|
||||
* to understand if a dataset with the proposed title (and so the id generated at server side) already exists
|
||||
|
@ -66,4 +66,11 @@ public interface CKanPublisherService extends RemoteService {
|
|||
* @return true if it exists, false otherwise
|
||||
*/
|
||||
boolean datasetIdAlreadyExists(String title);
|
||||
|
||||
// /**
|
||||
// * Return a tree object representing the whole folder hierarchy
|
||||
// * @param folderId
|
||||
// * @return ResourceElementBean
|
||||
// */
|
||||
// ResourceElementBean getTreeFolder(String folderId);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
|
@ -44,15 +44,15 @@ public interface CKanPublisherServiceAsync {
|
|||
* @param datasetId
|
||||
* @param callback
|
||||
*/
|
||||
void addResourceToDataset(ResourceBeanWrapper resource, String datasetId,
|
||||
AsyncCallback<ResourceBeanWrapper> callback);
|
||||
void addResourceToDataset(ResourceElementBean resource, String datasetId,
|
||||
AsyncCallback<ResourceElementBean> callback);
|
||||
|
||||
/**
|
||||
* Delete this resource from the dataset with id datasetId
|
||||
* @param resource
|
||||
* @return <b>true</b> on success, false otherwise
|
||||
*/
|
||||
void deleteResourceFromDataset(ResourceBeanWrapper resource, AsyncCallback<Boolean> callback);
|
||||
void deleteResourceFromDataset(ResourceElementBean resource, AsyncCallback<Boolean> callback);
|
||||
|
||||
/**
|
||||
* Retrieve the list of profiles for a given organization name .
|
||||
|
@ -68,4 +68,12 @@ public interface CKanPublisherServiceAsync {
|
|||
*/
|
||||
void datasetIdAlreadyExists(String title, AsyncCallback<Boolean> callback);
|
||||
|
||||
// /**
|
||||
// * Return a tree object representing the whole folder hierarchy
|
||||
// * @param folderId
|
||||
// * @return ResourceElementBean
|
||||
// */
|
||||
// void getTreeFolder(String folderId,
|
||||
// AsyncCallback<ResourceElementBean> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
@ -11,13 +11,13 @@ import com.google.gwt.event.shared.GwtEvent;
|
|||
public class AddResourceEvent extends GwtEvent<AddResourceEventHandler> {
|
||||
public static Type<AddResourceEventHandler> TYPE = new Type<AddResourceEventHandler>();
|
||||
|
||||
private ResourceBeanWrapper resource;
|
||||
private ResourceElementBean resource;
|
||||
|
||||
public AddResourceEvent(ResourceBeanWrapper resource) {
|
||||
public AddResourceEvent(ResourceElementBean resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public ResourceBeanWrapper getResource() {
|
||||
public ResourceElementBean getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.events;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
@ -11,13 +11,13 @@ import com.google.gwt.event.shared.GwtEvent;
|
|||
public class DeleteResourceEvent extends GwtEvent<DeleteResourceEventHandler> {
|
||||
public static Type<DeleteResourceEventHandler> TYPE = new Type<DeleteResourceEventHandler>();
|
||||
|
||||
private ResourceBeanWrapper resource;
|
||||
private ResourceElementBean resource;
|
||||
|
||||
public DeleteResourceEvent(ResourceBeanWrapper resource) {
|
||||
public DeleteResourceEvent(ResourceElementBean resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
public ResourceBeanWrapper getResource() {
|
||||
public ResourceElementBean getResource() {
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCre
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.CloseCreationFormEventHandler;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEvent;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteCustomFieldEventHandler;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection.TwinColumnSelectionMainPanel;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddResourceContainer;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddResourceToDataset;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.AddedResourcesSummary;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.ResourcesTable;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources.TagsPanel;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.utils.InfoIconsLabels;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||
|
@ -190,7 +190,7 @@ public class CreateDatasetForm extends Composite{
|
|||
private List<MetaDataFieldSkeleton> listOfMetadataFields = new ArrayList<MetaDataFieldSkeleton>();
|
||||
|
||||
// resource table
|
||||
private ResourcesTable resourcesTable;
|
||||
private TwinColumnSelectionMainPanel resourcesTwinPanel;
|
||||
|
||||
// List of opened popup'ids
|
||||
private List<String> popupOpenedIds = new ArrayList<String>();
|
||||
|
@ -336,15 +336,14 @@ public class CreateDatasetForm extends Composite{
|
|||
|
||||
if(isWorkspaceRequest){
|
||||
|
||||
resourcesTable = new ResourcesTable(bean.getResources());
|
||||
|
||||
// if there are not resources, for now just checked it ( and hide so that the step will be skipped) TODO
|
||||
if(bean.getResources() == null || bean.getResources().isEmpty()){
|
||||
|
||||
alertNoResources.setType(AlertType.WARNING);
|
||||
alertNoResources.setVisible(true);
|
||||
|
||||
}
|
||||
}else
|
||||
resourcesTwinPanel = new TwinColumnSelectionMainPanel(bean.getResources());
|
||||
|
||||
}
|
||||
|
||||
|
@ -658,7 +657,7 @@ public class CreateDatasetForm extends Composite{
|
|||
|
||||
// add the resources to the container panel
|
||||
if(workspaceResourcesContainer.getWidget() == null)
|
||||
workspaceResourcesContainer.add(resourcesTable);
|
||||
workspaceResourcesContainer.add(resourcesTwinPanel);
|
||||
|
||||
}else{
|
||||
|
||||
|
@ -758,6 +757,8 @@ public class CreateDatasetForm extends Composite{
|
|||
receivedBean.setTitle(title);
|
||||
receivedBean.setTags(tagsPanel.getTags());
|
||||
receivedBean.setSelectedOrganization(chosenOrganization);
|
||||
if(resourcesTwinPanel != null)
|
||||
receivedBean.setResources(resourcesTwinPanel.getResourcesToPublish());
|
||||
|
||||
Map<String, String> customFieldsMap = new HashMap<String, String>();
|
||||
|
||||
|
@ -1199,8 +1200,8 @@ public class CreateDatasetForm extends Composite{
|
|||
}
|
||||
|
||||
// freeze table of resources
|
||||
if(resourcesTable != null)
|
||||
resourcesTable.freezeTable();
|
||||
if(resourcesTwinPanel != null)
|
||||
resourcesTwinPanel.freeze();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Icon;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
|
||||
|
@ -9,28 +13,25 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|||
*/
|
||||
public class ResourceCellLeft extends AbstractCell<ResourceElementBean>{
|
||||
|
||||
private static final String HTML_FILE = new Icon(IconType.FILE_ALT).toString();
|
||||
private static final String HTML_FOLDER = new Icon(IconType.FOLDER_CLOSE_ALT).toString();
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
ResourceElementBean value, SafeHtmlBuilder sb) {
|
||||
|
||||
if (value == null || value.isMovedToRight()) {
|
||||
if (value == null || value.isToBeAdded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<table style='width:100%'");
|
||||
sb.appendHtmlConstant("<tr><td><b>");
|
||||
sb.appendEscaped("Parent");
|
||||
sb.appendHtmlConstant("<div style='width:100%; padding:2px'>");
|
||||
sb.appendHtmlConstant(value.isFolder() ? HTML_FOLDER : HTML_FILE);
|
||||
sb.appendHtmlConstant("<span style='margin-left:5px'>");
|
||||
sb.appendHtmlConstant("<b>");
|
||||
sb.appendEscaped(value.getName());
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendEscaped(": " + (value.getParent() == null ? "-" : value.getParent().getName()));
|
||||
sb.appendHtmlConstant("</td></tr><td><b>");
|
||||
sb.appendEscaped("Name");
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendEscaped(": " + value.getName());
|
||||
sb.appendHtmlConstant("</td></tr><td><b>");
|
||||
sb.appendEscaped("Type");
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendEscaped(": " + (value.isFolder() ? "Folder" : "File"));
|
||||
sb.appendHtmlConstant("<td></tr></table>");
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("</div>");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Icon;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.cell.client.AbstractCell;
|
||||
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
||||
|
||||
|
@ -9,22 +13,24 @@ import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
|
|||
*/
|
||||
public class ResourceCellRight extends AbstractCell<ResourceElementBean>{
|
||||
|
||||
private static final String HTML_FILE = new Icon(IconType.FILE_ALT).toString();
|
||||
|
||||
@Override
|
||||
public void render(com.google.gwt.cell.client.Cell.Context context,
|
||||
ResourceElementBean value, SafeHtmlBuilder sb) {
|
||||
|
||||
if (value == null || !value.isMovedToRight() || value.isFolder()) {
|
||||
if (value == null || !value.isToBeAdded() || value.isFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sb.appendHtmlConstant("<table style='width:100%'");
|
||||
sb.appendHtmlConstant("<tr><td>");
|
||||
|
||||
sb.appendHtmlConstant("<div style='width:100%; padding:2px'>");
|
||||
sb.appendHtmlConstant(HTML_FILE);
|
||||
sb.appendHtmlConstant("<span style='margin-left:5px'>");
|
||||
sb.appendHtmlConstant("<b>");
|
||||
sb.appendEscaped("Name");
|
||||
sb.appendEscaped(value.getFullPath());
|
||||
sb.appendHtmlConstant("</b>");
|
||||
sb.appendEscaped(": " + value.getFullPath());
|
||||
sb.appendHtmlConstant("</td></tr>");
|
||||
sb.appendHtmlConstant("</table>");
|
||||
sb.appendHtmlConstant("</span>");
|
||||
sb.appendHtmlConstant("</div>");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.view.client.ProvidesKey;
|
||||
|
||||
|
||||
/**
|
||||
* A left-side element for the list in TwinColumnSelection
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourceElementBean implements Comparable<ResourceElementBean>{
|
||||
|
||||
private int identifier;
|
||||
private String name;
|
||||
private boolean movedToRight;
|
||||
private boolean isFolder;
|
||||
private ResourceElementBean parent;
|
||||
private List<ResourceElementBean> children;
|
||||
private String fullPath;
|
||||
|
||||
// to generate the identifiers
|
||||
private static int nextId = 0;
|
||||
|
||||
/**
|
||||
* The key provider that provides the unique ID of a bean.
|
||||
*/
|
||||
public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() {
|
||||
@Override
|
||||
public Object getKey(ResourceElementBean item) {
|
||||
return item == null ? null : item.getIdentifier();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param identifier
|
||||
* @param parentFolder
|
||||
* @param name
|
||||
* @param movedToRight
|
||||
* @param isFolder
|
||||
*/
|
||||
public ResourceElementBean(
|
||||
ResourceElementBean parent,
|
||||
String name,
|
||||
boolean isFolder,
|
||||
List<ResourceElementBean> children,
|
||||
String fullPath) {
|
||||
this.identifier = nextId;
|
||||
nextId++;
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
this.isFolder = isFolder;
|
||||
this.children = children;
|
||||
this.fullPath = fullPath;
|
||||
}
|
||||
|
||||
public ResourceElementBean getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(ResourceElementBean parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isMovedToRight() {
|
||||
return movedToRight;
|
||||
}
|
||||
|
||||
public void setMovedToRight(boolean movedToRight) {
|
||||
this.movedToRight = movedToRight;
|
||||
}
|
||||
|
||||
public int getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(int identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public boolean isFolder() {
|
||||
return isFolder;
|
||||
}
|
||||
|
||||
public void setFolder(boolean isFolder) {
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
public List<ResourceElementBean> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<ResourceElementBean> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getFullPath() {
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public void setFullPath(String fullPath) {
|
||||
this.fullPath = fullPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceElementBean [identifier=" + identifier + ", name="
|
||||
+ name + ", movedToRight=" + movedToRight + ", isFolder="
|
||||
+ isFolder + ", fullPath=" + fullPath + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
boolean toReturn = false;
|
||||
if (o instanceof ResourceElementBean) {
|
||||
toReturn = identifier == ((ResourceElementBean) o).identifier;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ResourceElementBean o) {
|
||||
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
|
||||
return toReturn;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ public class ShowMorePagerPanel extends AbstractPager{
|
|||
/**
|
||||
* The default increment size.
|
||||
*/
|
||||
public static final int DEFAULT_INCREMENT = 5;
|
||||
public static final int DEFAULT_INCREMENT = 10;
|
||||
|
||||
/**
|
||||
* The increment size.
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.TwinColumnSelection;
|
||||
|
||||
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.Button;
|
||||
import com.github.gwtbootstrap.client.ui.Popover;
|
||||
import com.github.gwtbootstrap.client.ui.constants.Placement;
|
||||
|
@ -48,6 +51,8 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
@UiField
|
||||
Button goRootButton;
|
||||
@UiField
|
||||
Button goUpButton;
|
||||
@UiField
|
||||
Popover popoverResourceSelection;
|
||||
@UiField
|
||||
Button resourceInfoButton;
|
||||
|
@ -121,6 +126,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
ResourceElementBean selectedBean = (ResourceElementBean) selectedObjectsIterator.next();
|
||||
if(selectedBean.isFolder()){
|
||||
if(selectionModelLeft.getSelectedSet().size() == 1){
|
||||
Collections.sort(selectedBean.getChildren());
|
||||
dataProviderLeft.setList(selectedBean.getChildren());
|
||||
dataProviderLeft.refresh();
|
||||
dataProviderLeft.flush();
|
||||
|
@ -134,6 +140,7 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
});
|
||||
|
||||
// set the list into the provider
|
||||
Collections.sort(elements);
|
||||
dataProviderLeft.setList(elements);
|
||||
|
||||
// set the cell list into the provider
|
||||
|
@ -242,6 +249,29 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
}
|
||||
});
|
||||
|
||||
goUpButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
|
||||
ResourceElementBean firstElemCurrList = dataProviderLeft.getList().get(0);
|
||||
if(firstElemCurrList.getParent() == null){
|
||||
GWT.log("It is the root ...");
|
||||
return;
|
||||
}else{
|
||||
// get the children of the parent and show them
|
||||
GWT.log("Called " + firstElemCurrList.getParent());
|
||||
if(firstElemCurrList.getParent().getParent() == null){
|
||||
// still the root
|
||||
dataProviderLeft.setList(initialElements);
|
||||
}else{
|
||||
dataProviderLeft.setList(firstElemCurrList.getParent().getParent().getChildren());
|
||||
}
|
||||
dataProviderLeft.flush();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
allToRightButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
|
@ -296,13 +326,16 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
while (iterator.hasNext()) {
|
||||
ResourceElementBean resourceElementBean = (ResourceElementBean) iterator
|
||||
.next();
|
||||
resourceElementBean.setMovedToRight(true);
|
||||
resourceElementBean.setToBeAdded(true);
|
||||
|
||||
int indexRight = dataProviderRight.getList().indexOf(resourceElementBean);
|
||||
if(indexRight >= 0)
|
||||
dataProviderRight.getList().set(indexRight, resourceElementBean);
|
||||
else
|
||||
else{
|
||||
dataProviderRight.getList().add(resourceElementBean);
|
||||
Collections.sort(dataProviderRight.getList());
|
||||
dataProviderRight.refresh();
|
||||
}
|
||||
|
||||
int indexLeft = dataProviderLeft.getList().indexOf(resourceElementBean);
|
||||
dataProviderLeft.getList().set(indexLeft, resourceElementBean);
|
||||
|
@ -321,17 +354,31 @@ public class TwinColumnSelectionMainPanel extends Composite{
|
|||
Iterator<ResourceElementBean> iterator = setSelected.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ResourceElementBean resourceElementBean = (ResourceElementBean) iterator.next();
|
||||
resourceElementBean.setMovedToRight(false);
|
||||
|
||||
int indexLeft = dataProviderLeft.getList().indexOf(resourceElementBean);
|
||||
if(indexLeft != -1)
|
||||
dataProviderLeft.getList().set(indexLeft, resourceElementBean); // replace
|
||||
else
|
||||
dataProviderLeft.getList().add(resourceElementBean);
|
||||
|
||||
int indexRight = dataProviderRight.getList().indexOf(resourceElementBean);
|
||||
dataProviderLeft.getList().set(indexRight, resourceElementBean);
|
||||
resourceElementBean.setToBeAdded(false);
|
||||
}
|
||||
|
||||
Collections.sort(dataProviderLeft.getList());
|
||||
dataProviderLeft.refresh();
|
||||
dataProviderRight.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze the panel
|
||||
*/
|
||||
public void freeze() {
|
||||
|
||||
allToRightButton.setEnabled(false);
|
||||
toRightButton.setEnabled(false);
|
||||
allToLeftButton.setEnabled(false);
|
||||
toLeftButton.setEnabled(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of files to save
|
||||
* @return the resources to save
|
||||
*/
|
||||
public List<ResourceElementBean> getResourcesToPublish(){
|
||||
return dataProviderRight.getList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
<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>
|
||||
|
|
|
@ -3,7 +3,7 @@ package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.res
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherService;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.CKanPublisherServiceAsync;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEvent;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
|
@ -89,24 +89,28 @@ public class AddResourceToDataset extends Composite{
|
|||
}
|
||||
|
||||
// collect data and build up the bean
|
||||
final ResourceBeanWrapper resource =
|
||||
new ResourceBeanWrapper(
|
||||
final ResourceElementBean resource =
|
||||
new ResourceElementBean(
|
||||
resourceNameTextBox.getText(),
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
resourceUrlTextBox.getText(),
|
||||
resourceNameTextBox.getText(),
|
||||
resourceDescriptionTextArea.getText(),
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
resourceDescriptionTextArea.getText(),
|
||||
datasetOrg);
|
||||
|
||||
// disable add button
|
||||
addResourceButton.setEnabled(false);
|
||||
|
||||
// try to create
|
||||
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceBeanWrapper>() {
|
||||
ckanServices.addResourceToDataset(resource, datasetId, new AsyncCallback<ResourceElementBean>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResourceBeanWrapper result) {
|
||||
public void onSuccess(ResourceElementBean result) {
|
||||
|
||||
if(result != null){
|
||||
showAlert("Resource created correctly", AlertType.SUCCESS);
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResou
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.AddResourceEventHandler;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEvent;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.client.events.DeleteResourceEventHandler;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Accordion;
|
||||
import com.github.gwtbootstrap.client.ui.AccordionGroup;
|
||||
|
@ -46,7 +46,7 @@ public class AddedResourcesSummary extends Composite{
|
|||
private HandlerManager eventBus;
|
||||
|
||||
// list of added resources (beans)
|
||||
List<ResourceBeanWrapper> addedResources;
|
||||
List<ResourceElementBean> addedResources;
|
||||
|
||||
@UiField VerticalPanel addResourcesPanel;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class AddedResourcesSummary extends Composite{
|
|||
bind();
|
||||
|
||||
// init list
|
||||
addedResources = new ArrayList<ResourceBeanWrapper>();
|
||||
addedResources = new ArrayList<ResourceElementBean>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ public class AddedResourcesSummary extends Composite{
|
|||
public void onAddedResource(AddResourceEvent addResourceEvent) {
|
||||
|
||||
// get the resource
|
||||
final ResourceBeanWrapper justAddedResource = addResourceEvent.getResource();
|
||||
final ResourceElementBean justAddedResource = addResourceEvent.getResource();
|
||||
|
||||
// Build an accordion to show resource info
|
||||
Accordion accordion = new Accordion();
|
||||
|
@ -122,12 +122,12 @@ public class AddedResourcesSummary extends Composite{
|
|||
public void onDeletedResource(DeleteResourceEvent deleteResourceEvent) {
|
||||
|
||||
// to delete
|
||||
ResourceBeanWrapper toDelete = deleteResourceEvent.getResource();
|
||||
ResourceElementBean toDelete = deleteResourceEvent.getResource();
|
||||
|
||||
// find it
|
||||
for(int i = 0; i < addedResources.size(); i++){
|
||||
|
||||
if(addedResources.get(i).getId().equals(toDelete.getId())){
|
||||
if(addedResources.get(i).getOriginalIdInWorkspace().equals(toDelete.getOriginalIdInWorkspace())){
|
||||
|
||||
// get the associated widget and remove it
|
||||
final Widget widget = addResourcesPanel.getWidget(i);
|
||||
|
|
|
@ -1,325 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.client.ui.dataset.resources;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.AlertBlock;
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.CellTable;
|
||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||
import com.google.gwt.cell.client.Cell.Context;
|
||||
import com.google.gwt.cell.client.CheckboxCell;
|
||||
import com.google.gwt.cell.client.EditTextCell;
|
||||
import com.google.gwt.cell.client.FieldUpdater;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NativeEvent;
|
||||
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.safehtml.shared.SafeHtmlBuilder;
|
||||
import com.google.gwt.user.cellview.client.Column;
|
||||
import com.google.gwt.user.cellview.client.ColumnSortEvent.ListHandler;
|
||||
import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
|
||||
import com.google.gwt.user.cellview.client.TextColumn;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
import com.google.gwt.view.client.ListDataProvider;
|
||||
import com.google.gwt.view.client.ProvidesKey;
|
||||
import com.google.gwt.view.client.Range;
|
||||
|
||||
/**
|
||||
* The resources table class.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourcesTable extends Composite{
|
||||
|
||||
// the data provider
|
||||
protected ListDataProvider<ResourceBeanWrapper> dataProvider = new ListDataProvider<ResourceBeanWrapper>();
|
||||
|
||||
// the table that will be displayed
|
||||
private CellTable<ResourceBeanWrapper> table;
|
||||
|
||||
// save original list
|
||||
private List<ResourceBeanWrapper> originalResources;
|
||||
|
||||
// main panel
|
||||
private VerticalPanel mainPanel = new VerticalPanel();
|
||||
|
||||
// button labels
|
||||
private static final String SELECT_ALL_LABEL = "Select All";
|
||||
private static final String DESELECT_ALL_LABEL = "Deselect All";
|
||||
|
||||
// alert block
|
||||
private AlertBlock alert = new AlertBlock();
|
||||
|
||||
/*
|
||||
* The key provider that allows us to identify ResourceBeanWrapper even if a field
|
||||
* changes. We identify ResourceBeanWrapper by their unique ID.
|
||||
*/
|
||||
private static final ProvidesKey<ResourceBeanWrapper> KEY_PROVIDER = new ProvidesKey<ResourceBeanWrapper>() {
|
||||
@Override
|
||||
public Object getKey(ResourceBeanWrapper item) {
|
||||
return item.getId();
|
||||
}
|
||||
};
|
||||
|
||||
// maintain the selection status
|
||||
private boolean selectedAll = true;
|
||||
final Button selectAllButton = new Button(DESELECT_ALL_LABEL);
|
||||
|
||||
// is read only?
|
||||
private boolean readOnly = false;
|
||||
|
||||
public ResourcesTable(List<ResourceBeanWrapper> resources){
|
||||
|
||||
super();
|
||||
initWidget(mainPanel);
|
||||
|
||||
// set panel width
|
||||
mainPanel.setWidth("100%");
|
||||
|
||||
// save original resources
|
||||
this.originalResources = resources;
|
||||
|
||||
// create table with key provider
|
||||
table = new CellTable<ResourceBeanWrapper>(KEY_PROVIDER);
|
||||
table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
|
||||
|
||||
// add data to the provider
|
||||
dataProvider.setList(resources);
|
||||
dataProvider.addDataDisplay(table);
|
||||
|
||||
// style of the table
|
||||
table.setStriped(true);
|
||||
table.setWidth("100%", false);
|
||||
table.addStyleName("table-style");
|
||||
table.setBordered(true);
|
||||
|
||||
// visible rows
|
||||
table.setVisibleRange(new Range(0, originalResources.size()));
|
||||
table.setRowCount(originalResources.size(), true);
|
||||
|
||||
// Add a checked column to add the resource.
|
||||
Column<ResourceBeanWrapper, Boolean> chosenColumn = new Column<ResourceBeanWrapper, Boolean>(new CheckboxCell(true,false)) {
|
||||
|
||||
@Override
|
||||
public Boolean getValue(ResourceBeanWrapper object) {
|
||||
return object.isToBeAdded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowserEvent(Context context, final Element parent, final ResourceBeanWrapper res, NativeEvent event) {
|
||||
super.onBrowserEvent(context, parent, res, event);
|
||||
|
||||
// set the value
|
||||
res.setToBeAdded(!res.isToBeAdded());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Context context, ResourceBeanWrapper object,
|
||||
SafeHtmlBuilder sb) {
|
||||
|
||||
if(readOnly){
|
||||
|
||||
String checked = object.isToBeAdded() ? "checked" : "unchecked";
|
||||
sb.appendHtmlConstant("<input type='checkbox'" ).
|
||||
appendHtmlConstant("tabindex='-1' ").
|
||||
appendEscaped(checked).appendEscaped(" disabled ").appendHtmlConstant("/>");
|
||||
|
||||
}else{
|
||||
|
||||
super.render(context, object, sb);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
table.addColumn(chosenColumn, "Select");
|
||||
|
||||
// Add a text column to show the name (and make it sortable)
|
||||
final EditTextCell nameCell = new EditTextCell();
|
||||
Column<ResourceBeanWrapper, String> nameColumn = new Column<ResourceBeanWrapper, String>(nameCell) {
|
||||
|
||||
@Override
|
||||
public String getValue(ResourceBeanWrapper object) {
|
||||
return object.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowserEvent(Context context, Element elem,
|
||||
ResourceBeanWrapper object, NativeEvent event) {
|
||||
if(!readOnly){
|
||||
super.onBrowserEvent(context, elem, object, event);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Add a field updater to be notified when the user enters a new name for the resource.
|
||||
nameColumn.setFieldUpdater(new FieldUpdater<ResourceBeanWrapper, String>() {
|
||||
@Override
|
||||
public void update(int index, ResourceBeanWrapper object, String value) {
|
||||
if(value.isEmpty() || value.length() < 5){
|
||||
nameCell.clearViewData(KEY_PROVIDER.getKey(object));
|
||||
table.redraw();
|
||||
alert("Resource's name cannot be empty at should be at least of 5 characters", AlertType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// push the changes into the object
|
||||
object.setName(value);
|
||||
|
||||
// Redraw the table with the new data.
|
||||
table.redraw();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
ListHandler<ResourceBeanWrapper> nameColHandler = new ListHandler<ResourceBeanWrapper>(dataProvider.getList());
|
||||
|
||||
nameColHandler.setComparator(nameColumn, new Comparator<ResourceBeanWrapper>() {
|
||||
|
||||
public int compare(ResourceBeanWrapper o1, ResourceBeanWrapper o2) {
|
||||
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
|
||||
}
|
||||
});
|
||||
nameColumn.setSortable(true);
|
||||
nameColumn.setDefaultSortAscending(false);
|
||||
table.addColumnSortHandler(nameColHandler);
|
||||
table.addColumn(nameColumn, "Name (Editable)");
|
||||
|
||||
// Add a date column to show the url
|
||||
TextColumn<ResourceBeanWrapper> urlColumn = new TextColumn<ResourceBeanWrapper>() {
|
||||
@Override
|
||||
public String getValue(ResourceBeanWrapper object) {
|
||||
return object.getUrl();
|
||||
}
|
||||
};
|
||||
table.addColumn(urlColumn, "Url (Temporary)");
|
||||
|
||||
// Add a date column to show the description (and make it sortable)
|
||||
Column<ResourceBeanWrapper, String> descColumn = new Column<ResourceBeanWrapper, String>(new EditTextCell()) {
|
||||
@Override
|
||||
public String getValue(ResourceBeanWrapper object) {
|
||||
return object.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBrowserEvent(Context context, Element elem,
|
||||
ResourceBeanWrapper object, NativeEvent event) {
|
||||
if(!readOnly){
|
||||
super.onBrowserEvent(context, elem, object, event);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Add a field updater to be notified when the user enters a new description.
|
||||
descColumn.setFieldUpdater(new FieldUpdater<ResourceBeanWrapper, String>() {
|
||||
@Override
|
||||
public void update(int index, ResourceBeanWrapper object, String value) {
|
||||
|
||||
// push the changes into the object
|
||||
object.setDescription(value);
|
||||
|
||||
// Redraw the table with the new data.
|
||||
table.redraw();
|
||||
}
|
||||
});
|
||||
|
||||
table.addColumn(descColumn, "Description (Editable)");
|
||||
|
||||
// sort by columnName
|
||||
table.getColumnSortList().push(nameColumn);
|
||||
|
||||
// set width column chosen
|
||||
table.setColumnWidth(chosenColumn, 5, Unit.PCT);
|
||||
table.setColumnWidth(nameColumn, 20, Unit.PCT);
|
||||
table.setColumnWidth(urlColumn, 45, Unit.PCT);
|
||||
table.setColumnWidth(descColumn, 30, Unit.PCT);
|
||||
|
||||
// add a select all button
|
||||
|
||||
selectAllButton.getElement().getStyle().setMarginTop(15, Unit.PX);
|
||||
selectAllButton.getElement().getStyle().setMarginBottom(15, Unit.PX);
|
||||
|
||||
// add handler
|
||||
selectAllButton.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
selectedAll = !selectedAll;
|
||||
checkAllResources(selectedAll);
|
||||
}
|
||||
});
|
||||
|
||||
// add the button
|
||||
mainPanel.add(selectAllButton);
|
||||
|
||||
// add the table
|
||||
mainPanel.add(table);
|
||||
|
||||
// add the alert block
|
||||
mainPanel.add(alert);
|
||||
alert.setVisible(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check/Uncheck all resources according to value
|
||||
* @param boolean value
|
||||
*/
|
||||
public void checkAllResources(boolean value){
|
||||
|
||||
if(value)
|
||||
selectAllButton.setText(DESELECT_ALL_LABEL);
|
||||
else
|
||||
selectAllButton.setText(SELECT_ALL_LABEL);
|
||||
|
||||
for(ResourceBeanWrapper resource: originalResources)
|
||||
resource.setToBeAdded(value);
|
||||
|
||||
// refresh data
|
||||
dataProvider.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Freeze table content and select/deselect all button
|
||||
*/
|
||||
public void freezeTable() {
|
||||
|
||||
selectAllButton.setEnabled(false);
|
||||
readOnly = true;
|
||||
|
||||
// redraw the table (freezing it)
|
||||
table.redraw();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Alert the user
|
||||
*/
|
||||
private void alert(String msg, AlertType alertType){
|
||||
|
||||
alert.setText(msg);
|
||||
alert.setType(alertType);
|
||||
alert.setVisible(true);
|
||||
alert.setAnimation(true);
|
||||
|
||||
// hide anyway after a while
|
||||
Timer t = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
alert.setVisible(false);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
t.schedule(5000);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadata
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.LicensesBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
|
@ -39,13 +39,13 @@ import eu.trentorise.opendata.jackan.model.CkanLicense;
|
|||
* Server side of the data publisher.
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@SuppressWarnings({"serial","deprecation"})
|
||||
public class CKANPublisherServicesImpl extends RemoteServiceServlet implements CKanPublisherService{
|
||||
|
||||
// Logger
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class);
|
||||
|
||||
public static final String TEST_SCOPE = "/gcube/devsec/devVRE";
|
||||
public static final String TEST_SCOPE = "/gcube";
|
||||
public static final String TEST_USER = "test.user";
|
||||
private final static String TEST_SEC_TOKEN = "a1e19695-467f-42b8-966d-bf83dd2382ef";
|
||||
|
||||
|
@ -362,20 +362,18 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
|
||||
// get the list of resources and convert to ResourceBean
|
||||
List<ResourceBean> resources = null;
|
||||
List<ResourceBeanWrapper> resourcesToAdd = toCreate.getResources();
|
||||
List<ResourceElementBean> resourcesToAdd = toCreate.getResources();
|
||||
|
||||
// we need to copy such resource in the .catalogue area of the user's ws
|
||||
if(resourcesToAdd != null && !resourcesToAdd.isEmpty()){
|
||||
|
||||
resources = WorkspaceUtils.copyResourcesToUserCatalogueArea(resourcesToAdd, toCreate.getId(), userName, toCreate);
|
||||
|
||||
}
|
||||
|
||||
logger.debug("The user wants to publish in organization with name " + organizationNameOrId);
|
||||
String scope = getScopeFromOrgName(organizationNameOrId);
|
||||
DataCatalogue utils = getCatalogue(scope);
|
||||
|
||||
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(scope), title, organizationNameOrId, author,
|
||||
String datasetId = utils.createCKanDataset(getUserCKanTokenFromSession(scope), title, null, organizationNameOrId, author,
|
||||
authorMail, maintainer, maintainerMail, version, description, licenseId,
|
||||
listOfTags, customFields, resources, setPublic);
|
||||
|
||||
|
@ -417,22 +415,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
threadWritePost.start();
|
||||
|
||||
return toCreate;
|
||||
|
||||
}else{
|
||||
|
||||
logger.error("Failed to create the dataset");
|
||||
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Unable to create the dataset", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBeanWrapper addResourceToDataset(ResourceBeanWrapper resource, String datasetId) {
|
||||
public ResourceElementBean addResourceToDataset(ResourceElementBean resource, String datasetId) {
|
||||
|
||||
|
||||
ASLSession session = getASLSession();
|
||||
|
@ -472,7 +465,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
if(resourceId != null){
|
||||
logger.debug("Resource " + resource.getName() + " is now available");
|
||||
// set its id and turn it to the client
|
||||
resource.setId(resourceId);
|
||||
resource.setOriginalIdInWorkspace(resourceId);
|
||||
return resource;
|
||||
}
|
||||
}catch(Exception e){
|
||||
|
@ -485,7 +478,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteResourceFromDataset(ResourceBeanWrapper resource) {
|
||||
public boolean deleteResourceFromDataset(ResourceElementBean resource) {
|
||||
|
||||
logger.debug("Request for deleting resource " + resource);
|
||||
boolean deleted = false;
|
||||
|
@ -506,7 +499,7 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
// get the scope in which we should discover the ckan instance given the organization name in which the dataset was created
|
||||
String scope = getScopeFromOrgName(resource.getOrganizationNameDatasetParent());
|
||||
deleted = getCatalogue(scope).
|
||||
deleteResourceFromDataset(resource.getId(), getUserCKanTokenFromSession(scope));
|
||||
deleteResourceFromDataset(resource.getOriginalIdInWorkspace(), getUserCKanTokenFromSession(scope));
|
||||
if(deleted){
|
||||
logger.debug("Resource described by " + resource + " deleted");
|
||||
}else
|
||||
|
@ -587,4 +580,46 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C
|
|||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public ResourceElementBean getTreeFolder(String folderId) {
|
||||
//
|
||||
// if(folderId == null || folderId.isEmpty()){
|
||||
// logger.warn("Empty folder id or null, returning");
|
||||
// return null;
|
||||
// }
|
||||
// ASLSession session = getASLSession();
|
||||
// try{
|
||||
// if(!isWithinPortal()){
|
||||
// logger.warn("Running outside the portal");
|
||||
// Workspace ws = getFakeWS();
|
||||
// ResourceElementBean toReturn = WorkspaceUtils.getTreeFromFolder(folderId, ws);
|
||||
// logger.debug("Returning " + toReturn);
|
||||
// return toReturn;
|
||||
// }else{
|
||||
// if(session.getUsername().equals(TEST_USER)){
|
||||
// logger.warn("SESSION EXPIRED!");
|
||||
// return null;
|
||||
// }else{
|
||||
// // TODO
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }catch(Exception e){
|
||||
// logger.error("Failed to build the tree", e);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Retrieve the workspace for the development user
|
||||
// * @return
|
||||
// * @throws Exception
|
||||
// */
|
||||
// private Workspace getFakeWS() throws Exception{
|
||||
// return HomeLibrary
|
||||
// .getHomeManagerFactory()
|
||||
// .getHomeManager()
|
||||
// .getHome(getDevelopmentUser()).getWorkspace();
|
||||
// }
|
||||
}
|
|
@ -138,6 +138,7 @@ public class Utils {
|
|||
// get highest role according liferay
|
||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||
|
||||
// this is a tricky part... because we actually do not know if it is a member or there is no ckan instance there
|
||||
if(correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER))
|
||||
continue;
|
||||
|
||||
|
@ -158,6 +159,7 @@ public class Utils {
|
|||
// get highest role according liferay
|
||||
RolesCkanGroupOrOrg correspondentRoleToCheck = getLiferayHighestRoleInOrg(roles);
|
||||
|
||||
// this is a tricky part... because we actually do not know if it is a member or there is no ckan instance there
|
||||
if(correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER))
|
||||
continue;
|
||||
|
||||
|
@ -353,8 +355,6 @@ public class Utils {
|
|||
} catch (Exception e) {
|
||||
logger.error("Error while retrieving metadata beans ", e);
|
||||
}finally{
|
||||
|
||||
// set the scope back
|
||||
if(oldScope != scopeInWhichDiscover)
|
||||
ScopeProvider.instance.set(oldScope);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.homelibrary.home.HomeLibrary;
|
||||
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
||||
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
||||
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
||||
|
@ -12,7 +13,7 @@ import org.gcube.common.homelibrary.home.workspace.catalogue.WorkspaceCatalogue;
|
|||
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.models.ResourceBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DatasetMetadataBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceBeanWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class WorkspaceUtils {
|
||||
|
@ -30,8 +31,7 @@ public class WorkspaceUtils {
|
|||
* @param bean
|
||||
* @return
|
||||
*/
|
||||
public static List<ResourceBean> copyResourcesToUserCatalogueArea(
|
||||
List<ResourceBeanWrapper> resourcesToAdd, String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
||||
public static List<ResourceBean> copyResourcesToUserCatalogueArea(List<ResourceElementBean> resourcesToAdd, String folderId, String userName, DatasetMetadataBean bean) throws Exception{
|
||||
|
||||
logger.debug("Request to copy onto catalogue area....");
|
||||
List<ResourceBean> resources = new ArrayList<ResourceBean>();
|
||||
|
@ -42,7 +42,7 @@ public class WorkspaceUtils {
|
|||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome(userName)
|
||||
.getHome()
|
||||
.getWorkspace();
|
||||
|
||||
// Retrieve the catalogue of the user
|
||||
|
@ -58,12 +58,12 @@ public class WorkspaceUtils {
|
|||
((WorkspaceFolder)copiedFolder).rename(org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods.fromProductTitleToName(bean.getTitle()) + "_" + System.currentTimeMillis());
|
||||
|
||||
// copy only the selected ones
|
||||
for(ResourceBeanWrapper resourceBeanWrapper : resourcesToAdd){
|
||||
for(ResourceElementBean resourceBeanWrapper : resourcesToAdd){
|
||||
|
||||
if (resourceBeanWrapper.isToBeAdded()) {
|
||||
|
||||
// ok it is a file, so copy it into the copiedFolder
|
||||
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resourceBeanWrapper.getId(), copiedFolder.getId());
|
||||
WorkspaceItem copiedFile = userCatalogue.addWorkspaceItem(resourceBeanWrapper.getOriginalIdInWorkspace(), copiedFolder.getId());
|
||||
|
||||
// name and description could have been edited
|
||||
copiedFile.setDescription(resourceBeanWrapper.getDescription());
|
||||
|
@ -107,7 +107,7 @@ public class WorkspaceUtils {
|
|||
|
||||
// set some info
|
||||
String onlyAlphanumericTitle = originalFolder.getName().replaceAll("[^A-Za-z0-9.-_]", " "); // that is, remove characters different than the ones inside
|
||||
// since it will (likely) be the name of the product
|
||||
// since it will (likely) be the name of the product
|
||||
bean.setTitle(onlyAlphanumericTitle);
|
||||
bean.setDescription(originalFolder.getDescription());
|
||||
|
||||
|
@ -115,54 +115,62 @@ public class WorkspaceUtils {
|
|||
Map<String, String> folderItems = Utils.getGcubeItemProperties(originalFolder);
|
||||
bean.setCustomFields(folderItems);
|
||||
|
||||
// check the resources within the folder
|
||||
List<String> childrenIds = new ArrayList<String>();
|
||||
|
||||
for (WorkspaceItem file : originalFolder.getChildren()) {
|
||||
if(!file.isFolder()){
|
||||
childrenIds.add(file.getId());
|
||||
}
|
||||
}
|
||||
|
||||
// set them into the bean
|
||||
bean.setResources(getWorkspaceResourcesInformation(childrenIds, ws, userName));
|
||||
bean.setResources(WorkspaceUtils.getTreeFromFolder(folderId, ws).getChildren());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the resource beans.
|
||||
* @param resourceIds
|
||||
* Returns a tree object
|
||||
* @param workspaceFolderId
|
||||
* @param ws
|
||||
* @param username
|
||||
* @return a list of resource wrapper beans
|
||||
* @return ResourceElementBean a tree object
|
||||
* @throws Exception
|
||||
*/
|
||||
public static List<ResourceBeanWrapper> getWorkspaceResourcesInformation(
|
||||
List<String> resourceIds, Workspace ws, String username){
|
||||
|
||||
List<ResourceBeanWrapper> toReturn = new ArrayList<>();
|
||||
|
||||
for (String resourceId : resourceIds) {
|
||||
|
||||
try{
|
||||
logger.debug("RESOURCE ID IS " + resourceId);
|
||||
|
||||
ResourceBeanWrapper newResource = new ResourceBeanWrapper();
|
||||
WorkspaceItem item = ws.getItem(resourceId);
|
||||
newResource.setDescription(item.getDescription());
|
||||
newResource.setId(item.getId());
|
||||
newResource.setUrl(item.getPublicLink(true));
|
||||
newResource.setName(item.getName());
|
||||
newResource.setToBeAdded(true); // default is true
|
||||
newResource.setMimeType(((FolderItem)item).getMimeType());
|
||||
toReturn.add(newResource);
|
||||
}catch(Exception e ){
|
||||
logger.error("Unable to add resource with id " + resourceId + " to the product bean");
|
||||
}
|
||||
public static ResourceElementBean getTreeFromFolder(String workspaceFolderId, Workspace ws) throws Exception{
|
||||
|
||||
// start tree construction
|
||||
ResourceElementBean rootElem = new ResourceElementBean();
|
||||
try{
|
||||
WorkspaceItem initialItemWS = ws.getItem(workspaceFolderId);
|
||||
String fullPathBase = initialItemWS.getPath();
|
||||
// rootElem.setFolder(initialItemWS.isFolder());
|
||||
// rootElem.setFullPath(initialItemWS.getPath().replace(fullPathBase, ""));
|
||||
// rootElem.setParent(null);
|
||||
// rootElem.setName(initialItemWS.getName());
|
||||
// rootElem.setOriginalIdInWorkspace(initialItemWS.getId());
|
||||
// rootElem.setToBeAdded(false);
|
||||
// rootElem.setMimeType(((FolderItem)initialItemWS).getMimeType());
|
||||
// rootElem.setDescription(initialItemWS.getDescription());
|
||||
// start visiting
|
||||
visit(rootElem, initialItemWS, fullPathBase);
|
||||
return rootElem;
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to build the resource tree", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive visit of a workspace item
|
||||
* @param rootElem
|
||||
* @param initialItemWS
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
private static void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS, String fullPathBase) throws InternalErrorException {
|
||||
List<? extends WorkspaceItem> children = initialItemWS.getChildren();
|
||||
ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
ResourceElementBean elem = new ResourceElementBean();
|
||||
elem.setFolder(workspaceItem.isFolder());
|
||||
elem.setOriginalIdInWorkspace(workspaceItem.getId());
|
||||
elem.setFullPath(workspaceItem.getPath().replace(fullPathBase, "")); // remove this path
|
||||
elem.setParent(rootElem);
|
||||
elem.setName(workspaceItem.getName());
|
||||
childrenInTree.add(elem);
|
||||
visit(elem, workspaceItem, fullPathBase);
|
||||
}
|
||||
rootElem.setChildren(childrenInTree);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,12 +30,8 @@ public class DatasetMetadataBean implements Serializable {
|
|||
private String id;
|
||||
private String title;
|
||||
private String description;
|
||||
private Map<String, String> customFields;
|
||||
private List<String> tags; // on retrieve, they are the keys of the custom fields
|
||||
private String license; // chosen by the user
|
||||
private boolean visibility; // Private (false) or Public(true)
|
||||
private String source; // url of the folder in the workspace
|
||||
private long version; // version 1, 2 ...
|
||||
private String authorName; // author name
|
||||
private String authorSurname; // author surname
|
||||
private String authorFullName;
|
||||
|
@ -43,11 +39,15 @@ public class DatasetMetadataBean implements Serializable {
|
|||
private String maintainer;
|
||||
private String maintainerEmail;
|
||||
private String ownerIdentifier; // owner of the folder into the workspace (e.g., andrea.rossi)
|
||||
private List<OrganizationBean> organizationList; // list of organization in which the user is present and could create the dataset
|
||||
private String selectedOrganization;
|
||||
private List<ResourceBeanWrapper> resources; // in case of workspace, this is the list of children
|
||||
private List<MetaDataProfileBean> metadataList;
|
||||
private String chosenProfile; // the name of the MetaDataProfile chosen
|
||||
private String selectedOrganization;
|
||||
private long version; // version 1, 2 ...
|
||||
private boolean visibility; // Private (false) or Public(true)
|
||||
private List<OrganizationBean> organizationList; // list of organization in which the user is present and could create the dataset
|
||||
private List<ResourceElementBean> resources; // in case of workspace, this is the list of children of the folder
|
||||
private List<MetaDataProfileBean> metadataList;
|
||||
private List<String> tags; // on retrieve, they are the keys of the custom fields
|
||||
private Map<String, String> customFields;
|
||||
|
||||
public DatasetMetadataBean(){
|
||||
super();
|
||||
|
@ -80,7 +80,7 @@ public class DatasetMetadataBean implements Serializable {
|
|||
String authorName, String authorSurname, String authorEmail, String maintainer,
|
||||
String maintainerEmail, String ownerIdentifier,
|
||||
List<OrganizationBean> organizationList, String selectedOrganization,
|
||||
List<ResourceBeanWrapper> resources,
|
||||
List<ResourceElementBean> resources,
|
||||
List<MetaDataProfileBean> metadataList) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
@ -248,14 +248,14 @@ public class DatasetMetadataBean implements Serializable {
|
|||
this.selectedOrganization = selectedOrganization;
|
||||
}
|
||||
|
||||
public List<ResourceBeanWrapper> getResources() {
|
||||
public List<ResourceElementBean> getResources() {
|
||||
return resources;
|
||||
}
|
||||
|
||||
public void setResources(List<ResourceBeanWrapper> resources) {
|
||||
public void setResources(List<ResourceElementBean> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
|
||||
|
||||
public String getAuthorFullName() {
|
||||
return authorFullName;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ public class DatasetMetadataBean implements Serializable {
|
|||
public void setAuthorFullName(String authorFullName) {
|
||||
this.authorFullName = authorFullName;
|
||||
}
|
||||
|
||||
|
||||
public String getChosenProfile() {
|
||||
return chosenProfile;
|
||||
}
|
||||
|
@ -271,6 +271,7 @@ public class DatasetMetadataBean implements Serializable {
|
|||
public void setChosenProfile(String chosenProfile) {
|
||||
this.chosenProfile = chosenProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DatasetMetadataBean [id=" + id + ", title=" + title
|
||||
|
@ -287,5 +288,4 @@ public class DatasetMetadataBean implements Serializable {
|
|||
+ ", resources=" + resources + ", metadataList=" + metadataList
|
||||
+ ", chosenProfile=" + chosenProfile + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A dataset's resource bean
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourceBeanWrapper implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = -6542455246456049712L;
|
||||
private String url;
|
||||
private String name;
|
||||
private String description;
|
||||
private String id;
|
||||
private boolean toBeAdded;
|
||||
private String mimeType;
|
||||
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
|
||||
private List<ResourceBeanWrapper> subResources; // a list of sub resources
|
||||
private ResourceBeanWrapper parentResource;
|
||||
private boolean isFolder;
|
||||
|
||||
public ResourceBeanWrapper(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
* @param name
|
||||
* @param description
|
||||
* @param id
|
||||
* @param toBeAdded
|
||||
* @param mimeType
|
||||
* @param organizationNameDatasetParent
|
||||
* @param subResources
|
||||
* @param parentResource
|
||||
* @param isFolder
|
||||
*/
|
||||
public ResourceBeanWrapper(String url, String name, String description,
|
||||
String id, boolean toBeAdded, String mimeType,
|
||||
String organizationNameDatasetParent,
|
||||
List<ResourceBeanWrapper> subResources,
|
||||
ResourceBeanWrapper parentResource, boolean isFolder) {
|
||||
super();
|
||||
this.url = url;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.id = id;
|
||||
this.toBeAdded = toBeAdded;
|
||||
this.mimeType = mimeType;
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
this.subResources = subResources;
|
||||
this.parentResource = parentResource;
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when the user adds the resources after having created the product
|
||||
* @param url
|
||||
* @param name
|
||||
* @param description
|
||||
* @param id
|
||||
* @param toAdd
|
||||
* @param mimeType
|
||||
* @param datasetOrg
|
||||
*/
|
||||
public ResourceBeanWrapper(String url, String name, String description,
|
||||
String id, boolean toAdd, String mimeType, String datasetOrg) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.toBeAdded = toAdd;
|
||||
this.mimeType = mimeType;
|
||||
this.organizationNameDatasetParent = datasetOrg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the url
|
||||
*/
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url the url to set
|
||||
*/
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the toBeAdded
|
||||
*/
|
||||
public boolean isToBeAdded() {
|
||||
return toBeAdded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param toBeAdded the toBeAdded to set
|
||||
*/
|
||||
public void setToBeAdded(boolean toBeAdded) {
|
||||
this.toBeAdded = toBeAdded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mimeType
|
||||
*/
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mimeType the mimeType to set
|
||||
*/
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the organizationNameDatasetParent
|
||||
*/
|
||||
public String getOrganizationNameDatasetParent() {
|
||||
return organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param organizationNameDatasetParent the organizationNameDatasetParent to set
|
||||
*/
|
||||
public void setOrganizationNameDatasetParent(
|
||||
String organizationNameDatasetParent) {
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
public List<ResourceBeanWrapper> getSubResources() {
|
||||
return subResources;
|
||||
}
|
||||
|
||||
public void setSubResources(List<ResourceBeanWrapper> subResources) {
|
||||
this.subResources = subResources;
|
||||
}
|
||||
|
||||
public ResourceBeanWrapper getParentResource() {
|
||||
return parentResource;
|
||||
}
|
||||
|
||||
public void setParentResource(ResourceBeanWrapper parentResource) {
|
||||
this.parentResource = parentResource;
|
||||
}
|
||||
|
||||
public boolean isFolder() {
|
||||
return isFolder;
|
||||
}
|
||||
|
||||
public void setFolder(boolean isFolder) {
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceBeanWrapper [url=" + url + ", name=" + name
|
||||
+ ", description=" + description + ", id=" + id
|
||||
+ ", toBeAdded=" + toBeAdded + ", mimeType=" + mimeType
|
||||
+ ", organizationNameDatasetParent="
|
||||
+ organizationNameDatasetParent + ", subResources="
|
||||
+ subResources + ", parentResource=" + parentResource
|
||||
+ ", isFolder=" + isFolder + "]";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
package org.gcube.portlets.widgets.ckandatapublisherwidget.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gwt.view.client.ProvidesKey;
|
||||
|
||||
|
||||
/**
|
||||
* A resource element bean
|
||||
* @author Costantino Perciante at ISTI-CNR (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class ResourceElementBean implements Comparable<ResourceElementBean>, Serializable{
|
||||
|
||||
private static final long serialVersionUID = -1230871392599580669L;
|
||||
private int identifierGWT;
|
||||
private String name;
|
||||
private boolean toBeAdded;
|
||||
private boolean isFolder;
|
||||
private ResourceElementBean parent;
|
||||
private List<ResourceElementBean> children;
|
||||
private String fullPath;
|
||||
private String originalIdInWorkspace;
|
||||
private String mimeType;
|
||||
private String url;
|
||||
private String description;
|
||||
private String organizationNameDatasetParent; // the organization name in which the parent dataset was created
|
||||
|
||||
// to generate the identifiers
|
||||
private static int nextId = 0;
|
||||
|
||||
/**
|
||||
* The key provider that provides the unique ID of a bean.
|
||||
*/
|
||||
public static final ProvidesKey<ResourceElementBean> KEY_PROVIDER = new ProvidesKey<ResourceElementBean>() {
|
||||
@Override
|
||||
public Object getKey(ResourceElementBean item) {
|
||||
return item == null ? null : item.identifierGWT;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ResourceElementBean(){
|
||||
super();
|
||||
this.identifierGWT = nextId;
|
||||
nextId++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param identifier
|
||||
* @param parentFolder
|
||||
* @param name
|
||||
* @param movedToRight
|
||||
* @param isFolder
|
||||
*/
|
||||
public ResourceElementBean(
|
||||
ResourceElementBean parent,
|
||||
String name,
|
||||
boolean isFolder,
|
||||
List<ResourceElementBean> children,
|
||||
String fullPath) {
|
||||
this.identifierGWT = nextId;
|
||||
nextId++;
|
||||
this.parent = parent;
|
||||
this.name = name;
|
||||
this.isFolder = isFolder;
|
||||
this.children = children;
|
||||
this.fullPath = fullPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param toBeAdded
|
||||
* @param isFolder
|
||||
* @param parent
|
||||
* @param children
|
||||
* @param fullPath
|
||||
* @param originalIdInWorkspace
|
||||
* @param mimeType
|
||||
* @param url
|
||||
* @param description
|
||||
* @param organizationNameDatasetParent
|
||||
*/
|
||||
public ResourceElementBean(String name, boolean toBeAdded,
|
||||
boolean isFolder, ResourceElementBean parent,
|
||||
List<ResourceElementBean> children, String fullPath,
|
||||
String originalIdInWorkspace, String mimeType, String url,
|
||||
String description, String organizationNameDatasetParent) {
|
||||
super();
|
||||
this.identifierGWT = nextId;
|
||||
nextId++;
|
||||
this.name = name;
|
||||
this.toBeAdded = toBeAdded;
|
||||
this.isFolder = isFolder;
|
||||
this.parent = parent;
|
||||
this.children = children;
|
||||
this.fullPath = fullPath;
|
||||
this.originalIdInWorkspace = originalIdInWorkspace;
|
||||
this.mimeType = mimeType;
|
||||
this.url = url;
|
||||
this.description = description;
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
public ResourceElementBean getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(ResourceElementBean parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isToBeAdded() {
|
||||
return toBeAdded;
|
||||
}
|
||||
|
||||
public void setToBeAdded(boolean toBeAdded) {
|
||||
this.toBeAdded = toBeAdded;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getOrganizationNameDatasetParent() {
|
||||
return organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
public void setOrganizationNameDatasetParent(
|
||||
String organizationNameDatasetParent) {
|
||||
this.organizationNameDatasetParent = organizationNameDatasetParent;
|
||||
}
|
||||
|
||||
public boolean isFolder() {
|
||||
return isFolder;
|
||||
}
|
||||
|
||||
public void setFolder(boolean isFolder) {
|
||||
this.isFolder = isFolder;
|
||||
}
|
||||
|
||||
public List<ResourceElementBean> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<ResourceElementBean> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getFullPath() {
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public void setFullPath(String fullPath) {
|
||||
this.fullPath = fullPath;
|
||||
}
|
||||
|
||||
public String getOriginalIdInWorkspace() {
|
||||
return originalIdInWorkspace;
|
||||
}
|
||||
|
||||
public void setOriginalIdInWorkspace(String originalIdInWorkspace) {
|
||||
this.originalIdInWorkspace = originalIdInWorkspace;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return "ResourceElementBean [identifier=" + identifier + ", name="
|
||||
// + name + ", movedToRight=" + movedToRight + ", isFolder="
|
||||
// + isFolder + ", fullPath=" + fullPath + "]";
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
boolean toReturn = false;
|
||||
if (o instanceof ResourceElementBean) {
|
||||
toReturn = identifierGWT == ((ResourceElementBean) o).identifierGWT;
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResourceElementBean [identifierGWT=" + identifierGWT + ", name="
|
||||
+ name + ", toBeAdded=" + toBeAdded + ", isFolder=" + isFolder
|
||||
+ ", parent=" + parent + ", childrenSize=" + children.size()
|
||||
+ ", fullPath=" + fullPath + ", originalIdInWorkspace="
|
||||
+ originalIdInWorkspace + ", mimeType=" + mimeType + ", url="
|
||||
+ url + ", description=" + description
|
||||
+ ", organizationNameDatasetParent="
|
||||
+ organizationNameDatasetParent + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ResourceElementBean o) {
|
||||
int toReturn = (o == null || o.fullPath == null) ? -1 : -o.fullPath.compareTo(fullPath);
|
||||
return toReturn;
|
||||
}
|
||||
}
|
|
@ -27,11 +27,15 @@ import org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils.Utils;
|
|||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.DataType;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetaDataTypeWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.MetadataFieldWrapper;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.ResourceElementBean;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class TestClass {
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestClass.class);
|
||||
|
||||
@Test
|
||||
public void testUser() {
|
||||
|
||||
|
@ -169,7 +173,7 @@ public class TestClass {
|
|||
//@Test
|
||||
public void testDataCatalogueManagerApplication(){
|
||||
|
||||
String token = "d423aed7-e9e2-424a-b9e7-2bbbd151d9c4-98187548";
|
||||
String token = "";
|
||||
String scope = "/gcube/devNext/NextNext";
|
||||
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
@ -180,4 +184,66 @@ public class TestClass {
|
|||
"Costantino Perciante", Arrays.asList("tag1", "tag2", "tag33"), false);
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void treeVisitorTest() throws Exception{
|
||||
|
||||
ScopeProvider.instance.set("/gcube/devNext/NextNext");
|
||||
String itemName = "CkanTest1137";
|
||||
String itemId = null;
|
||||
|
||||
Workspace ws = HomeLibrary
|
||||
.getHomeManagerFactory()
|
||||
.getHomeManager()
|
||||
.getHome("costantino.perciante").getWorkspace();
|
||||
|
||||
List<WorkspaceItem> wsChildren = ws.getRoot().getChildren();
|
||||
|
||||
for (WorkspaceItem workspaceItem : wsChildren) {
|
||||
if(workspaceItem.getName().equals(itemName)){
|
||||
itemId = workspaceItem.getId();
|
||||
logger.debug("Id is " + itemId); //e87bfc7d-4fb0-4795-9c79-0c495500ca9c
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// start tree construction
|
||||
WorkspaceItem initialItemWS = ws.getItem(itemId);
|
||||
ResourceElementBean rootElem = new ResourceElementBean();
|
||||
rootElem.setFolder(initialItemWS.isFolder());
|
||||
rootElem.setFullPath(initialItemWS.getPath());
|
||||
rootElem.setParent(null);
|
||||
rootElem.setName(initialItemWS.getName());
|
||||
rootElem.setOriginalIdInWorkspace(initialItemWS.getId());
|
||||
|
||||
// start visiting
|
||||
visit(rootElem, initialItemWS);
|
||||
|
||||
// print final tree
|
||||
logger.debug("Final tree looks like " + rootElem);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive visit of a workspace item
|
||||
* @param rootElem
|
||||
* @param initialItemWS
|
||||
* @throws InternalErrorException
|
||||
*/
|
||||
private void visit(ResourceElementBean rootElem, WorkspaceItem initialItemWS) throws InternalErrorException {
|
||||
List<? extends WorkspaceItem> children = initialItemWS.getChildren();
|
||||
ArrayList<ResourceElementBean> childrenInTree = new ArrayList<ResourceElementBean>(children.size());
|
||||
for (WorkspaceItem workspaceItem : children) {
|
||||
ResourceElementBean elem = new ResourceElementBean();
|
||||
elem.setFolder(workspaceItem.isFolder());
|
||||
elem.setOriginalIdInWorkspace(workspaceItem.getId());
|
||||
elem.setFullPath(workspaceItem.getPath());
|
||||
elem.setParent(rootElem);
|
||||
elem.setName(workspaceItem.getName());
|
||||
childrenInTree.add(elem);
|
||||
visit(elem, workspaceItem);
|
||||
}
|
||||
rootElem.setChildren(childrenInTree);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue