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
This commit is contained in:
Jan Vonka
2007-11-27 18:44:24 +00:00
parent ab0ef44804
commit 529e25bf77
10 changed files with 301 additions and 7 deletions

View File

@@ -305,6 +305,10 @@ mimetype=Format
modifier=Modifier modifier=Modifier
locale=Locale locale=Locale
quota=Quota
sizeCurrent=Usage
sizeQuota=Quota
# Repo permission display labels # Repo permission display labels
# Note - these come from the server, the english translation is generally the same # Note - these come from the server, the english translation is generally the same
Administrator=Administrator Administrator=Administrator

View File

@@ -226,7 +226,7 @@
<config evaluator="aspect-name" condition="cm:ownable"> <config evaluator="aspect-name" condition="cm:ownable">
<property-sheet> <property-sheet>
<show-property name="cm:owner" /> <show-property name="cm:owner" read-only="true" />
</property-sheet> </property-sheet>
</config> </config>

View File

@@ -46,8 +46,10 @@ import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.OwnableService; import org.alfresco.service.cmr.security.OwnableService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; 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.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.web.app.Application; import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService; import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.repository.Repository;
@@ -65,6 +67,10 @@ public class CreateUserWizard extends BaseWizardBean
private static Logger logger = Logger.getLogger(CreateUserWizard.class); private static Logger logger = Logger.getLogger(CreateUserWizard.class);
protected static final String ERROR = "error_person"; 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 */ /** form variables */
protected String firstName = null; protected String firstName = null;
protected String lastName = null; protected String lastName = null;
@@ -78,6 +84,9 @@ public class CreateUserWizard extends BaseWizardBean
protected String presenceProvider = null; protected String presenceProvider = null;
protected String presenceUsername = 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 */ /** AuthenticationService bean reference */
private AuthenticationService authenticationService; private AuthenticationService authenticationService;
@@ -90,6 +99,10 @@ public class CreateUserWizard extends BaseWizardBean
/** OwnableService bean reference */ /** OwnableService bean reference */
private OwnableService ownableService; private OwnableService ownableService;
/** ContentUsageService bean reference */
private ContentUsageService contentUsageService;
/** ref to the company home space folder */ /** ref to the company home space folder */
private NodeRef companyHomeSpaceRef = null; private NodeRef companyHomeSpaceRef = null;
@@ -128,6 +141,14 @@ public class CreateUserWizard extends BaseWizardBean
this.ownableService = ownableService; this.ownableService = ownableService;
} }
/**
* @param contentUsageService The contentUsageService to set.
*/
public void setContentUsageService(ContentUsageService contentUsageService)
{
this.contentUsageService = contentUsageService;
}
/** /**
* Initialises the wizard * Initialises the wizard
*/ */
@@ -148,6 +169,9 @@ public class CreateUserWizard extends BaseWizardBean
this.homeSpaceLocation = getDefaultHomeSpace(); this.homeSpaceLocation = getDefaultHomeSpace();
this.presenceProvider = ""; this.presenceProvider = "";
this.presenceUsername = ""; this.presenceUsername = "";
this.sizeQuota = null;
this.sizeQuotaUnits = "";
} }
/** /**
@@ -353,6 +377,26 @@ public class CreateUserWizard extends BaseWizardBean
this.confirm = confirm; 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 // Validator methods
@@ -603,6 +647,8 @@ public class CreateUserWizard extends BaseWizardBean
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
logger.debug("Created User Authentication instance for username: " + this.userName); logger.debug("Created User Authentication instance for username: " + this.userName);
putSizeQuotaProperty(this.userName, this.sizeQuota, this.sizeQuotaUnits);
} }
else else
{ {
@@ -633,4 +679,59 @@ public class CreateUserWizard extends BaseWizardBean
} }
return true; 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<Long, String> 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<Long, String>(size, units);
}
} }

View File

@@ -34,6 +34,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.Pair;
import org.alfresco.web.app.Application; import org.alfresco.web.app.Application;
import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
@@ -72,6 +73,14 @@ public class EditUserWizard extends CreateUserWizard
this.companyId = (String) props.get("organizationId"); this.companyId = (String) props.get("organizationId");
this.presenceProvider = (String) props.get("presenceProvider"); this.presenceProvider = (String) props.get("presenceProvider");
this.presenceUsername = (String) props.get("presenceUsername"); this.presenceUsername = (String) props.get("presenceUsername");
this.sizeQuota = (Long) props.get("sizeQuota");
if (this.sizeQuota != null)
{
Pair<Long, String> size = convertFromBytes(this.sizeQuota);
this.sizeQuota = size.getFirst();
this.sizeQuotaUnits = size.getSecond();
}
// calculate home space name and parent space Id from homeFolderId // calculate home space name and parent space Id from homeFolderId
this.homeSpaceLocation = null; // default to Company root space 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! // TODO: RESET HomeSpace Ref found in top-level navigation bar!
// NOTE: not need cos only admin can do this? // NOTE: not need cos only admin can do this?
putSizeQuotaProperty(this.userName, this.sizeQuota, this.sizeQuotaUnits);
} }
catch (Throwable e) catch (Throwable e)
{ {

View File

@@ -24,10 +24,12 @@
*/ */
package org.alfresco.web.bean.users; package org.alfresco.web.bean.users;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService; 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.bean.repository.Node;
import org.alfresco.web.ui.common.component.data.UIRichList; import org.alfresco.web.ui.common.component.data.UIRichList;
@@ -45,6 +47,10 @@ public class UsersBeanProperties
/** PersonService bean reference */ /** PersonService bean reference */
private PersonService personService; private PersonService personService;
/** ContentUsageService bean reference */
private ContentUsageService contentUsageService;
/** Component reference for Users RichList control */ /** Component reference for Users RichList control */
private UIRichList usersRichList; private UIRichList usersRichList;
@@ -55,7 +61,7 @@ public class UsersBeanProperties
private String oldPassword = null; private String oldPassword = null;
private String confirm = null; private String confirm = null;
private String searchCriteria = null; private String searchCriteria = null;
private String userName = null;
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Bean property getters and setters // Bean property getters and setters
@@ -124,6 +130,14 @@ public class UsersBeanProperties
this.personService = personService; this.personService = personService;
} }
/**
* @param contentUsageService The ContentUsageService to set.
*/
public void setContentUsageService(ContentUsageService contentUsageService)
{
this.contentUsageService = contentUsageService;
}
/** /**
* @return Returns the usersRichList. * @return Returns the usersRichList.
*/ */
@@ -218,5 +232,29 @@ public class UsersBeanProperties
public void setPerson(Node person) public void setPerson(Node person)
{ {
this.person = 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();
} }
} }

View File

@@ -51,6 +51,7 @@ import org.alfresco.web.bean.LoginBean;
import org.alfresco.web.bean.dialog.BaseDialogBean; import org.alfresco.web.bean.dialog.BaseDialogBean;
import org.alfresco.web.bean.repository.MapNode; import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node; 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.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink; import org.alfresco.web.ui.common.component.UIActionLink;
@@ -111,6 +112,36 @@ public class UsersDialog extends BaseDialogBean implements IContextListener
return this.users; return this.users;
} }
public long getUsersTotalUsage()
{
long totalUsage = 0L;
List<Node> 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<Node> 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 * 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 * 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); props.put("homeSpace", homeFolderNodeRef);
} }
node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest);
this.users.add(node); this.users.add(node);
} }
@@ -331,6 +364,13 @@ public class UsersDialog extends BaseDialogBean implements IContextListener
return null; 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 * 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(), this.users = Repository.getUsers(FacesContext.getCurrentInstance(),
properties.getNodeService(), properties.getSearchService()); properties.getNodeService(), properties.getSearchService());
for (Node node : this.users)
{
node.addPropertyResolver("sizeLatest", this.resolverUserSizeLatest);
}
// return null to stay on the same page // return null to stay on the same page
return null; return null;
} }

View File

@@ -543,6 +543,12 @@
<property-name>personService</property-name> <property-name>personService</property-name>
<value>#{PersonService}</value> <value>#{PersonService}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>
@@ -644,6 +650,12 @@
<property-name>namespaceService</property-name> <property-name>namespaceService</property-name>
<value>#{NamespaceService}</value> <value>#{NamespaceService}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>
@@ -4388,6 +4400,12 @@
<property-name>ownableService</property-name> <property-name>ownableService</property-name>
<value>#{OwnableService}</value> <value>#{OwnableService}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>
@@ -4439,6 +4457,12 @@
<property-name>properties</property-name> <property-name>properties</property-name>
<value>#{UsersBeanProperties}</value> <value>#{UsersBeanProperties}</value>
</managed-property> </managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean> </managed-bean>
<managed-bean> <managed-bean>

View File

@@ -103,5 +103,16 @@
</f:verbatim><h:inputText value="#{WizardManager.bean.presenceUsername}" size="35" maxlength="256" /><f:verbatim> </f:verbatim><h:inputText value="#{WizardManager.bean.presenceUsername}" size="35" maxlength="256" /><f:verbatim>
</td> </td>
</tr> </tr>
<tr>
<td></f:verbatim><h:outputText value="#{msg.sizeQuota}:" rendered="#{UsersBeanProperties.usagesEnabled == true}"/><f:verbatim></td>
<td>
</f:verbatim><h:inputText value="#{WizardManager.bean.sizeQuota}" size="10" maxlength="256" rendered="#{UsersBeanProperties.usagesEnabled == true}"/><f:verbatim>
</f:verbatim><h:selectOneMenu value="#{WizardManager.bean.sizeQuotaUnits}" rendered="#{UsersBeanProperties.usagesEnabled == true}">
<f:selectItem itemValue="gigabyte" itemLabel="#{msg.gigabyte}"/>
<f:selectItem itemValue="megabyte" itemLabel="#{msg.megabyte}"/>
<f:selectItem itemValue="kilobyte" itemLabel="#{msg.kilobyte}"/>
</h:selectOneMenu><f:verbatim>
</td>
</tr>
</table></f:verbatim> </table></f:verbatim>

View File

@@ -119,6 +119,34 @@
rendered="#{NavigationBean.isGuest == false}" border="white" rendered="#{NavigationBean.isGuest == false}" border="white"
bgcolor="white" titleBorder="lbgrey" expandedTitleBorder="dotted" bgcolor="white" titleBorder="lbgrey" expandedTitleBorder="dotted"
titleBgcolor="white"> titleBgcolor="white">
<a:panel id="usage-quota" rendered="#{UsersBeanProperties.usagesEnabled == true}">
<f:verbatim>
<table cellspacing=2 cellpadding=2 border=0>
<tr>
<td class="propertiesLabel"></f:verbatim> <h:outputText
value="#{msg.sizeCurrent}" /> <f:verbatim>:
</td>
<td></f:verbatim><h:outputText value="#{UsersBeanProperties.userUsage}">
<a:convertSize />
</h:outputText><f:verbatim>
</td>
</tr>
<tr>
<td class="propertiesLabel"></f:verbatim> <h:outputText
value="#{msg.sizeQuota}" /> <f:verbatim>:
</td>
<td></f:verbatim>
<h:outputText value="#{UsersBeanProperties.userQuota}">
<a:convertSize />
</h:outputText>
<f:verbatim>
</td>
</tr>
</table>
</f:verbatim>
</a:panel>
<f:verbatim> <f:verbatim>
<table cellspacing=2 cellpadding=2 border=0> <table cellspacing=2 cellpadding=2 border=0>
<tr> <tr>

View File

@@ -189,6 +189,26 @@
<r:nodePath value="#{r.homeSpace}" disabled="true" showLeaf="true" /> <r:nodePath value="#{r.homeSpace}" disabled="true" showLeaf="true" />
</a:column> </a:column>
<%-- Usage column --%>
<a:column style="text-align:left">
<f:facet name="header">
<h:outputText value="#{msg.sizeCurrent}" rendered="#{UsersBeanProperties.usagesEnabled == true}"/>
</f:facet>
<h:outputText value="#{r.sizeLatest}" rendered="#{UsersBeanProperties.usagesEnabled == true}">
<a:convertSize />
</h:outputText>
</a:column>
<%-- Quota column --%>
<a:column style="text-align:left">
<f:facet name="header">
<h:outputText value="#{msg.sizeQuota}" rendered="#{UsersBeanProperties.usagesEnabled == true}"/>
</f:facet>
<h:outputText value="#{r.sizeQuota}" rendered="#{UsersBeanProperties.usagesEnabled == true}">
<a:convertSize />
</h:outputText>
</a:column>
<%-- Actions column --%> <%-- Actions column --%>
<a:column actions="true" style="text-align:left"> <a:column actions="true" style="text-align:left">
<f:facet name="header"> <f:facet name="header">
@@ -212,6 +232,17 @@
</a:panel> </a:panel>
<table>
<tr>
<td><h:outputText value="Total Usage (for this search):" rendered="#{UsersBeanProperties.usagesEnabled == true}"/></td>
<td><h:outputText value="#{UsersDialog.usersTotalUsage}" rendered="#{UsersBeanProperties.usagesEnabled == true}"><a:convertSize/></h:outputText></td>
</tr>
<tr>
<td><h:outputText value="Total Quota (for this search):" rendered="#{UsersBeanProperties.usagesEnabled == true}"/></td>
<td><h:outputText value="#{UsersDialog.usersTotalQuota}" rendered="#{UsersBeanProperties.usagesEnabled == true}"><a:convertSize/></h:outputText></td>
</tr>
</table>
</td> </td>
<td valign="top"> <td valign="top">