use of io.lumeer.api.model.function.FunctionRow in project engine by Lumeer.
the class FunctionRowCodec method decode.
@Override
public FunctionRow decode(final BsonReader reader, final DecoderContext decoderContext) {
Document bson = documentCodec.decode(reader, decoderContext);
String resourceId = bson.getString(RESOURCE_ID);
FunctionResourceType type = FunctionResourceType.valueOf(bson.getString(TYPE));
String attributeId = bson.getString(ATTRIBUTE_ID);
String dependentCollectionId = bson.getString(DEPENDENT_COLLECTION_ID);
String dependentLinkTypeId = bson.getString(DEPENDENT_LINK_TYPE_ID);
String dependentAttributeId = bson.getString(DEPENDENT_ATTRIBUTE_ID);
return new FunctionRow(resourceId, type, attributeId, dependentCollectionId, dependentLinkTypeId, dependentAttributeId);
}
use of io.lumeer.api.model.function.FunctionRow 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.api.model.function.FunctionRow in project engine by Lumeer.
the class FunctionFacadeIT method testCreateQueueSameLink.
@Test
public void testCreateQueueSameLink() {
createTestData();
// L12(a1) = L12(a2) + L12(a3)
LinkType l12 = getLinkType(c1, c2);
FunctionRow row1 = FunctionRow.createForLink(l12.getId(), "a1", null, l12.getId(), "a2");
FunctionRow row2 = FunctionRow.createForLink(l12.getId(), "a1", null, l12.getId(), "a3");
functionDao.createRows(Arrays.asList(row1, row2));
List<Document> c2Documents = getDocuments(c2).subList(0, 2);
List<Document> c1Documents = getDocuments(c1).subList(0, 2);
List<LinkInstance> linkInstances = createLinks(l12, c2Documents, c1Documents);
final Deque<FunctionFacade.FunctionParameterDocuments> queue = functionFacade.createQueueForLinkType(l12, getAttribute(l12, "a1"), Arrays.asList(row1, row2));
assertThat(queue).hasSize(1);
assertThat(queue.getFirst().getAttributeId()).isEqualTo("a1");
assertThat(queue.getFirst().getResourceId()).isEqualTo(l12.getId());
assertThat(queue.getFirst().getLinkInstances()).hasSize(linkInstances.size());
LinkInstance linkInstance = getAnyLink(l12);
final Deque<FunctionFacade.FunctionParameterDocuments> queue2 = functionFacade.createQueueForLinkChanged(l12.getId(), Collections.singletonList("a2"), linkInstance.getId());
assertThat(queue2).hasSize(1);
assertThat(queue2.getFirst().getAttributeId()).isEqualTo("a1");
assertThat(queue2.getFirst().getResourceId()).isEqualTo(l12.getId());
assertThat(queue2.getFirst().getLinkInstances()).hasSize(1);
final Deque<FunctionFacade.FunctionParameterDocuments> queue3 = functionFacade.createQueueForCreatedLinks(l12, Collections.singleton(linkInstance), null);
assertThat(queue3).hasSize(5);
}
use of io.lumeer.api.model.function.FunctionRow in project engine by Lumeer.
the class MongoFunctionDaoTest method testSearchByAnyCollection.
@Test
public void testSearchByAnyCollection() {
FunctionRow row1 = FunctionRow.createForCollection(COLLECTION1, ATTRIBUTE1, COLLECTION2, LINK_TYPE1, ATTRIBUTE2);
FunctionRow row2 = FunctionRow.createForCollection(COLLECTION1, ATTRIBUTE1, COLLECTION3, LINK_TYPE1, ATTRIBUTE3);
FunctionRow row3 = FunctionRow.createForCollection(COLLECTION2, ATTRIBUTE1, COLLECTION1, LINK_TYPE1, ATTRIBUTE2);
FunctionRow row4 = FunctionRow.createForCollection(COLLECTION2, ATTRIBUTE1, COLLECTION2, LINK_TYPE1, ATTRIBUTE3);
FunctionRow row5 = FunctionRow.createForCollection(COLLECTION3, ATTRIBUTE1, COLLECTION1, LINK_TYPE1, ATTRIBUTE1);
FunctionRow row6 = FunctionRow.createForCollection(COLLECTION3, ATTRIBUTE1, COLLECTION3, LINK_TYPE1, ATTRIBUTE3);
List<FunctionRow> rows = Arrays.asList(row1, row2, row3, row4, row5, row6);
functionDao.createRows(rows);
List<FunctionRow> storedRows = functionDao.searchByAnyCollection(COLLECTION1, ATTRIBUTE1);
assertThat(storedRows).hasSize(3).extracting(FunctionRow::getResourceId).containsOnly(COLLECTION1, COLLECTION1, COLLECTION3);
storedRows = functionDao.searchByAnyCollection(COLLECTION1, ATTRIBUTE2);
assertThat(storedRows).hasSize(1).extracting(FunctionRow::getResourceId).containsOnly(COLLECTION2);
storedRows = functionDao.searchByAnyCollection(COLLECTION1, null);
assertThat(storedRows).hasSize(4).extracting(FunctionRow::getResourceId).contains(COLLECTION1, COLLECTION2, COLLECTION3);
storedRows = functionDao.searchByAnyCollection(COLLECTION1, ATTRIBUTE3);
assertThat(storedRows).isEmpty();
}
use of io.lumeer.api.model.function.FunctionRow in project engine by Lumeer.
the class MongoFunctionDaoTest method testDeleteByLink.
@Test
public void testDeleteByLink() {
FunctionRow row1 = FunctionRow.createForLink(LINK_TYPE1, ATTRIBUTE1, COLLECTION2, LINK_TYPE1, ATTRIBUTE2);
FunctionRow row2 = FunctionRow.createForLink(LINK_TYPE1, ATTRIBUTE2, COLLECTION3, LINK_TYPE1, ATTRIBUTE3);
FunctionRow row3 = FunctionRow.createForLink(LINK_TYPE2, ATTRIBUTE1, COLLECTION1, LINK_TYPE1, ATTRIBUTE2);
FunctionRow row4 = FunctionRow.createForLink(LINK_TYPE2, ATTRIBUTE3, COLLECTION2, LINK_TYPE1, ATTRIBUTE3);
List<FunctionRow> rows = Arrays.asList(row1, row2, row3, row4);
functionDao.createRows(rows);
List<FunctionRow> storedRows = functionDao.databaseCollection().find().into(new ArrayList<>());
assertThat(storedRows).hasSize(4).extracting(FunctionRow::getResourceId).contains(LINK_TYPE1, LINK_TYPE2);
functionDao.deleteByLinkType(LINK_TYPE1, ATTRIBUTE2);
storedRows = functionDao.databaseCollection().find().into(new ArrayList<>());
assertThat(storedRows).hasSize(3).extracting(FunctionRow::getResourceId).contains(LINK_TYPE1, LINK_TYPE2);
functionDao.deleteByLinkType(LINK_TYPE1, ATTRIBUTE1);
storedRows = functionDao.databaseCollection().find().into(new ArrayList<>());
assertThat(storedRows).hasSize(2).extracting(FunctionRow::getResourceId).contains(LINK_TYPE2);
}
Aggregations