Search in sources :

Example 11 with NodeResource

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

Example 12 with NodeResource

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

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

the class UpdateRepoEventIT method testMoveNodeWithAspects.

@Test
public void testMoveNodeWithAspects() {
    final NodeRef folder1 = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef folder2 = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef moveFile = createNode(ContentModel.TYPE_CONTENT, folder1);
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.addAspect(moveFile, ContentModel.ASPECT_VERSIONABLE, null);
        return null;
    });
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.moveNode(moveFile, folder2, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE));
        return null;
    });
    NodeResource resource = getNodeResource(5);
    assertNotNull(resource.getAspectNames());
    assertTrue("Wrong aspect.", resource.getAspectNames().contains("cm:versionable"));
    final String folder2ID = getNodeResource(2).getId();
    final String moveFileParentAfterMove = getNodeResource(5).getPrimaryHierarchy().get(0);
    assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 14 with NodeResource

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

the class UpdateRepoEventIT method testMoveNodeWithProperties.

@Test
public void testMoveNodeWithProperties() {
    final NodeRef folder1 = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef folder2 = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef moveFile = createNode(ContentModel.TYPE_CONTENT, folder1);
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setProperty(moveFile, ContentModel.PROP_NAME, "test_new_name");
        nodeService.moveNode(moveFile, folder2, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE));
        return null;
    });
    NodeResource resource = getNodeResource(4);
    assertEquals("test_new_name", resource.getName());
    final String folder2ID = getNodeResource(2).getId();
    final String moveFileParentAfterMove = getNodeResource(4).getPrimaryHierarchy().get(0);
    assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 15 with NodeResource

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

the class UpdateRepoEventIT method testRemoveAspectFromContentTest.

@Test
public void testRemoveAspectFromContentTest() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    NodeResource resource = getNodeResource(1);
    final Set<String> originalAspects = resource.getAspectNames();
    assertNotNull(originalAspects);
    // Add cm:geographic aspect with default value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.addAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC, null);
        return null;
    });
    resource = getNodeResource(2);
    Set<String> aspectsBeforeRemove = resource.getAspectNames();
    assertNotNull(aspectsBeforeRemove);
    assertTrue(aspectsBeforeRemove.contains("cm:geographic"));
    // Remove cm:geographic aspect
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.removeAspect(nodeRef, ContentModel.ASPECT_GEOGRAPHIC);
        return null;
    });
    resource = getNodeResource(3);
    assertEquals(originalAspects, resource.getAspectNames());
    NodeResource resourceBefore = getNodeResourceBefore(3);
    assertNotNull(resourceBefore.getAspectNames());
    assertEquals(aspectsBeforeRemove, resourceBefore.getAspectNames());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

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