256: Workspace explorer

Task-Url: https://support.d4science.org/issues/256

Updated server side

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@115533 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-06-25 10:33:18 +00:00
parent 7ded01868f
commit 9f9ebc5b5b
5 changed files with 259 additions and 94 deletions

View File

@ -120,6 +120,9 @@ public class ItemsTable extends AbstractItemsCellTable{
}
};
icon.setCellStyleNames("img-centered-clickable");
icon.setSortable(false);
//ARTIFACT ID
name = new TextColumn<Item>() {
@ -152,12 +155,9 @@ public class ItemsTable extends AbstractItemsCellTable{
owner.setCellStyleNames("img-centered-clickable");
owner.setSortable(true);
packageTable.addColumn(owner, "Version");
packageTable.setColumnWidth(owner, 10.0, Unit.PCT);
*/
icon.setCellStyleNames("img-centered-clickable");
icon.setSortable(false);
packageTable.setColumnWidth(owner, 10.0, Unit.PCT);
packageTable.addColumn(icon, "Download");
packageTable.setColumnWidth(icon, 10.0, Unit.PCT);

View File

@ -1,7 +1,10 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client;
package org.gcube.portlets.widgets.wsexplorer.client.load;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerConstants;
import org.gcube.portlets.widgets.wsexplorer.client.WorkspaceExplorerPanel;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
@ -19,14 +22,14 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 24, 2015
*/
public class WorkspaceExplorerDialog extends DialogBox implements ClickHandler {
public class WorkspaceExplorerLoadDialog extends DialogBox implements ClickHandler {
/**
*
*/
private Button cancel;
private WorkspaceExplorerDialog INSTANCE = this;
private WorkspaceExplorerLoadDialog INSTANCE = this;
private boolean isValidHide;
private String captionTxt;
private WorkspaceExplorerPanel wsp = new WorkspaceExplorerPanel(5);
@ -36,7 +39,7 @@ public class WorkspaceExplorerDialog extends DialogBox implements ClickHandler {
*
* @param captionTxt sets the text inside the caption, if null sets "Workspace Explorer"
*/
public WorkspaceExplorerDialog(String captionTxt) {
public WorkspaceExplorerLoadDialog(String captionTxt) {
this.captionTxt = (captionTxt==null || captionTxt.isEmpty())?WorkspaceExplorerConstants.WORKSPACE_EXPLORER_CAPTION:captionTxt;
setText(this.captionTxt);
isValidHide = false;

View File

@ -7,11 +7,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.portlets.widgets.wsexplorer.client.Util;
@ -21,14 +22,23 @@ import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
/**
* The Class ItemBuilder.
*
* @author Federico De Faveri defaveri@isti.cnr.it
* Modified by Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*/
public class ItemBuilder {
/**
* Purge empty folders.
*
* @param item the item
* @return the item
*/
public static Item purgeEmptyFolders(Item item)
{
for (Item child:item.getChildren()) purgeEmptyFolders(child);
//for (Item child:item.getChildren()) purgeEmptyFolders(child); ONLY FIRST LEVEL
List<Item> toRemoveList = new LinkedList<Item>();
for (Item child:item.getChildren()) {
@ -40,26 +50,32 @@ public class ItemBuilder {
return item;
}
/**
* Checks if is an empty folder.
*
* @param item the item
* @return true, if is an empty folder
*/
protected static boolean isAnEmptyFolder(Item item)
{
return Util.isFolder(item.getType()) && item.getChildren().size() == 0;
}
/**
*
* @param parent
* @param workspaceItem
* @param showableTypes
* @param depth
* @return
* @throws InternalErrorException
* Gets the item.
*
* @param parent the parent
* @param workspaceItem the workspace item
* @param showableTypes the showable types
* @param filterCriteria the filter criteria
* @param loadChildren the load children
* @return the item
* @throws InternalErrorException the internal error exception
*/
public static Item getItem(Item parent, WorkspaceItem workspaceItem, List<ItemType> showableTypes, FilterCriteria filterCriteria, int depth) throws InternalErrorException
public static Item getItem(Item parent, WorkspaceItem workspaceItem, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws InternalErrorException
{
// System.out.println("\n\n workspaceItem: " + workspaceItem.getName() + ", depth : "+depth);
if (depth == 0) return null;
ItemType type = getItemType(workspaceItem);
if (!showableTypes.contains(type)) return null;
@ -73,34 +89,41 @@ public class ItemBuilder {
itemName = "My VRE Folders";
}
Item item = new Item(parent, workspaceItem.getId(), itemName, type, "");
item.setShared(workspaceItem.getType()==WorkspaceItemType.SHARED_FOLDER);
Item empty = null;
Item item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItem.getPath(), workspaceItem.getOwner().getPortalLogin(), workspaceItem.isFolder());
item.setSharedFolder(workspaceItem.getType()==WorkspaceItemType.SHARED_FOLDER);
/*
// Add temporary item
if(Util.isFolder(item.getType())){
empty = new Item(parent, UUID.randomUUID().toString(), "empty", ItemType.UNKNOWN_TYPE, "");
item.addChild(empty);
}
}*/
if(depth==1) return item;
for (WorkspaceItem child: workspaceItem.getChildren()){
Item itemChild = getItem(item, child, showableTypes, filterCriteria, depth-1);
if (itemChild!=null){
// item.removeChild(empty);
item.addChild(itemChild);
if(loadChildren){
for (WorkspaceItem child: workspaceItem.getChildren()){
Item itemChild = getItem(item, child, showableTypes, filterCriteria, false);
if (itemChild!=null){
// item.removeChild(empty);
item.addChild(itemChild);
}
}
}
// Remove the temporary item when we finish loading
if(Util.isFolder(item.getType())&& item.getChildren().size()>1)
item.removeChild(empty);
// // Remove the temporary item when we finish loading
// if(Util.isFolder(item.getType())&& item.getChildren().size()>1)
// item.removeChild(empty);
return item;
}
/**
* Gets the item type.
*
* @param item the item
* @return the item type
* @throws InternalErrorException the internal error exception
*/
protected static ItemType getItemType(WorkspaceItem item) throws InternalErrorException
{
switch(item.getType())
@ -111,16 +134,33 @@ public class ItemBuilder {
return ItemType.FOLDER;
}
case FOLDER_ITEM: return getFolderItemType((FolderItem) item);
default:
return null;
}
return null;
}
/**
* Gets the folder item type.
*
* @param item the item
* @return the folder item type
*/
protected static ItemType getFolderItemType(FolderItem item)
{
//System.out.println("getFolderItemType "+item.getFolderItemType().toString());
return ItemType.valueOf(item.getFolderItemType().toString());
}
/**
* Filter item.
*
* @param type the type
* @param item the item
* @param filterCriteria the filter criteria
* @return true, if successful
* @throws InternalErrorException the internal error exception
*/
protected static boolean filterItem(ItemType type, WorkspaceItem item, FilterCriteria filterCriteria) throws InternalErrorException
{
boolean mimeTypeCheck = checkAllowedMimeTypes(type, item, filterCriteria.getAllowedMimeTypes());
@ -130,6 +170,14 @@ public class ItemBuilder {
return propertiesCheck;
}
/**
* Check allowed mime types.
*
* @param type the type
* @param item the item
* @param allowedMimeTypes the allowed mime types
* @return true, if successful
*/
protected static boolean checkAllowedMimeTypes(ItemType type, WorkspaceItem item, List<String> allowedMimeTypes)
{
if (allowedMimeTypes.size()==0) return true;
@ -143,6 +191,14 @@ public class ItemBuilder {
}
/**
* Check properties.
*
* @param item the item
* @param requestedProperties the requested properties
* @return true, if successful
* @throws InternalErrorException the internal error exception
*/
protected static boolean checkProperties(WorkspaceItem item, Map<String, String> requestedProperties) throws InternalErrorException
{
if (requestedProperties.size()==0 || item.getType()!=WorkspaceItemType.FOLDER_ITEM) return true;
@ -156,4 +212,31 @@ public class ItemBuilder {
return true;
}
/**
* Builds the folder to breadcrumbs.
*
* @param wsFolder the ws folder
* @param parent the parent
* @return the item
* @throws InternalErrorException the internal error exception
*/
protected static Item buildFolderToBreadcrumbs(WorkspaceFolder wsFolder, Item parent) throws InternalErrorException {
String name = "";
//MANAGEMENT SHARED FOLDER NAME
if(wsFolder.isShared() && wsFolder.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceSharedFolder shared = (WorkspaceSharedFolder) wsFolder;
name = shared.isVreFolder()?shared.getDisplayName():wsFolder.getName();
//MANAGEMENT SPECIAL FOLDER
}else if(wsFolder.getName().compareTo(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot()){
name = WorkspaceExplorerConstants.VRE_FOLDERS_LABEL;
}else
name = wsFolder.getName();
return new Item(null, wsFolder.getId(), name, ItemType.FOLDER, "", wsFolder.getOwner().getPortalLogin(), wsFolder.isFolder());
}
}

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.widgets.wsexplorer.server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -27,14 +28,26 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 25, 2015
*/
@SuppressWarnings("serial")
public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implements WorkspaceExplorerService {
/**
*
*/
public static final Logger _log = LoggerFactory.getLogger(WorkspaceExplorerServiceImpl.class);
public static final String USERNAME_ATTRIBUTE = "username";
/**
* Gets the ASL session.
*
* @param httpSession the http session
* @return the ASL session
*/
private ASLSession getASLSession(HttpSession httpSession) {
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
@ -61,6 +74,14 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
}
/**
* Gets the workspace.
*
* @return the workspace
* @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
protected Workspace getWorkspace() throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException {
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
@ -81,7 +102,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
_log.trace("Start getRoot...");
WorkspaceFolder specials = workspace.getMySpecialFolders();
// WorkspaceFolder specials = workspace.getMySpecialFolders();
WorkspaceItem root = workspace.getRoot();
@ -90,12 +111,13 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, 2);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true);
/* SPECIAL FOLDERS
Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2);
specialFolders.setShared(true);
rootItem.addChild(specialFolders);
*/
if(rootItem==null)
_log.trace("############ rootItem null");
@ -140,12 +162,12 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
_log.trace("start time - " + startTime);
Item folderItem = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, 2);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true);
_log.trace("Only showable types:");
//printName("", folderItem);
if (purgeEmpyFolders) folderItem = ItemBuilder.purgeEmptyFolders(folderItem);
if (purgeEmpyFolders) itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
_log.trace("Returning:");
@ -155,9 +177,9 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
//printName("", folderItem);
Collections.sort(folderItem.getChildren(), new ItemComparator());
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return folderItem;
return itemFolder;
} catch (Exception e) {
_log.error("Error during folder retrieving", e);
@ -199,7 +221,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
*/
@Override
public List<Item> getListParentsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception {
/*List<Item> listParents = new ArrayList<Item>();
List<Item> listParents = new ArrayList<Item>();
_log.trace("get List Parents By Item Identifier "+ itemIdentifier);
try {
Workspace workspace = getWorkspace();
@ -207,18 +229,16 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
WorkspaceItem wsItem = workspace.getItem(itemIdentifier);
_log.trace("workspace retrieve item name: "+wsItem.getName());
String nameSpecialFolder = getNameForSpecialFolder();
// String nameSpecialFolder = getNameForSpecialFolder();
if(includeItemAsParent==true && wsItem.getType().equals(WorkspaceItemType.FOLDER)){
listParents.add(builder.buildGXTFolderModelItemHandleSpecialFolder((WorkspaceFolder) wsItem, null, nameSpecialFolder));
if(includeItemAsParent==true && wsItem.isFolder()){
listParents.add(ItemBuilder.buildFolderToBreadcrumbs((WorkspaceFolder) wsItem, null));
}
while(wsItem!=null && wsItem.getParent()!=null){
WorkspaceFolder wsFolder = wsItem.getParent();
listParents.add(builder.buildGXTFolderModelItemHandleSpecialFolder(wsFolder, null, nameSpecialFolder));
listParents.add(ItemBuilder.buildFolderToBreadcrumbs((WorkspaceFolder) wsFolder, null));
wsItem = wsFolder;
}
@ -226,11 +246,9 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
//SET PARENTS
for(int i=0; i<listParents.size()-1; i++){
Item parent = listParents.get(i);
Item fileModel = listParents.get(i+1);
fileModel.setParentFileModel(parent);
fileModel.setParent(parent);
}
_log.trace("list parents return size: "+listParents.size());
@ -242,7 +260,5 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
}
return listParents;
*/
return null;
}
}

View File

@ -8,11 +8,12 @@ import java.util.ArrayList;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* The Class Item.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 18, 2015
* Jun 25, 2015
*/
public class Item implements IsSerializable{
@ -20,54 +21,79 @@ public class Item implements IsSerializable{
protected String id;
protected String name;
protected ItemType type;
protected String path;
protected boolean shared;
protected boolean isSharedFolder;
protected ArrayList<Item> children;
private String owner;
private boolean isFolder;
/**
* Instantiates a new item.
*/
public Item(){}
/**
* Create a new item.
* @param parent the item parent.
* @param id the item id.
* @param name the item name.
* @param type the item type.
* @param path the item path.
* Instantiates a new item.
*
* @param parent the parent
* @param id the id
* @param name the name
* @param type the type
* @param path the path
* @param owner the owner
* @param isFolder the is folder
*/
public Item(Item parent, String id, String name, ItemType type, String path) {
public Item(Item parent, String id, String name, ItemType type, String path, String owner, boolean isFolder) {
this.parent = parent;
this.id = id;
this.name = name;
this.type = type;
this.path = path;
this.children = new ArrayList<Item>();
this.owner = owner;
this.isFolder = isFolder;
}
/**
* Checks if is folder.
*
* @return the isFolder
*/
public boolean isFolder() {
return isFolder;
}
/**
* Checks if is shared.
* Sets the folder.
*
* @return the shared
* @param isFolder the isFolder to set
*/
public boolean isShared() {
return shared;
public void setFolder(boolean isFolder) {
this.isFolder = isFolder;
}
/**
* Checks if is shared folder.
*
* @return the isSharedFolder
*/
public boolean isSharedFolder() {
return isSharedFolder;
}
/**
* Sets the shared.
* Sets the shared folder.
*
* @param shared the shared to set
* @param isSharedFolder the isSharedFolder to set
*/
public void setShared(boolean shared) {
this.shared = shared;
public void setSharedFolder(boolean isSharedFolder) {
this.isSharedFolder = isSharedFolder;
}
/**
* The item parent. Null if is the root.
* @return the item parent.
@ -109,6 +135,32 @@ public class Item implements IsSerializable{
return children;
}
/**
* Gets the owner.
*
* @return the owner
*/
public String getOwner() {
return owner;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Sets the owner.
*
* @param owner the owner to set
*/
public void setOwner(String owner) {
this.owner = owner;
}
/**
* The item child.
@ -185,22 +237,6 @@ public class Item implements IsSerializable{
return true;
}
/**
* {@inheritDoc}
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Item [name=");
builder.append(name);
builder.append(", type=");
builder.append(type);
builder.append(", id=");
builder.append(id);
builder.append("]");
return builder.toString();
}
/**
* Sets the parent.
*
@ -209,4 +245,31 @@ public class Item implements IsSerializable{
public void setParent(Item parent) {
this.parent = parent;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Item [id=");
builder.append(id);
builder.append(", name=");
builder.append(name);
builder.append(", type=");
builder.append(type);
builder.append(", path=");
builder.append(path);
builder.append(", shared=");
builder.append(isSharedFolder);
builder.append(", children=");
builder.append(children);
builder.append(", owner=");
builder.append(owner);
builder.append(", isFolder=");
builder.append(isFolder);
builder.append("]");
return builder.toString();
}
}