Search in sources :

Example 1 with EntityStatisticValueDao

use of org.finos.waltz.data.entity_statistic.EntityStatisticValueDao in project waltz by khartec.

the class EntityStatisticHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    EntityStatisticValueDao dao = ctx.getBean(EntityStatisticValueDao.class);
    EntityStatisticService service = ctx.getBean(EntityStatisticService.class);
    IdSelectionOptions selectionOptions = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.MEASURABLE, 49263), HierarchyQueryScope.CHILDREN);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityStatisticValueDao(org.finos.waltz.data.entity_statistic.EntityStatisticValueDao) DSLContext(org.jooq.DSLContext) EntityStatisticService(org.finos.waltz.service.entity_statistic.EntityStatisticService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 2 with EntityStatisticValueDao

use of org.finos.waltz.data.entity_statistic.EntityStatisticValueDao in project waltz by khartec.

the class EntityStatisticGenerator method createIntStatsFor.

private void createIntStatsFor(EntityStatisticDefinition defn, Application[] applications, EntityStatisticValueDao valueDao, int bound, BiFunction<StatisticValueState, Integer, String> outcomeFn) {
    Random rnd = RandomUtilities.getRandom();
    List<EntityStatisticValue> values = streamAppRefs(applications).map(appRef -> {
        StatisticValueState state = randomPick(StatisticValueState.values());
        int v = state == StatisticValueState.PROVIDED ? rnd.nextInt(bound) : 0;
        // naughty
        v = rnd.nextInt(bound);
        return ImmutableEntityStatisticValue.builder().entity(appRef).state(state).statisticId(defn.id().get()).current(true).createdAt(LocalDateTime.now()).value(Integer.toString(v)).outcome(outcomeFn.apply(state, v)).provenance(SAMPLE_DATA_PROVENANCE).build();
    }).collect(toList());
    valueDao.bulkSaveValues(values);
}
Also used : OrganisationalUnitDao(org.finos.waltz.data.orgunit.OrganisationalUnitDao) IntStream(java.util.stream.IntStream) ENTITY_STATISTIC_DEFINITION(org.finos.waltz.schema.tables.EntityStatisticDefinition.ENTITY_STATISTIC_DEFINITION) EntityKind(org.finos.waltz.model.EntityKind) BiFunction(java.util.function.BiFunction) ImmutableEntityReference(org.finos.waltz.model.ImmutableEntityReference) LocalDateTime(java.time.LocalDateTime) DIConfiguration(org.finos.waltz.service.DIConfiguration) Random(java.util.Random) Map(java.util.Map) DSLContext(org.jooq.DSLContext) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) ENTITY_STATISTIC_VALUE(org.finos.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) Application(org.finos.waltz.model.application.Application) EntityStatisticDefinitionDao(org.finos.waltz.data.entity_statistic.EntityStatisticDefinitionDao) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) org.finos.waltz.model.entity_statistic(org.finos.waltz.model.entity_statistic) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RandomUtilities(org.finos.waltz.common.RandomUtilities) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) EntityReference(org.finos.waltz.model.EntityReference) EntityStatisticValueDao(org.finos.waltz.data.entity_statistic.EntityStatisticValueDao) Random(java.util.Random)

Example 3 with EntityStatisticValueDao

use of org.finos.waltz.data.entity_statistic.EntityStatisticValueDao 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)

Aggregations

EntityStatisticValueDao (org.finos.waltz.data.entity_statistic.EntityStatisticValueDao)3 DSLContext (org.jooq.DSLContext)3 ApplicationDao (org.finos.waltz.data.application.ApplicationDao)2 EntityStatisticDefinitionDao (org.finos.waltz.data.entity_statistic.EntityStatisticDefinitionDao)2 OrganisationalUnitDao (org.finos.waltz.data.orgunit.OrganisationalUnitDao)2 Application (org.finos.waltz.model.application.Application)2 OrganisationalUnit (org.finos.waltz.model.orgunit.OrganisationalUnit)2 EntityHierarchyService (org.finos.waltz.service.entity_hierarchy.EntityHierarchyService)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 BiFunction (java.util.function.BiFunction)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 RandomUtilities (org.finos.waltz.common.RandomUtilities)1