Search in sources :

Example 1 with LicenseDescriptor

use of org.alfresco.service.license.LicenseDescriptor in project alfresco-remote-api by Alfresco.

the class AbstractAdminWebScript method putUsageInModel.

/**
 * Helper to assign JSON return variables based on the repository usage data.
 */
protected void putUsageInModel(Map<String, Object> model, RepoUsage repoUsage, boolean updated) {
    model.put(JSON_KEY_LAST_UPDATE, repoUsage.getLastUpdate());
    model.put(JSON_KEY_USERS, repoUsage.getUsers());
    model.put(JSON_KEY_DOCUMENTS, repoUsage.getDocuments());
    model.put(JSON_KEY_LICENSE_MODE, repoUsage.getLicenseMode());
    model.put(JSON_KEY_READ_ONLY, repoUsage.isReadOnly());
    model.put(JSON_KEY_LICENSE_VALID_UNTIL, repoUsage.getLicenseExpiryDate());
    model.put(JSON_KEY_UPDATED, updated);
    // Add license holder
    LicenseDescriptor license = descriptorService.getLicenseDescriptor();
    if (license != null) {
        model.put(JSON_KEY_LICENSE_HOLDER, license.getHolderOrganisation());
    }
    model.put(JSON_KEY_LEVEL, RepoUsageLevel.OK.ordinal());
    model.put(JSON_KEY_WARNINGS, Collections.emptyList());
    model.put(JSON_KEY_ERRORS, Collections.emptyList());
}
Also used : LicenseDescriptor(org.alfresco.service.license.LicenseDescriptor)

Example 2 with LicenseDescriptor

use of org.alfresco.service.license.LicenseDescriptor in project alfresco-remote-api by Alfresco.

the class BulkFilesystemImportStatusWebScript method executeImpl.

/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(WebScriptRequest, Status, Cache)
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest request, Status status, Cache cache) {
    Map<String, Object> result = new HashMap<String, Object>();
    cache.setNeverCache(true);
    LicenseDescriptor licenseDescriptor = descriptorService.getLicenseDescriptor();
    boolean isEnterprise = (licenseDescriptor == null ? false : (licenseDescriptor.getLicenseMode() == LicenseMode.ENTERPRISE));
    result.put(IS_ENTERPRISE, Boolean.valueOf(isEnterprise));
    result.put(RESULT_IMPORT_STATUS, bulkImporter.getStatus());
    return (result);
}
Also used : HashMap(java.util.HashMap) LicenseDescriptor(org.alfresco.service.license.LicenseDescriptor)

Example 3 with LicenseDescriptor

use of org.alfresco.service.license.LicenseDescriptor in project records-management by Alfresco.

the class ModuleCompatibilityComponent method onApplicationEvent.

/**
 * @see org.springframework.context.ApplicationListener#onApplicationEvent(org.springframework.context.ApplicationEvent)
 */
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
    // license mode
    LicenseMode licenseMode = LicenseMode.UNKNOWN;
    // grab the application context
    ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
    // get the license mode
    LicenseDescriptor license = descriptorService.getLicenseDescriptor();
    if (license != null) {
        licenseMode = license.getLicenseMode();
    }
    // determine whether RM Enterprise is installed or not
    boolean isRMEnterprise = isRMEnterprise();
    // debug log
    if (logger.isDebugEnabled()) {
        logger.debug("Module compatibility information:");
        logger.debug("   Repository licence mode = " + licenseMode.toString());
        logger.debug("   RM Enterprise installed = " + isRMEnterprise);
    }
    if (LicenseMode.ENTERPRISE.equals(licenseMode) && !isRMEnterprise) {
        // running enterprise rm on community core so close application
        // context
        closeApplicationContext(applicationContext, "Running Community Records Management Module on Enterprise Alfresco One is not a supported configuration.");
    } else if (!LicenseMode.ENTERPRISE.equals(licenseMode) && isRMEnterprise) {
        // running community rm on enterprise core so close application
        // context
        closeApplicationContext(applicationContext, "Running Enterprise Records Management module on Community Alfresco One is not a supported configuration.");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) LicenseMode(org.alfresco.service.cmr.admin.RepoUsage.LicenseMode) LicenseDescriptor(org.alfresco.service.license.LicenseDescriptor)

Example 4 with LicenseDescriptor

use of org.alfresco.service.license.LicenseDescriptor 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

LicenseDescriptor (org.alfresco.service.license.LicenseDescriptor)4 Date (java.util.Date)1 HashMap (java.util.HashMap)1 RepoUsage (org.alfresco.service.cmr.admin.RepoUsage)1 LicenseMode (org.alfresco.service.cmr.admin.RepoUsage.LicenseMode)1 RepoUsageStatus (org.alfresco.service.cmr.admin.RepoUsageStatus)1 JSONObject (org.json.JSONObject)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)1 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)1