use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.
the class FunctionFacadeIT method testCreateLinkTaskToCollection.
@Test
public void testCreateLinkTaskToCollection() {
createTestData();
// L12(a1) = C2(a2) + C2(a3); C2(a2) = L23(a1) + L23(a2); L23(a1) = C3(a3) + C3(a4)
LinkType l12 = getLinkType(c1, c2);
LinkType l23 = getLinkType(c2, c3);
FunctionRow row1 = FunctionRow.createForLink(l12.getId(), "a1", c2.getId(), l12.getId(), "a2");
FunctionRow row2 = FunctionRow.createForLink(l12.getId(), "a1", c2.getId(), l12.getId(), "a3");
FunctionRow row3 = FunctionRow.createForCollection(c2.getId(), "a2", c3.getId(), l23.getId(), "a1");
FunctionRow row4 = FunctionRow.createForCollection(c2.getId(), "a2", c3.getId(), l23.getId(), "a2");
FunctionRow row5 = FunctionRow.createForLink(l23.getId(), "a1", c3.getId(), l23.getId(), "a3");
FunctionRow row6 = FunctionRow.createForLink(l23.getId(), "a1", c3.getId(), l23.getId(), "a4");
functionDao.createRows(Arrays.asList(row1, row2, row3, row4, row5, row6));
List<Document> c1Documents = getDocuments(c1).subList(0, 2);
List<Document> c2Documents = getDocuments(c2).subList(0, 2);
List<Document> c3Documents = getDocuments(c3).subList(0, 2);
createLinks(l12, c1Documents, c2Documents);
List<LinkInstance> l23Links = createLinks(l23, c2Documents, c3Documents);
Deque<FunctionFacade.FunctionParameterDocuments> queue = functionFacade.createQueueForLinkChanged(l23.getId(), Collections.singletonList("a1"), l23Links.get(0).getId());
assertThat(queue).hasSize(2);
assertThat(queue.getFirst().getResourceId()).isEqualTo(c2.getId());
assertThat(queue.getLast().getResourceId()).isEqualTo(l12.getId());
FunctionTask task = functionFacade.convertQueueToTask(queue);
assertThat(task.getCollection().getId()).isEqualTo(c2.getId());
assertThat(task.getDocuments()).hasSize(1);
assertThat(task.getParent()).isNotNull();
task = (FunctionTask) task.getParent();
assertThat(task.getLinkType().getId()).isEqualTo(l12.getId());
assertThat(task.getLinkInstances()).hasSize(2);
assertThat(task.getParent()).isNull();
}
use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.
the class TaskProcessingFacade method onDocumentUpdate.
public void onDocumentUpdate(final UpdateDocument updateDocument, final String skipTask) {
final Collection collection = getCollectionForEvent(updateDocument);
if (collection == null) {
return;
}
FunctionTask functionTask = functionFacade.createTaskForUpdateDocument(collection, new Document(updateDocument.getOriginalDocument()), new Document(updateDocument.getDocument()));
List<RuleTask> tasks = createDocumentUpdateRuleTasks(collection, updateDocument, skipTask);
RuleTask ruleTask = createOrderedRuleTask(tasks);
processTasks(functionTask, ruleTask);
}
use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.
the class TaskProcessingFacade method onUpdateLink.
public void onUpdateLink(final UpdateLinkInstance updateLinkEvent, final String skipTask) {
LinkType linkType = getLinkTypeForEvent(updateLinkEvent);
if (linkType == null) {
return;
}
FunctionTask functionTask = functionFacade.creatTaskForChangedLink(linkType, new LinkInstance(updateLinkEvent.getOriginalLinkInstance()), new LinkInstance(updateLinkEvent.getLinkInstance()));
List<RuleTask> tasks = createLinkInstanceUpdateRuleTasks(linkType, updateLinkEvent, skipTask);
RuleTask ruleTask = createOrderedRuleTask(tasks);
processTasks(functionTask, ruleTask);
}
use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.
the class TaskProcessingFacade method onRemoveDocument.
public void onRemoveDocument(@Observes final RemoveDocument removeDocument) {
final Collection collection = getCollectionForEvent(removeDocument);
if (collection == null) {
return;
}
FunctionTask functionTask = functionFacade.createTaskForRemovedDocument(collection, new Document(removeDocument.getDocument()));
List<RuleTask> tasks = createDocumentRemoveRuleTasks(collection, removeDocument.getDocument());
RuleTask ruleTask = createOrderedRuleTask(tasks);
processTasks(functionTask, ruleTask);
}
use of io.lumeer.core.task.FunctionTask in project engine by Lumeer.
the class FunctionFacade method convertQueueToTask.
public FunctionTask convertQueueToTask(final Deque<FunctionParameterDocuments> queue) {
Set<String> collectionIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.COLLECTION && q.getCollection() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
Set<String> linkTypeIds = queue.stream().filter(q -> q.getType() == FunctionResourceType.LINK && q.getLinkType() == null).map(FunctionParameter::getResourceId).collect(Collectors.toSet());
Map<String, Collection> collectionMap = collectionIds.size() > 0 ? collectionDao.getCollectionsByIds(collectionIds).stream().collect(Collectors.toMap(Resource::getId, c -> c)) : new HashMap<>();
List<LinkType> linkTypes = linkTypeIds.size() > 0 ? linkTypeAdapter.mapLinkTypesComputedProperties(linkTypeDao.getLinkTypesByIds(linkTypeIds)) : new ArrayList<>();
Map<String, LinkType> linkTypeMap = linkTypes.stream().collect(Collectors.toMap(LinkType::getId, c -> c));
FunctionTask task = null;
final Iterator<FunctionParameterDocuments> iterator = queue.descendingIterator();
while (iterator.hasNext()) {
final FunctionParameterDocuments parameter = iterator.next();
if (parameter.getType() == FunctionResourceType.COLLECTION) {
Collection collection = parameter.getCollection() != null ? parameter.getCollection() : collectionMap.get(parameter.getResourceId());
Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInCollection(collection, parameter.getAttributeId());
if (collection != null && attribute != null) {
FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
functionTask.setFunctionTask(attribute, collection, parameter.getDocuments(), task);
task = functionTask;
}
} else if (parameter.getType() == FunctionResourceType.LINK) {
LinkType linkType = parameter.getLinkType() != null ? parameter.getLinkType() : linkTypeMap.get(parameter.getResourceId());
Attribute attribute = parameter.getAttribute() != null ? parameter.getAttribute() : findAttributeInLinkType(linkType, parameter.getAttributeId());
if (linkType != null && attribute != null) {
FunctionTask functionTask = contextualTaskFactory.getInstance(FunctionTask.class);
functionTask.setFunctionTask(attribute, linkType, parameter.getLinkInstances(), task);
task = functionTask;
}
}
}
return task;
}
Aggregations