@Test public void testOnDataTreeChanged() throws Exception { writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, LOCAL_MEMBER_NAME)); writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID2, LOCAL_MEMBER_NAME)); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME)); assertStatistics(ownershipStatistics.all(), LOCAL_MEMBER_NAME, 1L); writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, REMOTE_MEMBER_NAME1)); assertStatistics(ownershipStatistics.all(), LOCAL_MEMBER_NAME, 1L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME1)); Map<String, Map<String, Long>> statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 1L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, REMOTE_MEMBER_NAME2)); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 1L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, "")); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID1), entityEntryWithOwner(ENTITY_ID1, LOCAL_MEMBER_NAME)); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 1L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, REMOTE_MEMBER_NAME1)); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 1L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 1L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, LOCAL_MEMBER_NAME)); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 2L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, LOCAL_MEMBER_NAME)); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 2L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, "")); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 1L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); writeNode(entityPath(ENTITY_TYPE, ENTITY_ID2), entityEntryWithOwner(ENTITY_ID2, "")); statistics = ownershipStatistics.all(); assertStatistics(statistics, LOCAL_MEMBER_NAME, 1L); assertStatistics(statistics, REMOTE_MEMBER_NAME1, 0L); assertStatistics(statistics, REMOTE_MEMBER_NAME2, 0L); }
@Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } }
EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { @Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } } }
EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { @Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } } EntityOwnershipStatistics(); }
EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { @Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } } EntityOwnershipStatistics(); @Override void onDataTreeChanged(final Collection<DataTreeCandidate> changes); }
EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { @Override public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode<?> ownerLeaf = (LeafNode<?>) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional<NormalizedNode<?, ?>> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode<?>) changeRoot.getDataBefore().get()); if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } } } EntityOwnershipStatistics(); @Override void onDataTreeChanged(final Collection<DataTreeCandidate> changes);  }