use of org.alfresco.repo.event.v1.model.ChildAssociationResource in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testOneParentMultipleChildrenDifferentTransaction.
@Test
public void testOneParentMultipleChildrenDifferentTransaction() {
final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef child1NodeRef = createNode(ContentModel.TYPE_CONTENT);
final NodeRef child2NodeRef = createNode(ContentModel.TYPE_CONTENT);
final NodeRef child3NodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> children = Arrays.asList(child1NodeRef, child2NodeRef, child3NodeRef);
checkNumOfEvents(4);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
for (NodeRef child : children) {
retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parentNodeRef, child, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
}
retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent = nodeService.getChildAssocs(parentNodeRef);
assertEquals(3, childAssocParent.size());
return null;
});
checkNumOfEvents(7);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getParent().getId());
assertEquals(child1NodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(0)).getAssocType());
assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getParent().getId());
assertEquals(child2NodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(1)).getAssocType());
assertEquals(parentNodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getParent().getId());
assertEquals(child3NodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(2)).getAssocType());
}
use of org.alfresco.repo.event.v1.model.ChildAssociationResource in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testRemoveChildAssociation.
@Test
public void testRemoveChildAssociation() {
final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
checkNumOfEvents(2);
RepoEvent<EventData<NodeResource>> parentRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), parentRepoEvent.getType());
RepoEvent<EventData<NodeResource>> childRepoEvent = getRepoEventWithoutWait(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), childRepoEvent.getType());
ChildAssociationRef childAssociationRef = retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parentNodeRef, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
List<ChildAssociationRef> childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getChildAssocs(parentNodeRef));
assertEquals(1, childAssociationRefs.size());
assertFalse(childAssociationRefs.get(0).isPrimary());
checkNumOfEvents(3);
retryingTransactionHelper.doInTransaction(() -> nodeService.removeChildAssociation(childAssociationRef));
childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getChildAssocs(parentNodeRef));
assertEquals(0, childAssociationRefs.size());
checkNumOfEvents(4);
final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.CHILD_ASSOC_DELETED.getType(), childAssocRepoEvent.getType());
assertNotNull("Repo event ID is not available. ", childAssocRepoEvent.getId());
assertNotNull("Source is not available", childAssocRepoEvent.getSource());
assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), childAssocRepoEvent.getSource().toString());
assertNotNull("Repo event creation time is not available. ", childAssocRepoEvent.getTime());
assertEquals("Repo event datacontenttype", "application/json", childAssocRepoEvent.getDatacontenttype());
assertNotNull(childAssocRepoEvent.getDataschema());
assertEquals(EventJSONSchema.CHILD_ASSOC_DELETED_V1.getSchema(), childAssocRepoEvent.getDataschema());
final EventData<ChildAssociationResource> nodeResourceEventData = getEventData(childAssocRepoEvent);
// EventData attributes
assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
final ChildAssociationResource childAssociationResource = getChildAssocResource(childAssocRepoEvent);
assertEquals("Wrong parent", parentNodeRef.getId(), childAssociationResource.getParent().getId());
assertEquals("Wrong child", childNodeRef.getId(), childAssociationResource.getChild().getId());
assertEquals("Wrong assoc type", "cm:contains", childAssociationResource.getAssocType());
}
use of org.alfresco.repo.event.v1.model.ChildAssociationResource in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testDeleteChildWithMultipleParentAssociations.
@Test
public void testDeleteChildWithMultipleParentAssociations() {
final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
checkNumOfEvents(4);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
assertEquals(1, childAssocParent1.size());
assertEquals(1, childAssocParent2.size());
assertEquals(1, childAssocParent3.size());
return null;
});
deleteNode(childNodeRef);
checkNumOfEvents(11);
// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
}
use of org.alfresco.repo.event.v1.model.ChildAssociationResource in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testOneChildListOfParentsAssociations.
@Test
public void testOneChildListOfParentsAssociations() {
final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
checkNumOfEvents(4);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
assertEquals(1, childAssocParent1.size());
assertEquals(1, childAssocParent2.size());
assertEquals(1, childAssocParent3.size());
return null;
});
checkNumOfEvents(7);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
}
use of org.alfresco.repo.event.v1.model.ChildAssociationResource in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testDeleteAssociationOneParentMultipleChildrenDifferentTransactions.
@Test
public void testDeleteAssociationOneParentMultipleChildrenDifferentTransactions() {
final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
checkNumOfEvents(4);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(2);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
List<ChildAssociationRef> listChildAssociationRefs = retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
assertEquals(1, childAssocParent1.size());
assertEquals(1, childAssocParent2.size());
assertEquals(1, childAssocParent3.size());
return Arrays.asList(childAssocParent1.get(0), childAssocParent2.get(0), childAssocParent3.get(0));
});
for (ChildAssociationRef childAssociationRef : listChildAssociationRefs) {
retryingTransactionHelper.doInTransaction(() -> nodeService.removeChildAssociation(childAssociationRef));
}
checkNumOfEvents(10);
// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
assertEquals(parent1NodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getParent().getId());
assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(0)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(0)).getAssocType());
assertEquals(parent2NodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getParent().getId());
assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(1)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(1)).getAssocType());
assertEquals(parent3NodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getParent().getId());
assertEquals(childNodeRef.getId(), getChildAssocResource(childAssocEvents.get(2)).getChild().getId());
assertEquals("cm:contains", getChildAssocResource(childAssocEvents.get(2)).getAssocType());
}
Aggregations