Search in sources :

Example 11 with RepoEvent

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

Example 12 with RepoEvent

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

the class ChildAssociationEventConsolidator method getRepoEvent.

/**
 * Builds and returns the {@link RepoEvent} instance.
 *
 * @param eventInfo the object holding the event information
 * @return the {@link RepoEvent} instance
 */
public RepoEvent<DataAttributes<ChildAssociationResource>> getRepoEvent(EventInfo eventInfo) {
    EventType eventType = getDerivedEvent();
    DataAttributes<ChildAssociationResource> eventData = buildEventData(eventInfo, resource);
    return RepoEvent.<DataAttributes<ChildAssociationResource>>builder().setId(eventInfo.getId()).setSource(eventInfo.getSource()).setTime(eventInfo.getTimestamp()).setType(eventType.getType()).setData(eventData).setDataschema(EventJSONSchema.getSchemaV1(eventType)).build();
}
Also used : EventType(org.alfresco.repo.event.v1.model.EventType) ChildAssociationResource(org.alfresco.repo.event.v1.model.ChildAssociationResource)

Example 13 with RepoEvent

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

the class PeerAssociationEventConsolidator method getRepoEvent.

/**
 * Builds and returns the {@link RepoEvent} instance.
 *
 * @param eventInfo the object holding the event information
 * @return the {@link RepoEvent} instance
 */
public RepoEvent<DataAttributes<PeerAssociationResource>> getRepoEvent(EventInfo eventInfo) {
    EventType eventType = getDerivedEvent();
    DataAttributes<PeerAssociationResource> eventData = buildEventData(eventInfo, resource);
    return RepoEvent.<DataAttributes<PeerAssociationResource>>builder().setId(eventInfo.getId()).setSource(eventInfo.getSource()).setTime(eventInfo.getTimestamp()).setType(eventType.getType()).setData(eventData).setDataschema(EventJSONSchema.getSchemaV1(eventType)).build();
}
Also used : PeerAssociationResource(org.alfresco.repo.event.v1.model.PeerAssociationResource) EventType(org.alfresco.repo.event.v1.model.EventType)

Example 14 with RepoEvent

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

the class UpdateRepoEventIT method testUpdateTwiceNodeTypeInTheSameTransaction.

@Test
public void testUpdateTwiceNodeTypeInTheSameTransaction() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    // node.Created event should be generated
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
    // old type
    assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
        nodeService.setType(nodeRef, ContentModel.TYPE_CONTENT);
        // new type
        assertEquals("Wrong node type", ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
        return null;
    });
    // we should have only 2 events, node.Created and node.Updated
    checkNumOfEvents(2);
    resultRepoEvent = getRepoEvent(2);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
    nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertEquals("Incorrect node type was found", "cm:folder", resourceBefore.getNodeType());
    // assertNotNull(resourceBefore.getModifiedAt()); uncomment this when the issue will be fixed
    assertNull(resourceBefore.getId());
    assertNull(resourceBefore.getContent());
    assertNull(resourceBefore.isFile());
    assertNull(resourceBefore.isFolder());
    assertNull(resourceBefore.getModifiedByUser());
    assertNull(resourceBefore.getCreatedAt());
    assertNull(resourceBefore.getCreatedByUser());
    assertNull(resourceBefore.getProperties());
    assertNull(resourceBefore.getAspectNames());
    assertNull(resourceBefore.getPrimaryHierarchy());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 15 with RepoEvent

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

the class UpdateRepoEventIT method testCreateAndUpdateNodeTypeInTheSameTransaction.

@Test
public void testCreateAndUpdateNodeTypeInTheSameTransaction() {
    retryingTransactionHelper.doInTransaction(() -> {
        final NodeRef nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
        // old type
        assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
        nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
        // new type
        assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(nodeRef));
        return null;
    });
    // we should have only 1 event, node.Created
    checkNumOfEvents(1);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:folder", nodeResource.getNodeType());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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