public static void main(String[] args) { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); ApplicationIdSelectorFactory factory = ctx.getBean(ApplicationIdSelectorFactory.class); DSLContext dsl = ctx.getBean(DSLContext.class); ApplicationService applicationService = ctx.getBean(ApplicationService.class); IdSelectionOptions options = IdSelectionOptions.mkOpts( EntityReference.mkRef(EntityKind.MEASURABLE, 1L), HierarchyQueryScope.EXACT); Select<Record1<Long>> selector = factory.apply(options); System.out.println(selector); List<Application> apps = applicationService.findByAppIdSelector(options); System.out.println("--- sz: "+apps.size()); apps.forEach(System.out::println); System.out.println("--- done"); }
public List<LogicalFlowDecorator> findByIdSelectorAndKind(IdSelectionOptions options, EntityKind decoratorEntityKind) { checkNotNull(options, "options cannot be null"); checkNotNull(decoratorEntityKind, "decoratorEntityKind cannot be null"); switch (options.entityReference().kind()) { case APPLICATION: case APP_GROUP: case ORG_UNIT: case PERSON: Select<Record1<Long>> selector = applicationIdSelectorFactory.apply(options); return logicalFlowDecoratorDao.findByEntityIdSelectorAndKind( APPLICATION, selector, decoratorEntityKind); case ACTOR: long actorId = options.entityReference().id(); Select<Record1<Long>> actorIdSelector = DSL.select(DSL.val(actorId)); return logicalFlowDecoratorDao.findByEntityIdSelectorAndKind( ACTOR, actorIdSelector, decoratorEntityKind); default: throw new UnsupportedOperationException("Cannot find decorators for selector kind: " + options.entityReference().kind()); } }
private Collection<OrganisationalUnit> getAllRelatedOrgUnits(long orgUnitId) { IdSelectionOptions parentSelectorOptions = ImmutableIdSelectionOptions .builder() .entityReference(ImmutableEntityReference.builder() .id(orgUnitId) .kind(EntityKind.ORG_UNIT) .build()) .scope(HierarchyQueryScope.PARENTS) .build(); IdSelectionOptions childSelectorOptions = ImmutableIdSelectionOptions .copyOf(parentSelectorOptions) .withScope(HierarchyQueryScope.CHILDREN); Select<Record1<Long>> parentSelector = selectorFactory.apply(parentSelectorOptions); Select<Record1<Long>> childSelector = selectorFactory.apply(childSelectorOptions); Select<Record1<Long>> relatedSelector = DSL.selectFrom(parentSelector.asTable()).union(childSelector); List<OrganisationalUnit> related = dao.findBySelector(relatedSelector); return SetUtilities.fromCollection(related); }
private LogicalFlowStatistics calculateStatsForAppIdSelector(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select<Record1<Long>> appIdSelector = appIdSelectorFactory.apply(options); Future<List<TallyPack<String>>> dataTypeCounts = dbExecutorPool.submit(() -> FunctionUtilities.time("DFS.dataTypes", () -> logicalFlowStatsDao.tallyDataTypesByAppIdSelector(appIdSelector))); Future<LogicalFlowMeasures> appCounts = dbExecutorPool.submit(() -> FunctionUtilities.time("DFS.appCounts", () -> logicalFlowStatsDao.countDistinctAppInvolvementByAppIdSelector(appIdSelector))); Future<LogicalFlowMeasures> flowCounts = dbExecutorPool.submit(() -> FunctionUtilities.time("DFS.flowCounts", () -> logicalFlowStatsDao.countDistinctFlowInvolvementByAppIdSelector(appIdSelector))); Supplier<ImmutableLogicalFlowStatistics> statSupplier = Unchecked.supplier(() -> ImmutableLogicalFlowStatistics.builder() .dataTypeCounts(dataTypeCounts.get()) .appCounts(appCounts.get()) .flowCounts(flowCounts.get()) .build()); return statSupplier.get(); }
public TallyPack<String> calculateStatTally(Long statisticId, RollupKind rollupKind, IdSelectionOptions options) { Checks.checkNotNull(statisticId, "statisticId cannot be null"); Checks.checkNotNull(options, "options cannot be null"); Checks.checkNotNull(rollupKind, "rollupKind cannot be null"); Select<Record1<Long>> appIdSelector = factory.apply(options); switch(rollupKind) { case COUNT_BY_ENTITY: return summaryDao.generateWithCountByEntity(statisticId, appIdSelector); case SUM_BY_VALUE: return summaryDao.generateWithSumByValue(statisticId, appIdSelector); case AVG_BY_VALUE: return summaryDao.generateWithAvgByValue(statisticId, appIdSelector); case NONE: return summaryDao.generateWithNoRollup(statisticId, options.entityReference()); default: throw new UnsupportedOperationException(String.format("Rollup kind [%s] not supported.", rollupKind)); } }
public List<TallyPack<String>> calculateHistoricStatTally(Long statisticId, RollupKind rollupKind, IdSelectionOptions options, Duration duration) { Checks.checkNotNull(statisticId, "statisticId cannot be null"); Checks.checkNotNull(rollupKind, "rollupKind cannot be null"); Checks.checkNotNull(options, "options cannot be null"); Checks.checkNotNull(duration, "duration cannot be null"); Select<Record1<Long>> appIdSelector = factory.apply(options); switch(rollupKind) { case COUNT_BY_ENTITY: return summaryDao.generateHistoricWithCountByEntity(statisticId, appIdSelector, duration); case SUM_BY_VALUE: return summaryDao.generateHistoricWithSumByValue(statisticId, appIdSelector, duration); case AVG_BY_VALUE: return summaryDao.generateHistoricWithAvgByValue(statisticId, appIdSelector, duration); case NONE: return summaryDao.generateHistoricWithNoRollup(statisticId, options.entityReference(), duration); default: throw new UnsupportedOperationException(String.format("Rollup kind [%s] not supported.", rollupKind)); } }
private Select<Record1<Long>> mkForRef(IdSelectionOptions options) { EntityReference ref = options.entityReference(); Select<Record1<Long>> aToB = selectDistinct(ENTITY_RELATIONSHIP.ID_A) .from(ENTITY_RELATIONSHIP) .where(ENTITY_RELATIONSHIP.KIND_A.eq(EntityKind.CHANGE_INITIATIVE.name())) .and(ENTITY_RELATIONSHIP.KIND_B.eq(ref.kind().name())) .and(ENTITY_RELATIONSHIP.ID_B.eq(ref.id())); Select<Record1<Long>> bToA = selectDistinct(ENTITY_RELATIONSHIP.ID_B) .from(ENTITY_RELATIONSHIP) .where(ENTITY_RELATIONSHIP.KIND_B.eq(EntityKind.CHANGE_INITIATIVE.name())) .and(ENTITY_RELATIONSHIP.KIND_A.eq(ref.kind().name())) .and(ENTITY_RELATIONSHIP.ID_A.eq(ref.id())); return aToB.union(bToA); }
@Override public Select<Record1<Long>> apply(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); switch (options.entityReference().kind()) { case APPLICATION: case APP_GROUP: case MEASURABLE: case ORG_UNIT: case PERSON: return wrapAppIdSelector(options); case DATA_TYPE: return mkForDataType(options); case FLOW_DIAGRAM: return mkForFlowDiagram(options); case PHYSICAL_SPECIFICATION: return mkForPhysicalSpecification(options); default: throw new UnsupportedOperationException("Cannot create physical specification selector from options: " + options); } }
private Select<Record1<Long>> mkForSelf(IdSelectionOptions options) { Select<Record1<Long>> selector = null; switch (options.scope()) { case EXACT: selector = DSL.select(DSL.val(options.entityReference().id())); break; case CHILDREN: selector = DSL.select(ENTITY_HIERARCHY.ID) .from(ENTITY_HIERARCHY) .where(ENTITY_HIERARCHY.ANCESTOR_ID.eq(options.entityReference().id())) .and(ENTITY_HIERARCHY.KIND.eq(entityKind.name())); break; case PARENTS: selector = DSL.select(ENTITY_HIERARCHY.ANCESTOR_ID) .from(ENTITY_HIERARCHY) .where(ENTITY_HIERARCHY.ID.eq(options.entityReference().id())) .and(ENTITY_HIERARCHY.KIND.eq(entityKind.name())); break; } return selector; }
@Override public Select<Record1<Long>> apply(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); switch(options.entityReference().kind()) { case ACTOR: case APPLICATION: case LOGICAL_DATA_FLOW: case PHYSICAL_FLOW: case MEASURABLE: return mkForDirectEntity(options); case PHYSICAL_SPECIFICATION: return mkForPhysicalSpecification(options); default: throw new UnsupportedOperationException("Cannot create physical flow selector from options: "+options); } }
@Override public Select<Record1<Long>> apply(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); switch(options.entityReference().kind()) { case PHYSICAL_FLOW: return mkForPhysicalFlow(options); case LOGICAL_DATA_FLOW: return mkForLogicalFlow(options); case FLOW_DIAGRAM: return mkForFlowDiagram(options); case PHYSICAL_SPECIFICATION: return mkForSpecification(options); default: throw new UnsupportedOperationException("Cannot create physical specification selector from options: "+options); } }
private static void deleteSurveyRunsAndResponses(DSLContext dsl) { Condition previousSurveyRunCondition = SURVEY_RUN.NAME.like("% " + SURVEY_RUN_SUFFIX); Select<Record1<Long>> surveyRunIdSelector = DSL .select(SURVEY_RUN.ID) .from(SURVEY_RUN) .where(previousSurveyRunCondition); Select<Record1<Long>> surveyInstanceIdSelector = DSL .select(SURVEY_INSTANCE.ID) .from(SURVEY_INSTANCE) .where(SURVEY_INSTANCE.SURVEY_RUN_ID.in(surveyRunIdSelector)); int deleteCount = dsl .deleteFrom(SURVEY_QUESTION_RESPONSE) .where(SURVEY_QUESTION_RESPONSE.SURVEY_INSTANCE_ID.in(surveyInstanceIdSelector)) .execute(); LOG.debug("Deleted: {} existing question responses", deleteCount); deleteCount = dsl .deleteFrom(SURVEY_INSTANCE_RECIPIENT) .where(SURVEY_INSTANCE_RECIPIENT.SURVEY_INSTANCE_ID.in(surveyInstanceIdSelector)) .execute(); LOG.debug("Deleted: {} existing instance recipients", deleteCount); deleteCount = dsl .deleteFrom(SURVEY_INSTANCE) .where(SURVEY_INSTANCE.SURVEY_RUN_ID.in(surveyRunIdSelector)) .execute(); LOG.debug("Deleted: {} existing survey instances", deleteCount); deleteCount = dsl .deleteFrom(SURVEY_RUN) .where(previousSurveyRunCondition) .execute(); LOG.debug("Deleted: {} existing survey runs", deleteCount); }
public static void main(String[] args) throws ParseException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class); DSLContext dsl = ctx.getBean(DSLContext.class); LogicalFlowService service = ctx.getBean(LogicalFlowService.class); LogicalFlowDao dao = ctx.getBean(LogicalFlowDao.class); LogicalFlowIdSelectorFactory factory = ctx.getBean(LogicalFlowIdSelectorFactory.class); IdSelectionOptions options = IdSelectionOptions.mkOpts( EntityReference.mkRef(EntityKind.ORG_UNIT, 5000), HierarchyQueryScope.CHILDREN); Select<Record1<Long>> selector = factory.apply(options); System.out.println(selector); List<LogicalFlow> flows = dao.findBySelector(selector); flows.forEach(System.out::println); // by data type EntityReference dataType = EntityReference.mkRef(EntityKind.DATA_TYPE, 6000); IdSelectionOptions dataTypeOptions = IdSelectionOptions.mkOpts(dataType, HierarchyQueryScope.CHILDREN); List<LogicalFlow> byDataTypeFlows = service.findBySelector(dataTypeOptions); byDataTypeFlows.forEach(System.out::println); System.out.println(byDataTypeFlows.size()); }
public List<ComplexityScore> findByAppIdSelector(Select<Record1<Long>> idSelector, int baseline) { return serverComplexityDao.findCountsByAppIdSelector(idSelector) .stream() .map(tally -> tallyToComplexityScore( ComplexityKind.SERVER, tally, baseline, Math::log)) .collect(Collectors.toList()); }
public List<ComplexityScore> findByAppIdSelector(Select<Record1<Long>> idSelector, double baseline) { return measurableComplexityDao.findScoresForAppIdSelector(idSelector) .stream() .map(tally -> tallyToComplexityScore( ComplexityKind.MEASURABLE, tally, baseline)) .collect(Collectors.toList()); }
public List<NonAuthoritativeSource> findNonAuthSources(EntityReference parentRef) { Condition customSelectionCriteria; switch(parentRef.kind()) { case DATA_TYPE: Select<Record1<Long>> dtSelector = dataTypeIdSelectorFactory.apply(mkOpts( parentRef, HierarchyQueryScope.CHILDREN)); customSelectionCriteria = LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID.in(dtSelector); break; case ORG_UNIT: Select<Record1<Long>> ouSelector = organisationalUnitIdSelectorFactory.apply(mkOpts( parentRef, HierarchyQueryScope.CHILDREN)); customSelectionCriteria = AuthoritativeSourceDao.CONSUMER_APP.ORGANISATIONAL_UNIT_ID.in(ouSelector); break; case MEASURABLE: case PERSON: customSelectionCriteria = mkConsumerSelectionCondition(parentRef, HierarchyQueryScope.CHILDREN); break; case APP_GROUP: case FLOW_DIAGRAM: customSelectionCriteria = mkConsumerSelectionCondition(parentRef, HierarchyQueryScope.EXACT); break; default: throw new UnsupportedOperationException("Cannot calculate non-auth sources for ref" + parentRef); } return authoritativeSourceDao.findNonAuthSources(customSelectionCriteria); }
public List<AuthoritativeSource> findAuthSources(EntityReference parentRef) { Condition customSelectionCriteria; switch(parentRef.kind()) { case ORG_UNIT: Select<Record1<Long>> ouSelector = organisationalUnitIdSelectorFactory.apply( mkOpts(parentRef, HierarchyQueryScope.PARENTS)); customSelectionCriteria = AUTHORITATIVE_SOURCE.PARENT_ID.in(ouSelector); break; case DATA_TYPE: Select<Record1<Long>> dtSelector = dataTypeIdSelectorFactory.apply( mkOpts(parentRef, HierarchyQueryScope.CHILDREN)); SelectConditionStep<Record1<String>> codeSelector = DSL .select(DATA_TYPE.CODE) .from(DATA_TYPE) .where(DATA_TYPE.ID.in(dtSelector)); customSelectionCriteria = AUTHORITATIVE_SOURCE.DATA_TYPE.in(codeSelector); break; case MEASURABLE: case PERSON: customSelectionCriteria = mkConsumerSelectionCondition(parentRef, HierarchyQueryScope.CHILDREN); break; case APP_GROUP: case FLOW_DIAGRAM: customSelectionCriteria = mkConsumerSelectionCondition(parentRef, HierarchyQueryScope.EXACT); break; default: throw new UnsupportedOperationException("Cannot calculate auth sources for ref" + parentRef); } return authoritativeSourceDao.findAuthSources(customSelectionCriteria); }
private int[] update(DataType dataType, EntityReference vantageRef) { LOG.info("Updating ratings for auth source - dataType: {}, vantage point: {}", dataType, vantageRef); IdSelectionOptions selectorOptions = mkOpts(vantageRef, HierarchyQueryScope.CHILDREN); Select<Record1<Long>> selector = appIdSelectorFactory.apply(selectorOptions); Collection<LogicalFlowDecorator> impactedDecorators = logicalFlowDecoratorDao .findByEntityIdSelectorAndKind( EntityKind.APPLICATION, selector, EntityKind.DATA_TYPE) .stream() .filter(decorator -> decorator.decoratorEntity().id() == dataType.id().get()) .collect(toList()); Collection<LogicalFlowDecorator> reRatedDecorators = ratingsCalculator.calculate(impactedDecorators); Set<LogicalFlowDecorator> modifiedDecorators = SetUtilities.minus( fromCollection(reRatedDecorators), fromCollection(impactedDecorators)); LOG.info("Need to update {} ratings due to auth source change - dataType: {}, parent: {}", modifiedDecorators.size(), dataType, vantageRef); return updateDecorators(modifiedDecorators); }
public boolean recalculateForApplications(Collection<EntityReference> refs) { checkNotNull(refs, "refs cannot be null"); Set<Long> appIds = refs .stream() .filter(r -> r.kind() == EntityKind.APPLICATION) .map(r -> r.id()) .collect(Collectors.toSet()); if (isEmpty(appIds)) { return true; } else { Select<Record1<Long>> idSelector = convertApplicationIdsToIdSelector(appIds); return dataTypeUsageDao.recalculateForAppIdSelector(idSelector); } }
public List<TallyPack<String>> findStatTallies(List<Long> statisticIds, IdSelectionOptions options) { Checks.checkNotNull(statisticIds, "statisticIds cannot be null"); Checks.checkNotNull(options, "options cannot be null"); Select<Record1<Long>> appIdSelector = factory.apply(options); Map<RollupKind, Collection<Long>> definitionIdsByRollupKind = groupBy( d -> d.rollupKind(), d -> d.id().orElse(null), definitionDao.findByIds(statisticIds)); return concat( summaryDao.generateWithCountByEntity( definitionIdsByRollupKind.getOrDefault(RollupKind.COUNT_BY_ENTITY, emptyList()), appIdSelector), summaryDao.generateWithSumByValue( definitionIdsByRollupKind.getOrDefault(RollupKind.SUM_BY_VALUE, emptyList()), appIdSelector), summaryDao.generateWithAvgByValue( definitionIdsByRollupKind.getOrDefault(RollupKind.AVG_BY_VALUE, emptyList()), appIdSelector), summaryDao.generateWithNoRollup( definitionIdsByRollupKind.getOrDefault(RollupKind.NONE, emptyList()), options.entityReference()) ); }
public List<SurveyInstanceRecipient> generateSurveyInstanceRecipients(long surveyRunId) { SurveyRun surveyRun = surveyRunDao.getById(surveyRunId); checkNotNull(surveyRun, "surveyRun " + surveyRunId + " not found"); SurveyTemplate surveyTemplate = surveyTemplateDao.getById(surveyRun.surveyTemplateId()); checkNotNull(surveyTemplate, "surveyTemplate " + surveyRun.surveyTemplateId() + " not found"); IdSelectorFactory idSelectorFactory = idSelectorFactoryProvider.getForKind(surveyTemplate.targetEntityKind()); Select<Record1<Long>> idSelector = idSelectorFactory.apply(surveyRun.selectionOptions()); Map<EntityReference, List<Person>> entityRefToPeople = involvementDao.findPeopleByEntitySelectorAndInvolvement( surveyTemplate.targetEntityKind(), idSelector, surveyRun.involvementKindIds()); return entityRefToPeople.entrySet() .stream() .flatMap(e -> e.getValue().stream() .map(p -> ImmutableSurveyInstanceRecipient.builder() .surveyInstance(ImmutableSurveyInstance.builder() .surveyEntity(e.getKey()) .surveyRunId(surveyRun.id().get()) .status(SurveyInstanceStatus.NOT_STARTED) .dueDate(surveyRun.dueDate()) .build()) .person(p) .build())) .distinct() .collect(toList()); }
@Override public Select<Record1<Long>> apply(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); EntityReference ref = options.entityReference(); switch (ref.kind()) { case APP_GROUP: case APPLICATION: case CHANGE_INITIATIVE: return mkForNonHierarchicalEntity(ref, options.scope()); case ORG_UNIT: return mkForOrgUnit(ref, options.scope()); default: throw new IllegalArgumentException("Cannot create selector for entity kind: " + ref.kind()); } }
private Select<Record1<Long>> mkForNonHierarchicalEntity(EntityReference ref, HierarchyQueryScope scope) { checkTrue(scope == EXACT, "Can only create selector for exact matches if given a non-hierarchical ref"); return dsl .select(SURVEY_INSTANCE.ID) .from(SURVEY_INSTANCE) .where(SURVEY_INSTANCE.ENTITY_KIND.eq(ref.kind().name()) .and(SURVEY_INSTANCE.ENTITY_ID.eq(ref.id()))); }
private SelectConditionStep<Record1<Long>> mkForOrgUnit(EntityReference ref, HierarchyQueryScope scope) { ImmutableIdSelectionOptions ouSelectorOptions = ImmutableIdSelectionOptions.builder() .entityReference(ref) .scope(scope) .build(); Select<Record1<Long>> ouSelector = orgUnitIdSelectorFactory.apply(ouSelectorOptions); return dsl .selectDistinct(SURVEY_INSTANCE.ID) .from(SURVEY_INSTANCE) .where(SURVEY_INSTANCE.ENTITY_KIND.eq(ref.kind().name()) .and(SURVEY_INSTANCE.ENTITY_ID.in(ouSelector))); }
public AttestationCreateSummary getCreateSummary(AttestationRunCreateCommand command){ Select<Record1<Long>> idSelector = mkIdSelector(command.targetEntityKind(), command.selectionOptions()); Map<EntityReference, List<Person>> entityReferenceToPeople = getEntityReferenceToPeople( command.targetEntityKind(), command.selectionOptions(), command.involvementKindIds()); int entityCount = attestationRunDao.getEntityCount(idSelector); int instanceCount = entityReferenceToPeople .keySet() .size(); long recipientCount = entityReferenceToPeople.values() .stream() .flatMap(Collection::stream) .distinct() .count(); return ImmutableAttestationCreateSummary.builder() .entityCount(entityCount) .instanceCount(instanceCount) .recipientCount(recipientCount) .build(); }
private Map<EntityReference, List<Person>> getEntityReferenceToPeople(EntityKind targetEntityKind, IdSelectionOptions selectionOptions, Set<Long> involvementKindIds) { Select<Record1<Long>> idSelector = mkIdSelector(targetEntityKind, selectionOptions); return involvementDao.findPeopleByEntitySelectorAndInvolvement( targetEntityKind, idSelector, involvementKindIds); }
public List<ApplicationCost> findAppCostsByAppIds(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select<Record1<Long>> selector = idSelectorFactory.apply(options); return assetCostDao .findLatestYear() .map(year -> assetCostDao.findAppCostsByAppIdSelector(year, selector)) .orElse(Collections.emptyList()); }
public List<ApplicationCost> findTopAppCostsByAppIds(IdSelectionOptions options, int limit) { checkNotNull(options, "options cannot be null"); Select<Record1<Long>> selector = idSelectorFactory.apply(options); return assetCostDao .findLatestYear() .map(year -> assetCostDao.findTopAppCostsByAppIdSelector(year, selector, limit)) .orElse(Collections.emptyList()); }
public List<Tuple2<Long, BigDecimal>> calculateCombinedAmountsForSelector(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select<Record1<Long>> appIdSelector = idSelectorFactory.apply(options); return assetCostDao .findLatestYear() .map(y -> assetCostDao.calculateCombinedAmountsForSelector(y, appIdSelector)) .orElse(Collections.emptyList()); }
public Cost calculateTotalCostForAppSelector(IdSelectionOptions options) { checkNotNull(options, "options cannot be null"); Select<Record1<Long>> appIdSelector = idSelectorFactory.apply(options); return assetCostDao .findLatestYear() .map(year -> assetCostStatsDao .calculateTotalCostByAppIdSelector(year, appIdSelector)) .orElse(null); }
@Override protected Select<Record1<Long>> mkForOrgUnit(EntityReference ref, HierarchyQueryScope scope) { IdSelectionOptions ouSelectorOptions = ImmutableIdSelectionOptions.builder() .entityReference(ref) .scope(scope) .build(); Select<Record1<Long>> ouSelector = orgUnitIdSelectorFactory.apply(ouSelectorOptions); return dsl .selectDistinct(eua.ID) .from(eua) .where(dsl.renderInlined(eua.ORGANISATIONAL_UNIT_ID.in(ouSelector))); }
/** * Attempts to remove the named note type specified by the * given id. The removal will only take place if no * entity named notes refer to this id. * * @param id * @return boolean - whether the note was removed. */ public boolean removeById(Long id) { Select anyUsageOfType = DSL .select(ENTITY_NAMED_NOTE.ENTITY_ID) .from(ENTITY_NAMED_NOTE) .where(ENTITY_NAMED_NOTE.NAMED_NOTE_TYPE_ID.eq(id)); return dsl .deleteFrom(ENTITY_NAMED_NOTE_TYPE) .where(ENTITY_NAMED_NOTE_TYPE.ID.eq(id)) .andNotExists(anyUsageOfType) .execute() == 1; }
@Override protected Select<Record1<Long>> mkForOptions(IdSelectionOptions options) { switch (options.entityReference().kind()) { case APP_GROUP: case APPLICATION: case MEASURABLE: return mkForRef(options); case PERSON: return mkForPerson(options); case CHANGE_INITIATIVE: return mkForChangeInitiative(options); case ORG_UNIT: return mkForOrgUnit(options); case FLOW_DIAGRAM: return mkForFlowDiagram(options); default: String msg = String.format( "Cannot create Change Initiative Id selector from kind: %s", options.entityReference().kind()); throw new UnsupportedOperationException(msg); } }
private Select<Record1<Long>> mkForFlowDiagram(IdSelectionOptions options) { ensureScopeIsExact(options); return dsl.selectDistinct(FLOW_DIAGRAM_ENTITY.ENTITY_ID) .from(FLOW_DIAGRAM_ENTITY) .where(FLOW_DIAGRAM_ENTITY.ENTITY_KIND.eq(EntityKind.CHANGE_INITIATIVE.name())) .and(FLOW_DIAGRAM_ENTITY.DIAGRAM_ID.eq(options.entityReference().id())); }
private Select<Record1<Long>> mkForPerson(IdSelectionOptions options) { SelectConditionStep<Record1<String>> empIdSelector = DSL .selectDistinct(PERSON.EMPLOYEE_ID) .from(PERSON) .where(PERSON.ID.eq(options.entityReference().id())); return dsl.selectDistinct(CHANGE_INITIATIVE.ID) .from(CHANGE_INITIATIVE) .innerJoin(INVOLVEMENT) .on(INVOLVEMENT.ENTITY_ID.eq(CHANGE_INITIATIVE.ID)) .where(INVOLVEMENT.ENTITY_KIND.eq(EntityKind.CHANGE_INITIATIVE.name())) .and(INVOLVEMENT.EMPLOYEE_ID.in(empIdSelector)); }
private Select<Record1<Long>> mkForOrgUnit(IdSelectionOptions options) { Select<Record1<Long>> ouSelector = organisationalUnitIdSelectorFactory.apply(options); return dsl .selectDistinct(CHANGE_INITIATIVE.ID) .from(CHANGE_INITIATIVE) .where(CHANGE_INITIATIVE.ORGANISATIONAL_UNIT_ID.in(ouSelector)); }
private Select<Record1<Long>> mkForPhysicalSpecification(IdSelectionOptions options) { ensureScopeIsExact(options); return DSL.select(LOGICAL_FLOW.ID) .from(LOGICAL_FLOW) .innerJoin(PHYSICAL_FLOW) .on(PHYSICAL_FLOW.LOGICAL_FLOW_ID.eq(LOGICAL_FLOW.ID)) .where(PHYSICAL_FLOW.SPECIFICATION_ID.eq(options.entityReference().id())) .and(NOT_REMOVED); }
private Select<Record1<Long>> mkForFlowDiagram(IdSelectionOptions options) { ensureScopeIsExact(options); return DSL.select(LOGICAL_FLOW.ID) .from(LOGICAL_FLOW) .innerJoin(FLOW_DIAGRAM_ENTITY) .on(FLOW_DIAGRAM_ENTITY.ENTITY_ID.eq(LOGICAL_FLOW.ID)) .where(FLOW_DIAGRAM_ENTITY.ENTITY_KIND.eq(EntityKind.LOGICAL_DATA_FLOW.name())) .and(FLOW_DIAGRAM_ENTITY.DIAGRAM_ID.eq(options.entityReference().id())); }
private Select<Record1<Long>> wrapAppIdSelector(IdSelectionOptions options) { Select<Record1<Long>> appIdSelector = applicationIdSelectorFactory.apply(options); Condition sourceCondition = LOGICAL_FLOW.SOURCE_ENTITY_ID.in(appIdSelector) .and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name())); Condition targetCondition = LOGICAL_FLOW.TARGET_ENTITY_ID.in(appIdSelector) .and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name())); return DSL.select(LOGICAL_FLOW.ID) .from(LOGICAL_FLOW) .where(sourceCondition.or(targetCondition)) .and(NOT_REMOVED); }
private Select<Record1<Long>> mkForApplication(IdSelectionOptions options) { ensureScopeIsExact(options); long appId = options.entityReference().id(); return DSL.select(LOGICAL_FLOW.ID) .from(LOGICAL_FLOW) .where(LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(appId) .and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))) .or(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(appId) .and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))) .and(NOT_REMOVED); }