Search in sources :

Example 1 with EntityHierarchyService

use of org.finos.waltz.service.entity_hierarchy.EntityHierarchyService in project waltz by khartec.

the class EntityHierarchyHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    EntityHierarchyService svc = ctx.getBean(EntityHierarchyService.class);
    svc.buildFor(EntityKind.ORG_UNIT);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService)

Example 2 with EntityHierarchyService

use of org.finos.waltz.service.entity_hierarchy.EntityHierarchyService in project waltz by khartec.

the class EntityStatisticGenerator method create.

public Map<String, Integer> create(ApplicationContext context) {
    DSLContext dsl = context.getBean(DSLContext.class);
    ApplicationDao applicationDao = context.getBean(ApplicationDao.class);
    OrganisationalUnitDao organisationalUnitDao = context.getBean(OrganisationalUnitDao.class);
    EntityStatisticValueDao valueDao = context.getBean(EntityStatisticValueDao.class);
    EntityStatisticDefinitionDao definitionDao = context.getBean(EntityStatisticDefinitionDao.class);
    EntityHierarchyService entityHierarchyService = context.getBean(EntityHierarchyService.class);
    Application[] applications = applicationDao.findAll().toArray(new Application[0]);
    OrganisationalUnit[] orgUnits = organisationalUnitDao.findAll().toArray(new OrganisationalUnit[0]);
    dsl.deleteFrom(ENTITY_STATISTIC_DEFINITION).where(ENTITY_STATISTIC_DEFINITION.PROVENANCE.eq("DEMO")).execute();
    log("deleted existing statistics (provenance: '" + SAMPLE_DATA_PROVENANCE + "')");
    dsl.update(ENTITY_STATISTIC_VALUE).set(ENTITY_STATISTIC_VALUE.CURRENT, false).where(ENTITY_STATISTIC_VALUE.PROVENANCE.eq("DEMO")).execute();
    log("marked existing statistic values as non-current (provenance: '" + SAMPLE_DATA_PROVENANCE + "')");
    definitionDao.insert(SDLC);
    definitionDao.insert(SDLC_TECH);
    definitionDao.insert(SDLC_PROCESS);
    definitionDao.insert(SDLC_JIRA);
    definitionDao.insert(SDLC_SVN);
    definitionDao.insert(SDLC_WIKI);
    definitionDao.insert(AUDIT);
    definitionDao.insert(SERVER_COUNT);
    definitionDao.insert(PRE_COMPUTED);
    createAdoptionStatsFor(SDLC_TECH, applications, valueDao);
    createAdoptionStatsFor(SDLC_PROCESS, applications, valueDao);
    createAdoptionStatsFor(SDLC_JIRA, applications, valueDao);
    createAdoptionStatsFor(SDLC_SVN, applications, valueDao);
    createAdoptionStatsFor(SDLC_WIKI, applications, valueDao);
    createIntStatsFor(AUDIT, applications, valueDao, 20, failIfPositiveFn);
    createIntStatsFor(SDLC, applications, valueDao, 20, failIfPositiveFn);
    createIntStatsFor(SERVER_COUNT, applications, valueDao, 20, (x, y) -> "VIRTUAL");
    createIntStatsFor(SERVER_COUNT, applications, valueDao, 20, (x, y) -> "BARE_METAL");
    createPreComputedStatsFor(PRE_COMPUTED, orgUnits, valueDao);
    entityHierarchyService.buildFor(EntityKind.ENTITY_STATISTIC);
    log("Rebuilt entity hierarchy");
    return null;
}
Also used : OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) EntityStatisticDefinitionDao(org.finos.waltz.data.entity_statistic.EntityStatisticDefinitionDao) EntityStatisticValueDao(org.finos.waltz.data.entity_statistic.EntityStatisticValueDao) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) Application(org.finos.waltz.model.application.Application)

Example 3 with EntityHierarchyService

use of org.finos.waltz.service.entity_hierarchy.EntityHierarchyService in project waltz by khartec.

the class DataTypeGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    dsl.deleteFrom(DATA_TYPE).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "BOOK").set(DATA_TYPE.DESCRIPTION, "Book Data").set(DATA_TYPE.NAME, "Book Data").set(DATA_TYPE.ID, 1000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "PARTY").set(DATA_TYPE.DESCRIPTION, "Party Data").set(DATA_TYPE.NAME, "Counterparty etc.").set(DATA_TYPE.ID, 2000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "PRICING").set(DATA_TYPE.DESCRIPTION, "Pricing Data").set(DATA_TYPE.NAME, "Pricing Data").set(DATA_TYPE.ID, 3000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "TRADE").set(DATA_TYPE.DESCRIPTION, "Trade Data").set(DATA_TYPE.NAME, "Transactions etc.").set(DATA_TYPE.ID, 4000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "RATE").set(DATA_TYPE.DESCRIPTION, "Rates").set(DATA_TYPE.NAME, "Interest rates etc").set(DATA_TYPE.ID, 5000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "CURRENCY").set(DATA_TYPE.DESCRIPTION, "Currency").set(DATA_TYPE.NAME, "Currencies etc").set(DATA_TYPE.ID, 6000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "VIRTUAL_CURRENCIES").set(DATA_TYPE.DESCRIPTION, "Virtual Currencies eg: Bitcoin").set(DATA_TYPE.NAME, "Virtual Currencies").set(DATA_TYPE.ID, 6100L).set(DATA_TYPE.PARENT_ID, 6000L).execute();
    dsl.insertInto(DATA_TYPE).set(DATA_TYPE.CODE, "UNKNOWN").set(DATA_TYPE.DESCRIPTION, "Unknown").set(DATA_TYPE.NAME, "Unknown").set(DATA_TYPE.ID, 1L).set(DATA_TYPE.UNKNOWN, true).execute();
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.DATA_TYPE);
    return null;
}
Also used : EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext)

Example 4 with EntityHierarchyService

use of org.finos.waltz.service.entity_hierarchy.EntityHierarchyService in project waltz by khartec.

the class MeasurableGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    System.out.println("Importing data for category: " + category);
    Supplier<List<String>> lineSupplier = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/" + category + ".tsv")));
    long categoryId = getCategory(dsl);
    List<String> lines = lineSupplier.get();
    List<String[]> sheet = lineSupplier.get().stream().skip(1).map(line -> line.split("\\t")).filter(cells -> cells.length > 3).collect(Collectors.toList());
    List<MeasurableRecord> records = sheet.stream().map(cells -> {
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setName(cells[2]);
        record.setDescription(cells[3]);
        record.setMeasurableCategoryId(categoryId);
        record.setLastUpdatedBy("admin");
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setConcrete(!StringUtilities.isEmpty(cells[1]));
        record.setExternalId(category + " _ " + cells[0]);
        return record;
    }).collect(Collectors.toList());
    dsl.batchStore(records).execute();
    sheet.stream().filter(cells -> !StringUtilities.isEmpty(cells[1])).forEach(cells -> {
        String pExtId = cells[1];
        System.out.println(Arrays.toString(cells));
        long pId = dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.EXTERNAL_ID.eq(category + " _ " + pExtId)).fetchOne(MEASURABLE.ID);
        dsl.update(MEASURABLE).set(MEASURABLE.PARENT_ID, pId).where(MEASURABLE.EXTERNAL_ID.equal(category + " _ " + cells[0])).execute();
    });
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.MEASURABLE);
    return null;
}
Also used : Arrays(java.util.Arrays) Checks.checkNotEmpty(org.finos.waltz.common.Checks.checkNotEmpty) Unchecked(org.jooq.lambda.Unchecked) IOUtilities.readLines(org.finos.waltz.common.IOUtilities.readLines) EntityKind(org.finos.waltz.model.EntityKind) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) MEASURABLE_CATEGORY(org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) ApplicationContext(org.springframework.context.ApplicationContext) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SelectConditionStep(org.jooq.SelectConditionStep) List(java.util.List) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) List(java.util.List)

Example 5 with EntityHierarchyService

use of org.finos.waltz.service.entity_hierarchy.EntityHierarchyService 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

EntityHierarchyService (org.finos.waltz.service.entity_hierarchy.EntityHierarchyService)8 DSLContext (org.jooq.DSLContext)5 List (java.util.List)2 Map (java.util.Map)2 Supplier (java.util.function.Supplier)2 Collectors (java.util.stream.Collectors)2 IOUtilities.readLines (org.finos.waltz.common.IOUtilities.readLines)2 StringUtilities (org.finos.waltz.common.StringUtilities)2 OrganisationalUnitDao (org.finos.waltz.data.orgunit.OrganisationalUnitDao)2 EntityKind (org.finos.waltz.model.EntityKind)2 OrganisationalUnit (org.finos.waltz.model.orgunit.OrganisationalUnit)2 Unchecked (org.jooq.lambda.Unchecked)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Timestamp (java.sql.Timestamp)1 Arrays (java.util.Arrays)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Checks.checkNotEmpty (org.finos.waltz.common.Checks.checkNotEmpty)1 MapUtilities (org.finos.waltz.common.MapUtilities)1 FlatNode (org.finos.waltz.common.hierarchy.FlatNode)1