Search in sources :

Example 1 with ChildAssociationResource

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());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 2 with ChildAssociationResource

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());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 3 with ChildAssociationResource

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());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 4 with ChildAssociationResource

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());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 5 with ChildAssociationResource

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());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Aggregations

ChildAssociationResource (org.alfresco.repo.event.v1.model.ChildAssociationResource)13 EventData (org.alfresco.repo.event.v1.model.EventData)11 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 Test (org.junit.Test)11 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)9 EventType (org.alfresco.repo.event.v1.model.EventType)1 GUID (org.alfresco.util.GUID)1