Search in sources :

Example 6 with GenericSelector

use of org.finos.waltz.data.GenericSelector 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 7 with GenericSelector

use of org.finos.waltz.data.GenericSelector in project waltz by khartec.

the class ComplexityExtractor method register.

@Override
public void register() {
    String findBySelectorPath = WebUtilities.mkPath("data-extract", "complexity", "target-kind", ":kind", "selector");
    post(findBySelectorPath, (request, response) -> {
        IdSelectionOptions idSelectionOptions = WebUtilities.readIdSelectionOptionsFromBody(request);
        EntityKind targetKind = WebUtilities.getKind(request);
        GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, idSelectionOptions);
        SelectConditionStep<Record> qry = dsl.select(ENTITY_NAME_FIELD.as("Entity Name")).select(COMPLEXITY.ENTITY_ID).select(COMPLEXITY_KIND.NAME.as("Complexity Kind")).select(COMPLEXITY.SCORE.as("Score")).select(COMPLEXITY.PROVENANCE).from(COMPLEXITY).innerJoin(COMPLEXITY_KIND).on(COMPLEXITY.COMPLEXITY_KIND_ID.eq(COMPLEXITY_KIND.ID)).where(COMPLEXITY.ENTITY_ID.in(genericSelector.selector()).and(COMPLEXITY.ENTITY_KIND.eq(genericSelector.kind().name())));
        return writeExtract(mkFilename(idSelectionOptions), qry, request, response);
    });
}
Also used : GenericSelector(org.finos.waltz.data.GenericSelector) Record(org.jooq.Record) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) EntityKind(org.finos.waltz.model.EntityKind)

Example 8 with GenericSelector

use of org.finos.waltz.data.GenericSelector in project waltz by khartec.

the class PeopleExtractor method registerExtractForApp.

private void registerExtractForApp(String path) {
    post(path, (request, response) -> {
        EntityReference entityRef = WebUtilities.getEntityReference(request);
        IdSelectionOptions selectionOptions = mkOpts(entityRef, HierarchyQueryScope.determineUpwardsScopeForKind(entityRef.kind()));
        GenericSelector selector = genericSelectorFactory.apply(selectionOptions);
        SelectSeekStep1<Record5<String, String, String, String, String>, String> qry = dsl.select(PERSON.DISPLAY_NAME.as("Name"), PERSON.TITLE.as("Title"), PERSON.OFFICE_PHONE.as("Telephone"), PERSON.EMAIL.as("Email"), INVOLVEMENT_KIND.NAME.as("Role")).from(PERSON).innerJoin(INVOLVEMENT).on(INVOLVEMENT.EMPLOYEE_ID.eq(PERSON.EMPLOYEE_ID)).innerJoin(INVOLVEMENT_KIND).on(INVOLVEMENT_KIND.ID.eq(INVOLVEMENT.KIND_ID)).where(INVOLVEMENT.ENTITY_ID.in(selector.selector()).and(INVOLVEMENT.ENTITY_KIND.eq(selector.kind().name()))).orderBy(PERSON.DISPLAY_NAME);
        return writeExtract("involved_people", qry, request, response);
    });
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) WebUtilities.getEntityReference(org.finos.waltz.web.WebUtilities.getEntityReference) GenericSelector(org.finos.waltz.data.GenericSelector) Record5(org.jooq.Record5) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 9 with GenericSelector

use of org.finos.waltz.data.GenericSelector in project waltz by khartec.

the class SurveyRunService method generateSurveyInstanceOwners.

public List<SurveyInstanceOwner> generateSurveyInstanceOwners(InstancesAndRecipientsCreateCommand command) {
    SurveyRun surveyRun = surveyRunDao.getById(command.surveyRunId());
    checkNotNull(surveyRun, "surveyRun " + command.surveyRunId() + " not found");
    SurveyTemplate surveyTemplate = surveyTemplateDao.getById(surveyRun.surveyTemplateId());
    checkNotNull(surveyTemplate, "surveyTemplate " + surveyRun.surveyTemplateId() + " not found");
    GenericSelector genericSelector = genericSelectorFactory.applyForKind(surveyTemplate.targetEntityKind(), surveyRun.selectionOptions());
    Map<EntityReference, List<Person>> entityRefToPeople = involvementDao.findPeopleByEntitySelectorAndInvolvement(surveyTemplate.targetEntityKind(), genericSelector.selector(), surveyRun.ownerInvKindIds());
    return entityRefToPeople.entrySet().stream().flatMap(e -> e.getValue().stream().map(p -> ImmutableSurveyInstanceOwner.builder().surveyInstance(ImmutableSurveyInstance.builder().surveyEntity(e.getKey()).surveyRunId(command.surveyRunId()).status(SurveyInstanceStatus.NOT_STARTED).dueDate(command.dueDate()).approvalDueDate(command.approvalDueDate()).owningRole(command.owningRole()).build()).person(p).build())).distinct().collect(toList());
}
Also used : org.finos.waltz.data.survey(org.finos.waltz.data.survey) java.util(java.util) org.finos.waltz.model(org.finos.waltz.model) InvolvementDao(org.finos.waltz.data.involvement.InvolvementDao) GenericSelector(org.finos.waltz.data.GenericSelector) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Autowired(org.springframework.beans.factory.annotation.Autowired) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) Person(org.finos.waltz.model.person.Person) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) GenericSelectorFactory(org.finos.waltz.data.GenericSelectorFactory) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Select(org.jooq.Select) ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) org.finos.waltz.model.survey(org.finos.waltz.model.survey) PersonDao(org.finos.waltz.data.person.PersonDao) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) ListUtilities.map(org.finos.waltz.common.ListUtilities.map) Collectors.toList(java.util.stream.Collectors.toList) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ListUtilities(org.finos.waltz.common.ListUtilities) LocalDate(java.time.LocalDate) SetUtilities(org.finos.waltz.common.SetUtilities) SetUtilities.fromCollection(org.finos.waltz.common.SetUtilities.fromCollection) GenericSelector(org.finos.waltz.data.GenericSelector) Collectors.toList(java.util.stream.Collectors.toList)

Example 10 with GenericSelector

use of org.finos.waltz.data.GenericSelector in project waltz by khartec.

the class CostService method summariseByCostKindAndSelector.

public EntityCostsSummary summariseByCostKindAndSelector(Long costKindId, IdSelectionOptions selectionOptions, EntityKind targetKind, int limit) {
    GenericSelector genericSelector = genericSelectorFactory.applyForKind(targetKind, selectionOptions);
    Set<EntityCost> topCosts = time("topCosts: " + selectionOptions.entityReference(), () -> costDao.findTopCostsForCostKindAndSelector(costKindId, genericSelector, limit));
    Integer year = maybeFirst(topCosts).map(EntityCost::year).orElse(LocalDate.now().getYear());
    BigDecimal totalCost = time("totalCosts: " + selectionOptions.entityReference(), () -> costDao.getTotalForKindAndYearBySelector(costKindId, year, genericSelector));
    Tuple2<Integer, Integer> mappedAndMissingCounts = time("missingCosts: " + selectionOptions.entityReference(), () -> costDao.getMappedAndMissingCountsForKindAndYearBySelector(costKindId, year, genericSelector));
    return ImmutableEntityCostsSummary.builder().costKind(costKindDao.getById(costKindId)).year(year).total(ofNullable(totalCost).orElse(BigDecimal.ZERO)).topCosts(topCosts).mappedCount(mappedAndMissingCounts.v1).missingCount(mappedAndMissingCounts.v2).build();
}
Also used : EntityCost(org.finos.waltz.model.cost.EntityCost) GenericSelector(org.finos.waltz.data.GenericSelector) BigDecimal(java.math.BigDecimal)

Aggregations

GenericSelector (org.finos.waltz.data.GenericSelector)13 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)4 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 java.util (java.util)2 Collectors.groupingBy (java.util.stream.Collectors.groupingBy)2 Collectors.toList (java.util.stream.Collectors.toList)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)2 ListUtilities (org.finos.waltz.common.ListUtilities)2 ListUtilities.map (org.finos.waltz.common.ListUtilities.map)2 MapUtilities.groupBy (org.finos.waltz.common.MapUtilities.groupBy)2 MapUtilities.indexBy (org.finos.waltz.common.MapUtilities.indexBy)2 SetUtilities (org.finos.waltz.common.SetUtilities)2 SetUtilities.fromCollection (org.finos.waltz.common.SetUtilities.fromCollection)2 GenericSelectorFactory (org.finos.waltz.data.GenericSelectorFactory)2 InvolvementDao (org.finos.waltz.data.involvement.InvolvementDao)2 PersonDao (org.finos.waltz.data.person.PersonDao)2 org.finos.waltz.data.survey (org.finos.waltz.data.survey)2 org.finos.waltz.model (org.finos.waltz.model)2