Search in sources :

Example 1 with ORGANISATIONAL_UNIT

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

use of com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT in project waltz by khartec.

the class InvolvementGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> developers = getEmployeeIdsByTitle(dsl, "%Developer%");
    List<String> managers = getEmployeeIdsByTitle(dsl, "%Manager%");
    List<String> analysts = getEmployeeIdsByTitle(dsl, "%Analyst%");
    List<String> administrators = getEmployeeIdsByTitle(dsl, "%Administrator%");
    List<String> qa = getEmployeeIdsByTitle(dsl, "%QA%");
    List<String> directors = getEmployeeIdsByTitle(dsl, "%Director%");
    ;
    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    Map<String, Long> involvementKindMap = dsl.select(INVOLVEMENT_KIND.NAME, INVOLVEMENT_KIND.ID).from(INVOLVEMENT_KIND).fetch().stream().collect(toMap(r -> r.getValue(INVOLVEMENT_KIND.NAME), r -> r.getValue(INVOLVEMENT_KIND.ID)));
    List<Long> inHouseApps = getAppIdsByKind(dsl, ApplicationKind.IN_HOUSE);
    List<Long> hostedApps = getAppIdsByKind(dsl, ApplicationKind.INTERNALLY_HOSTED);
    List<Long> externalApps = getAppIdsByKind(dsl, ApplicationKind.EXTERNALLY_HOSTED);
    List<Long> eucApps = getAppIdsByKind(dsl, ApplicationKind.EUC);
    List<InvolvementRecord> devInvolvements = inHouseApps.stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, developers, involvementKindMap.get("Developer"), 7)).collect(Collectors.toList());
    List<InvolvementRecord> qaInvolvements = concat(inHouseApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, qa, involvementKindMap.get("Quality Assurance"), 3)).collect(Collectors.toList());
    List<InvolvementRecord> projectManagerInvolvements = concat(inHouseApps, externalApps, hostedApps, eucApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, managers, involvementKindMap.get("Project Manager"), 1)).collect(Collectors.toList());
    List<InvolvementRecord> supportManagerInvolvments = concat(inHouseApps, externalApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, managers, involvementKindMap.get("Support Manager"), 1)).collect(Collectors.toList());
    List<InvolvementRecord> analystInvolvments = concat(inHouseApps, externalApps, hostedApps).stream().map(id -> toAppRef(id)).flatMap(appRef -> mkInvolvments(appRef, analysts, involvementKindMap.get("Business Analyst"), 3)).collect(Collectors.toList());
    List<InvolvementRecord> ouArchitects = orgUnitIds.stream().map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id, randomPick(directors), "RANDOM_GENERATOR", Long.valueOf(rnd.nextInt(13) + 1))).collect(Collectors.toList());
    List<InvolvementRecord> ouSponsors = orgUnitIds.stream().map(id -> new InvolvementRecord(EntityKind.ORG_UNIT.name(), id, randomPick(directors), "RANDOM_GENERATOR", Long.valueOf(rnd.nextInt(13) + 1))).collect(Collectors.toList());
    dsl.delete(INVOLVEMENT).execute();
    dsl.batchInsert(devInvolvements).execute();
    dsl.batchInsert(qaInvolvements).execute();
    dsl.batchInsert(supportManagerInvolvments).execute();
    dsl.batchInsert(projectManagerInvolvements).execute();
    dsl.batchInsert(analystInvolvments).execute();
    dsl.batchInsert(ouArchitects).execute();
    dsl.batchInsert(ouSponsors).execute();
    System.out.println("Done");
}
Also used : IntStream(java.util.stream.IntStream) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord) ImmutableEntityReference(com.khartec.waltz.model.ImmutableEntityReference) INVOLVEMENT_KIND(com.khartec.waltz.schema.tables.InvolvementKind.INVOLVEMENT_KIND) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) INVOLVEMENT(com.khartec.waltz.schema.tables.Involvement.INVOLVEMENT) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ListUtilities.concat(com.khartec.waltz.common.ListUtilities.concat) EntityKind(com.khartec.waltz.model.EntityKind) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Stream(java.util.stream.Stream) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) ApplicationKind(com.khartec.waltz.model.application.ApplicationKind) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord)

Example 3 with ORGANISATIONAL_UNIT

use of com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT in project waltz by khartec.

the class OrgUnitGenerator method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/org-units.csv"));
    System.out.println("Deleting existing OU's");
    dsl.deleteFrom(ORGANISATIONAL_UNIT).execute();
    List<OrganisationalUnitRecord> records = lines.stream().skip(1).map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> cells.length == 4).map(cells -> {
        OrganisationalUnitRecord record = new OrganisationalUnitRecord();
        record.setId(longVal(cells[0]));
        record.setParentId(longVal(cells[1]));
        record.setName(cells[2]);
        record.setDescription(cells[3]);
        record.setUpdatedAt(new Timestamp(System.currentTimeMillis()));
        System.out.println(record);
        return record;
    }).collect(Collectors.toList());
    System.out.println("Inserting new OU's");
    dsl.batchInsert(records).execute();
    System.out.println("Done");
}
Also used : List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitRecord(com.khartec.waltz.schema.tables.records.OrganisationalUnitRecord) Timestamp(java.sql.Timestamp) DSLContext(org.jooq.DSLContext) IOException(java.io.IOException) StringUtilities(com.khartec.waltz.common.StringUtilities) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) IOUtilities.readLines(com.khartec.waltz.common.IOUtilities.readLines) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) OrganisationalUnitRecord(com.khartec.waltz.schema.tables.records.OrganisationalUnitRecord) Timestamp(java.sql.Timestamp)

Example 4 with ORGANISATIONAL_UNIT

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

ORGANISATIONAL_UNIT (com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)4 List (java.util.List)4 DSLContext (org.jooq.DSLContext)4 DIConfiguration (com.khartec.waltz.service.DIConfiguration)3 Collectors (java.util.stream.Collectors)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 EntityKind (com.khartec.waltz.model.EntityKind)2 PERSON (com.khartec.waltz.schema.tables.Person.PERSON)2 InvolvementRecord (com.khartec.waltz.schema.tables.records.InvolvementRecord)2 Random (java.util.Random)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 IOUtilities.readLines (com.khartec.waltz.common.IOUtilities.readLines)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 ListUtilities.concat (com.khartec.waltz.common.ListUtilities.concat)1 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)1 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)1 StringUtilities (com.khartec.waltz.common.StringUtilities)1 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)1