Search in sources :

Example 1 with PERSON

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

use of com.khartec.waltz.schema.tables.Person.PERSON in project waltz by khartec.

the class ChangeLogGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    // get applications and emails
    List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
    List<String> emails = dsl.select(PERSON.EMAIL).from(PERSON).fetch(PERSON.EMAIL);
    Set<ChangeLogRecord> records = emails.stream().flatMap(email -> Stream.of(mkChangeLog(randomPick(appIds), email), mkChangeLog(randomPick(appIds), randomPick(emails)))).collect(toSet());
    dsl.deleteFrom(CHANGE_LOG).execute();
    dsl.batchInsert(records).execute();
    System.out.println("Inserted " + records.size() + " change log entries");
}
Also used : ChangeLogRecord(com.khartec.waltz.schema.tables.records.ChangeLogRecord) Set(java.util.Set) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) Severity(com.khartec.waltz.model.Severity) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) Stream(java.util.stream.Stream) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) CHANGE_LOG(com.khartec.waltz.schema.tables.ChangeLog.CHANGE_LOG) Collectors.toSet(java.util.stream.Collectors.toSet) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) ChangeLogRecord(com.khartec.waltz.schema.tables.records.ChangeLogRecord)

Example 3 with PERSON

use of com.khartec.waltz.schema.tables.Person.PERSON in project waltz by khartec.

the class SurveyRunGenerator method main.

public static void main(String[] args) {
    try {
        final AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
        final DSLContext dsl = ctx.getBean(DSLContext.class);
        List<Person> owners = dsl.selectFrom(PERSON).limit(NUMBER_OF_RUNS).fetch().map(PersonDao.personMapper);
        checkFalse(isEmpty(owners), "No person found, please generate person data first");
        final SurveyTemplateDao surveyTemplateDao = ctx.getBean(SurveyTemplateDao.class);
        List<SurveyTemplate> surveyTemplates = surveyTemplateDao.findAll(owners.get(0).id().get());
        checkFalse(isEmpty(surveyTemplates), "No template found, please generate templates first");
        final AppGroupDao appGroupDao = ctx.getBean(AppGroupDao.class);
        List<AppGroup> appGroups = appGroupDao.findPublicGroups();
        checkFalse(isEmpty(appGroups), "No public app group found, please generate app groups first");
        final InvolvementKindDao involvementKindDao = ctx.getBean(InvolvementKindDao.class);
        List<InvolvementKind> involvementKinds = involvementKindDao.findAll();
        final SurveyRunService surveyRunService = ctx.getBean(SurveyRunService.class);
        final SurveyInstanceService surveyInstanceService = ctx.getBean(SurveyInstanceService.class);
        final SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
        deleteSurveyRunsAndResponses(dsl);
        AtomicInteger surveyCompletedCount = new AtomicInteger(0);
        IntStream.range(0, NUMBER_OF_RUNS).forEach(idx -> {
            SurveyTemplate surveyTemplate = surveyTemplates.get(random.nextInt(surveyTemplates.size()));
            Person owner = owners.get(random.nextInt(owners.size()));
            SurveyRunRecord surveyRunRecord = mkRandomSurveyRunRecord(dsl, appGroups, involvementKinds, surveyTemplate, owner);
            surveyRunRecord.store();
            long surveyRunId = surveyRunRecord.getId();
            LOG.debug("Survey Run: {} / {} / {}", surveyRunRecord.getStatus(), surveyRunId, surveyRunRecord.getName());
            surveyRunService.createSurveyInstancesAndRecipients(surveyRunId, Collections.emptyList());
            List<SurveyInstanceQuestionResponse> surveyInstanceQuestionResponses = mkRandomSurveyRunResponses(surveyRunId, surveyInstanceService, surveyQuestionService);
            Map<SurveyInstanceStatus, Set<Long>> surveyInstanceStatusMap = surveyInstanceQuestionResponses.stream().mapToLong(response -> response.surveyInstanceId()).distinct().mapToObj(id -> Tuple.tuple(ArrayUtilities.randomPick(SurveyInstanceStatus.NOT_STARTED, SurveyInstanceStatus.IN_PROGRESS, SurveyInstanceStatus.COMPLETED), id)).collect(groupingBy(t -> t.v1, mapping(t -> t.v2, toSet())));
            dsl.batchInsert(surveyInstanceQuestionResponses.stream().map(r -> {
                if (surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.NOT_STARTED) && surveyInstanceStatusMap.get(SurveyInstanceStatus.NOT_STARTED).contains(r.surveyInstanceId())) {
                    // don't create response for NOT_STARTED
                    return null;
                }
                SurveyQuestionResponse questionResponse = r.questionResponse();
                SurveyQuestionResponseRecord record = new SurveyQuestionResponseRecord();
                record.setSurveyInstanceId(r.surveyInstanceId());
                record.setPersonId(r.personId());
                record.setQuestionId(questionResponse.questionId());
                record.setBooleanResponse(questionResponse.booleanResponse().orElse(null));
                record.setNumberResponse(questionResponse.numberResponse().map(BigDecimal::valueOf).orElse(null));
                record.setStringResponse(questionResponse.stringResponse().orElse(null));
                record.setComment(r.questionResponse().comment().orElse(null));
                record.setLastUpdatedAt(Timestamp.valueOf(nowUtc()));
                return record;
            }).filter(Objects::nonNull).collect(toList())).execute();
            if (SurveyRunStatus.valueOf(surveyRunRecord.getStatus()) == SurveyRunStatus.COMPLETED) {
                surveyRunRecord.setStatus(SurveyRunStatus.COMPLETED.name());
                surveyRunRecord.store();
                surveyCompletedCount.incrementAndGet();
                // save instances to COMPLETED
                if (surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.COMPLETED)) {
                    Set<Long> completedInstanceIds = surveyInstanceStatusMap.get(SurveyInstanceStatus.COMPLETED);
                    dsl.update(SURVEY_INSTANCE).set(SURVEY_INSTANCE.STATUS, SurveyInstanceStatus.COMPLETED.name()).where(SURVEY_INSTANCE.ID.in(completedInstanceIds)).execute();
                    LOG.debug(" --- {} instances: {}", SurveyInstanceStatus.COMPLETED, completedInstanceIds);
                }
                // save instances to EXPIRED
                if (surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.NOT_STARTED) || surveyInstanceStatusMap.containsKey(SurveyInstanceStatus.IN_PROGRESS)) {
                    Set<Long> expiredInstanceIds = surveyInstanceStatusMap.entrySet().stream().filter(e -> e.getKey() != SurveyInstanceStatus.COMPLETED).flatMap(e -> e.getValue().stream()).collect(toSet());
                    dsl.update(SURVEY_INSTANCE).set(SURVEY_INSTANCE.STATUS, SurveyInstanceStatus.EXPIRED.name()).where(SURVEY_INSTANCE.ID.in(expiredInstanceIds)).execute();
                    LOG.debug(" --- {} instances: {}", SurveyInstanceStatus.EXPIRED, expiredInstanceIds);
                }
            } else {
                surveyInstanceStatusMap.forEach(((status, instanceIds) -> {
                    dsl.update(SURVEY_INSTANCE).set(SURVEY_INSTANCE.STATUS, status.name()).where(SURVEY_INSTANCE.ID.in(instanceIds)).execute();
                    LOG.debug(" --- {} instances: {}", status.name(), instanceIds);
                }));
            }
        });
        LOG.debug("Generated: {} survey runs, in which {} are completed", NUMBER_OF_RUNS, surveyCompletedCount.get());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) IntStream(java.util.stream.IntStream) AppGroup(com.khartec.waltz.model.app_group.AppGroup) java.util(java.util) DSL(org.jooq.impl.DSL) DateTimeUtilities.nowUtc(com.khartec.waltz.common.DateTimeUtilities.nowUtc) LoggerFactory(org.slf4j.LoggerFactory) HierarchyQueryScope(com.khartec.waltz.model.HierarchyQueryScope) Condition(org.jooq.Condition) CollectionUtilities.randomPick(com.khartec.waltz.common.CollectionUtilities.randomPick) EntityKind(com.khartec.waltz.model.EntityKind) SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) BigDecimal(java.math.BigDecimal) SurveyRunService(com.khartec.waltz.service.survey.SurveyRunService) DIConfiguration(com.khartec.waltz.service.DIConfiguration) InvolvementKind(com.khartec.waltz.model.involvement_kind.InvolvementKind) Record1(org.jooq.Record1) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SurveyInstanceService(com.khartec.waltz.service.survey.SurveyInstanceService) PersonDao(com.khartec.waltz.data.person.PersonDao) DSLContext(org.jooq.DSLContext) SurveyQuestionResponseRecord(com.khartec.waltz.schema.tables.records.SurveyQuestionResponseRecord) com.khartec.waltz.model.survey(com.khartec.waltz.model.survey) Select(org.jooq.Select) SurveyTemplateDao(com.khartec.waltz.data.survey.SurveyTemplateDao) Logger(org.slf4j.Logger) Timestamp(java.sql.Timestamp) Checks.checkFalse(com.khartec.waltz.common.Checks.checkFalse) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AppGroupDao(com.khartec.waltz.data.app_group.AppGroupDao) Tuple(org.jooq.lambda.tuple.Tuple) CollectionUtilities.isEmpty(com.khartec.waltz.common.CollectionUtilities.isEmpty) Tables(com.khartec.waltz.schema.Tables) Person(com.khartec.waltz.model.person.Person) LocalDate(java.time.LocalDate) InvolvementKindDao(com.khartec.waltz.data.involvement_kind.InvolvementKindDao) ArrayUtilities(com.khartec.waltz.common.ArrayUtilities) SurveyRunRecord(com.khartec.waltz.schema.tables.records.SurveyRunRecord) SurveyQuestionResponseRecord(com.khartec.waltz.schema.tables.records.SurveyQuestionResponseRecord) InvolvementKindDao(com.khartec.waltz.data.involvement_kind.InvolvementKindDao) AppGroup(com.khartec.waltz.model.app_group.AppGroup) SurveyInstanceService(com.khartec.waltz.service.survey.SurveyInstanceService) AppGroupDao(com.khartec.waltz.data.app_group.AppGroupDao) InvolvementKind(com.khartec.waltz.model.involvement_kind.InvolvementKind) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) SurveyTemplateDao(com.khartec.waltz.data.survey.SurveyTemplateDao) DSLContext(org.jooq.DSLContext) BigDecimal(java.math.BigDecimal) SurveyRunService(com.khartec.waltz.service.survey.SurveyRunService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SurveyRunRecord(com.khartec.waltz.schema.tables.records.SurveyRunRecord) Person(com.khartec.waltz.model.person.Person)

Aggregations

EntityKind (com.khartec.waltz.model.EntityKind)3 PERSON (com.khartec.waltz.schema.tables.Person.PERSON)3 DIConfiguration (com.khartec.waltz.service.DIConfiguration)3 DSLContext (org.jooq.DSLContext)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 List (java.util.List)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 Tuple (org.jooq.lambda.tuple.Tuple)2 ArrayUtilities (com.khartec.waltz.common.ArrayUtilities)1 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 Checks.checkFalse (com.khartec.waltz.common.Checks.checkFalse)1 CollectionUtilities.isEmpty (com.khartec.waltz.common.CollectionUtilities.isEmpty)1 CollectionUtilities.randomPick (com.khartec.waltz.common.CollectionUtilities.randomPick)1 DateTimeUtilities.nowUtc (com.khartec.waltz.common.DateTimeUtilities.nowUtc)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 ListUtilities.randomPick (com.khartec.waltz.common.ListUtilities.randomPick)1 AppGroupDao (com.khartec.waltz.data.app_group.AppGroupDao)1 InvolvementKindDao (com.khartec.waltz.data.involvement_kind.InvolvementKindDao)1 PersonDao (com.khartec.waltz.data.person.PersonDao)1