From 18619ec86650d72cbe326ada5f295b800cc7b2e9 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Fri, 31 Oct 2014 16:27:52 +0000 Subject: [PATCH] latest version to integrate workspace quote git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@101325 82a268e6-3cf1-43bd-a215-b396298e98cf --- .gwt/.gwt-log | 64 +++++++++++++ .../client/AppControllerExplorer.java | 3 +- .../client/rpc/GWTWorkspaceService.java | 13 +++ .../client/rpc/GWTWorkspaceServiceAsync.java | 3 + .../workspace/server/GWTWorkspaceBuilder.java | 32 +++++++ .../server/GWTWorkspaceServiceImpl.java | 90 +++++++++++-------- .../workspace/shared/WorkspaceUserQuote.java | 80 +++++++++++++++++ 7 files changed, 245 insertions(+), 40 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceUserQuote.java diff --git a/.gwt/.gwt-log b/.gwt/.gwt-log index 0b19bf2..353922a 100644 --- a/.gwt/.gwt-log +++ b/.gwt/.gwt-log @@ -48597,3 +48597,67 @@ Compiling... Compilation completed in 0.00 seconds Removing invalidated units Finding entry point classes +Public resources found in... +Translatable source found in... +Found 0 cached/archived units. Used 0 / 2719 units from cache. +Compiling... + 50% complete (ETR: 4 seconds) + 50% complete (ETR: 4 seconds) + 50% complete (ETR: 4 seconds) + 50% complete (ETR: 4 seconds) + 50% complete (ETR: 4 seconds) + 50% complete (ETR: 4 seconds) + 60% complete (ETR: 3 seconds) + 70% complete (ETR: 2 seconds) + 80% complete (ETR: 1 seconds) + 90% complete (ETR: 1 seconds) + 100% complete (ETR: 0 seconds) + Compilation completed in 8.26 seconds +Removing invalidated units +Finding entry point classes +Public resources found in... +Translatable source found in... +Found 2719 cached/archived units. Used 2719 / 2719 units from cache. +Compiling... + Compilation completed in 0.00 seconds +Removing invalidated units +Finding entry point classes +Public resources found in... +Translatable source found in... +Found 2719 cached/archived units. Used 2719 / 2719 units from cache. +Compiling... + Compilation completed in 0.00 seconds +Removing invalidated units +Finding entry point classes +Public resources found in... +Translatable source found in... +Found 0 cached/archived units. Used 0 / 2719 units from cache. +Compiling... + 40% complete (ETR: 7 seconds) + 40% complete (ETR: 7 seconds) + 40% complete (ETR: 7 seconds) + 40% complete (ETR: 7 seconds) + 40% complete (ETR: 7 seconds) + 50% complete (ETR: 5 seconds) + 60% complete (ETR: 4 seconds) + 70% complete (ETR: 3 seconds) + 80% complete (ETR: 2 seconds) + 90% complete (ETR: 1 seconds) + 100% complete (ETR: 0 seconds) + Compilation completed in 23.24 seconds +Removing invalidated units +Finding entry point classes +Public resources found in... +Translatable source found in... +Found 2719 cached/archived units. Used 2719 / 2719 units from cache. +Compiling... + Compilation completed in 0.00 seconds +Removing invalidated units +Finding entry point classes +Public resources found in... +Translatable source found in... +Found 2719 cached/archived units. Used 2719 / 2719 units from cache. +Compiling... + Compilation completed in 0.00 seconds +Removing invalidated units +Finding entry point classes diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index cff9a9a..1f09426 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -220,8 +220,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt eventBus.addHandler(RenderForm.TYPE, new RenderFormEventHandler() { @Override public void onRenderForm(RenderForm event) { - - + } }); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java index 274c6c9..9bdc81e 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java @@ -23,6 +23,7 @@ import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; +import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField; import com.google.gwt.user.client.rpc.RemoteService; @@ -261,4 +262,16 @@ public interface GWTWorkspaceService extends RemoteService{ WorkspaceACL getACLBySharedFolderId(String identifier) throws Exception; + /** + * @return + * @throws Exception + */ + long getUserWorkspaceTotalItems() throws Exception; + + /** + * @return + * @throws Exception + */ + WorkspaceUserQuote getUserWorkspaceQuote() throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index 859b6d1..7575cc0 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -22,6 +22,7 @@ import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; +import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -218,6 +219,8 @@ public interface GWTWorkspaceServiceAsync { void getACLBySharedFolderId(String identifier, AsyncCallback callback); + void getUserWorkspaceTotalItems(AsyncCallback callback); + void getUserWorkspaceQuote(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index d8db8db..64206ec 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -1,5 +1,6 @@ package org.gcube.portlets.user.workspace.server; +import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -2325,4 +2326,35 @@ public class GWTWorkspaceBuilder { return html; } + + /** + * returns dynamically the formated size + * @param size + * @return + */ + public static String formatFileSize(long size) { + String formattedSize = null; + + double b = size; + double k = size/1024.0; + double m = ((size/1024.0)/1024.0); + double g = (((size/1024.0)/1024.0)/1024.0); + double t = ((((size/1024.0)/1024.0)/1024.0)/1024.0); + + DecimalFormat dec = new DecimalFormat("0.00"); + + if ( t>1 ) { + formattedSize = dec.format(t).concat(" TB"); + } else if ( g>1 ) { + formattedSize = dec.format(g).concat(" GB"); + } else if ( m>1 ) { + formattedSize = dec.format(m).concat(" MB"); + } else if ( k>1 ) { + formattedSize = dec.format(k).concat(" KB"); + } else { + formattedSize = dec.format(b).concat(" Bytes"); + } + + return formattedSize; + } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index bd1f056..3559ccd 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -1,7 +1,6 @@ package org.gcube.portlets.user.workspace.server; import java.io.File; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -76,6 +75,7 @@ import org.gcube.portlets.user.workspace.shared.TrashOperationContent; import org.gcube.portlets.user.workspace.shared.UserBean; import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; +import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField; import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource; @@ -3227,44 +3227,58 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } @Override - public String getUserWorkspaceSize() throws Exception { - workspaceLogger.info("Getting workspace size.."); - Workspace workspace = getWorkspace(); - long size = workspace.getRoot().getSize(); - workspaceLogger.info("Root size is: "+size +" formatting.."); - String formatSize = formatFileSize(size); - workspaceLogger.info("returning workspace size: "+formatSize); - return formatSize; + public WorkspaceUserQuote getUserWorkspaceQuote() throws Exception { + try{ + workspaceLogger.info("Getting UserWorkspaceQuote.."); + Workspace workspace = getWorkspace(); + long size = workspace.getDiskUsage(); + workspaceLogger.info("Root size is: "+size +" formatting.."); + String formatSize = GWTWorkspaceBuilder.formatFileSize(size); + long total = getUserWorkspaceTotalItems(); + + WorkspaceUserQuote quote = new WorkspaceUserQuote(); + quote.setDiskSpace(size); + quote.setDiskSpaceFormatted(formatSize); + quote.setTotalItems(total); + workspaceLogger.info("returning user quote: "+quote); + return quote; + }catch(Exception e){ + workspaceLogger.error("Error on UserWorkspaceQuote",e); + return null; + } } - /** - * returns dynamically the formated size - * @param size - * @return - */ - private static String formatFileSize(long size) { - String formattedSize = null; - - double b = size; - double k = size/1024.0; - double m = ((size/1024.0)/1024.0); - double g = (((size/1024.0)/1024.0)/1024.0); - double t = ((((size/1024.0)/1024.0)/1024.0)/1024.0); - - DecimalFormat dec = new DecimalFormat("0.00"); - - if ( t>1 ) { - formattedSize = dec.format(t).concat(" TB"); - } else if ( g>1 ) { - formattedSize = dec.format(g).concat(" GB"); - } else if ( m>1 ) { - formattedSize = dec.format(m).concat(" MB"); - } else if ( k>1 ) { - formattedSize = dec.format(k).concat(" KB"); - } else { - formattedSize = dec.format(b).concat(" Bytes"); - } - - return formattedSize; + + @Override + public String getUserWorkspaceSize() throws Exception { + try{ + workspaceLogger.info("Getting workspace size.."); + Workspace workspace = getWorkspace(); + long size = workspace.getDiskUsage(); +// workspaceLogger.info("Root size is: "+size +" formatting.."); + String formatSize = GWTWorkspaceBuilder.formatFileSize(size); + workspaceLogger.info("returning workspace size: "+formatSize); + return formatSize; + }catch(Exception e){ + workspaceLogger.error("Error on UserWorkspaceSize",e); + String error = ConstantsExplorer.SERVER_ERROR +" getting disk usage"; + throw new Exception(error); + } + + } + + @Override + public long getUserWorkspaceTotalItems() throws Exception { + try{ + workspaceLogger.info("Getting total items.."); + Workspace workspace = getWorkspace(); + long size = workspace.getTotalItems(); + workspaceLogger.info("returning total items value: "+size); + return size; + }catch(Exception e){ + workspaceLogger.error("Error on UserWorkspaceSize",e); + String error = ConstantsExplorer.SERVER_ERROR +" getting total items"; + throw new Exception(error); + } } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceUserQuote.java b/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceUserQuote.java new file mode 100644 index 0000000..f58d582 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/WorkspaceUserQuote.java @@ -0,0 +1,80 @@ +/** + * + */ +package org.gcube.portlets.user.workspace.shared; + +import java.io.Serializable; + +/** + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * @Oct 31, 2014 + * + */ +public class WorkspaceUserQuote implements Serializable{ + + + /** + * + */ + private static final long serialVersionUID = -5363340286390074157L; + + + private Long diskSpace; + private String diskSpaceFormatted; + private Long totalItems; + + public WorkspaceUserQuote(){ + } + + + + /** + * @param diskSpace + * @param diskSpaceFormatted + * @param totalItems + */ + public WorkspaceUserQuote(Long diskSpace, String diskSpaceFormatted, + Long totalItems) { + this.diskSpace = diskSpace; + this.diskSpaceFormatted = diskSpaceFormatted; + this.totalItems = totalItems; + } + + public Long getDiskSpace() { + return diskSpace; + } + + public String getDiskSpaceFormatted() { + return diskSpaceFormatted; + } + + public Long getTotalItems() { + return totalItems; + } + + public void setDiskSpace(Long diskSpace) { + this.diskSpace = diskSpace; + } + + public void setDiskSpaceFormatted(String diskSpaceFormatted) { + this.diskSpaceFormatted = diskSpaceFormatted; + } + + public void setTotalItems(Long totalItems) { + this.totalItems = totalItems; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("WorkspaceUserQuote [diskSpace="); + builder.append(diskSpace); + builder.append(", diskSpaceFormatted="); + builder.append(diskSpaceFormatted); + builder.append(", totalItems="); + builder.append(totalItems); + builder.append("]"); + return builder.toString(); + } + +}