Search in sources :

Example 11 with OrganisationalUnit

use of com.khartec.waltz.model.orgunit.OrganisationalUnit in project waltz by khartec.

the class SqlServerOrganisationalUnitSearch method search.

@Override
public List<OrganisationalUnit> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition nameCondition = terms.stream().map(term -> ORGANISATIONAL_UNIT.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<OrganisationalUnit> orgUnitsViaName = dsl.selectDistinct(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(nameCondition).orderBy(ORGANISATIONAL_UNIT.NAME).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    List<OrganisationalUnit> orgUnitsViaFullText = dsl.select(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(orgUnitsViaName, orgUnitsViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DSLContext(org.jooq.DSLContext) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) 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) ArrayList(java.util.ArrayList) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit)

Aggregations

OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)11 Application (com.khartec.waltz.model.application.Application)8 DSLContext (org.jooq.DSLContext)7 AuthoritativeSource (com.khartec.waltz.model.authoritativesource.AuthoritativeSource)5 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 OrganisationalUnitDao (com.khartec.waltz.data.orgunit.OrganisationalUnitDao)4 EntityReference (com.khartec.waltz.model.EntityReference)4 OrganisationalUnitService (com.khartec.waltz.service.orgunit.OrganisationalUnitService)4 List (java.util.List)4 EntityKind (com.khartec.waltz.model.EntityKind)3 DataType (com.khartec.waltz.model.datatype.DataType)3 DIConfiguration (com.khartec.waltz.service.DIConfiguration)3 ApplicationService (com.khartec.waltz.service.application.ApplicationService)3 EntityHierarchyService (com.khartec.waltz.service.entity_hierarchy.EntityHierarchyService)3 Collectors.toList (java.util.stream.Collectors.toList)3 IntStream (java.util.stream.IntStream)3 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)2 SetUtilities (com.khartec.waltz.common.SetUtilities)2 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)2 AuthoritativeSourceDao (com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao)2