256: Workspace explorer

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

Removed ItemType.Root
Removed isRoot due to speed issue
Fixed bug on isSpecialFolder

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@117191 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-13 15:15:21 +00:00
parent 5740a38697
commit 7b96c4083a
13 changed files with 282 additions and 45 deletions

View File

@ -18,8 +18,7 @@ public class Util {
// public static final NumberFormat numberFormatterKB = NumberFormat.getFormat("#,##0 KB;(#,##0 KB)");
public static final ItemType[] FOLDERS = new ItemType[] { ItemType.ROOT,
ItemType.FOLDER };
public static final ItemType[] FOLDERS = new ItemType[] {ItemType.FOLDER};
/**
* Checks if is folder.
@ -68,7 +67,7 @@ public class Util {
public static ImageResource getImage(Item item)
{
switch (item.getType()) {
case ROOT: return WorkspaceLightTreeResources.INSTANCE.root();
// case ROOT: return WorkspaceLightTreeResources.INSTANCE.root();
case FOLDER: {
if (item.isSharedFolder()) return WorkspaceLightTreeResources.INSTANCE.sharedFolder();
else return WorkspaceLightTreeResources.INSTANCE.folder();

View File

@ -6,7 +6,7 @@ package org.gcube.portlets.widgets.wsexplorer.client;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 30, 2015
*/
public class WorkspaceExplorerConstants {
public static final String SPECIAL_FOLDERS_LABEL = "MySpecialFolders";
public static final String SPECIAL_FOLDERS_NAME = "MySpecialFolders";
public static final String VRE_FOLDERS_LABEL = "My VRE Folders";

View File

@ -69,9 +69,8 @@ public class WorkspaceExplorerSaveDialog extends Modal implements HasWorskpaceEx
public WorkspaceExplorerSaveDialog(String captionTxt, String fileName, boolean showOnlyFolders) {
if (showOnlyFolders) {
ItemType[] itemsType = new ItemType[2];
itemsType[0] = ItemType.ROOT;
itemsType[1] = ItemType.FOLDER;
ItemType[] itemsType = new ItemType[1];
itemsType[0] = ItemType.FOLDER;
setSelectableTypes(itemsType);
setShowableTypes(itemsType);
}
@ -90,9 +89,8 @@ public class WorkspaceExplorerSaveDialog extends Modal implements HasWorskpaceEx
public WorkspaceExplorerSaveDialog(String fileName, boolean showOnlyFolders) {
if (showOnlyFolders) {
ItemType[] itemsType = new ItemType[2];
itemsType[0] = ItemType.ROOT;
itemsType[1] = ItemType.FOLDER;
ItemType[] itemsType = new ItemType[1];
itemsType[0] = ItemType.FOLDER;
setSelectableTypes(itemsType);
setShowableTypes(itemsType);
}
@ -188,7 +186,7 @@ public class WorkspaceExplorerSaveDialog extends Modal implements HasWorskpaceEx
Item itemB = controller.getBreadcrumbs().getLastParent();
if (itemB != null) {
if(itemB.getPath().equals(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)){
if(itemB.isSpecialFolder()){
Window.alert("Destination folder "+WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH+" is not valid!");
return;
}

View File

@ -69,9 +69,8 @@ public class WorkspaceExplorerSavePanel extends ScrollPanel implements HasWorskp
public WorkspaceExplorerSavePanel(String fileName, boolean showOnlyFolders) {
if (showOnlyFolders) {
ItemType[] itemsType = new ItemType[2];
itemsType[0] = ItemType.ROOT;
itemsType[1] = ItemType.FOLDER;
ItemType[] itemsType = new ItemType[1];
itemsType[0] = ItemType.FOLDER;
setSelectableTypes(itemsType);
setShowableTypes(itemsType);
}
@ -130,7 +129,7 @@ public class WorkspaceExplorerSavePanel extends ScrollPanel implements HasWorskp
Item itemB = controller.getBreadcrumbs().getLastParent();
if (itemB != null) {
if(itemB.getPath().equals(WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH)){
if(itemB.isSpecialFolder()){
Window.alert("Destination folder "+WorkspaceExplorerConstants.WORKSPACE_MY_SPECIAL_FOLDERS_PATH+" is not valid!");
return;
}

View File

@ -64,9 +64,8 @@ public class WorkspaceExplorerSelectDialog extends Modal implements HasWorskpace
public WorkspaceExplorerSelectDialog(String captionTxt, boolean showOnlyFolders) {
if(showOnlyFolders){
ItemType[] itemsType = new ItemType[2];
itemsType[0] = ItemType.ROOT;
itemsType[1] = ItemType.FOLDER;
ItemType[] itemsType = new ItemType[1];
itemsType[0] = ItemType.FOLDER;
setSelectableTypes(itemsType);
setShowableTypes(itemsType);
}

View File

@ -86,15 +86,16 @@ public class ItemBuilder {
String itemName = workspaceItem.getName();
_log.info("Building Item for: "+itemName);
//TODO ADD CONTROL ON THE PATH WHEN WILL BE MORE FAST
if (itemName.equals(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL))
itemName = "My VRE Folders";
// //TODO ADD CONTROL ON THE PATH WHEN WILL BE MORE FAST
// if (itemName.equals(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL))
// itemName = WorkspaceExplorerConstants.VRE_FOLDERS_LABEL;
boolean isFolder = false;
if(type.equals(ItemType.FOLDER) || type.equals(ItemType.ROOT))
if(type.equals(ItemType.FOLDER))
isFolder = true;
Item item = new Item(parent, workspaceItem.getId(), itemName, type, "", UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), isFolder, type.equals(ItemType.ROOT));
//TODO ADD GET PATH WHEN WILL BE MORE FAST
Item item = new Item(parent, workspaceItem.getId(), itemName, type, "", UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), isFolder, false);
item.setSharedFolder(workspaceItem.getType().equals(WorkspaceItemType.SHARED_FOLDER));
if(loadChildren){
@ -124,7 +125,7 @@ public class ItemBuilder {
{
case SHARED_FOLDER:
case FOLDER:{
if (item.isRoot()) return ItemType.ROOT;
// if (item.isRoot()) return ItemType.ROOT;
return ItemType.FOLDER;
}
case FOLDER_ITEM: return getFolderItemType((FolderItem) item);
@ -224,7 +225,6 @@ public class ItemBuilder {
String name = "";
boolean isSpecialFolder = false;
boolean isRoot = false;
if(wsFolder.isRoot()){ //IS ROOT
name = WorkspaceExplorerConstants.HOME_LABEL;
@ -243,13 +243,14 @@ public class ItemBuilder {
Item item = new Item(null, wsFolder.getId(), name, ItemType.FOLDER, "", null, true, isRoot);
item.setSpecialFolder(isSpecialFolder);
_log.debug("breadcrumb returning: "+item);
return item;
}
public static boolean isSpecialFolder(WorkspaceFolder wsFolder){
try {
return (wsFolder.getName().compareTo(WorkspaceExplorerConstants.SPECIAL_FOLDERS_LABEL)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot());
return (wsFolder.getName().compareTo(WorkspaceExplorerConstants.SPECIAL_FOLDERS_NAME)==0 && wsFolder.getParent()!=null && wsFolder.getParent().isRoot());
} catch (InternalErrorException e) {
_log.warn("isSpecialFolder exception, returning false");
return false;

View File

@ -37,6 +37,7 @@ public class ItemComparator implements Comparator<Item> {
}
private boolean isSpecialFolder(Item item) {
return item.getName().equals(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL) && item.getParent()!=null && item.getParent().isRoot();
// return item.getName().equals(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL) && item.getParent()!=null && item.getParent().isRoot();
return item.getName().equals(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL) && item.isSpecialFolder();
}
}

View File

@ -0,0 +1,23 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.server;
import java.text.DecimalFormat;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 13, 2015
*/
public class StringUtil {
public static String readableFileSize(long size) {
if(size < 0) return "Unknown";
if(size == 0) return "Empty";
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups))+units[digitGroups];
}
}

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.widgets.wsexplorer.server;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -116,7 +115,8 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true);
rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL);
rootItem.setIsRoot(true);
/* SPECIAL FOLDERS
Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2);
specialFolders.setShared(true);
@ -196,12 +196,14 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
}else if(fullName.indexOf(".")>0){
fullName = fullName.substring(0, fullName.indexOf("."));
}
item = new Item(null, root.getId(), fullName+"'s", ItemType.ROOT, root.getPath(), root.getOwner().getPortalLogin(), true, true);
item = new Item(null, root.getId(), fullName+"'s", ItemType.FOLDER, root.getPath(), root.getOwner().getPortalLogin(), true, true);
break;
}
case VRE_FOLDER:{
WorkspaceItem folder = workspace.getMySpecialFolders();
item = new Item(null, folder.getId(), WorkspaceExplorerConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), true, false);
//SET SPECIAL FOLDER /Workspace/MySpecialFolders
item.setSpecialFolder(true);
break;
}
}
@ -228,6 +230,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
_log.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true);
//OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders
itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL);
itemFolder.setSpecialFolder(true);
@ -304,7 +307,9 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
listParents.add(ItemBuilder.buildFolderForBreadcrumbs((WorkspaceFolder) wsItem, null));
}
//HANDLE MY_SPECIAL_FOLDER
/** HANDLE MY_SPECIAL_FOLDER TO AVOID COMPLETE PATH WORKSPACE/MY_SPECIAL_FOLDER
* BUT RETURNING ONLY /MY_SPECIAL_FOLDER
*/
if(wsItem.isFolder()){
if(ItemBuilder.isSpecialFolder((WorkspaceFolder) wsItem))
return listParents;
@ -462,18 +467,10 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
try{
_log.info("getFormattedSize ByItemId "+ itemId);
long size = getSizeByItemId(itemId);
return readableFileSize(size);
return StringUtil.readableFileSize(size);
} catch (Exception e) {
_log.error("getFormattedSize By ItemId ", e);
throw new Exception(e.getMessage());
}
}
private static String readableFileSize(long size) {
if(size < 0) return "Unknown";
if(size == 0) return "Empty";
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups))+units[digitGroups];
}
}

View File

@ -22,9 +22,9 @@ public class Item implements IsSerializable {
protected ArrayList<Item> children;
private String owner;
private boolean isFolder;
private boolean isSpecialFolder;
private boolean isSharedFolder;
private boolean isRoot;
private boolean isSpecialFolder = false;
private boolean isSharedFolder = false;
private boolean isRoot = false;
/**
* Instantiates a new item.

View File

@ -12,7 +12,6 @@ package org.gcube.portlets.widgets.wsexplorer.shared;
*/
public enum ItemType {
ROOT, //MANDATORY
FOLDER, //MANDATORY
EXTERNAL_IMAGE,
EXTERNAL_FILE,

View File

@ -18,7 +18,6 @@ import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.widgets.wsexplorer.server.ItemBuilder;
import org.gcube.portlets.widgets.wsexplorer.server.ItemComparator;
import org.gcube.portlets.widgets.wsexplorer.server.WorkspaceExplorerServiceImpl;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;

View File

@ -0,0 +1,222 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.WorkspaceSharedFolder;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.portlets.widgets.wsexplorer.server.ItemBuilder;
import org.gcube.portlets.widgets.wsexplorer.server.ItemComparator;
import org.gcube.portlets.widgets.wsexplorer.server.StringUtil;
import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import org.gcube.portlets.widgets.wsexplorer.shared.WorkspaceNavigatorServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 6, 2015
*/
public class TestGetSize {
/**
*
*/
private static final String TEST_SCOPE = "/gcube/devsec";
/**
*
*/
public static final String TEST_USER = "francesco.mangiacrapa";
public static final Logger _log = LoggerFactory.getLogger(TestGetSize.class);
private static Workspace workspace;
public static void main(String[] args) throws WorkspaceNavigatorServiceException {
List<ItemType> showableTypes = new ArrayList<ItemType>();
showableTypes.addAll(Arrays.asList(ItemType.values()));
boolean purgeEmpyFolders = false;
List<String> allowedMimeTypes = new ArrayList<String>();
Map<String, String> requiredProperties = new HashMap<String, String>();
FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,requiredProperties);
try {
ScopeBean scope = new ScopeBean(TEST_SCOPE);
ScopeProvider.instance.set(scope.toString());
workspace = HomeLibrary
.getHomeManagerFactory()
.getHomeManager()
.getHome(TEST_USER)
.getWorkspace();
for (WorkspaceItem child: workspace.getRoot().getChildren()){
_log.debug("Child item: "+child);
// Item itemChild = getItem(item, child, showableTypes, filterCriteria, false);
// _log.debug("Item: "+itemName +" converted!!!");
// if (itemChild!=null){
// item.addChild(itemChild);
// }
}
/*
Item mySpecial = getMySpecialFolder(showableTypes, false, filterCriteria);
for (Item spf : mySpecial.getChildren()) {
String size = getReadableSizeByItemId(spf.getId());
System.out.println(spf.getName() + ", size: "+size);
}*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
getRoot(showableTypes, purgeEmpyFolders, filterCriteria);
}
public static Item getRoot(List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException {
_log.trace("getRoot showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+ filterCriteria);
try {
_log.trace("Start getRoot...");
WorkspaceItem root = workspace.getRoot();
_log.trace("GetRoot - Replyiing root");
long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true);
rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL);
/* SPECIAL FOLDERS
Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2);
specialFolders.setShared(true);
rootItem.addChild(specialFolders);
*/
if (purgeEmpyFolders) rootItem = ItemBuilder.purgeEmptyFolders(rootItem);
_log.trace("Returning:");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
_log.info("end time - " + time);
Collections.sort(rootItem.getChildren(), new ItemComparator());
_log.info("Returning children size: "+rootItem.getChildren().size());
return rootItem;
} catch (Exception e) {
_log.error("Error during root retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get root");
}
}
/**
* {@inheritDoc}
*/
public static Item getMySpecialFolder(List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException {
_log.trace("GetMySpecialFolder showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+filterCriteria);
try {
WorkspaceItem folder = workspace.getMySpecialFolders();
long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true);
itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL);
itemFolder.setSpecialFolder(true);
_log.trace("Builded MySpecialFolder: "+itemFolder);
_log.trace("Only showable types:");
//printName("", folderItem);
if (purgeEmpyFolders) itemFolder = ItemBuilder.purgeEmptyFolders(itemFolder);
_log.trace("Returning:");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
_log.trace("end time - " + time);
//printName("", folderItem);
Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder;
} catch (Exception e) {
_log.error("Error during special folders retrieving", e);
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get My Special Folder");
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String)
*/
public static Long getSizeByItemId(String itemId) throws Exception {
_log.info("get Size By ItemId "+ itemId);
try {
WorkspaceItem wsItem = workspace.getItem(itemId);
Long size = new Long(-1);
if(wsItem instanceof FolderItem){ //ITEM
FolderItem folderItem = (FolderItem) wsItem;
size = new Long(folderItem.getLength());
} else if (wsItem instanceof WorkspaceFolder ){ //FOLDER
WorkspaceFolder theFolder = (WorkspaceFolder) wsItem;
size = theFolder.getSize();
} else if (wsItem instanceof WorkspaceSharedFolder){ //SHARED FOLDER
WorkspaceSharedFolder theFolder = (WorkspaceSharedFolder) wsItem;
size = theFolder.getSize();
}
_log.info("returning size: " +size);
return size;
} catch (Exception e) {
_log.error("get Size By ItemId ", e);
throw new Exception(e.getMessage());
}
}
public static String getReadableSizeByItemId(String itemId) throws Exception {
try{
_log.info("getFormattedSize ByItemId "+ itemId);
long size = getSizeByItemId(itemId);
return StringUtil.readableFileSize(size);
} catch (Exception e) {
_log.error("getFormattedSize By ItemId ", e);
throw new Exception(e.getMessage());
}
}
}