use of com.ibm.watson.discovery.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());
}
use of com.ibm.watson.discovery.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());
}
use of com.ibm.watson.discovery.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());
}
use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-java-sdk by Alfresco.
the class AspectAddedFilterTest method should_testFalse_when_eventWithoutAspectsIsSent.
@Test
public void should_testFalse_when_eventWithoutAspectsIsSent() {
final NodeResource nodeResource = NodeResource.builder().build();
final NodeResource nodeResourceBefore = NodeResource.builder().build();
final EventData<NodeResource> eventData = EventData.<NodeResource>builder().setResource(nodeResource).setResourceBefore(nodeResourceBefore).build();
final RepoEvent<? extends DataAttributes<? extends Resource>> repoEvent = RepoEvent.<EventData<NodeResource>>builder().setData(eventData).build();
final boolean result = aspectAddedFilter.test((RepoEvent<DataAttributes<Resource>>) repoEvent);
assertThat(result).isFalse();
}
use of com.ibm.watson.discovery.v1.model.EventData in project alfresco-java-sdk by Alfresco.
the class AspectRemovedFilterTest method should_testFalse_when_eventWithAspectAlreadyRemovedIsSent.
@Test
public void should_testFalse_when_eventWithAspectAlreadyRemovedIsSent() {
final NodeResource nodeResource = NodeResource.builder().setAspectNames(Set.of(TEST_ASPECT, "test:other")).build();
final NodeResource nodeResourceBefore = NodeResource.builder().setAspectNames(Set.of("test:other")).build();
final EventData<NodeResource> eventData = EventData.<NodeResource>builder().setResource(nodeResource).setResourceBefore(nodeResourceBefore).build();
final RepoEvent<? extends DataAttributes<? extends Resource>> repoEvent = RepoEvent.<EventData<NodeResource>>builder().setData(eventData).build();
final boolean result = aspectRemovedFilter.test((RepoEvent<DataAttributes<Resource>>) repoEvent);
assertThat(result).isFalse();
}
Aggregations