Search in sources :

Example 1 with CHANGE_INITIATIVE

use of com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE in project waltz by khartec.

the class ChangeInitiativeGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> groupIds = dsl.select(APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(APPLICATION_GROUP.ID);
    List<String> employeeIds = dsl.select(PERSON.EMPLOYEE_ID).from(PERSON).fetch(PERSON.EMPLOYEE_ID);
    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    List<TableRecord<?>> records = LongStream.range(0, 400).mapToObj(i -> {
        String name = randomPick(p1) + " " + randomPick(p2) + " " + randomPick(p3);
        Long ouId = randomPick(orgUnitIds.toArray(new Long[0]));
        return Tuple.tuple(i, name, ouId);
    }).map(t -> buildChangeInitiativeRecord(t)).flatMap(r -> Stream.concat(Stream.of(r), buildLinks(r, groupIds, employeeIds))).collect(toList());
    System.out.println("-- deleting");
    dsl.deleteFrom(CHANGE_INITIATIVE).execute();
    System.out.println("-- inserting");
    dsl.batchInsert(records).execute();
    System.out.println(" -- done");
}
Also used : IntStream(java.util.stream.IntStream) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord) Random(java.util.Random) EntityKind(com.khartec.waltz.model.EntityKind) Tuple3(org.jooq.lambda.tuple.Tuple3) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) APP_GROUP(com.khartec.waltz.model.EntityKind.APP_GROUP) LongStream(java.util.stream.LongStream) LifecyclePhase(com.khartec.waltz.model.application.LifecyclePhase) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) ListUtilities(com.khartec.waltz.common.ListUtilities) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) TableRecord(org.jooq.TableRecord) Instant(java.time.Instant) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Date(java.sql.Date) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Collectors.toList(java.util.stream.Collectors.toList) Tuple(org.jooq.lambda.tuple.Tuple) Stream(java.util.stream.Stream) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) APPLICATION_GROUP(com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) RelationshipKind(com.khartec.waltz.model.entity_relationship.RelationshipKind) CHANGE_INITIATIVE(com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) ChangeInitiativeRecord(com.khartec.waltz.schema.tables.records.ChangeInitiativeRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) TableRecord(org.jooq.TableRecord)

Example 2 with CHANGE_INITIATIVE

use of com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE 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

CHANGE_INITIATIVE (com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE)2 List (java.util.List)2 DSLContext (org.jooq.DSLContext)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 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 ChangeInitiativeDao (com.khartec.waltz.data.change_initiative.ChangeInitiativeDao)1 EntityKind (com.khartec.waltz.model.EntityKind)1 APP_GROUP (com.khartec.waltz.model.EntityKind.APP_GROUP)1 LifecyclePhase (com.khartec.waltz.model.application.LifecyclePhase)1 ChangeInitiative (com.khartec.waltz.model.change_initiative.ChangeInitiative)1 RelationshipKind (com.khartec.waltz.model.entity_relationship.RelationshipKind)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1 APPLICATION_GROUP (com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP)1 ORGANISATIONAL_UNIT (com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)1 PERSON (com.khartec.waltz.schema.tables.Person.PERSON)1