Search in sources :

Example 36 with EventData

use of com.ibm.watson.discovery.v1.model.EventData 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 37 with EventData

use of com.ibm.watson.discovery.v1.model.EventData 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 38 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class CreateRepoEventIT method testCreateEvent.

@Test
public void testCreateEvent() {
    // Create a node without content
    final String name = "TestFile-" + System.currentTimeMillis() + ".txt";
    PropertyMap propertyMap = new PropertyMap();
    propertyMap.put(ContentModel.PROP_TITLE, "test title");
    propertyMap.put(ContentModel.PROP_NAME, name);
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, propertyMap);
    final RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    // Repo event attributes
    assertEquals("Repo event type", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    assertNotNull("Repo event ID is not available. ", resultRepoEvent.getId());
    assertNotNull(resultRepoEvent.getSource());
    assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), resultRepoEvent.getSource().toString());
    assertNotNull("Repo event creation time is not available. ", resultRepoEvent.getTime());
    assertEquals("Repo event datacontenttype", "application/json", resultRepoEvent.getDatacontenttype());
    assertNotNull(resultRepoEvent.getDataschema());
    assertEquals(EventJSONSchema.NODE_CREATED_V1.getSchema(), resultRepoEvent.getDataschema());
    final EventData<NodeResource> nodeResourceEventData = getEventData(resultRepoEvent);
    // EventData attributes
    assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
    assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
    final NodeResource nodeResource = getNodeResource(resultRepoEvent);
    // NodeResource attributes
    assertEquals(nodeRef.getId(), nodeResource.getId());
    assertEquals(name, nodeResource.getName());
    assertEquals("cm:content", nodeResource.getNodeType());
    assertNotNull(nodeResource.getPrimaryHierarchy());
    assertNotNull("Default aspects were not added. ", nodeResource.getAspectNames());
    assertEquals("test title", getProperty(nodeResource, "cm:title"));
    assertNull("There is no content.", nodeResource.getContent());
    assertNotNull("Missing createdByUser property.", nodeResource.getCreatedByUser());
    assertEquals("Wrong node creator id.", "admin", nodeResource.getCreatedByUser().getId());
    assertEquals("Wrong node creator display name.", "Administrator", nodeResource.getCreatedByUser().getDisplayName());
    assertNotNull("Missing createdAt property.", nodeResource.getCreatedAt());
    assertNotNull("Missing modifiedByUser property.", nodeResource.getModifiedByUser());
    assertEquals("Wrong node modifier id.", "admin", nodeResource.getModifiedByUser().getId());
    assertEquals("Wrong node modifier display name.", "Administrator", nodeResource.getModifiedByUser().getDisplayName());
    assertNotNull("Missing modifiedAt property.", nodeResource.getModifiedAt());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 39 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class DeleteRepoEventIT method testDeleteContent.

@Test
public void testDeleteContent() {
    PropertyMap propertyMap = new PropertyMap();
    propertyMap.put(ContentModel.PROP_TITLE, "test title");
    NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT, propertyMap);
    NodeResource createdResource = getNodeResource(1);
    assertNotNull("Resource ID is null", createdResource.getId());
    assertNotNull("Default aspects were not added. ", createdResource.getAspectNames());
    assertNotNull("Missing createdByUser property.", createdResource.getCreatedByUser());
    assertNotNull("Missing createdAt property.", createdResource.getCreatedAt());
    assertNotNull("Missing modifiedByUser property.", createdResource.getModifiedByUser());
    assertNotNull("Missing modifiedAt property.", createdResource.getModifiedAt());
    assertNotNull("Missing node resource properties", createdResource.getProperties());
    deleteNode(nodeRef);
    final RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(2);
    assertEquals("Repo event type:", EventType.NODE_DELETED.getType(), resultRepoEvent.getType());
    assertEquals(createdResource.getId(), getNodeResource(resultRepoEvent).getId());
    // There should be no resourceBefore
    EventData<NodeResource> eventData = getEventData(resultRepoEvent);
    assertNull("There should be no 'resourceBefore' object for the Deleted event type.", eventData.getResourceBefore());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyMap(org.alfresco.util.PropertyMap) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 40 with EventData

use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-repository by Alfresco.

the class PeerAssociationRepoEventIT method testAddMultiplePeerAssociationDifferentTransaction.

@Test
public void testAddMultiplePeerAssociationDifferentTransaction() {
    final NodeRef content1NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef content2NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef content3NodeRef = createNode(ContentModel.TYPE_CONTENT);
    checkNumOfEvents(3);
    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());
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.createAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
        return null;
    });
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.createAssociation(content3NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
        return null;
    });
    List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(2, peerAssociationRefs.size());
    checkNumOfEvents(7);
    List<RepoEvent<EventData<PeerAssociationResource>>> peerAssocRepoEvent = getFilteredEvents(EventType.PEER_ASSOC_CREATED);
    // we should have 2 assoc.peer.Created events
    assertEquals("Wrong association events number", 2, peerAssocRepoEvent.size());
    assertEquals("Wrong source", content1NodeRef.getId(), getPeerAssocResource(peerAssocRepoEvent.get(0)).getSource().getId());
    assertEquals("Wrong target", content2NodeRef.getId(), getPeerAssocResource(peerAssocRepoEvent.get(0)).getTarget().getId());
    assertEquals("Wrong assoc type", "cm:original", getPeerAssocResource(peerAssocRepoEvent.get(0)).getAssocType());
    assertEquals("Wrong source", content3NodeRef.getId(), getPeerAssocResource(peerAssocRepoEvent.get(1)).getSource().getId());
    assertEquals("Wrong target", content2NodeRef.getId(), getPeerAssocResource(peerAssocRepoEvent.get(1)).getTarget().getId());
    assertEquals("Wrong assoc type", "cm:original", getPeerAssocResource(peerAssocRepoEvent.get(1)).getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RepoEvent(org.alfresco.repo.event.v1.model.RepoEvent) PeerAssociationResource(org.alfresco.repo.event.v1.model.PeerAssociationResource) EventData(org.alfresco.repo.event.v1.model.EventData) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)79 EventData (org.alfresco.event.sdk.model.v1.model.EventData)54 DataAttributes (org.alfresco.event.sdk.model.v1.model.DataAttributes)52 NodeResource (org.alfresco.event.sdk.model.v1.model.NodeResource)51 EventData (org.alfresco.repo.event.v1.model.EventData)25 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 ChildAssociationResource (org.alfresco.repo.event.v1.model.ChildAssociationResource)11 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)8 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)6 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)4 ContentInfo (org.alfresco.event.sdk.model.v1.model.ContentInfo)3 PeerAssociationResource (org.alfresco.event.sdk.model.v1.model.PeerAssociationResource)3 CreateEventOptions (com.ibm.watson.discovery.v1.model.CreateEventOptions)2 CreateEventResponse (com.ibm.watson.discovery.v1.model.CreateEventResponse)2 EventData (com.ibm.watson.discovery.v1.model.EventData)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2