Added a patch to avoid a slow getPath()

Added several patch on getPath(), see //TODO PATCH

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@122811 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-02-03 16:08:33 +00:00
parent 567cce8630
commit 25245738a2
10 changed files with 128 additions and 137 deletions

33
pom.xml
View File

@ -51,14 +51,19 @@
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<!-- <dependency> --> <!-- <dependency> -->
<!-- <groupId>xerces</groupId> --> <!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xerces</artifactId> --> <!-- <artifactId>xerces</artifactId> -->
<!-- <version>2.4.0</version> --> <!-- <version>2.4.0</version> -->
<!-- <scope>provided</scope> --> <!-- <scope>compile</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.thoughtworks.xstream</groupId> -->
<!-- <artifactId>xstream</artifactId> -->
<!-- <version>1.4.7</version> -->
<!-- </dependency> --> <!-- </dependency> -->
<!-- Google Web Toolkit (GWT) --> <!-- Google Web Toolkit (GWT) -->
@ -95,18 +100,18 @@
</dependency> </dependency>
<!-- HOME LIBRARY --> <!-- HOME LIBRARY -->
<!-- <dependency> --> <dependency>
<!-- <groupId>org.gcube.common</groupId> --> <groupId>org.gcube.common</groupId>
<!-- <artifactId>home-library-model</artifactId> --> <artifactId>home-library-model</artifactId>
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> --> <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<!-- <scope>provided</scope> --> <scope>provided</scope>
<!-- </dependency> --> </dependency>
<!-- <dependency> --> <dependency>
<!-- <groupId>org.gcube.common</groupId> --> <groupId>org.gcube.common</groupId>
<!-- <artifactId>home-library-jcr</artifactId> --> <artifactId>home-library-jcr</artifactId>
<!-- <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> --> <version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<!-- <scope>provided</scope> --> <scope>provided</scope>
<!-- </dependency> --> </dependency>
<dependency> <dependency>
<groupId>org.gcube.common</groupId> <groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId> <artifactId>home-library</artifactId>

View File

@ -138,13 +138,14 @@ public class WorkspaceExplorerController implements EventHandler {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
GWT.log(caught.getMessage()); GWT.log(caught.getMessage());
breadcrumbs.clear(); breadcrumbs.clear();
navigation.setVisibleNewFolderFacility(false);
} }
@Override @Override
public void onSuccess(Item result) { public void onSuccess(Item result) {
result.setName(WorkspaceExplorerConstants.HOME_LABEL); //FORCE SET NAME LIKE "HOME_LABEL" result.setName(WorkspaceExplorerConstants.HOME_LABEL); //FORCE SET NAME LIKE "HOME_LABEL"
breadcrumbs.init(result); breadcrumbs.init(result);
navigation.setVisibleNewFolderFacility(true);
clearMoreInfo(); clearMoreInfo();
} }
}); });
@ -155,7 +156,7 @@ public class WorkspaceExplorerController implements EventHandler {
@Override @Override
public void onBreadcrumbInit(BreadcrumbInitEvent breadcrumbInitEvent) { public void onBreadcrumbInit(BreadcrumbInitEvent breadcrumbInitEvent) {
navigation.activeButtons(true); navigation.setVisibleNewFolderFacility(true);
} }
}); });
@ -183,11 +184,13 @@ public class WorkspaceExplorerController implements EventHandler {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
GWT.log(caught.getMessage()); GWT.log(caught.getMessage());
navigation.setVisibleNewFolderFacility(false);
} }
@Override @Override
public void onSuccess(Item result) { public void onSuccess(Item result) {
breadcrumbs.init(result); breadcrumbs.init(result);
navigation.setVisibleNewFolderFacility(false);
clearMoreInfo(); clearMoreInfo();
} }
}); });
@ -204,18 +207,21 @@ public class WorkspaceExplorerController implements EventHandler {
@Override @Override
public void subtmitHandler(String folderName) { public void subtmitHandler(String folderName) {
showMessage(AlertType.INFO, "Creating folder \""+folderName+"\"");
WorkspaceExplorerConstants.workspaceNavigatorService.createFolder(folderName, "", breadcrumbs.getLastParent().getId(), new AsyncCallback<Item>() { WorkspaceExplorerConstants.workspaceNavigatorService.createFolder(folderName, "", breadcrumbs.getLastParent().getId(), new AsyncCallback<Item>() {
@Override @Override
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
hideMessage();
clearMoreInfo();
Window.alert(caught.getMessage()); Window.alert(caught.getMessage());
GWT.log(caught.getMessage()); GWT.log(caught.getMessage());
} }
@Override @Override
public void onSuccess(Item result) { public void onSuccess(Item result) {
hideMessage();
if(result!=null){ if(result!=null){
wsExplorer.addItemToExplorer(result); wsExplorer.addItemToExplorer(result);
clearMoreInfo(); clearMoreInfo();

View File

@ -45,17 +45,15 @@ public abstract class CreateFolderForm extends Composite {
@UiField @UiField
FluidRow validator_field; FluidRow validator_field;
@UiField
FluidRow form_fields;
@UiField @UiField
Form form_create_folder; Form form_create_folder;
private Alert alertError = new Alert("Required Field"); private Alert alert = new Alert();
private Alert alertSubmitResult = new Alert("");
private static AbstractFormReleaseUiBinder uiBinder = GWT.create(AbstractFormReleaseUiBinder.class); private static AbstractFormReleaseUiBinder uiBinder = GWT.create(AbstractFormReleaseUiBinder.class);
private int width = 300;
/** /**
* Subtmit handler. * Subtmit handler.
* *
@ -88,13 +86,6 @@ public abstract class CreateFolderForm extends Composite {
input_folder_name.addStyleName("gwt-TextBox-personal"); input_folder_name.addStyleName("gwt-TextBox-personal");
submit_create_folder.addStyleName("margin-right-5px"); submit_create_folder.addStyleName("margin-right-5px");
// setSize(width+"px", "200px");
// input_folder_name.setWidth(width-10+"px");
// input_layer_name.addStyleName("textbox-geo");
// input_layer_title.addStyleName("textbox-geo");
// input_WMS_URI.addStyleName("textbox-geo");
close_dialog.addClickHandler(new ClickHandler() { close_dialog.addClickHandler(new ClickHandler() {
@Override @Override
@ -128,21 +119,25 @@ public abstract class CreateFolderForm extends Composite {
} }
}); });
alertError.addStyleName("marginTop10"); alert.addStyleName("marginTop10");
alertError.setType(AlertType.ERROR); alert.setType(AlertType.ERROR);
alertError.setVisible(false); alert.setVisible(false);
alertError.setClose(false); alert.setClose(false);
validator_field.add(alertError); validator_field.add(alert);
}
// alertSubmitResult.addStyleName("marginTop10"); public void showMessage(AlertType type, String message){
alertSubmitResult.setType(AlertType.INFO); alert.setType(type);
alertSubmitResult.setVisible(false); alert.setHTML(message);
alertSubmitResult.setClose(false); alert.setVisible(true);
form_fields.setVisible(false);
}
// hp_form_actions.setCellHorizontalAlignment(close_dialog, HasHorizontalAlignment.ALIGN_RIGHT); public void hideMessage(){
if(alert.isVisible())
alert.setVisible(false);
showAlertSubmitResult(false, ""); form_fields.setVisible(true);
form_create_folder.add(alertSubmitResult);
} }
/** /**
@ -162,18 +157,6 @@ public abstract class CreateFolderForm extends Composite {
return valid; return valid;
} }
/**
* Show alert submit result.
*
* @param visible the visible
* @param text the text
*/
public void showAlertSubmitResult(boolean visible, String text){
alertSubmitResult.setText(text);
alertSubmitResult.setVisible(visible);
}
/** /**
* Gets the submit button. * Gets the submit button.
* *
@ -198,28 +181,9 @@ public abstract class CreateFolderForm extends Composite {
* @return the alert error * @return the alert error
*/ */
public Alert getAlertError() { public Alert getAlertError() {
return alertError; return alert;
} }
/**
* Gets the alert submit result.
*
* @return the alert submit result
*/
public Alert getAlertSubmitResult() {
return alertSubmitResult;
}
/**
* Sets the alert error visible.
*
* @param bool the new alert error visible
*/
public void setAlertErrorVisible(boolean bool){
alertError.setVisible(bool);
}
/** /**
* Gets the text box folder name. * Gets the text box folder name.
* *

View File

@ -3,11 +3,13 @@
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:b="urn:import:com.github.gwtbootstrap.client.ui">
<b:WellForm type="INLINE" ui:field="form_create_folder"> <b:WellForm type="INLINE" ui:field="form_create_folder">
<b:ControlLabel ui:field="control_label">New Folder</b:ControlLabel>
<b:TextBox placeholder="Type Folder name..." b:id="input_folder_name"
ui:field="input_folder_name" styleName="gwt-TextBox-personal"></b:TextBox>
<b:Button ui:field="submit_create_folder">Create</b:Button>
<b:Button ui:field="close_dialog">Close</b:Button>
<b:FluidRow ui:field="validator_field"></b:FluidRow> <b:FluidRow ui:field="validator_field"></b:FluidRow>
<b:FluidRow ui:field="form_fields">
<b:ControlLabel ui:field="control_label">New Folder</b:ControlLabel>
<b:TextBox placeholder="Type Folder name..." b:id="input_folder_name"
ui:field="input_folder_name" styleName="gwt-TextBox-personal"></b:TextBox>
<b:Button ui:field="submit_create_folder">Create</b:Button>
<b:Button ui:field="close_dialog">Close</b:Button>
</b:FluidRow>
</b:WellForm> </b:WellForm>
</ui:UiBinder> </ui:UiBinder>

View File

@ -128,7 +128,7 @@ public class Navigation extends Composite{
}); });
} }
public void activeButtons(boolean bool){ public void setVisibleNewFolderFacility(boolean bool){
new_folder.setActive(bool); new_folder.setVisible(bool);
} }
} }

View File

@ -68,18 +68,20 @@ public class ItemBuilder {
return Util.isFolder(item.getType()) && item.getChildren().size() == 0; return Util.isFolder(item.getType()) && item.getChildren().size() == 0;
} }
/** /**
* Gets the item. * Gets the item.
* *
* @param parent the parent * @param parent the parent
* @param workspaceItem the workspace item * @param workspaceItem the workspace item
* @param workspaceItemPath the workspace item path
* @param showableTypes the showable types * @param showableTypes the showable types
* @param filterCriteria the filter criteria * @param filterCriteria the filter criteria
* @param loadChildren the load children * @param loadChildren the load children
* @return the item * @return the item
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
*/ */
public static Item getItem(Item parent, WorkspaceItem workspaceItem, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws InternalErrorException public static Item getItem(Item parent, WorkspaceItem workspaceItem, String workspaceItemPath, List<ItemType> showableTypes, FilterCriteria filterCriteria, boolean loadChildren) throws InternalErrorException
{ {
ItemType type = getItemType(workspaceItem); ItemType type = getItemType(workspaceItem);
@ -110,14 +112,12 @@ public class ItemBuilder {
Item item = null; Item item = null;
try{ try{
//THIS CALL IS VERY SLOW!! //THIS CALL IS VERY SLOW!!
// String storageID = null; // String storageID = null;
// if(workspaceItem instanceof FolderItem){ // if(workspaceItem instanceof FolderItem){
// storageID = workspaceItem.getStorageID(); // storageID = workspaceItem.getStorageID();
// } // }
item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItemPath, UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), isFolder, false);
item = new Item(parent, workspaceItem.getId(), itemName, type, workspaceItem.getPath(), UserUtil.getUserFullName(workspaceItem.getOwner().getPortalLogin()), isFolder, false);
item.setSharedFolder(isSharedFolder); item.setSharedFolder(isSharedFolder);
}catch(Exception e){ }catch(Exception e){
_log.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item"); _log.error("Error on getting item: "+itemName+" with id: "+workspaceItem.getId()+", from HL, so skipping item");
@ -125,9 +125,15 @@ public class ItemBuilder {
} }
if(loadChildren){ if(loadChildren){
//TODO A PATCH TO AVOID A SLOW GETPATH
workspaceItemPath = workspaceItem.getPath();
for (WorkspaceItem child: workspaceItem.getChildren()){ for (WorkspaceItem child: workspaceItem.getChildren()){
_log.trace("\n\nConverting child item: "+child.getName()); // workspaceItemPath+="/"+child.getName();
Item itemChild = getItem(item, child, showableTypes, filterCriteria, false); if(child.isFolder())
workspaceItemPath+="/"+child.getName();
// _log.trace("\nConverting child item: "+child.getName());
Item itemChild = getItem(item, child, workspaceItemPath, showableTypes, filterCriteria, false);
_log.trace("Item: "+child.getName() +" converted!!!"); _log.trace("Item: "+child.getName() +" converted!!!");
if (itemChild!=null){ if (itemChild!=null){
item.addChild(itemChild); item.addChild(itemChild);

View File

@ -62,8 +62,6 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
String sessionID = httpSession.getId(); String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
_log.error("WORKSPACE PORTLET SessionID= " + sessionID);
//TODO we check for the older attribute name //TODO we check for the older attribute name
if (user == null) { if (user == null) {
user = (String) httpSession.getAttribute("user"); user = (String) httpSession.getAttribute("user");
@ -122,7 +120,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime); _log.trace("start time - " + startTime);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true); Item rootItem = ItemBuilder.getItem(null, root, root.getPath(), showableTypes, filterCriteria, true);
rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL); rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL);
rootItem.setIsRoot(true); rootItem.setIsRoot(true);
@ -167,7 +165,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime); _log.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true); Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria, true);
_log.trace("Only showable types:"); _log.trace("Only showable types:");
if (purgeEmpyFolders) { if (purgeEmpyFolders) {
@ -242,7 +240,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime); _log.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true); Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria, true);
//OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders //OVERRIDING VRE FOLDERS NAME - SET SPECIAL FOLDER /Workspace/MySpecialFolders
itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL); itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL);
itemFolder.setSpecialFolder(true); itemFolder.setSpecialFolder(true);
@ -331,10 +329,8 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
* BUT RETURNING ONLY /MY_SPECIAL_FOLDER * BUT RETURNING ONLY /MY_SPECIAL_FOLDER
*/ */
if(wsItem.isFolder()){ if(wsItem.isFolder()){
if(ItemBuilder.isSpecialFolder((WorkspaceFolder) wsItem)) if(ItemBuilder.isSpecialFolder((WorkspaceFolder) wsItem)){
{
return new ArrayList<Item>(Arrays.asList(arrayParents)); return new ArrayList<Item>(Arrays.asList(arrayParents));
// return listParents;
} }
} }
@ -619,12 +615,22 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
Item parent = null; Item parent = null;
try{ try{
parent = ItemBuilder.getItem(null, wsFolder.getParent(), allTypes, null, false); String parentPath = wsFolder.getParent()!=null?wsFolder.getParent().getPath():"";
parent = ItemBuilder.getItem(null, wsFolder.getParent(), parentPath, allTypes, null, false);
}catch(Exception e){ }catch(Exception e){
_log.error("Get parent thown an exception, is it the root id? "+parentId); _log.error("Get parent thown an exception, is it the root id? "+parentId);
} }
return ItemBuilder.getItem(parent, wsFolder, allTypes, null, false); //TODO PATCH TO AVOID PROBLEM ON GETPATH. FOR EXAMPLE WHEN PARENT IS ROOT
String itemPath = null;
try{
itemPath = wsFolder.getPath();
}catch(Exception e){
_log.error("Get path thown an exception, for id: "+wsFolder.getId());
itemPath= wsFolder.isFolder()?workspace.getRoot().getPath()+"/"+wsFolder.getName():workspace.getRoot().getPath();
}
return ItemBuilder.getItem(parent, wsFolder, itemPath, allTypes, null, false);
} catch(InsufficientPrivilegesException e){ } catch(InsufficientPrivilegesException e){
String error = "Insufficient Privileges to create the folder"; String error = "Insufficient Privileges to create the folder";

View File

@ -318,9 +318,7 @@ public class Item implements IsSerializable {
public String toString() { public String toString() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append("Item [parent="); builder.append("Item id=");
builder.append(parent);
builder.append(", id=");
builder.append(id); builder.append(id);
builder.append(", name="); builder.append(", name=");
builder.append(name); builder.append(name);

View File

@ -40,7 +40,11 @@ public class TestGetChildren {
List<String> allowedMimeTypes = new ArrayList<String>(); List<String> allowedMimeTypes = new ArrayList<String>();
Map<String, String> requiredProperties = new HashMap<String, String>(); Map<String, String> requiredProperties = new HashMap<String, String>();
FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,null,null); FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,null,null);
getRoot(showableTypes, purgeEmpyFolders, filterCriteria); Item item = getRoot(showableTypes, purgeEmpyFolders, filterCriteria);
for (Item child : item.getChildren()) {
System.out.println(child);
}
} }
@ -66,7 +70,7 @@ public class TestGetChildren {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.debug("start time - " + startTime); _log.debug("start time - " + startTime);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true); Item rootItem = ItemBuilder.getItem(null, root, root.getPath(),showableTypes, filterCriteria, true);
if(rootItem==null) if(rootItem==null)
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get root"); throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get root");

View File

@ -1,5 +1,5 @@
/** /**
* *
*/ */
package org.gcube.portlets.widgets.wsexplorer.client; package org.gcube.portlets.widgets.wsexplorer.client;
@ -30,24 +30,24 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* *
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 6, 2015 * Jul 6, 2015
*/ */
public class TestGetSize { public class TestGetSize {
/** /**
* *
*/ */
private static final String TEST_SCOPE = "/gcube/devsec"; private static final String TEST_SCOPE = "/gcube/devsec";
/** /**
* *
*/ */
public static final String TEST_USER = "francesco.mangiacrapa"; public static final String TEST_USER = "francesco.mangiacrapa";
public static final Logger _log = LoggerFactory.getLogger(TestGetSize.class); public static final Logger _log = LoggerFactory.getLogger(TestGetSize.class);
private static Workspace workspace; private static Workspace workspace;
public static void main(String[] args) throws WorkspaceNavigatorServiceException { public static void main(String[] args) throws WorkspaceNavigatorServiceException {
List<ItemType> showableTypes = new ArrayList<ItemType>(); List<ItemType> showableTypes = new ArrayList<ItemType>();
showableTypes.addAll(Arrays.asList(ItemType.values())); showableTypes.addAll(Arrays.asList(ItemType.values()));
@ -55,10 +55,10 @@ public class TestGetSize {
List<String> allowedMimeTypes = new ArrayList<String>(); List<String> allowedMimeTypes = new ArrayList<String>();
Map<String, String> requiredProperties = new HashMap<String, String>(); Map<String, String> requiredProperties = new HashMap<String, String>();
FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,null,null); FilterCriteria filterCriteria = new FilterCriteria(allowedMimeTypes,null,null);
try { try {
ScopeBean scope = new ScopeBean(TEST_SCOPE); ScopeBean scope = new ScopeBean(TEST_SCOPE);
ScopeProvider.instance.set(scope.toString()); ScopeProvider.instance.set(scope.toString());
workspace = HomeLibrary workspace = HomeLibrary
@ -66,19 +66,19 @@ public class TestGetSize {
.getHomeManager() .getHomeManager()
.getHome(TEST_USER) .getHome(TEST_USER)
.getWorkspace(); .getWorkspace();
for (WorkspaceItem child: workspace.getRoot().getChildren()){ for (WorkspaceItem child: workspace.getRoot().getChildren()){
_log.debug("Child item: "+child); _log.debug("Child item: "+child);
// Item itemChild = getItem(item, child, showableTypes, filterCriteria, false); // Item itemChild = getItem(item, child, showableTypes, filterCriteria, false);
// _log.debug("Item: "+itemName +" converted!!!"); // _log.debug("Item: "+itemName +" converted!!!");
// if (itemChild!=null){ // if (itemChild!=null){
// item.addChild(itemChild); // item.addChild(itemChild);
// } // }
} }
/* /*
Item mySpecial = getMySpecialFolder(showableTypes, false, filterCriteria); Item mySpecial = getMySpecialFolder(showableTypes, false, filterCriteria);
for (Item spf : mySpecial.getChildren()) { for (Item spf : mySpecial.getChildren()) {
String size = getReadableSizeByItemId(spf.getId()); String size = getReadableSizeByItemId(spf.getId());
System.out.println(spf.getName() + ", size: "+size); System.out.println(spf.getName() + ", size: "+size);
@ -87,32 +87,32 @@ public class TestGetSize {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
getRoot(showableTypes, purgeEmpyFolders, filterCriteria); getRoot(showableTypes, purgeEmpyFolders, filterCriteria);
} }
public static Item getRoot(List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException { public static Item getRoot(List<ItemType> showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException {
_log.trace("getRoot showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+ filterCriteria); _log.trace("getRoot showableTypes: "+showableTypes+" purgeEmpyFolders: "+purgeEmpyFolders+" filterCriteria: "+ filterCriteria);
try { try {
_log.trace("Start getRoot..."); _log.trace("Start getRoot...");
WorkspaceItem root = workspace.getRoot(); WorkspaceItem root = workspace.getRoot();
_log.trace("GetRoot - Replyiing root"); _log.trace("GetRoot - Replyiing root");
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime); _log.trace("start time - " + startTime);
Item rootItem = ItemBuilder.getItem(null, root, showableTypes, filterCriteria, true); Item rootItem = ItemBuilder.getItem(null, root, root.getPath(), showableTypes, filterCriteria, true);
rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL); rootItem.setName(WorkspaceExplorerConstants.HOME_LABEL);
/* SPECIAL FOLDERS /* SPECIAL FOLDERS
Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2); Item specialFolders = ItemBuilder.getItem(null, specials, showableTypes, filterCriteria, 2);
specialFolders.setShared(true); specialFolders.setShared(true);
rootItem.addChild(specialFolders); rootItem.addChild(specialFolders);
*/ */
if (purgeEmpyFolders) rootItem = ItemBuilder.purgeEmptyFolders(rootItem); if (purgeEmpyFolders) rootItem = ItemBuilder.purgeEmptyFolders(rootItem);
@ -123,7 +123,7 @@ public class TestGetSize {
Collections.sort(rootItem.getChildren(), new ItemComparator()); Collections.sort(rootItem.getChildren(), new ItemComparator());
_log.info("Returning children size: "+rootItem.getChildren().size()); _log.info("Returning children size: "+rootItem.getChildren().size());
return rootItem; return rootItem;
} catch (Exception e) { } catch (Exception e) {
@ -131,7 +131,7 @@ public class TestGetSize {
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get root"); throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get root");
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -146,10 +146,10 @@ public class TestGetSize {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
_log.trace("start time - " + startTime); _log.trace("start time - " + startTime);
Item itemFolder = ItemBuilder.getItem(null, folder, showableTypes, filterCriteria, true); Item itemFolder = ItemBuilder.getItem(null, folder, folder.getPath(), showableTypes, filterCriteria, true);
itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL); itemFolder.setName(WorkspaceExplorerConstants.VRE_FOLDERS_LABEL);
itemFolder.setSpecialFolder(true); itemFolder.setSpecialFolder(true);
_log.trace("Builded MySpecialFolder: "+itemFolder); _log.trace("Builded MySpecialFolder: "+itemFolder);
_log.trace("Only showable types:"); _log.trace("Only showable types:");
@ -164,7 +164,7 @@ public class TestGetSize {
_log.trace("end time - " + time); _log.trace("end time - " + time);
//printName("", folderItem); //printName("", folderItem);
Collections.sort(itemFolder.getChildren(), new ItemComparator()); Collections.sort(itemFolder.getChildren(), new ItemComparator());
return itemFolder; return itemFolder;
@ -174,19 +174,19 @@ public class TestGetSize {
throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get My Special Folder"); throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get My Special Folder");
} }
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String) * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String)
*/ */
public static Long getSizeByItemId(String itemId) throws Exception { public static Long getSizeByItemId(String itemId) throws Exception {
_log.info("get Size By ItemId "+ itemId); _log.info("get Size By ItemId "+ itemId);
try { try {
WorkspaceItem wsItem = workspace.getItem(itemId); WorkspaceItem wsItem = workspace.getItem(itemId);
Long size = new Long(-1); Long size = new Long(-1);
if(wsItem instanceof FolderItem){ //ITEM if(wsItem instanceof FolderItem){ //ITEM
FolderItem folderItem = (FolderItem) wsItem; FolderItem folderItem = (FolderItem) wsItem;
size = new Long(folderItem.getLength()); size = new Long(folderItem.getLength());
@ -199,16 +199,16 @@ public class TestGetSize {
} }
_log.info("returning size: " +size); _log.info("returning size: " +size);
return size; return size;
} catch (Exception e) { } catch (Exception e) {
_log.error("get Size By ItemId ", e); _log.error("get Size By ItemId ", e);
throw new Exception(e.getMessage()); throw new Exception(e.getMessage());
} }
} }
public static String getReadableSizeByItemId(String itemId) throws Exception { public static String getReadableSizeByItemId(String itemId) throws Exception {
try{ try{
_log.info("getFormattedSize ByItemId "+ itemId); _log.info("getFormattedSize ByItemId "+ itemId);
long size = getSizeByItemId(itemId); long size = getSizeByItemId(itemId);