Search in sources :

Example 1 with ContentInfo

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

the class NodeResourceHelper method getContentInfo.

public ContentInfo getContentInfo(Map<QName, Serializable> props) {
    final Serializable content = props.get(ContentModel.PROP_CONTENT);
    ContentInfo contentInfo = null;
    if ((content instanceof ContentData)) {
        ContentData cd = (ContentData) content;
        contentInfo = new ContentInfo(cd.getMimetype(), cd.getSize(), cd.getEncoding());
    }
    return contentInfo;
}
Also used : Serializable(java.io.Serializable) ContentData(org.alfresco.service.cmr.repository.ContentData) ContentInfo(org.alfresco.repo.event.v1.model.ContentInfo)

Example 2 with ContentInfo

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

the class EventConsolidator method buildNodeResourceBeforeDelta.

protected NodeResource buildNodeResourceBeforeDelta(NodeResource after) {
    if (after == null) {
        return null;
    }
    Builder builder = NodeResource.builder();
    Map<QName, Serializable> changedPropsBefore = getBeforeMapChanges(propertiesBefore, propertiesAfter);
    if (!changedPropsBefore.isEmpty()) {
        // Set only the changed properties
        Map<String, Serializable> mappedProps = helper.mapToNodeProperties(changedPropsBefore);
        if (!mappedProps.isEmpty()) {
            builder.setProperties(mappedProps);
            resourceBeforeAllFieldsNull = false;
        }
        String name = (String) changedPropsBefore.get(ContentModel.PROP_NAME);
        if (name != null) {
            builder.setName(name);
            resourceBeforeAllFieldsNull = false;
        }
        ContentInfo contentInfo = helper.getContentInfo(changedPropsBefore);
        if (contentInfo != null) {
            builder.setContent(contentInfo);
            resourceBeforeAllFieldsNull = false;
        }
        UserInfo modifier = helper.getUserInfo((String) changedPropsBefore.get(ContentModel.PROP_MODIFIER));
        if (modifier != null) {
            builder.setModifiedByUser(modifier);
            resourceBeforeAllFieldsNull = false;
        }
        ZonedDateTime modifiedAt = helper.getZonedDateTime((Date) changedPropsBefore.get(ContentModel.PROP_MODIFIED));
        if (modifiedAt != null) {
            builder.setModifiedAt(modifiedAt);
            resourceBeforeAllFieldsNull = false;
        }
    }
    Set<String> aspectsBefore = getMappedAspectsBefore(after.getAspectNames());
    if (!aspectsBefore.isEmpty()) {
        builder.setAspectNames(aspectsBefore);
        resourceBeforeAllFieldsNull = false;
    }
    if (primaryHierarchyBefore != null && !primaryHierarchyBefore.isEmpty()) {
        builder.setPrimaryHierarchy(primaryHierarchyBefore);
        resourceBeforeAllFieldsNull = false;
    }
    if (nodeTypeBefore != null) {
        builder.setNodeType(helper.getQNamePrefixString(nodeTypeBefore));
        resourceBeforeAllFieldsNull = false;
    }
    return builder.build();
}
Also used : Serializable(java.io.Serializable) ContentInfo(org.alfresco.repo.event.v1.model.ContentInfo) ZonedDateTime(java.time.ZonedDateTime) QName(org.alfresco.service.namespace.QName) Builder(org.alfresco.repo.event.v1.model.NodeResource.Builder) UserInfo(org.alfresco.repo.event.v1.model.UserInfo)

Example 3 with ContentInfo

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

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

ContentInfo (org.alfresco.repo.event.v1.model.ContentInfo)4 Serializable (java.io.Serializable)2 EventData (org.alfresco.repo.event.v1.model.EventData)2 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 Test (org.junit.Test)2 ZonedDateTime (java.time.ZonedDateTime)1 Builder (org.alfresco.repo.event.v1.model.NodeResource.Builder)1 UserInfo (org.alfresco.repo.event.v1.model.UserInfo)1 ContentData (org.alfresco.service.cmr.repository.ContentData)1 QName (org.alfresco.service.namespace.QName)1