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;
}
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);
}
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;
}
Aggregations