use of org.finos.waltz.schema.tables.records.PersonHierarchyRecord in project waltz by khartec.
the class PersonHierarchyService method build.
public int[] build() {
LOG.warn("Building person hierarchy");
List<Person> all = personDao.all();
Forest<Person, String> forest = toForest(all);
List<PersonHierarchyRecord> records = toHierarchyRecords(forest);
return dsl.transactionResult(configuration -> {
DSLContext txDsl = DSL.using(configuration);
txDsl.deleteFrom(PERSON_HIERARCHY).execute();
return txDsl.batchStore(records).execute();
});
}
use of org.finos.waltz.schema.tables.records.PersonHierarchyRecord in project waltz by khartec.
the class PersonHierarchyService method toHierarchyRecords.
private List<PersonHierarchyRecord> toHierarchyRecords(Forest<Person, String> forest) {
List<PersonHierarchyRecord> records = new LinkedList<>();
for (Node<Person, String> node : forest.getAllNodes().values()) {
List<Person> ancestors = ListUtilities.reverse(HierarchyUtilities.parents(node).stream().map(Node::getData).collect(Collectors.toList()));
for (int i = 0; i < ancestors.size(); i++) {
String ancestorId = ancestors.get(i).employeeId();
String selfId = node.getData().employeeId();
PersonHierarchyRecord record = new PersonHierarchyRecord(ancestorId, selfId, i + 1);
records.add(record);
}
}
return records;
}
Aggregations