Search in sources :

Example 1 with EphemeralResult

use of com.zimbra.cs.ephemeral.EphemeralResult in project zm-mailbox by Zimbra.

the class Entry method getEphemeralAttrs.

/**
 * Returns values for non-dynamic ephemeral attributes.
 */
public Map<String, Object> getEphemeralAttrs() {
    Map<String, Object> attrs = new HashMap<String, Object>();
    try {
        EphemeralStore.Factory ephemeralFactory = EphemeralStore.getFactory(FailureMode.safe);
        if (ephemeralFactory == null || ephemeralFactory instanceof LdapEphemeralStore.Factory) {
            // This also catches scenarios where the EphemeralStore is not available.
            return attrs;
        }
        Map<String, AttributeInfo> ephemeralAttrs = mAttrMgr.getNonDynamicEphemeralAttrs(getEntryType());
        if (ephemeralAttrs == null) {
            return attrs;
        }
        for (Map.Entry<String, AttributeInfo> entry : ephemeralAttrs.entrySet()) {
            String attrName = entry.getKey();
            AttributeInfo info = entry.getValue();
            EphemeralResult result = getEphemeralAttr(attrName);
            if (!result.isEmpty()) {
                switch(info.getType()) {
                    case TYPE_BOOLEAN:
                        attrs.put(attrName, result.getBoolValue());
                        break;
                    case TYPE_INTEGER:
                        attrs.put(attrName, result.getIntValue());
                        break;
                    case TYPE_LONG:
                        attrs.put(attrName, result.getLongValue());
                        break;
                    default:
                        attrs.put(attrName, result.getValue());
                        break;
                }
            }
        }
    } catch (ServiceException e) {
        // don't propagate this exception, since we don't want to interrupt getAttrs() calls
        ZimbraLog.ephemeral.warn("unable to get ephemeral attributes for %s %s", getEntryType().getName(), getLabel());
    }
    return attrs;
}
Also used : LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) HashMap(java.util.HashMap) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult) ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore)

Example 2 with EphemeralResult

use of com.zimbra.cs.ephemeral.EphemeralResult in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testAttributeMigration.

/*
     * Test end-to-end AttributeMigration
     */
@Test
public void testAttributeMigration() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    // DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
    MigrationCallback callback = new DummyMigrationCallback(destination);
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    // disable running in separate thread
    // run migration
    migration.migrateAllAccounts();
    EphemeralLocation location = new LdapEntryLocation(acct);
    EphemeralResult result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "1234"), location);
    assertEquals("server_1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "5678"), location);
    assertEquals("server_2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1"), location);
    assertEquals("data1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2"), location);
    assertEquals("data2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraLastLogonTimestamp), location);
    assertEquals("currentdate", result.getValue());
    assertTrue(info.getStatus() == Status.COMPLETED);
}
Also used : EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult) LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) Test(org.junit.Test)

Example 3 with EphemeralResult

use of com.zimbra.cs.ephemeral.EphemeralResult in project zm-mailbox by Zimbra.

the class Entry method getEphemeralAttr.

public EphemeralResult getEphemeralAttr(String key, String dynamicComponent) throws ServiceException {
    EphemeralLocation location = new LdapEntryLocation(this);
    EphemeralStore store = EphemeralStore.getFactory().getStore();
    EphemeralKey ephemeralKey = new EphemeralKey(key, dynamicComponent);
    EphemeralResult result = store.get(ephemeralKey, location);
    return result == null ? EphemeralResult.emptyResult(ephemeralKey) : result;
}
Also used : LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult)

Aggregations

EphemeralResult (com.zimbra.cs.ephemeral.EphemeralResult)3 EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)3 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)2 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)2 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)2 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)2 ToZJSONObject (com.zimbra.client.ToZJSONObject)1 ZJSONObject (com.zimbra.client.ZJSONObject)1 ServiceException (com.zimbra.common.service.ServiceException)1 EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)1 MigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1