Search in sources :

Example 36 with NodeResource

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

the class UpdateRepoEventIT method testAddAspectToContent.

@Test
public void testAddAspectToContent() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    NodeResource resource = getNodeResource(1);
    final Set<String> originalAspects = resource.getAspectNames();
    assertNotNull(originalAspects);
    assertFalse(originalAspects.contains("cm:versionable"));
    // Check properties
    assertTrue(resource.getProperties().isEmpty());
    // Add cm:versionable aspect with default value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
        return null;
    });
    resource = getNodeResource(2);
    assertNotNull(resource.getAspectNames());
    assertTrue(resource.getAspectNames().contains("cm:versionable"));
    // Check all aspects
    Set<String> expectedAspects = new HashSet<>(originalAspects);
    expectedAspects.add("cm:versionable");
    assertEquals(expectedAspects, resource.getAspectNames());
    // Check properties
    assertFalse(resource.getProperties().isEmpty());
    // Check resourceBefore
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertNotNull(resourceBefore.getAspectNames());
    assertEquals(originalAspects, resourceBefore.getAspectNames());
    assertNull(resourceBefore.getProperties());
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 37 with NodeResource

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

the class UpdateRepoEventIT method testAddAspectRemoveAspectFromContentSameTransactionTest.

@Test
public void testAddAspectRemoveAspectFromContentSameTransactionTest() {
    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);
        return null;
    });
    checkNumOfEvents(1);
}
Also used : NodeResource(org.alfresco.repo.event.v1.model.NodeResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Test(org.junit.Test)

Example 38 with NodeResource

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

the class UpdateRepoEventIT method testUpdateContentName.

@Test
public void testUpdateContentName() {
    final NodeRef nodeRef = createNode(ContentModel.TYPE_CONTENT);
    NodeResource resource = getNodeResource(1);
    String oldName = resource.getName();
    assertEquals(nodeRef.getId(), oldName);
    // update cm:name property with "test_new_name" value
    retryingTransactionHelper.doInTransaction(() -> {
        nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "test_new_name");
        return null;
    });
    resource = getNodeResource(2);
    assertEquals("test_new_name", resource.getName());
    NodeResource resourceBefore = getNodeResourceBefore(2);
    assertEquals(oldName, resourceBefore.getName());
    assertNotNull(resourceBefore.getModifiedAt());
    // Apart from the 'name' and 'modifiedAt' properties the rest should be not be not set
    // for the resourceBefore object
    assertNull(resourceBefore.getId());
    assertNull(resourceBefore.getContent());
    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) Test(org.junit.Test)

Example 39 with NodeResource

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

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

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