Search in sources :

Example 6 with RepoEvent

use of org.alfresco.repo.event.v1.model.RepoEvent 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 7 with RepoEvent

use of org.alfresco.repo.event.v1.model.RepoEvent 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 8 with RepoEvent

use of org.alfresco.repo.event.v1.model.RepoEvent in project alfresco-repository by Alfresco.

the class ChildAssociationRepoEventIT method testUpdateNodeAddChildAssociationNodeEventsFirst.

@Test
public void testUpdateNodeAddChildAssociationNodeEventsFirst() {
    final NodeRef parentNodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
    checkNumOfEvents(2);
    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());
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setType(parentNodeRef, ContentModel.TYPE_FOLDER);
        return 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(4);
    // Check the node events occur before the child association event
    List<RepoEvent<?>> repoEvents = getRepoEventsContainer().getEvents();
    assertEquals("org.alfresco.event.node.Created", repoEvents.get(0).getType());
    assertEquals("org.alfresco.event.node.Created", repoEvents.get(1).getType());
    assertEquals("org.alfresco.event.node.Updated", repoEvents.get(2).getType());
    assertEquals("org.alfresco.event.assoc.child.Created", repoEvents.get(3).getType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 9 with RepoEvent

use of org.alfresco.repo.event.v1.model.RepoEvent 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 10 with RepoEvent

use of org.alfresco.repo.event.v1.model.RepoEvent 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)

Aggregations

EventData (org.alfresco.repo.event.v1.model.EventData)25 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 Test (org.junit.Test)25 ChildAssociationResource (org.alfresco.repo.event.v1.model.ChildAssociationResource)13 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)11 PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)6 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 GUID (org.alfresco.util.GUID)4 EventType (org.alfresco.repo.event.v1.model.EventType)3 ContentInfo (org.alfresco.repo.event.v1.model.ContentInfo)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 PropertyMap (org.alfresco.util.PropertyMap)2 M2Model (org.alfresco.repo.dictionary.M2Model)1 M2Type (org.alfresco.repo.dictionary.M2Type)1 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1 QName (org.alfresco.service.namespace.QName)1