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
This commit is contained in:
Francesco Mangiacrapa 2014-10-31 16:27:52 +00:00
parent 658bbc3f28
commit 18619ec866
7 changed files with 245 additions and 40 deletions

View File

@ -48597,3 +48597,67 @@ Compiling...
Compilation completed in 0.00 seconds Compilation completed in 0.00 seconds
Removing invalidated units Removing invalidated units
Finding entry point classes 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

View File

@ -220,8 +220,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
eventBus.addHandler(RenderForm.TYPE, new RenderFormEventHandler() { eventBus.addHandler(RenderForm.TYPE, new RenderFormEventHandler() {
@Override @Override
public void onRenderForm(RenderForm event) { public void onRenderForm(RenderForm event) {
} }
}); });

View File

@ -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.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; 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 org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import com.google.gwt.user.client.rpc.RemoteService; import com.google.gwt.user.client.rpc.RemoteService;
@ -261,4 +262,16 @@ public interface GWTWorkspaceService extends RemoteService{
WorkspaceACL getACLBySharedFolderId(String identifier) throws Exception; WorkspaceACL getACLBySharedFolderId(String identifier) throws Exception;
/**
* @return
* @throws Exception
*/
long getUserWorkspaceTotalItems() throws Exception;
/**
* @return
* @throws Exception
*/
WorkspaceUserQuote getUserWorkspaceQuote() throws Exception;
} }

View File

@ -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.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; 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 org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
@ -218,6 +219,8 @@ public interface GWTWorkspaceServiceAsync {
void getACLBySharedFolderId(String identifier, AsyncCallback<WorkspaceACL> callback); void getACLBySharedFolderId(String identifier, AsyncCallback<WorkspaceACL> callback);
void getUserWorkspaceTotalItems(AsyncCallback<Long> callback);
void getUserWorkspaceQuote(AsyncCallback<WorkspaceUserQuote> callback);
} }

View File

@ -1,5 +1,6 @@
package org.gcube.portlets.user.workspace.server; package org.gcube.portlets.user.workspace.server;
import java.text.DecimalFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -2325,4 +2326,35 @@ public class GWTWorkspaceBuilder {
return html; 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;
}
} }

View File

@ -1,7 +1,6 @@
package org.gcube.portlets.user.workspace.server; package org.gcube.portlets.user.workspace.server;
import java.io.File; import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; 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.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL; import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.WorkspaceTrashOperation; 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.GxtAccountingEntryType;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField; import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource; import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
@ -3227,44 +3227,58 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
} }
@Override @Override
public String getUserWorkspaceSize() throws Exception { public WorkspaceUserQuote getUserWorkspaceQuote() throws Exception {
workspaceLogger.info("Getting workspace size.."); try{
Workspace workspace = getWorkspace(); workspaceLogger.info("Getting UserWorkspaceQuote..");
long size = workspace.getRoot().getSize(); Workspace workspace = getWorkspace();
workspaceLogger.info("Root size is: "+size +" formatting.."); long size = workspace.getDiskUsage();
String formatSize = formatFileSize(size); workspaceLogger.info("Root size is: "+size +" formatting..");
workspaceLogger.info("returning workspace size: "+formatSize); String formatSize = GWTWorkspaceBuilder.formatFileSize(size);
return formatSize; 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 @Override
* @param size public String getUserWorkspaceSize() throws Exception {
* @return try{
*/ workspaceLogger.info("Getting workspace size..");
private static String formatFileSize(long size) { Workspace workspace = getWorkspace();
String formattedSize = null; long size = workspace.getDiskUsage();
// workspaceLogger.info("Root size is: "+size +" formatting..");
double b = size; String formatSize = GWTWorkspaceBuilder.formatFileSize(size);
double k = size/1024.0; workspaceLogger.info("returning workspace size: "+formatSize);
double m = ((size/1024.0)/1024.0); return formatSize;
double g = (((size/1024.0)/1024.0)/1024.0); }catch(Exception e){
double t = ((((size/1024.0)/1024.0)/1024.0)/1024.0); workspaceLogger.error("Error on UserWorkspaceSize",e);
String error = ConstantsExplorer.SERVER_ERROR +" getting disk usage";
DecimalFormat dec = new DecimalFormat("0.00"); throw new Exception(error);
}
if ( t>1 ) {
formattedSize = dec.format(t).concat(" TB"); }
} else if ( g>1 ) {
formattedSize = dec.format(g).concat(" GB"); @Override
} else if ( m>1 ) { public long getUserWorkspaceTotalItems() throws Exception {
formattedSize = dec.format(m).concat(" MB"); try{
} else if ( k>1 ) { workspaceLogger.info("Getting total items..");
formattedSize = dec.format(k).concat(" KB"); Workspace workspace = getWorkspace();
} else { long size = workspace.getTotalItems();
formattedSize = dec.format(b).concat(" Bytes"); workspaceLogger.info("returning total items value: "+size);
} return size;
}catch(Exception e){
return formattedSize; workspaceLogger.error("Error on UserWorkspaceSize",e);
String error = ConstantsExplorer.SERVER_ERROR +" getting total items";
throw new Exception(error);
}
} }
} }

View File

@ -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();
}
}