Search in sources :

Example 16 with NodeResource

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

the class UpdateRepoEventIT method testMoveFile.

@Test
public void testMoveFile() {
    final NodeRef folder1 = createNode(ContentModel.TYPE_FOLDER);
    final String folder1ID = getNodeResource(1).getId();
    final NodeRef folder2 = createNode(ContentModel.TYPE_FOLDER);
    final String folder2ID = getNodeResource(2).getId();
    final NodeRef moveFile = createNode(ContentModel.TYPE_CONTENT, folder1);
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.moveNode(moveFile, folder2, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE));
        return null;
    });
    checkNumOfEvents(4);
    NodeResource resourceBefore = getNodeResourceBefore(4);
    NodeResource resource = getNodeResource(4);
    final String moveFileParentBeforeMove = resourceBefore.getPrimaryHierarchy().get(0);
    final String moveFileParentAfterMove = resource.getPrimaryHierarchy().get(0);
    assertEquals("Wrong node parent.", folder1ID, moveFileParentBeforeMove);
    assertEquals("Wrong node parent.", folder2ID, moveFileParentAfterMove);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), getRepoEvent(4).getType());
    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());
    assertNotNull(resourceBefore.getPrimaryHierarchy());
    assertNull("Content should have been null.", resource.getContent());
    assertNull("Content should have been null.", resourceBefore.getContent());
    assertNotNull(resource.getModifiedAt());
    assertNotNull(resource.getModifiedByUser());
    assertNotNull(resource.getAspectNames());
    assertNull(resource.getContent());
    assertTrue(resource.getProperties().isEmpty());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 17 with NodeResource

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

the class UpdateRepoEventIT method testUpdateTwiceNodeTypeInTheSameTransaction.

@Test
public void testUpdateTwiceNodeTypeInTheSameTransaction() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    // node.Created event should be generated
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
    // old type
    assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
        nodeService.setType(nodeRef, ContentModel.TYPE_CONTENT);
        // new type
        assertEquals("Wrong node type", ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
        return null;
    });
    // we should have only 2 events, node.Created and node.Updated
    checkNumOfEvents(2);
    resultRepoEvent = getRepoEvent(2);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
    nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:content", nodeResource.getNodeType());
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertEquals("Incorrect node type was found", "cm:folder", resourceBefore.getNodeType());
    // assertNotNull(resourceBefore.getModifiedAt()); uncomment this when the issue will be fixed
    assertNull(resourceBefore.getId());
    assertNull(resourceBefore.getContent());
    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) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 18 with NodeResource

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

the class UpdateRepoEventIT method testCreateAndUpdateNodeTypeInTheSameTransaction.

@Test
public void testCreateAndUpdateNodeTypeInTheSameTransaction() {
    retryingTransactionHelper.doInTransaction(() -> {
        final NodeRef nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
        // old type
        assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
        nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
        // new type
        assertEquals(ContentModel.TYPE_FOLDER, nodeService.getType(nodeRef));
        return null;
    });
    // we should have only 1 event, node.Created
    checkNumOfEvents(1);
    RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEvent(1);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    NodeResource nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", "cm:folder", nodeResource.getNodeType());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) EventData(org.alfresco.repo.event.v1.model.EventData) Test(org.junit.Test)

Example 19 with NodeResource

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

the class EventConsolidator 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<NodeResource>> getRepoEvent(EventInfo eventInfo) {
    NodeResource resource = buildNodeResource();
    EventType eventType = getDerivedEvent();
    DataAttributes<NodeResource> eventData = buildEventData(eventInfo, resource, eventType);
    return RepoEvent.<DataAttributes<NodeResource>>builder().setId(eventInfo.getId()).setSource(eventInfo.getSource()).setTime(eventInfo.getTimestamp()).setType(eventType.getType()).setData(eventData).setDataschema(EventJSONSchema.getSchemaV1(eventType)).build();
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) EventType(org.alfresco.repo.event.v1.model.EventType)

Example 20 with NodeResource

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

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