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
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

View File

@@ -226,7 +226,7 @@
<config evaluator="aspect-name" condition="cm:ownable">
<property-sheet>
<show-property name="cm:owner" />
<show-property name="cm:owner" read-only="true" />
</property-sheet>
</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.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<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.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<Long, String> 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)
{

View File

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

View File

@@ -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<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
* 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;
}

View File

@@ -542,7 +542,13 @@
<managed-property>
<property-name>personService</property-name>
<value>#{PersonService}</value>
</managed-property>
</managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean>
<managed-bean>
@@ -643,7 +649,13 @@
<managed-property>
<property-name>namespaceService</property-name>
<value>#{NamespaceService}</value>
</managed-property>
</managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean>
<managed-bean>
@@ -4387,7 +4399,13 @@
<managed-property>
<property-name>ownableService</property-name>
<value>#{OwnableService}</value>
</managed-property>
</managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean>
<managed-bean>
@@ -4438,7 +4456,13 @@
<managed-property>
<property-name>properties</property-name>
<value>#{UsersBeanProperties}</value>
</managed-property>
</managed-property>
<managed-property>
<property-name>contentUsageService</property-name>
<value>#{ContentUsageService}</value>
</managed-property>
</managed-bean>
<managed-bean>

View File

@@ -103,5 +103,16 @@
</f:verbatim><h:inputText value="#{WizardManager.bean.presenceUsername}" size="35" maxlength="256" /><f:verbatim>
</td>
</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>

View File

@@ -119,6 +119,34 @@
rendered="#{NavigationBean.isGuest == false}" border="white"
bgcolor="white" titleBorder="lbgrey" expandedTitleBorder="dotted"
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>
<table cellspacing=2 cellpadding=2 border=0>
<tr>

View File

@@ -187,6 +187,26 @@
<h:outputText value="#{msg.homespace}"/>
</f:facet>
<r:nodePath value="#{r.homeSpace}" disabled="true" showLeaf="true" />
</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 --%>
@@ -210,7 +230,18 @@
<a:dataPager styleClass="pager" />
</a:richList>
</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>