Search in sources :

Example 31 with NodeResource

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

the class UpdateRepoEventIT method testAddAspectRemoveAspectAddAspectFromContentSameTransactionTest.

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

Example 32 with NodeResource

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

the class UpdateRepoEventIT method testUpdateNodeResourceContent.

@Test
public void testUpdateNodeResourceContent() {
    ContentService contentService = (ContentService) applicationContext.getBean("contentService");
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource resource = getNodeResource(resultRepoEvent);
    assertNull("Content should have been null.", resource.getContent());
    retryingTransactionHelper.doInTransaction(() -> {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer.setEncoding("UTF-8");
        writer.putContent("test content.");
        return null;
    });
    checkNumOfEvents(2);
    resultRepoEvent = getRepoEvent(2);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
    resource = getNodeResource(resultRepoEvent);
    ContentInfo content = resource.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertTrue(content.getSizeInBytes() > 0);
    NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
    assertNull("Content should have been null.", resourceBefore.getContent());
    // Update the content again
    retryingTransactionHelper.doInTransaction(() -> {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer.setEncoding("UTF-8");
        writer.putContent("A quick brown fox jumps over the lazy dog.");
        return null;
    });
    resource = getNodeResource(3);
    content = resource.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertTrue(content.getSizeInBytes() > 0);
    resourceBefore = getNodeResourceBefore(3);
    assertNotNull("Content should not have been null.", resourceBefore.getContent());
    content = resourceBefore.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertTrue(content.getSizeInBytes() > 0);
    assertNotNull(resourceBefore.getModifiedAt());
    // Apart from the 'content' and 'modifiedAt' properties the rest should be not be not set
    // for the resourceBefore object
    assertNull(resourceBefore.getId());
    assertNull(resourceBefore.getName());
    assertNull(resourceBefore.getNodeType());
    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) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentInfo(org.alfresco.repo.event.v1.model.ContentInfo) ContentService(org.alfresco.service.cmr.repository.ContentService) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 33 with NodeResource

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

the class UpdateRepoEventIT method testUpdateContentDescription.

@Test
public void testUpdateContentDescription() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    NodeResource resource = getNodeResource(1);
    String desc = getProperty(resource, "cm:description");
    assertNull("Description should have been null.", desc);
    // update content cm:description property with "test_description" value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, "test description");
        return null;
    });
    resource = getNodeResource(2);
    desc = getProperty(resource, "cm:description");
    assertEquals("test description", desc);
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertNull(resourceBefore.getProperties());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 34 with NodeResource

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

the class UpdateRepoEventIT method testUpdateContentTitle.

@Test
public void testUpdateContentTitle() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    NodeResource resource = getNodeResource(1);
    assertNotNull(resource.getProperties());
    String title = getProperty(resource, "cm:title");
    assertNull("Title should have been null.", title);
    // update content cm:title property with "test title" value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "test title");
        return null;
    });
    resource = getNodeResource(2);
    title = getProperty(resource, "cm:title");
    assertEquals("test title", title);
    // update content cm:title property again with "new test title" value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setProperty(nodeRef, ContentModel.PROP_TITLE, "new test title");
        return null;
    });
    resource = getNodeResource(3);
    title = getProperty(resource, "cm:title");
    assertEquals("new test title", title);
    NodeResource resourceBefore = getNodeResourceBefore(3);
    title = getProperty(resourceBefore, "cm:title");
    assertEquals("Wrong old property.", "test title", title);
    assertNotNull(resourceBefore.getModifiedAt());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 35 with NodeResource

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

the class UpdateRepoEventIT method testUpdateNodeResourceContentSameContentSize.

@Test
public void testUpdateNodeResourceContentSameContentSize() {
    ContentService contentService = (ContentService) applicationContext.getBean("contentService");
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource resource = getNodeResource(resultRepoEvent);
    assertNull("Content should have been null.", resource.getContent());
    retryingTransactionHelper.doInTransaction(() -> {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer.setEncoding("UTF-8");
        writer.putContent("test content a");
        return null;
    });
    checkNumOfEvents(2);
    resultRepoEvent = getRepoEvent(2);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
    resource = getNodeResource(resultRepoEvent);
    ContentInfo content = resource.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertEquals(14, (long) content.getSizeInBytes());
    NodeResource resourceBefore = getNodeResourceBefore(resultRepoEvent);
    assertNull("Content should have been null.", resourceBefore.getContent());
    // Update the content again - different content but same size
    retryingTransactionHelper.doInTransaction(() -> {
        ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.TYPE_CONTENT, true);
        writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
        writer.setEncoding("UTF-8");
        writer.putContent("test content b");
        return null;
    });
    resource = getNodeResource(3);
    content = resource.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertEquals(14, (long) content.getSizeInBytes());
    resourceBefore = getNodeResourceBefore(3);
    assertNotNull("Content should not have been null.", resourceBefore.getContent());
    content = resourceBefore.getContent();
    assertNotNull(content);
    assertEquals(MimetypeMap.MIMETYPE_PDF, content.getMimeType());
    assertEquals("UTF-8", content.getEncoding());
    assertEquals(14, (long) content.getSizeInBytes());
    assertNotNull(resourceBefore.getModifiedAt());
    // Apart from the 'content' and 'modifiedAt' properties the rest should be not be not set
    // for the resourceBefore object
    assertNull(resourceBefore.getId());
    assertNull(resourceBefore.getName());
    assertNull(resourceBefore.getNodeType());
    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) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) ContentInfo(org.alfresco.repo.event.v1.model.ContentInfo) ContentService(org.alfresco.service.cmr.repository.ContentService) EventData(org.alfresco.repo.event.v1.model.EventData) 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