use of org.alfresco.repo.event.v1.model.RepoEvent 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());
}
use of org.alfresco.repo.event.v1.model.RepoEvent 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());
}
use of org.alfresco.repo.event.v1.model.RepoEvent in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testOneChildMultipleParentsSameTransaction.
@Test
public void testOneChildMultipleParentsSameTransaction() {
final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
checkNumOfEvents(4);
RepoEvent<EventData<NodeResource>> resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(1);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> {
for (NodeRef parent : parents) {
nodeService.addChild(parent, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate()));
}
return null;
});
retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
assertEquals(1, childAssocParent1.size());
assertEquals(1, childAssocParent2.size());
assertEquals(1, childAssocParent3.size());
return null;
});
checkNumOfEvents(7);
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
// All events in the transaction should have the same eventGroupId
String assocEventGroupID1 = getEventData(childAssocEvents.get(0)).getEventGroupId();
String assocEventGroupID2 = getEventData(childAssocEvents.get(1)).getEventGroupId();
String assocEventGroupID3 = getEventData(childAssocEvents.get(2)).getEventGroupId();
assertEquals(assocEventGroupID1, assocEventGroupID2);
assertEquals(assocEventGroupID2, assocEventGroupID3);
}
use of org.alfresco.repo.event.v1.model.RepoEvent in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testOneParentMultipleChildrenSameTransaction.
@Test
public void testOneParentMultipleChildrenSameTransaction() {
final NodeRef parentNodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef child1NodeRef = createNode(ContentModel.TYPE_CONTENT);
final NodeRef child2NodeRef = createNode(ContentModel.TYPE_CONTENT);
final NodeRef child3NodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> children = Arrays.asList(child1NodeRef, child2NodeRef, child3NodeRef);
checkNumOfEvents(4);
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());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> {
for (NodeRef child : children) {
nodeService.addChild(parentNodeRef, child, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate()));
}
return null;
});
retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent = nodeService.getChildAssocs(parentNodeRef);
assertEquals(3, childAssocParent.size());
return null;
});
// 3 assoc.child.Created events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_CREATED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
}
use of org.alfresco.repo.event.v1.model.RepoEvent in project alfresco-repository by Alfresco.
the class ChildAssociationRepoEventIT method testDeleteAssociationsOneChildMultipleParentsSameTransaction.
@Test
public void testDeleteAssociationsOneChildMultipleParentsSameTransaction() {
final NodeRef parent1NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent2NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef parent3NodeRef = createNode(ContentModel.TYPE_FOLDER);
final NodeRef childNodeRef = createNode(ContentModel.TYPE_CONTENT);
List<NodeRef> parents = Arrays.asList(parent1NodeRef, parent2NodeRef, parent3NodeRef);
checkNumOfEvents(4);
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());
resultRepoEvent = getRepoEventWithoutWait(3);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
resultRepoEvent = getRepoEventWithoutWait(4);
assertEquals("Wrong repo event type.", EventType.NODE_CREATED.getType(), resultRepoEvent.getType());
retryingTransactionHelper.doInTransaction(() -> nodeService.addChild(parents, childNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(TEST_NAMESPACE, GUID.generate())));
List<ChildAssociationRef> listChildAssociationRefs = retryingTransactionHelper.doInTransaction(() -> {
List<ChildAssociationRef> childAssocParent1 = nodeService.getChildAssocs(parent1NodeRef);
List<ChildAssociationRef> childAssocParent2 = nodeService.getChildAssocs(parent2NodeRef);
List<ChildAssociationRef> childAssocParent3 = nodeService.getChildAssocs(parent3NodeRef);
assertEquals(1, childAssocParent1.size());
assertEquals(1, childAssocParent2.size());
assertEquals(1, childAssocParent3.size());
return Arrays.asList(childAssocParent1.get(0), childAssocParent2.get(0), childAssocParent3.get(0));
});
retryingTransactionHelper.doInTransaction(() -> {
for (ChildAssociationRef childAssociationRef : listChildAssociationRefs) {
nodeService.removeChildAssociation(childAssociationRef);
}
return null;
});
checkNumOfEvents(10);
// 3 assoc.child.Deleted events should be created
List<RepoEvent<EventData<ChildAssociationResource>>> childAssocEvents = getFilteredEvents(EventType.CHILD_ASSOC_DELETED);
assertEquals("Wrong association events number", 3, childAssocEvents.size());
}
Aggregations