- if (identitiesLoaded) {
-
- /* check for changes. */
- checkOwnIdentities(currentOwnIdentities);
-
- /* now check for changes in remote identities. */
- for (OwnIdentity ownIdentity : currentOwnIdentities.values()) {
-
- /* find new identities. */
- for (Identity currentIdentity : currentIdentities.get(ownIdentity).values()) {
- if (!oldIdentities.containsKey(ownIdentity) || !oldIdentities.get(ownIdentity).containsKey(currentIdentity.getId())) {
- logger.finest(String.format("Identity added for %s: %s", ownIdentity.getId(), currentIdentity));
- eventBus.post(new IdentityAddedEvent(ownIdentity, currentIdentity));
- }
- }
-
- /* find removed identities. */
- if (oldIdentities.containsKey(ownIdentity)) {
- for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) {
- if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) {
- logger.finest(String.format("Identity removed for %s: %s", ownIdentity.getId(), oldIdentity));
- eventBus.post(new IdentityRemovedEvent(ownIdentity, oldIdentity));
- }
- }
-
- /* check for changes in the contexts. */
- for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) {
- if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) {
- continue;
- }
- Identity newIdentity = currentIdentities.get(ownIdentity).get(oldIdentity.getId());
- Set<String> oldContexts = oldIdentity.getContexts();
- Set<String> newContexts = newIdentity.getContexts();
- if (oldContexts.size() != newContexts.size()) {
- logger.finest(String.format("Contexts changed for %s: was: %s, is now: %s", ownIdentity.getId(), oldContexts, newContexts));
- eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity));
- continue;
- }
- for (String oldContext : oldContexts) {
- if (!newContexts.contains(oldContext)) {
- logger.finest(String.format("Context was removed for %s: %s", ownIdentity.getId(), oldContext));
- eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity));
- break;
- }
- }
- }
-
- /* check for changes in the properties. */
- for (Identity oldIdentity : oldIdentities.get(ownIdentity).values()) {
- if (!currentIdentities.get(ownIdentity).containsKey(oldIdentity.getId())) {
- continue;
- }
- Identity newIdentity = currentIdentities.get(ownIdentity).get(oldIdentity.getId());
- Map<String, String> oldProperties = oldIdentity.getProperties();
- Map<String, String> newProperties = newIdentity.getProperties();
- if (oldProperties.size() != newProperties.size()) {
- logger.finest(String.format("Properties changed for %s: was: %s, is now: %s", ownIdentity.getId(), oldProperties, newProperties));
- eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity));
- continue;
- }
- for (Entry<String, String> oldProperty : oldProperties.entrySet()) {
- if (!newProperties.containsKey(oldProperty.getKey()) || !newProperties.get(oldProperty.getKey()).equals(oldProperty.getValue())) {
- logger.finest(String.format("Property was removed for %s: %s", ownIdentity.getId(), oldProperty));
- eventBus.post(new IdentityUpdatedEvent(ownIdentity, newIdentity));
- break;
- }
- }
- }
- }
- }
-
- /* remember the current set of identities. */
- oldIdentities = currentIdentities;
- }
-