use of org.finos.waltz.schema.tables.OrganisationalUnit in project waltz by khartec.
the class DataExtractHarness method main.
public static void main(String[] args) throws ParseException {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
LogicalFlowIdSelectorFactory logicalFlowIdSelectorFactory = new LogicalFlowIdSelectorFactory();
IdSelectionOptions options = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.ORG_UNIT, 4326), HierarchyQueryScope.CHILDREN);
Select<Record1<Long>> flowIdSelector = logicalFlowIdSelectorFactory.apply(options);
Application sourceApp = APPLICATION.as("sourceApp");
Application targetApp = APPLICATION.as("targetApp");
OrganisationalUnit sourceOrgUnit = ORGANISATIONAL_UNIT.as("sourceOrgUnit");
OrganisationalUnit targetOrgUnit = ORGANISATIONAL_UNIT.as("targetOrgUnit");
Result<Record> fetch = dsl.select(LOGICAL_FLOW.fields()).select(SOURCE_NAME_FIELD, TARGET_NAME_FIELD).select(sourceApp.fields()).select(targetApp.fields()).select(sourceOrgUnit.fields()).select(targetOrgUnit.fields()).select(LOGICAL_FLOW_DECORATOR.fields()).from(LOGICAL_FLOW).leftJoin(sourceApp).on(LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(sourceApp.ID).and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))).leftJoin(targetApp).on(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(targetApp.ID).and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))).leftJoin(sourceOrgUnit).on(sourceApp.ORGANISATIONAL_UNIT_ID.eq(sourceOrgUnit.ID)).leftJoin(targetOrgUnit).on(targetApp.ORGANISATIONAL_UNIT_ID.eq(targetOrgUnit.ID)).join(LOGICAL_FLOW_DECORATOR).on(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID.eq(LOGICAL_FLOW.ID).and(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND.eq("DATA_TYPE"))).where(LOGICAL_FLOW.ID.in(flowIdSelector)).and(LOGICAL_FLOW.ENTITY_LIFECYCLE_STATUS.ne(REMOVED.name())).fetch();
System.out.printf("got records: %s", fetch.size());
}
use of org.finos.waltz.schema.tables.OrganisationalUnit in project waltz by khartec.
the class QuestionEntityPredicateNamespace method belongsToOrgUnit.
// --- HELPER ---
protected boolean belongsToOrgUnit(String name, Table<?> subjectTable, Field<Long> subjectId, Field<Long> subjectOu) {
EntityHierarchy eh = ENTITY_HIERARCHY.as("eh");
OrganisationalUnit ou = OrganisationalUnit.ORGANISATIONAL_UNIT.as("ou");
SelectConditionStep<Record1<Long>> targetOrgUnitId = DSL.select(ou.ID).from(ou).where(ou.NAME.eq(name)).or(ou.EXTERNAL_ID.eq(name));
Condition subjectInTargetOuTree = subjectOu.in(DSL.selectDistinct(eh.ID).from(eh).where(eh.ANCESTOR_ID.eq(targetOrgUnitId)));
Condition subjectEntitiesMatch = subjectId.eq(subjectRef.id());
SelectConditionStep<Record1<Long>> qry = DSL.select(subjectId).from(subjectTable).where(subjectEntitiesMatch).and(subjectInTargetOuTree);
return dsl.fetchExists(qry);
}
Aggregations