Search in sources :

Example 1 with OrganisationalUnitRecord

use of org.finos.waltz.schema.tables.records.OrganisationalUnitRecord in project waltz by khartec.

the class BaseInMemoryIntegrationTest method createOrgUnit.

public Long createOrgUnit(String nameStem, Long parentId) {
    OrganisationalUnitRecord record = getDsl().newRecord(ORGANISATIONAL_UNIT);
    record.setId(counter.incrementAndGet());
    record.setName(nameStem + "Name");
    record.setDescription(nameStem + "Desc");
    record.setParentId(parentId);
    record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
    record.setLastUpdatedBy("admin");
    record.setProvenance("integration-test");
    record.insert();
    return record.getId();
}
Also used : OrganisationalUnitRecord(org.finos.waltz.schema.tables.records.OrganisationalUnitRecord)

Example 2 with OrganisationalUnitRecord

use of org.finos.waltz.schema.tables.records.OrganisationalUnitRecord in project waltz by khartec.

the class OrgUnitGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    Supplier<List<String>> lineSupplier = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/org-units.csv")));
    List<OrganisationalUnitRecord> records = lineSupplier.get().stream().skip(1).map(line -> line.split(",")).filter(cells -> cells.length > 2).map(cells -> {
        OrganisationalUnitRecord record = new OrganisationalUnitRecord();
        record.setId(longVal(cells[0]));
        record.setParentId(longVal(cells[1]));
        record.setName(cells[2]);
        if (cells.length > 3) {
            record.setDescription(cells[3]);
        }
        record.setLastUpdatedAt(new Timestamp(System.currentTimeMillis()));
        return record;
    }).collect(Collectors.toList());
    log("Inserting new OU's");
    dsl.batchInsert(records).execute();
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.ORG_UNIT);
    return MapUtilities.newHashMap("created", records.size());
}
Also used : MapUtilities(org.finos.waltz.common.MapUtilities) Unchecked(org.jooq.lambda.Unchecked) IOUtilities.readLines(org.finos.waltz.common.IOUtilities.readLines) EntityKind(org.finos.waltz.model.EntityKind) Timestamp(java.sql.Timestamp) ApplicationContext(org.springframework.context.ApplicationContext) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) OrganisationalUnitRecord(org.finos.waltz.schema.tables.records.OrganisationalUnitRecord) List(java.util.List) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) OrganisationalUnitRecord(org.finos.waltz.schema.tables.records.OrganisationalUnitRecord) List(java.util.List) Timestamp(java.sql.Timestamp)

Aggregations

OrganisationalUnitRecord (org.finos.waltz.schema.tables.records.OrganisationalUnitRecord)2 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 IOUtilities.readLines (org.finos.waltz.common.IOUtilities.readLines)1 MapUtilities (org.finos.waltz.common.MapUtilities)1 StringUtilities (org.finos.waltz.common.StringUtilities)1 EntityKind (org.finos.waltz.model.EntityKind)1 ORGANISATIONAL_UNIT (org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)1 EntityHierarchyService (org.finos.waltz.service.entity_hierarchy.EntityHierarchyService)1 DSLContext (org.jooq.DSLContext)1 Unchecked (org.jooq.lambda.Unchecked)1 ApplicationContext (org.springframework.context.ApplicationContext)1