Search in sources :

Example 26 with EventData

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

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

Example 28 with EventData

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

the class UpdateRepoEventIT method testUpdateNodeType.

@Test
public void testUpdateNodeType() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    // old node's type
    assertEquals("Created node does not have the correct type", ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
    // 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("cm:content node type was not found", "cm:content", nodeResource.getNodeType());
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setType(nodeRef, ContentModel.TYPE_FOLDER);
        // new node's type
        assertEquals("Wrong node type", ContentModel.TYPE_FOLDER, nodeService.getType(nodeRef));
        return null;
    });
    // we should have 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:folder", nodeResource.getNodeType());
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertEquals("Incorrect node type was found", "cm:content", 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 29 with EventData

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

the class UpdateRepoEventIT method testUpdateNodeTypeWithCustomType.

@Test
public void testUpdateNodeTypeWithCustomType() {
    String modelName = "testModel" + System.currentTimeMillis();
    String modelDescription = "testModel description";
    Pair<String, String> namespacePair = getNamespacePair();
    M2Model model = M2Model.createModel(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + modelName);
    model.createNamespace(namespacePair.getFirst(), namespacePair.getSecond());
    model.setDescription(modelDescription);
    String typeName = "testType";
    M2Type m2Type = model.createType(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName);
    m2Type.setTitle("Test type title");
    // Create active model
    CustomModelDefinition modelDefinition = retryingTransactionHelper.doInTransaction(() -> customModelService.createCustomModel(model, true));
    assertNotNull(modelDefinition);
    assertEquals(modelName, modelDefinition.getName().getLocalName());
    assertEquals(modelDescription, modelDefinition.getDescription());
    // List all of the model's types
    Collection<TypeDefinition> types = modelDefinition.getTypeDefinitions();
    assertEquals(1, types.size());
    // node.Created event should be generated for the model
    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:dictionaryModel", nodeResource.getNodeType());
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    // old node's type
    assertEquals(ContentModel.TYPE_CONTENT, nodeService.getType(nodeRef));
    // node.Created event should be generated
    resultRepoEvent = getRepoEvent(2);
    assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
    nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("cm:content node type was not found", "cm:content", nodeResource.getNodeType());
    QName typeQName = QName.createQName("{" + namespacePair.getFirst() + "}" + typeName);
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setType(nodeRef, typeQName);
        // new node's type
        assertEquals(typeQName, nodeService.getType(nodeRef));
        return null;
    });
    // we should have 3 events, node.Created for the model, node.Created for the node and node.Updated
    checkNumOfEvents(3);
    resultRepoEvent = getRepoEvent(3);
    assertEquals("Wrong repo event type.", EventType.NODE_UPDATED.getType(), resultRepoEvent.getType());
    nodeResource = getNodeResource(resultRepoEvent);
    assertEquals("Incorrect node type was found", namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeName, nodeResource.getNodeType());
    NodeResource resourceBefore = getNodeResourceBefore(3);
    assertEquals("Incorrect node type was found", "cm:content", resourceBefore.getNodeType());
    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) CustomModelDefinition(org.alfresco.service.cmr.dictionary.CustomModelDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Type(org.alfresco.repo.dictionary.M2Type) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) EventData(org.alfresco.repo.event.v1.model.EventData) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) Test(org.junit.Test)

Example 30 with EventData

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

the class ChildAssociationRepoEventIT method testAddChildAssociation.

@Test
public void testAddChildAssociation() {
    final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
    final NodeRef childNodeRef = 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.addChild(parentNodeRef, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
    List<ChildAssociationRef> childAssociationRefs = retryingTransactionHelper.doInTransaction(() -> nodeService.getChildAssocs(parentNodeRef));
    assertEquals(1, childAssociationRefs.size());
    assertFalse(childAssociationRefs.get(0).isPrimary());
    checkNumOfEvents(3);
    final RepoEvent<EventData<ChildAssociationResource>> childAssocRepoEvent = getRepoEventWithoutWait(3);
    assertEquals("Wrong repo event type.", EventType.CHILD_ASSOC_CREATED.getType(), childAssocRepoEvent.getType());
    assertNotNull("Repo event ID is not available.", childAssocRepoEvent.getId());
    assertNotNull("Source is not available", childAssocRepoEvent.getSource());
    assertEquals("Repo event source is not available.", "/" + descriptorService.getCurrentRepositoryDescriptor().getId(), childAssocRepoEvent.getSource().toString());
    assertNotNull("Repo event creation time is not available.", childAssocRepoEvent.getTime());
    assertEquals("Invalid repo event datacontenttype", "application/json", childAssocRepoEvent.getDatacontenttype());
    assertNotNull(childAssocRepoEvent.getDataschema());
    assertEquals(EventJSONSchema.CHILD_ASSOC_CREATED_V1.getSchema(), childAssocRepoEvent.getDataschema());
    final EventData<ChildAssociationResource> nodeResourceEventData = getEventData(childAssocRepoEvent);
    // EventData attributes
    assertNotNull("Event data group ID is not available. ", nodeResourceEventData.getEventGroupId());
    assertNull("resourceBefore property is not available", nodeResourceEventData.getResourceBefore());
    final ChildAssociationResource childAssociationResource = getChildAssocResource(childAssocRepoEvent);
    assertEquals("Wrong parent", parentNodeRef.getId(), childAssociationResource.getParent().getId());
    assertEquals("Wrong child", childNodeRef.getId(), childAssociationResource.getChild().getId());
    assertEquals("Wrong assoc type", "cm:contains", childAssociationResource.getAssocType());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) 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)

Aggregations

EventData (org.alfresco.repo.event.v1.model.EventData)25 NodeRef (org.alfresco.service.cmr.repository.NodeRef)25 Test (org.junit.Test)25 NodeResource (org.alfresco.repo.event.v1.model.NodeResource)14 ChildAssociationResource (org.alfresco.repo.event.v1.model.ChildAssociationResource)13 RepoEvent (org.alfresco.repo.event.v1.model.RepoEvent)12 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)12 PeerAssociationResource (org.alfresco.repo.event.v1.model.PeerAssociationResource)6 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 GUID (org.alfresco.util.GUID)4 EventType (org.alfresco.repo.event.v1.model.EventType)3 ContentInfo (org.alfresco.repo.event.v1.model.ContentInfo)2 ContentService (org.alfresco.service.cmr.repository.ContentService)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 PropertyMap (org.alfresco.util.PropertyMap)2 M2Model (org.alfresco.repo.dictionary.M2Model)1 M2Type (org.alfresco.repo.dictionary.M2Type)1 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1 QName (org.alfresco.service.namespace.QName)1