Search in sources :

Example 1 with RepoUsage

use of org.alfresco.service.cmr.admin.RepoUsage in project alfresco-remote-api by Alfresco.

the class RepoUsageGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status, final Cache cache) {
    // Runas system to obtain the info
    RunAsWork<Map<String, Object>> runAs = new RunAsWork<Map<String, Object>>() {

        @Override
        public Map<String, Object> doWork() throws Exception {
            Map<String, Object> model = new HashMap<String, Object>(7);
            RepoUsageStatus usageStatus = repoAdminService.getUsageStatus();
            RepoUsage usage = usageStatus.getUsage();
            putUsageInModel(model, usage, false);
            // Add usage messages
            model.put(JSON_KEY_LEVEL, usageStatus.getLevel().ordinal());
            model.put(JSON_KEY_WARNINGS, usageStatus.getWarnings());
            model.put(JSON_KEY_ERRORS, usageStatus.getErrors());
            // Done
            if (logger.isDebugEnabled()) {
                logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
            }
            return model;
        }
    };
    return AuthenticationUtil.runAs(runAs, AuthenticationUtil.getSystemUserName());
}
Also used : RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) HashMap(java.util.HashMap) RepoUsage(org.alfresco.service.cmr.admin.RepoUsage) Map(java.util.Map) HashMap(java.util.HashMap) RepoUsageStatus(org.alfresco.service.cmr.admin.RepoUsageStatus)

Example 2 with RepoUsage

use of org.alfresco.service.cmr.admin.RepoUsage in project alfresco-remote-api by Alfresco.

the class RepoUsagePost method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>(7);
    boolean updated = repoAdminService.updateUsage(UsageType.USAGE_ALL);
    RepoUsage repoUsage = repoAdminService.getUsage();
    putUsageInModel(model, repoUsage, updated);
    // Done
    if (logger.isDebugEnabled()) {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
Also used : HashMap(java.util.HashMap) RepoUsage(org.alfresco.service.cmr.admin.RepoUsage)

Example 3 with RepoUsage

use of org.alfresco.service.cmr.admin.RepoUsage in project alfresco-remote-api by Alfresco.

the class AdminWebScriptTest method testGetRestrictions.

public void testGetRestrictions() throws Exception {
    RepoUsage restrictions = repoAdminService.getRestrictions();
    String url = "/api/admin/restrictions";
    TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
    Response response = sendRequest(req, Status.STATUS_OK, guest);
    JSONObject json = new JSONObject(response.getContentAsString());
    Long maxUsers = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
    assertEquals("Mismatched max users", restrictions.getUsers(), maxUsers);
    Long maxDocuments = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
    assertEquals("Mismatched max documents", restrictions.getDocuments(), maxDocuments);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONObject(org.json.JSONObject) RepoUsage(org.alfresco.service.cmr.admin.RepoUsage)

Example 4 with RepoUsage

use of org.alfresco.service.cmr.admin.RepoUsage in project alfresco-remote-api by Alfresco.

the class RepoRestrictionsGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>(7);
    RepoUsage restrictions = repoAdminService.getRestrictions();
    putUsageInModel(model, restrictions, false);
    // Done
    if (logger.isDebugEnabled()) {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
Also used : HashMap(java.util.HashMap) RepoUsage(org.alfresco.service.cmr.admin.RepoUsage)

Example 5 with RepoUsage

use of org.alfresco.service.cmr.admin.RepoUsage in project alfresco-remote-api by Alfresco.

the class AdminWebScriptTest method testGetUsage.

public void testGetUsage() throws Exception {
    RepoUsageStatus usageStatus = repoAdminService.getUsageStatus();
    RepoUsage usage = usageStatus.getUsage();
    LicenseDescriptor licenseDescriptor = descriptorService.getLicenseDescriptor();
    // might be null
    Date validUntil = (licenseDescriptor == null) ? null : licenseDescriptor.getValidUntil();
    Integer checkLevel = new Integer(usageStatus.getLevel().ordinal());
    String url = "/api/admin/usage";
    TestWebScriptServer.GetRequest req = new TestWebScriptServer.GetRequest(url);
    Response response = sendRequest(req, Status.STATUS_OK, guest);
    System.out.println(response.getContentAsString());
    JSONObject json = new JSONObject(response.getContentAsString());
    Long users = json.isNull(AbstractAdminWebScript.JSON_KEY_USERS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_USERS);
    assertEquals("Mismatched users", usage.getUsers(), users);
    Long documents = json.isNull(AbstractAdminWebScript.JSON_KEY_DOCUMENTS) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_DOCUMENTS);
    assertEquals("Mismatched documents", usage.getDocuments(), documents);
    String licenseMode = json.isNull(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE) ? null : json.getString(AbstractAdminWebScript.JSON_KEY_LICENSE_MODE);
    assertEquals("Mismatched licenseMode", usage.getLicenseMode().toString(), licenseMode);
    boolean readOnly = json.getBoolean(AbstractAdminWebScript.JSON_KEY_READ_ONLY);
    assertEquals("Mismatched readOnly", usage.isReadOnly(), readOnly);
    boolean updated = json.getBoolean(AbstractAdminWebScript.JSON_KEY_UPDATED);
    assertEquals("Mismatched updated", false, updated);
    Long licenseValidUntil = json.isNull(AbstractAdminWebScript.JSON_KEY_LICENSE_VALID_UNTIL) ? null : json.getLong(AbstractAdminWebScript.JSON_KEY_LICENSE_VALID_UNTIL);
    assertEquals("Mismatched licenseValidUntil", (validUntil == null) ? null : validUntil.getTime(), licenseValidUntil);
    Integer level = json.isNull(AbstractAdminWebScript.JSON_KEY_LEVEL) ? null : json.getInt(AbstractAdminWebScript.JSON_KEY_LEVEL);
    assertEquals("Mismatched level", checkLevel, level);
    json.getJSONArray(AbstractAdminWebScript.JSON_KEY_WARNINGS);
    json.getJSONArray(AbstractAdminWebScript.JSON_KEY_ERRORS);
}
Also used : RepoUsage(org.alfresco.service.cmr.admin.RepoUsage) Date(java.util.Date) Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) TestWebScriptServer(org.springframework.extensions.webscripts.TestWebScriptServer) JSONObject(org.json.JSONObject) LicenseDescriptor(org.alfresco.service.license.LicenseDescriptor) RepoUsageStatus(org.alfresco.service.cmr.admin.RepoUsageStatus)

Aggregations

RepoUsage (org.alfresco.service.cmr.admin.RepoUsage)6 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)3 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)3 RepoUsageStatus (org.alfresco.service.cmr.admin.RepoUsageStatus)2 Date (java.util.Date)1 Map (java.util.Map)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 LicenseDescriptor (org.alfresco.service.license.LicenseDescriptor)1