Search in sources :

Example 1 with OrganisationalUnitRecord

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

the class OrgUnitGenerator method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));
    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();
    List<OrganisationalUnitRecord> records = lines.stream().skip(1).map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4).map(cells -> {
        OrganisationalUnitRecord record = new OrganisationalUnitRecord();
        record.setId(longVal(cells[0]));
        record.setParentId(longVal(cells[1]));
        record.setName(cells[2]);
        record.setDescription(cells[3]);
        record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
        System.out.println(record);
        return record;
    }).collect(Collectors.toList());
    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();
    System.out.println("Done");
}
Also used : List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitRecord(com.khartec.waltz.schema.tables.records.OrganisationalUnitRecord) Timestamp(java.sql.Timestamp) DSLContext(org.jooq.DSLContext) IOException(java.io.IOException) StringUtilities(com.khartec.waltz.common.StringUtilities) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) IOUtilities.readLines(com.khartec.waltz.common.IOUtilities.readLines) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) OrganisationalUnitRecord(com.khartec.waltz.schema.tables.records.OrganisationalUnitRecord) Timestamp(java.sql.Timestamp)

Aggregations

IOUtilities.readLines (com.khartec.waltz.common.IOUtilities.readLines)1 StringUtilities (com.khartec.waltz.common.StringUtilities)1 ORGANISATIONAL_UNIT (com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)1 OrganisationalUnitRecord (com.khartec.waltz.schema.tables.records.OrganisationalUnitRecord)1 DIConfiguration (com.khartec.waltz.service.DIConfiguration)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 DSLContext (org.jooq.DSLContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1