Search in sources :

Example 1 with ChangeInitiative

use of com.khartec.waltz.model.change_initiative.ChangeInitiative in project waltz by khartec.

the class ChangeInitiativeHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ChangeInitiativeDao dao = ctx.getBean(ChangeInitiativeDao.class);
    ChangeInitiative changeInitiative = dao.getById(1L);
    System.out.println(changeInitiative);
    SelectConditionStep<Record1<Long>> ouHier = dsl.selectDistinct(ENTITY_HIERARCHY.ANCESTOR_ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.ID.eq(210L).and(ENTITY_HIERARCHY.KIND.eq(EntityKind.ORG_UNIT.name())));
    SelectConditionStep<Record1<Long>> baseIdSelector = dsl.selectDistinct(CHANGE_INITIATIVE.ID).from(CHANGE_INITIATIVE).where(CHANGE_INITIATIVE.ORGANISATIONAL_UNIT_ID.in(ouHier));
    SelectConditionStep<Record1<Long>> ciHier = dsl.selectDistinct(ENTITY_HIERARCHY.ANCESTOR_ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.ID.in(baseIdSelector).and(ENTITY_HIERARCHY.KIND.eq(EntityKind.CHANGE_INITIATIVE.name())));
    dsl.select(CHANGE_INITIATIVE.NAME).from(CHANGE_INITIATIVE).where(CHANGE_INITIATIVE.ID.in(ciHier)).forEach(System.out::println);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ChangeInitiativeDao(com.khartec.waltz.data.change_initiative.ChangeInitiativeDao) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) DSLContext(org.jooq.DSLContext) Record1(org.jooq.Record1)

Example 2 with ChangeInitiative

use of com.khartec.waltz.model.change_initiative.ChangeInitiative in project waltz by khartec.

the class SqlServerChangeInitiativeSearch method search.

@Override
public List<ChangeInitiative> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition nameCondition = terms.stream().map(term -> CHANGE_INITIATIVE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<ChangeInitiative> ciViaName = dsl.selectDistinct(CHANGE_INITIATIVE.fields()).from(CHANGE_INITIATIVE).where(nameCondition).orderBy(CHANGE_INITIATIVE.NAME).limit(options.limit()).fetch(ChangeInitiativeDao.TO_DOMAIN_MAPPER);
    List<ChangeInitiative> ciViaFullText = dsl.select(CHANGE_INITIATIVE.fields()).from(CHANGE_INITIATIVE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(ChangeInitiativeDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(ciViaName, ciViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) List(java.util.List) ChangeInitiativeDao(com.khartec.waltz.data.change_initiative.ChangeInitiativeDao) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) CHANGE_INITIATIVE(com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) Collections(java.util.Collections) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) ArrayList(java.util.ArrayList)

Aggregations

ChangeInitiativeDao (com.khartec.waltz.data.change_initiative.ChangeInitiativeDao)2 ChangeInitiative (com.khartec.waltz.model.change_initiative.ChangeInitiative)2 DSLContext (org.jooq.DSLContext)2 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)1 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)1 FullTextSearch (com.khartec.waltz.data.FullTextSearch)1 JooqUtilities (com.khartec.waltz.data.JooqUtilities)1 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1 CHANGE_INITIATIVE (com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Condition (org.jooq.Condition)1 Record1 (org.jooq.Record1)1 DSL (org.jooq.impl.DSL)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1