Search in sources :

Example 1 with PersonHierarchyRecord

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();
    });
}
Also used : PersonHierarchyRecord(org.finos.waltz.schema.tables.records.PersonHierarchyRecord) DSLContext(org.jooq.DSLContext) Person(org.finos.waltz.model.person.Person)

Example 2 with PersonHierarchyRecord

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;
}
Also used : Node(org.finos.waltz.common.hierarchy.Node) FlatNode(org.finos.waltz.common.hierarchy.FlatNode) PersonHierarchyRecord(org.finos.waltz.schema.tables.records.PersonHierarchyRecord) Person(org.finos.waltz.model.person.Person) LinkedList(java.util.LinkedList)

Aggregations

Person (org.finos.waltz.model.person.Person)2 PersonHierarchyRecord (org.finos.waltz.schema.tables.records.PersonHierarchyRecord)2 LinkedList (java.util.LinkedList)1 FlatNode (org.finos.waltz.common.hierarchy.FlatNode)1 Node (org.finos.waltz.common.hierarchy.Node)1 DSLContext (org.jooq.DSLContext)1