From 529e25bf77a6c19d0538aec5959b4909c25222e7 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Tue, 27 Nov 2007 18:44:24 +0000 Subject: [PATCH] User content usages & quotas - initial check-in git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7453 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 4 + .../alfresco/web-client-config-properties.xml | 2 +- .../web/bean/users/CreateUserWizard.java | 101 ++++++++++++++++++ .../web/bean/users/EditUserWizard.java | 12 +++ .../web/bean/users/UsersBeanProperties.java | 40 ++++++- .../alfresco/web/bean/users/UsersDialog.java | 45 ++++++++ source/web/WEB-INF/faces-config-beans.xml | 32 +++++- source/web/jsp/users/person-properties.jsp | 11 ++ source/web/jsp/users/user-console.jsp | 28 +++++ source/web/jsp/users/users.jsp | 33 +++++- 10 files changed, 301 insertions(+), 7 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index be6804d68f..c3066dae99 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -305,6 +305,10 @@ mimetype=Format modifier=Modifier locale=Locale +quota=Quota +sizeCurrent=Usage +sizeQuota=Quota + # Repo permission display labels # Note - these come from the server, the english translation is generally the same Administrator=Administrator diff --git a/config/alfresco/web-client-config-properties.xml b/config/alfresco/web-client-config-properties.xml index ff232a0bb0..1f35589008 100644 --- a/config/alfresco/web-client-config-properties.xml +++ b/config/alfresco/web-client-config-properties.xml @@ -226,7 +226,7 @@ - + diff --git a/source/java/org/alfresco/web/bean/users/CreateUserWizard.java b/source/java/org/alfresco/web/bean/users/CreateUserWizard.java index 5543e49d11..2e96c58cf7 100644 --- a/source/java/org/alfresco/web/bean/users/CreateUserWizard.java +++ b/source/java/org/alfresco/web/bean/users/CreateUserWizard.java @@ -46,8 +46,10 @@ import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.cmr.usage.ContentUsageService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; import org.alfresco.web.app.Application; import org.alfresco.web.app.context.UIContextService; import org.alfresco.web.bean.repository.Repository; @@ -65,6 +67,10 @@ public class CreateUserWizard extends BaseWizardBean private static Logger logger = Logger.getLogger(CreateUserWizard.class); protected static final String ERROR = "error_person"; + protected static final String QUOTA_UNITS_KB = "kilobyte"; + protected static final String QUOTA_UNITS_MB = "megabyte"; + protected static final String QUOTA_UNITS_GB = "gigabyte"; + /** form variables */ protected String firstName = null; protected String lastName = null; @@ -77,6 +83,9 @@ public class CreateUserWizard extends BaseWizardBean protected NodeRef homeSpaceLocation = null; protected String presenceProvider = null; protected String presenceUsername = null; + + protected Long sizeQuota = null; // null is also equivalent to -1 (ie. no quota limit set) + protected String sizeQuotaUnits = null; /** AuthenticationService bean reference */ private AuthenticationService authenticationService; @@ -89,6 +98,10 @@ public class CreateUserWizard extends BaseWizardBean /** OwnableService bean reference */ private OwnableService ownableService; + + /** ContentUsageService bean reference */ + private ContentUsageService contentUsageService; + /** ref to the company home space folder */ private NodeRef companyHomeSpaceRef = null; @@ -127,6 +140,14 @@ public class CreateUserWizard extends BaseWizardBean { this.ownableService = ownableService; } + + /** + * @param contentUsageService The contentUsageService to set. + */ + public void setContentUsageService(ContentUsageService contentUsageService) + { + this.contentUsageService = contentUsageService; + } /** * Initialises the wizard @@ -148,6 +169,9 @@ public class CreateUserWizard extends BaseWizardBean this.homeSpaceLocation = getDefaultHomeSpace(); this.presenceProvider = ""; this.presenceUsername = ""; + + this.sizeQuota = null; + this.sizeQuotaUnits = ""; } /** @@ -352,6 +376,26 @@ public class CreateUserWizard extends BaseWizardBean { this.confirm = confirm; } + + public Long getSizeQuota() + { + return sizeQuota; + } + + public void setSizeQuota(Long sizeQuota) + { + this.sizeQuota = sizeQuota; + } + + public String getSizeQuotaUnits() + { + return sizeQuotaUnits; + } + + public void setSizeQuotaUnits(String sizeQuotaUnits) + { + this.sizeQuotaUnits = sizeQuotaUnits; + } // ------------------------------------------------------------------------------ // Validator methods @@ -603,6 +647,8 @@ public class CreateUserWizard extends BaseWizardBean if (logger.isDebugEnabled()) logger.debug("Created User Authentication instance for username: " + this.userName); + + putSizeQuotaProperty(this.userName, this.sizeQuota, this.sizeQuotaUnits); } else { @@ -633,4 +679,59 @@ public class CreateUserWizard extends BaseWizardBean } return true; } + + protected void putSizeQuotaProperty(String userName, Long quota, String quotaUnits) + { + if ((quota != null) && (quota > 0)) + { + quota = convertToBytes(quota, quotaUnits); + } + + this.contentUsageService.setUserQuota(userName, (quota == null ? -1 : quota)); + } + + protected long convertToBytes(long size, String units) + { + if (units != null) + { + if (units.equals(QUOTA_UNITS_KB)) + { + size = size * 1024L; + } + else if (units.equals(QUOTA_UNITS_MB)) + { + size = size * 1048576L; + } + else if (units.equals(QUOTA_UNITS_GB)) + { + size = size * 1073741824L; + } + } + return size; + } + + protected Pair convertFromBytes(long size) + { + String units = null; + if (size <= 0) + { + units = QUOTA_UNITS_GB; + } + else if (size < 999999) + { + size = (long)((double)size / 1024.0d); + units = QUOTA_UNITS_KB; + } + else if (size < 999999999) + { + size = (long)((double)size / 1048576.0d); + units = QUOTA_UNITS_MB; + } + else + { + size = (long)((double)size / 1073741824.0d); + units = QUOTA_UNITS_GB; + } + return new Pair(size, units); + } } diff --git a/source/java/org/alfresco/web/bean/users/EditUserWizard.java b/source/java/org/alfresco/web/bean/users/EditUserWizard.java index 525f319245..04991c3ef9 100644 --- a/source/java/org/alfresco/web/bean/users/EditUserWizard.java +++ b/source/java/org/alfresco/web/bean/users/EditUserWizard.java @@ -34,6 +34,7 @@ import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; +import org.alfresco.util.Pair; import org.alfresco.web.app.Application; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; @@ -72,6 +73,14 @@ public class EditUserWizard extends CreateUserWizard this.companyId = (String) props.get("organizationId"); this.presenceProvider = (String) props.get("presenceProvider"); this.presenceUsername = (String) props.get("presenceUsername"); + this.sizeQuota = (Long) props.get("sizeQuota"); + + if (this.sizeQuota != null) + { + Pair size = convertFromBytes(this.sizeQuota); + this.sizeQuota = size.getFirst(); + this.sizeQuotaUnits = size.getSecond(); + } // calculate home space name and parent space Id from homeFolderId this.homeSpaceLocation = null; // default to Company root space @@ -185,6 +194,9 @@ public class EditUserWizard extends CreateUserWizard // TODO: RESET HomeSpace Ref found in top-level navigation bar! // NOTE: not need cos only admin can do this? + + putSizeQuotaProperty(this.userName, this.sizeQuota, this.sizeQuotaUnits); + } catch (Throwable e) { diff --git a/source/java/org/alfresco/web/bean/users/UsersBeanProperties.java b/source/java/org/alfresco/web/bean/users/UsersBeanProperties.java index 4852967083..fabfec5ec6 100644 --- a/source/java/org/alfresco/web/bean/users/UsersBeanProperties.java +++ b/source/java/org/alfresco/web/bean/users/UsersBeanProperties.java @@ -24,10 +24,12 @@ */ package org.alfresco.web.bean.users; +import org.alfresco.model.ContentModel; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.cmr.usage.ContentUsageService; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.ui.common.component.data.UIRichList; @@ -45,6 +47,10 @@ public class UsersBeanProperties /** PersonService bean reference */ private PersonService personService; + /** ContentUsageService bean reference */ + private ContentUsageService contentUsageService; + + /** Component reference for Users RichList control */ private UIRichList usersRichList; @@ -55,7 +61,7 @@ public class UsersBeanProperties private String oldPassword = null; private String confirm = null; private String searchCriteria = null; - + private String userName = null; // ------------------------------------------------------------------------------ // Bean property getters and setters @@ -123,6 +129,14 @@ public class UsersBeanProperties { this.personService = personService; } + + /** + * @param contentUsageService The ContentUsageService to set. + */ + public void setContentUsageService(ContentUsageService contentUsageService) + { + this.contentUsageService = contentUsageService; + } /** * @return Returns the usersRichList. @@ -218,5 +232,29 @@ public class UsersBeanProperties public void setPerson(Node person) { this.person = person; + this.userName = (String)person.getProperties().get(ContentModel.PROP_USERNAME); + } + + public Long getUserUsage(String userName) + { + long usage = this.contentUsageService.getUserUsage(userName); + return (usage == -1 ? null : usage); + } + + public Long getUserUsage() + { + long usage = this.contentUsageService.getUserUsage(this.userName); + return (usage == -1 ? null : usage); + } + + public Long getUserQuota() + { + long quota = this.contentUsageService.getUserQuota(this.userName); + return (quota == -1 ? null : quota); + } + + public boolean getUsagesEnabled() + { + return this.contentUsageService.getEnabled(); } } diff --git a/source/java/org/alfresco/web/bean/users/UsersDialog.java b/source/java/org/alfresco/web/bean/users/UsersDialog.java index c5e0ecc74a..1b0344b80f 100644 --- a/source/java/org/alfresco/web/bean/users/UsersDialog.java +++ b/source/java/org/alfresco/web/bean/users/UsersDialog.java @@ -51,6 +51,7 @@ import org.alfresco.web.bean.LoginBean; import org.alfresco.web.bean.dialog.BaseDialogBean; import org.alfresco.web.bean.repository.MapNode; import org.alfresco.web.bean.repository.Node; +import org.alfresco.web.bean.repository.NodePropertyResolver; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.UIActionLink; @@ -111,6 +112,36 @@ public class UsersDialog extends BaseDialogBean implements IContextListener return this.users; } + public long getUsersTotalUsage() + { + long totalUsage = 0L; + List users = getUsers(); + for(Node user : users) + { + Long sizeLatest = (Long)properties.getUserUsage((String)user.getProperties().get("userName")); + if (sizeLatest != null) + { + totalUsage = totalUsage + sizeLatest; + } + } + return totalUsage; + } + + public long getUsersTotalQuota() + { + long totalQuota = 0L; + List users = getUsers(); + for(Node user : users) + { + Long sizeCurrent = (Long)user.getProperties().get("sizeQuota"); + if (sizeCurrent != null) + { + totalQuota = totalQuota + sizeCurrent; + } + } + return totalQuota; + } + /** * Action event called by all actions that need to setup a Person context on * the Users bean before an action page is called. The context will be a @@ -305,6 +336,8 @@ public class UsersDialog extends BaseDialogBean implements IContextListener props.put("homeSpace", homeFolderNodeRef); } + node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest); + this.users.add(node); } @@ -331,6 +364,13 @@ public class UsersDialog extends BaseDialogBean implements IContextListener return null; } + public NodePropertyResolver resolverUserSizeLatest = new NodePropertyResolver() { + public Object get(Node personNode) { + Long sizeLatest = (Long)properties.getUserUsage((String)personNode.getProperties().get("userName")); + return sizeLatest; + } + }; + /** * Action handler to show all the users currently in the system * @@ -343,6 +383,11 @@ public class UsersDialog extends BaseDialogBean implements IContextListener this.users = Repository.getUsers(FacesContext.getCurrentInstance(), properties.getNodeService(), properties.getSearchService()); + for (Node node : this.users) + { + node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest); + } + // return null to stay on the same page return null; } diff --git a/source/web/WEB-INF/faces-config-beans.xml b/source/web/WEB-INF/faces-config-beans.xml index 0dbf65dfaa..5551df98a4 100644 --- a/source/web/WEB-INF/faces-config-beans.xml +++ b/source/web/WEB-INF/faces-config-beans.xml @@ -542,7 +542,13 @@ personService #{PersonService} - + + + + contentUsageService + #{ContentUsageService} + + @@ -643,7 +649,13 @@ namespaceService #{NamespaceService} - + + + + contentUsageService + #{ContentUsageService} + + @@ -4387,7 +4399,13 @@ ownableService #{OwnableService} - + + + + contentUsageService + #{ContentUsageService} + + @@ -4438,7 +4456,13 @@ properties #{UsersBeanProperties} - + + + + contentUsageService + #{ContentUsageService} + + diff --git a/source/web/jsp/users/person-properties.jsp b/source/web/jsp/users/person-properties.jsp index 2ac16d260a..b5a3465bf1 100644 --- a/source/web/jsp/users/person-properties.jsp +++ b/source/web/jsp/users/person-properties.jsp @@ -103,5 +103,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/source/web/jsp/users/user-console.jsp b/source/web/jsp/users/user-console.jsp index 76460ed7af..6ca392397b 100644 --- a/source/web/jsp/users/user-console.jsp +++ b/source/web/jsp/users/user-console.jsp @@ -119,6 +119,34 @@ rendered="#{NavigationBean.isGuest == false}" border="white" bgcolor="white" titleBorder="lbgrey" expandedTitleBorder="dotted" titleBgcolor="white"> + + + + + + + + + + + + +
: + + + +
: + + + + + +
+
+
+ diff --git a/source/web/jsp/users/users.jsp b/source/web/jsp/users/users.jsp index 554d7b4086..3b2674c720 100644 --- a/source/web/jsp/users/users.jsp +++ b/source/web/jsp/users/users.jsp @@ -187,6 +187,26 @@ + + + <%-- Usage column --%> + + + + + + + + + + <%-- Quota column --%> + + + + + + + <%-- Actions column --%> @@ -210,7 +230,18 @@ - + + +
+ + + + + + + + +