Search in sources :

Example 1 with EntityHierarchy

use of org.finos.waltz.schema.tables.EntityHierarchy in project waltz by khartec.

the class QuestionAppPredicateNamespace method dataTypeUsages.

public Set<String> dataTypeUsages(String name) {
    DataTypeUsage dtu = DATA_TYPE_USAGE.as("dtu");
    DataType dt = DATA_TYPE.as("dt");
    EntityHierarchy eh = ENTITY_HIERARCHY.as("eh");
    Condition dtNameMatches = dt.CODE.eq(name).or(dt.NAME.eq(name));
    Condition subjectMatches = dtu.ENTITY_ID.eq(subjectRef.id()).and(dtu.ENTITY_KIND.eq(subjectRef.kind().name()));
    return dsl.select(dtu.USAGE_KIND).from(dt).innerJoin(eh).on(eh.ANCESTOR_ID.eq(dt.ID).and(eh.KIND.eq(EntityKind.DATA_TYPE.name()))).innerJoin(dtu).on(dtu.DATA_TYPE_ID.eq(eh.ID)).where(dtNameMatches).and(subjectMatches).fetchSet(dtu.USAGE_KIND);
}
Also used : Condition(org.jooq.Condition) DataTypeUsage(org.finos.waltz.schema.tables.DataTypeUsage) DataType(org.finos.waltz.schema.tables.DataType) EntityHierarchy(org.finos.waltz.schema.tables.EntityHierarchy)

Example 2 with EntityHierarchy

use of org.finos.waltz.schema.tables.EntityHierarchy 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);
}
Also used : EntityHierarchy(org.finos.waltz.schema.tables.EntityHierarchy) OrganisationalUnit(org.finos.waltz.schema.tables.OrganisationalUnit)

Aggregations

EntityHierarchy (org.finos.waltz.schema.tables.EntityHierarchy)2 DataType (org.finos.waltz.schema.tables.DataType)1 DataTypeUsage (org.finos.waltz.schema.tables.DataTypeUsage)1 OrganisationalUnit (org.finos.waltz.schema.tables.OrganisationalUnit)1 Condition (org.jooq.Condition)1