Search in sources :

Example 1 with PeerAssociationResource

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

Example 2 with PeerAssociationResource

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

the class PeerAssociationRepoEventIT method testRemovePeerAssociation.

@Test
public void testRemovePeerAssociation() {
    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));
    List<AssociationRef> peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(1, peerAssociationRefs.size());
    checkNumOfEvents(4);
    // Remove peer association
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.removeAssociation(content1NodeRef, content2NodeRef, ContentModel.ASSOC_ORIGINAL);
        return null;
    });
    peerAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getSourceAssocs(content2NodeRef, ContentModel.ASSOC_ORIGINAL));
    assertEquals(0, peerAssociationRefs.size());
    checkNumOfEvents(6);
    // Check the peer assoc created event
    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());
    // Check the peer assoc deleted event
    final RepoEvent<EventData<PeerAssociationResource>> peerAssocRepoEvent2 = getFilteredEvent(EventType.PEER_ASSOC_DELETED, 0);
    assertEquals("Wrong repo event type.", EventType.PEER_ASSOC_DELETED.getType(), peerAssocRepoEvent2.getType());
    assertNotNull("Repo event ID is not available. ", peerAssocRepoEvent2.getId());
    assertNotNull("Source is not available", peerAssocRepoEvent2.getSource());
    assertEquals("Repo event source is not available. ", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), peerAssocRepoEvent2.getSource().toString());
    assertNotNull("Repo event creation time is not available. ", peerAssocRepoEvent2.getTime());
    assertEquals("Repo event datacontenttype", "application/json", peerAssocRepoEvent2.getDatacontenttype());
    assertNotNull(peerAssocRepoEvent2.getDataschema());
    assertEquals(EventJSONSchema.PEER_ASSOC_DELETED_V1.getSchema(), peerAssocRepoEvent2.getDataschema());
    final EventData<PeerAssociationResource> nodeResourceEventData2 = getEventData(peerAssocRepoEvent2);
    // EventData attributes
    assertNotNull("Event data group ID is not available. ", nodeResourceEventData2.getEventGroupId());
    assertNull("resourceBefore property is not available", nodeResourceEventData2.getResourceBefore());
    final PeerAssociationResource peerAssociationResource2 = getPeerAssocResource(peerAssocRepoEvent2);
    assertEquals("Wrong source", content1NodeRef.getId(), peerAssociationResource2.getSource().getId());
    assertEquals("Wrong target", content2NodeRef.getId(), peerAssociationResource2.getTarget().getId());
    assertEquals("Wrong assoc type", "cm:original", peerAssociationResource2.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 3 with PeerAssociationResource

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

the class AbstractContextAwareRepoEvent method getPeerAssocResource.

protected <D extends DataAttributes<PeerAssociationResource>> PeerAssociationResource getPeerAssocResource(RepoEvent<D> repoEvent) {
    assertNotNull(repoEvent);
    D eventData = repoEvent.getData();
    assertNotNull(eventData);
    PeerAssociationResource resource = eventData.getResource();
    assertNotNull(resource);
    return resource;
}
Also used : PeerAssociationResource(org.alfresco.repo.event.v1.model.PeerAssociationResource) GUID(org.alfresco.util.GUID)

Example 4 with PeerAssociationResource

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

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

Aggregations

PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)6 EventData (org.alfresco.repo.event.v1.model.EventData)4 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Test (org.junit.Test)4 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)2 EventType (org.alfresco.repo.event.v1.model.EventType)1 GUID (org.alfresco.util.GUID)1