Search in sources :

Example 21 with NodeResource

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

the class PeerAssociationRepoEventIT method testAddAndRemovePeerAssociationSameTransaction.

@Test
public void testAddAndRemovePeerAssociationSameTransaction() {
    final NodeRef content1NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef content2NodeRef = 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());
    // Create peer association
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.createAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
        nodeService.removeAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
        return null;
    });
    List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(0, peerAssociationRefs.size());
    checkNumOfEvents(2);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) EventData(org.alfresco.repo.event.v1.model.EventData) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Test(org.junit.Test)

Example 22 with NodeResource

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

the class PeerAssociationRepoEventIT method testAddPeerAssociation.

@Test
public void testAddPeerAssociation() {
    final NodeRef content1NodeRef = createNode(ContentModel.TYPE_CONTENT);
    final NodeRef content2NodeRef = 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.createAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(1, peerAssociationRefs.size());
    checkNumOfEvents(4);
    final RepoEvent<EventData<PeerAssociationResource>> peerAssocRepoEvent = getFilteredEvent(EventType.PEER_ASSOC_CREATED, 0);
    assertEquals("Wrong repo event type.", EventType.PEER_ASSOC_CREATED.getType(), peerAssocRepoEvent.getType());
    assertNotNull("Repo event ID is not available. ", peerAssocRepoEvent.getId());
    assertNotNull("Source is not available", peerAssocRepoEvent.getSource());
    assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), peerAssocRepoEvent.getSource().toString());
    assertNotNull("Repo event creation time is not available. ", peerAssocRepoEvent.getTime());
    assertEquals("Repo event datacontenttype", "application/json", peerAssocRepoEvent.getDatacontenttype());
    assertNotNull(peerAssocRepoEvent.getDataschema());
    assertEquals(EventJSONSchema.PEER_ASSOC_CREATED_V1.getSchema(), peerAssocRepoEvent.getDataschema());
    final EventData<PeerAssociationResource> nodeResourceEventData = getEventData(peerAssocRepoEvent);
    // EventData attributes
    assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
    assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
    final PeerAssociationResource peerAssociationResource = getPeerAssocResource(peerAssocRepoEvent);
    assertEquals("Wrong source", content1NodeRef.getId(), peerAssociationResource.getSource().getId());
    assertEquals("Wrong target", content2NodeRef.getId(), peerAssociationResource.getTarget().getId());
    assertEquals("Wrong assoc type", "cm:original", peerAssociationResource.getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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)

Example 23 with NodeResource

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

the class PeerAssociationRepoEventIT method testAddMultiplePeerAssociationSameTransaction.

@Test
public void testAddMultiplePeerAssociationSameTransaction() {
    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);
        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());
}
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)

Example 24 with NodeResource

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

the class AbstractContextAwareRepoEvent method getNodeResourceBefore.

protected NodeResource getNodeResourceBefore(int eventSequenceNumber) {
    DataAttributes<NodeResource> eventData = getEventData(eventSequenceNumber);
    NodeResource resourceBefore = eventData.getResourceBefore();
    assertNotNull(resourceBefore);
    return resourceBefore;
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource)

Example 25 with NodeResource

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

the class AbstractContextAwareRepoEvent method getNodeResourceBefore.

protected <D extends DataAttributes<NodeResource>> NodeResource getNodeResourceBefore(RepoEvent<D> repoEvent) {
    assertNotNull(repoEvent);
    D eventData = repoEvent.getData();
    assertNotNull(eventData);
    NodeResource resourceBefore = eventData.getResourceBefore();
    assertNotNull(resourceBefore);
    return resourceBefore;
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) GUID(org.alfresco.util.GUID)

Aggregations

Test (org.junit.Test)39 NodeRef (org.alfresco.service.cmr.repository.NodeRef)36 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)28 EventData (org.alfresco.repo.event.v1.model.EventData)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 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)4 ContentInfo (org.alfresco.repo.event.v1.model.ContentInfo)3 PropertyMap (org.alfresco.util.PropertyMap)3 ContentService (org.alfresco.service.cmr.repository.ContentService)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 QName (org.alfresco.service.namespace.QName)2 GUID (org.alfresco.util.GUID)2 Serializable (java.io.Serializable)1 ZonedDateTime (java.time.ZonedDateTime)1 HashSet (java.util.HashSet)1 M2Model (org.alfresco.repo.dictionary.M2Model)1 M2Type (org.alfresco.repo.dictionary.M2Type)1