02-02-2010 06:50 PM
07-26-2010 04:42 AM
public static class ClassA implements RunAsWork<Object> {
dowork….
{
calculate size of CompanyHome directory.
}
}
AuthenticationUtil.setRunAsUser('"admin@tenant";
classA .doWork();
this concept lets you get access to tenant you like, and where calculate size of … stands you add code for calculating space sice. I hope it is more clear now.
07-27-2010 01:10 AM
package org.example;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.alfresco.repo.tenant.Tenant;
import org.alfresco.repo.tenant.TenantAdminService;
import org.alfresco.service.cmr.attributes.AttributeService;
import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.apache.commons.io.FileUtils;
public class TenantDetails extends AbstractWebScript
{
private TenantAdminService tenantAdminService;
private static final long MEGABYTE = 1024L * 1024L;
public TenantAdminService getTenantAdminService()
{
return tenantAdminService;
}
public void setTenantAdminService(TenantAdminService tenantAdminService)
{
this.tenantAdminService = tenantAdminService;
}
@Override
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
List<Tenant> tenants = tenantAdminService.getAllTenants();
File directory;
for (Tenant tenant : tenants)
{
res.getWriter().write(tenant.getTenantDomain());
directory = new File(tenant.getRootContentStoreDir());
res.getWriter().write(bytesToMeg(FileUtils.sizeOfDirectory(directory))+"MB");
}
}
public static long bytesToMeg(long bytes)
{
return bytes / MEGABYTE ;
}
public static long getMegabyte() {
return MEGABYTE;
}
}
public NodeRef getCompanyHome()
{
String tenantDomain = tenantAdminService.getCurrentUserDomain();
NodeRef companyHomeRef = companyHomeRefs.get(tenantDomain);
if (companyHomeRef == null)
{
companyHomeRef = AuthenticationUtil.runAs(new RunAsWork<NodeRef>()
{
public NodeRef doWork() throws Exception
{
return retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<NodeRef>()
{
public NodeRef execute() throws Exception
{
List<NodeRef> refs = searchService.selectNodes(nodeService.getRootNode(companyHomeStore), companyHomePath, null, namespaceService, false);
if (refs.size() != 1)
{
throw new IllegalStateException("Invalid company home path: " + companyHomePath + " - found: " + refs.size());
}
return refs.get(0);
}
}, true);
}
}, AuthenticationUtil.getSystemUserName());
companyHomeRefs.put(tenantDomain, companyHomeRef);
}
return companyHomeRef;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.