Search in sources :

Example 21 with IdSelectionOptions

use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.

the class SurveyRunExtractor method getSurveysForEntity.

private SelectWhereStep<?> getSurveysForEntity(EntityReference entityReference) {
    IdSelectionOptions idSelectionOptions = mkOpts(entityReference);
    GenericSelector genericSelectorForChangeInitiativeIds = genericSelectorFactory.applyForKind(EntityKind.CHANGE_INITIATIVE, idSelectionOptions);
    GenericSelector genericSelectorForApplications = genericSelectorFactory.applyForKind(EntityKind.APPLICATION, idSelectionOptions);
    SelectConditionStep<Record14<String, String, String, String, Long, String, String, String, String, Date, String, Date, String, Date>> applicationSurveySelect = DSL.select(ORGANISATIONAL_UNIT.NAME.as("Org Unit"), APPLICATION.ASSET_CODE.as("Entity Id"), APPLICATION.NAME.as("Entity Name"), SURVEY_INSTANCE.ENTITY_KIND.as("Entity Kind"), SURVEY_INSTANCE.ID.as("Survey Instance Id"), SURVEY_TEMPLATE.NAME.as("Survey Template"), SURVEY_RUN.NAME.as("Survey Run"), PERSON.DISPLAY_NAME.as("Survey Owner"), SURVEY_INSTANCE.STATUS.as("Status"), SURVEY_INSTANCE.DUE_DATE.as("Due Date"), SURVEY_INSTANCE.SUBMITTED_BY.as("Submitted By"), DSL.date(SURVEY_INSTANCE.SUBMITTED_AT).as("Submitted At"), SURVEY_INSTANCE.APPROVED_BY.as("Approved By"), DSL.date(SURVEY_INSTANCE.APPROVED_AT).as("Approved At")).from(SURVEY_INSTANCE).innerJoin(SURVEY_RUN).on(SURVEY_INSTANCE.SURVEY_RUN_ID.eq(SURVEY_RUN.ID)).innerJoin(SURVEY_TEMPLATE).on(SURVEY_RUN.SURVEY_TEMPLATE_ID.eq(SURVEY_TEMPLATE.ID).and(SURVEY_TEMPLATE.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))).innerJoin(APPLICATION).on(SURVEY_INSTANCE.ENTITY_KIND.eq(EntityKind.APPLICATION.name()).and(APPLICATION.ID.eq(SURVEY_INSTANCE.ENTITY_ID))).innerJoin(ORGANISATIONAL_UNIT).on(APPLICATION.ORGANISATIONAL_UNIT_ID.eq(ORGANISATIONAL_UNIT.ID)).leftJoin(PERSON).on(SURVEY_RUN.OWNER_ID.eq(PERSON.ID)).where(SURVEY_INSTANCE.ORIGINAL_INSTANCE_ID.isNull().and(APPLICATION.ENTITY_LIFECYCLE_STATUS.eq(EntityLifecycleStatus.ACTIVE.name()).and(APPLICATION.IS_REMOVED.isFalse().and(APPLICATION.ID.in(genericSelectorForApplications.selector())))));
    SelectConditionStep<Record14<String, String, String, String, Long, String, String, String, String, Date, String, Date, String, Date>> changeInitiativeSurveySelect = DSL.select(ORGANISATIONAL_UNIT.NAME.as("Org Unit"), CHANGE_INITIATIVE.EXTERNAL_ID.as("Entity Id"), CHANGE_INITIATIVE.NAME.as("Entity Name"), SURVEY_INSTANCE.ENTITY_KIND.as("Entity Kind"), SURVEY_INSTANCE.ID.as("Survey Instance Id"), SURVEY_TEMPLATE.NAME.as("Survey Template"), SURVEY_RUN.NAME.as("Survey Run"), PERSON.DISPLAY_NAME.as("Survey Owner"), SURVEY_INSTANCE.STATUS.as("Status"), SURVEY_INSTANCE.DUE_DATE.as("Due Date"), SURVEY_INSTANCE.SUBMITTED_BY.as("Submitted By"), DSL.date(SURVEY_INSTANCE.SUBMITTED_AT).as("Submitted At"), SURVEY_INSTANCE.APPROVED_BY.as("Approved By"), DSL.date(SURVEY_INSTANCE.APPROVED_AT).as("Approved At")).from(SURVEY_INSTANCE).innerJoin(SURVEY_RUN).on(SURVEY_INSTANCE.SURVEY_RUN_ID.eq(SURVEY_RUN.ID)).innerJoin(SURVEY_TEMPLATE).on(SURVEY_RUN.SURVEY_TEMPLATE_ID.eq(SURVEY_TEMPLATE.ID).and(SURVEY_TEMPLATE.TARGET_ENTITY_KIND.eq(EntityKind.CHANGE_INITIATIVE.name()))).innerJoin(CHANGE_INITIATIVE).on(SURVEY_INSTANCE.ENTITY_KIND.eq(EntityKind.CHANGE_INITIATIVE.name()).and(CHANGE_INITIATIVE.ID.eq(SURVEY_INSTANCE.ENTITY_ID))).innerJoin(ORGANISATIONAL_UNIT).on(CHANGE_INITIATIVE.ORGANISATIONAL_UNIT_ID.eq(ORGANISATIONAL_UNIT.ID)).leftJoin(PERSON).on(SURVEY_RUN.OWNER_ID.eq(PERSON.ID)).where(SURVEY_INSTANCE.ORIGINAL_INSTANCE_ID.isNull().and(CHANGE_INITIATIVE.ID.in(genericSelectorForChangeInitiativeIds.selector())));
    return dsl.selectFrom(applicationSurveySelect.union(changeInitiativeSurveySelect).asTable());
}
Also used : GenericSelector(org.finos.waltz.data.GenericSelector) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 22 with IdSelectionOptions

use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.

the class RoadmapGenerator method populateScenario.

private void populateScenario(ApplicationContext ctx, Scenario scenario) {
    ScenarioAxisItemDao scenarioAxisItemDao = getScenarioAxisItemDao(ctx);
    MeasurableRatingService measurableRatingService = getMeasurableRatingService(ctx);
    scenario.id().ifPresent(scenarioId -> {
        Collection<ScenarioAxisItem> axisItems = scenarioAxisItemDao.findForScenarioId(scenarioId);
        Map<AxisOrientation, Collection<ScenarioAxisItem>> byOrientation = groupBy(ScenarioAxisItem::axisOrientation, axisItems);
        IdSelectionOptions options = mkOpts(scenario.entityReference());
        Map<Long, Collection<MeasurableRating>> ratingsByMeasurableId = groupBy(MeasurableRating::measurableId, measurableRatingService.findByMeasurableIdSelector(options));
        List<ScenarioRatingItemRecord> scenarioRatingItems = IntStream.range(0, randomIntBetween(10, 300)).mapToObj(i -> tuple(randomPick(byOrientation.get(AxisOrientation.COLUMN)), randomPick(byOrientation.get(AxisOrientation.ROW)))).map(t -> t.map1(d -> d.domainItem().id()).map2(d -> d.domainItem().id())).map(t -> t.concat(tuple(randomPick(ratingsByMeasurableId.get(t.v1)), randomPick(ratingsByMeasurableId.get(t.v2))))).map(t -> {
            MeasurableRating rating = t.v3 != null ? t.v3 : t.v4;
            ScenarioRatingItemRecord record = getDsl(ctx).newRecord(SCENARIO_RATING_ITEM);
            record.setScenarioId(scenarioId);
            record.setColumnId(t.v1);
            record.setColumnKind(EntityKind.MEASURABLE.name());
            record.setRowId(t.v2);
            record.setRowKind(EntityKind.MEASURABLE.name());
            record.setDomainItemId(rating.entityReference().id());
            record.setDomainItemKind(rating.entityReference().kind().name());
            record.setRating(String.valueOf(rating.rating()));
            record.setLastUpdatedBy("admin");
            record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
            return record;
        }).collect(Collectors.toList());
        getDsl(ctx).batchInsert(scenarioRatingItems).execute();
    });
}
Also used : IntStream(java.util.stream.IntStream) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) java.util(java.util) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) DSL(org.jooq.impl.DSL) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) RandomUtilities.randomIntBetween(org.finos.waltz.common.RandomUtilities.randomIntBetween) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) Scenario(org.finos.waltz.model.scenario.Scenario) SelectConditionStep(org.jooq.SelectConditionStep) ObjectUtilities.any(org.finos.waltz.common.ObjectUtilities.any) MeasurableRatingDao(org.finos.waltz.data.measurable_rating.MeasurableRatingDao) Measurable(org.finos.waltz.model.measurable.Measurable) Record1(org.jooq.Record1) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) DSLContext(org.jooq.DSLContext) ROADMAP(org.finos.waltz.schema.tables.Roadmap.ROADMAP) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) ScenarioDao(org.finos.waltz.data.scenario.ScenarioDao) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) AxisOrientation(org.finos.waltz.model.AxisOrientation) MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) ListUtilities.filter(org.finos.waltz.common.ListUtilities.filter) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) RoadmapDao(org.finos.waltz.data.roadmap.RoadmapDao) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) EntityReference(org.finos.waltz.model.EntityReference) Roadmap(org.finos.waltz.model.roadmap.Roadmap) MeasurableIdSelectorFactory(org.finos.waltz.data.measurable.MeasurableIdSelectorFactory) MeasurableRatingService(org.finos.waltz.service.measurable_rating.MeasurableRatingService) ScenarioAxisItem(org.finos.waltz.model.scenario.ScenarioAxisItem) MeasurableRating(org.finos.waltz.model.measurable_rating.MeasurableRating) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) ScenarioAxisItemDao(org.finos.waltz.data.scenario.ScenarioAxisItemDao) AxisOrientation(org.finos.waltz.model.AxisOrientation) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 23 with IdSelectionOptions

use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.

the class ChangeInitiativeHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ChangeInitiativeDao dao = ctx.getBean(ChangeInitiativeDao.class);
    ChangeInitiativeIdSelectorFactory selectorFactory = new ChangeInitiativeIdSelectorFactory();
    IdSelectionOptions opts = mkOpts(mkRef(EntityKind.APP_GROUP, 2), HierarchyQueryScope.EXACT);
    Select<Record1<Long>> selector = selectorFactory.apply(opts);
    dsl.fetch(selector).formatCSV(System.out);
    dao.findForSelector(selector);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ChangeInitiativeDao(org.finos.waltz.data.change_initiative.ChangeInitiativeDao) DSLContext(org.jooq.DSLContext) ChangeInitiativeIdSelectorFactory(org.finos.waltz.data.change_initiative.ChangeInitiativeIdSelectorFactory) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 24 with IdSelectionOptions

use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.

the class DatabaseHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DatabaseInformationService databaseInfoService = ctx.getBean(DatabaseInformationService.class);
    DatabaseInformationDao databaseDao = ctx.getBean(DatabaseInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    /*
        List<DatabaseInformation> dbs = databaseDao.findByApplicationId(801L);
        System.out.println(dbs.size());


        List<Tally<String>> eolCounts = calculateStringTallies(
                dsl,
                DATABASE_INFORMATION,
                DSL.when(DATABASE_INFORMATION.END_OF_LIFE_DATE.lt(DSL.currentDate()), DSL.inline(EndOfLifeStatus.END_OF_LIFE.name()))
                        .otherwise(DSL.inline(EndOfLifeStatus.NOT_END_OF_LIFE.name())),
                DSL.trueCondition());

        System.out.println(eolCounts);
        */
    IdSelectionOptions options = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.ORG_UNIT, 10), HierarchyQueryScope.CHILDREN);
    for (int i = 0; i < 5; i++) {
        HarnessUtilities.time("stats", () -> databaseInfoService.calculateStatsForAppIdSelector(options));
    }
}
Also used : DatabaseInformationDao(org.finos.waltz.data.database_information.DatabaseInformationDao) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) DatabaseInformationService(org.finos.waltz.service.database_information.DatabaseInformationService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 25 with IdSelectionOptions

use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.

the class ApplicationIdSelectorHarness method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ApplicationIdSelectorFactory factory = new ApplicationIdSelectorFactory();
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationService applicationService = ctx.getBean(ApplicationService.class);
    IdSelectionOptions options = mkOpts(EntityReference.mkRef(EntityKind.DATA_TYPE, 5000L), HierarchyQueryScope.CHILDREN);
    Select<Record1<Long>> selector = factory.apply(options);
    dsl.settings().withRenderFormatted(true);
    List<Application> apps = applicationService.findByAppIdSelector(options);
    System.out.println("--- sz: " + apps.size());
    apps.forEach(System.out::println);
    System.out.println("--- done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) DSLContext(org.jooq.DSLContext) Application(org.finos.waltz.model.application.Application) ApplicationService(org.finos.waltz.service.application.ApplicationService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Aggregations

IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)39 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)15 EntityReference (org.finos.waltz.model.EntityReference)14 Record1 (org.jooq.Record1)9 DSLContext (org.jooq.DSLContext)8 EntityKind (org.finos.waltz.model.EntityKind)7 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)6 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)5 LogicalFlowService (org.finos.waltz.service.logical_flow.LogicalFlowService)5 Collection (java.util.Collection)4 List (java.util.List)4 GenericSelector (org.finos.waltz.data.GenericSelector)4 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)4 Set (java.util.Set)3 MeasurableIdSelectorFactory (org.finos.waltz.data.measurable.MeasurableIdSelectorFactory)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 Collections.emptySet (java.util.Collections.emptySet)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2