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());
}
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);
});
}
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);
});
}
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());
}
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();
}
Aggregations