diff --git a/pom.xml b/pom.xml index 82e64a5..13d038d 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ - 2.6.1 + 2.7.0 distro 1.7 diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/WorkspaceExplorerController.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/WorkspaceExplorerController.java index 7e52141..90c4297 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/WorkspaceExplorerController.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/WorkspaceExplorerController.java @@ -202,15 +202,15 @@ public class WorkspaceExplorerController implements EventHandler { if(!item.isFolder()) hp.add(labelMime); hp.add(labelACL); - workspaceNavigatorService.loadSizeByItemId(item.getId(), new AsyncCallback() { + workspaceNavigatorService.getReadableSizeByItemId(item.getId(), new AsyncCallback() { @Override public void onFailure(Throwable caught) { } @Override - public void onSuccess(Long result) { - labelSize.setText("Size: " +Util.getFormattedSize(result)); + public void onSuccess(String result) { + labelSize.setText("Size: " +result); } }); diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerService.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerService.java index 4469990..4469c86 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerService.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerService.java @@ -6,6 +6,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory; import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; +import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter; import org.gcube.portlets.widgets.wsexplorer.shared.WorkspaceNavigatorServiceException; import com.google.gwt.user.client.rpc.RemoteService; @@ -13,85 +14,116 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath; /** * The client side stub for the RPC service. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jul 10, 2015 */ @RemoteServiceRelativePath("WorkspaceExplorerService") public interface WorkspaceExplorerService extends RemoteService { /** - * @param itemIdentifier - * @param includeItemAsParent - * @return - * @throws Exception + * Gets the breadcrumbs by item identifier. + * + * @param itemIdentifier the item identifier + * @param includeItemAsParent the include item as parent + * @return the breadcrumbs by item identifier + * @throws Exception the exception */ List getBreadcrumbsByItemIdentifier(String itemIdentifier, boolean includeItemAsParent) throws Exception; /** - * @param name - * @return - * @throws WorkspaceNavigatorServiceException + * Check name. + * + * @param name the name + * @return true, if successful + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ boolean checkName(String name) throws WorkspaceNavigatorServiceException; /** - * @param folderId - * @param showableTypes - * @param purgeEmpyFolders - * @param filterCriteria - * @return - * @throws WorkspaceNavigatorServiceException + * Gets the folder. + * + * @param folderId the folder id + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @return the folder + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ Item getFolder(String folderId, List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; /** - * @param showableTypes - * @param purgeEmpyFolders - * @param filterCriteria - * @return - * @throws WorkspaceNavigatorServiceException + * Gets the root. + * + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @return the root + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ Item getRoot(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; /** - * @param showableTypes - * @param purgeEmpyFolders - * @param filterCriteria - * @return - * @throws WorkspaceNavigatorServiceException + * Gets the my special folder. + * + * @param showableTypes the showable types + * @param purgeEmpyFolders the purge empy folders + * @param filterCriteria the filter criteria + * @return the my special folder + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ Item getMySpecialFolder(List showableTypes, boolean purgeEmpyFolders, FilterCriteria filterCriteria) throws WorkspaceNavigatorServiceException; /** - * @param category - * @return - * @throws WorkspaceNavigatorServiceException + * Gets the item by category. + * + * @param category the category + * @return the item by category + * @throws WorkspaceNavigatorServiceException the workspace navigator service exception */ Item getItemByCategory(ItemCategory category)throws WorkspaceNavigatorServiceException; /** - * @param itemId - * @return - * @throws Exception + * Gets the size by item id. + * + * @param itemId the item id + * @return the size by item id + * @throws Exception the exception */ - Long loadSizeByItemId(String itemId) throws Exception; + Long getSizeByItemId(String itemId) throws Exception; /** - * @param itemId - * @return - * @throws Exception + * Gets the mime type. + * + * @param itemId the item id + * @return the mime type + * @throws Exception the exception */ String getMimeType(String itemId) throws Exception; /** - * @param folderId - * @return - * @throws Exception + * Gets the user acl for folder id. + * + * @param folderId the folder id + * @return the user acl for folder id + * @throws Exception the exception */ String getUserACLForFolderId(String folderId) throws Exception; + + + /** + * Gets the readable size by item id. + * + * @param id the id + * @return the readable size by item id + * @throws Exception the exception + */ + String getReadableSizeByItemId(String id) throws Exception; } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerServiceAsync.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerServiceAsync.java index b0b30cf..e252d46 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerServiceAsync.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/rpc/WorkspaceExplorerServiceAsync.java @@ -9,6 +9,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory; import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; +import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -99,20 +100,39 @@ public interface WorkspaceExplorerServiceAsync { public void getItemByCategory(ItemCategory category, AsyncCallback asyncCallback); /** - * @param id - * @param asyncCallback + * Gets the size by item id. + * + * @param id the id + * @param asyncCallback the async callback + * @return the size by item id */ - public void loadSizeByItemId(String id, AsyncCallback asyncCallback); + public void getSizeByItemId(String id, AsyncCallback asyncCallback); + /** - * @param id - * @param asyncCallback + * Gets the readable size by item id. + * + * @param id the id + * @param asyncCallback the async callback + * @return the readable size by item id + */ + public void getReadableSizeByItemId(String id, AsyncCallback asyncCallback); + + /** + * Gets the mime type. + * + * @param id the id + * @param asyncCallback the async callback + * @return the mime type */ public void getMimeType(String id, AsyncCallback asyncCallback); /** - * @param id - * @param asyncCallback + * Gets the user acl for folder id. + * + * @param id the id + * @param asyncCallback the async callback + * @return the user acl for folder id */ public void getUserACLForFolderId(String id, AsyncCallback asyncCallback); diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/public/workspace-explorer.css b/src/main/java/org/gcube/portlets/widgets/wsexplorer/public/workspace-explorer.css index 05e37fe..823de94 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/public/workspace-explorer.css +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/public/workspace-explorer.css @@ -31,6 +31,7 @@ margin-right: 10px; margin-left: 5px; width: 550px; + font-size: 12px !important; } .footerHP{ diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/ItemBuilder.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/ItemBuilder.java index 338e354..bb8575d 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/ItemBuilder.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/ItemBuilder.java @@ -65,7 +65,7 @@ public class ItemBuilder { } /** - * Gets the item. + * Gets the item * * @param parent the parent * @param workspaceItem the workspace item diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java index bc3416c..3a431d7 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/WorkspaceExplorerServiceImpl.java @@ -1,5 +1,7 @@ package org.gcube.portlets.widgets.wsexplorer.server; +import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -25,6 +27,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria; import org.gcube.portlets.widgets.wsexplorer.shared.Item; import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory; import org.gcube.portlets.widgets.wsexplorer.shared.ItemType; +import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter; import org.gcube.portlets.widgets.wsexplorer.shared.WorkspaceNavigatorServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +48,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement */ public static final Logger _log = LoggerFactory.getLogger(WorkspaceExplorerServiceImpl.class); public static final String USERNAME_ATTRIBUTE = "username"; - public static final String TEST_USER = "francesco.mangiacrapa"; + public static final String TEST_USER = "test.user"; /** @@ -349,7 +352,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String) */ @Override - public Long loadSizeByItemId(String itemId) throws Exception { + public Long getSizeByItemId(String itemId) throws Exception { _log.info("get Size By ItemId "+ itemId); try { @@ -451,4 +454,29 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement return false; } } + + + /* (non-Javadoc) + * @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter) + */ + @Override + public String getReadableSizeByItemId(String itemId) throws Exception { + + try{ + _log.info("getFormattedSize ByItemId "+ itemId); + long size = getSizeByItemId(itemId); + return 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]; + } } diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/shared/SizeFormatter.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/shared/SizeFormatter.java new file mode 100644 index 0000000..862ce80 --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/shared/SizeFormatter.java @@ -0,0 +1,43 @@ +/** + * + */ +package org.gcube.portlets.widgets.wsexplorer.shared; + +/** + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jul 10, 2015 + */ +public enum SizeFormatter { + + + KB("KB", 1024), + MB("MB", 1048576); + + private long value; + private String unit; + + /** + * + */ + private SizeFormatter(String unit, long value) { + this.unit = unit; + this.value = value; + } + + /** + * @return the value + */ + public long getValue() { + return value; + } + + /** + * @return the unit + */ + public String getUnit() { + return unit; + } + + +}