Search in sources :

Example 1 with SurveyQuestionService

use of com.khartec.waltz.service.survey.SurveyQuestionService in project waltz by khartec.

the class SurveyHarness method surveyTempateHarness.

private static void surveyTempateHarness(AnnotationConfigApplicationContext ctx) {
    SurveyTemplateService surveyTemplateService = ctx.getBean(SurveyTemplateService.class);
    SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
    SurveyTemplateChangeCommand surveyTemplateChangeCommand = ImmutableSurveyTemplateChangeCommand.builder().name("AAA").description("BBB").targetEntityKind(EntityKind.CHANGE_INITIATIVE).build();
    long templateId = surveyTemplateService.create("admin", surveyTemplateChangeCommand);
    System.out.println("Created: template create with ID = " + templateId);
    SurveyQuestion surveyQuestion = ImmutableSurveyQuestion.builder().surveyTemplateId(templateId).sectionName("SSS").questionText("QQQ").helpText("HHH").fieldType(SurveyQuestionFieldType.TEXTAREA).position(1).isMandatory(false).allowComment(true).build();
    long questionId = surveyQuestionService.create(surveyQuestion);
    System.out.println("Created: question create with ID = " + questionId);
}
Also used : SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) SurveyTemplateService(com.khartec.waltz.service.survey.SurveyTemplateService)

Example 2 with SurveyQuestionService

use of com.khartec.waltz.service.survey.SurveyQuestionService in project waltz by khartec.

the class SurveyHarness method surveyRunHarness.

private static void surveyRunHarness(AnnotationConfigApplicationContext ctx) {
    SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
    surveyQuestionService.findForSurveyTemplate(1).forEach(System.out::println);
    IdSelectionOptions idSelectionOptions = ImmutableIdSelectionOptions.builder().entityReference(ImmutableEntityReference.mkRef(EntityKind.APP_GROUP, 1)).scope(HierarchyQueryScope.EXACT).build();
    SurveyRunCreateCommand surveyRunCreateCommand = ImmutableSurveyRunCreateCommand.builder().surveyTemplateId(1L).name("Q1 Quality Survey").selectionOptions(idSelectionOptions).issuanceKind(SurveyIssuanceKind.INDIVIDUAL).involvementKindIds(SetUtilities.fromCollection(LongStream.range(1, 5).mapToObj(Long::valueOf).collect(toList()))).contactEmail("jack.livingston12@gmail.com").build();
    SurveyRunService surveyRunService = ctx.getBean(SurveyRunService.class);
    String userName = "livingston@mail.com";
    long surveyRunId = surveyRunService.createSurveyRun(userName, surveyRunCreateCommand).id().get();
    List<SurveyInstanceRecipient> surveyInstanceRecipients = surveyRunService.generateSurveyInstanceRecipients(surveyRunId);
    surveyInstanceRecipients.forEach(r -> System.out.println(r.surveyInstance().surveyEntity().name().get() + " => " + r.person().email()));
    System.out.println("Generated recipients count: " + surveyInstanceRecipients.size());
    surveyRunService.createSurveyInstancesAndRecipients(surveyRunId, surveyInstanceRecipients.subList(0, 5));
    ImmutableSurveyRunChangeCommand surveyRunChangeCommand = ImmutableSurveyRunChangeCommand.builder().surveyTemplateId(1L).name("Q2 Quality Survey").selectionOptions(idSelectionOptions).issuanceKind(SurveyIssuanceKind.GROUP).involvementKindIds(SetUtilities.fromCollection(LongStream.range(3, 7).mapToObj(Long::valueOf).collect(toList()))).contactEmail("jack.livingston12@gmail.com").build();
    // update survey run
    surveyRunService.updateSurveyRun(userName, surveyRunId, surveyRunChangeCommand);
    List<SurveyInstanceRecipient> updatedSurveyInstanceRecipients = surveyRunService.generateSurveyInstanceRecipients(surveyRunId);
    System.out.println("Updated Generated recipients count: " + updatedSurveyInstanceRecipients.size());
    // generate the instances and recipients again
    surveyRunService.createSurveyInstancesAndRecipients(surveyRunId, Collections.emptyList());
    // finally publish
    surveyRunService.updateSurveyRunStatus(userName, surveyRunId, SurveyRunStatus.ISSUED);
}
Also used : SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) SurveyRunService(com.khartec.waltz.service.survey.SurveyRunService)

Example 3 with SurveyQuestionService

use of com.khartec.waltz.service.survey.SurveyQuestionService in project waltz by khartec.

the class SurveyHarness method surveyResponseHarness.

private static void surveyResponseHarness(AnnotationConfigApplicationContext ctx) {
    String userName = "1258battle@gmail.com";
    SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
    SurveyInstanceService surveyInstanceService = ctx.getBean(SurveyInstanceService.class);
    List<SurveyInstance> instances = surveyInstanceService.findForRecipient(userName);
    System.out.println("===========Instances==========");
    System.out.println(instances);
    SurveyInstance instance = instances.get(0);
    List<SurveyQuestion> questions = surveyQuestionService.findForSurveyInstance(instance.id().get());
    System.out.println("===========Questions==========");
    System.out.println(questions);
    List<SurveyInstanceQuestionResponse> responses = surveyInstanceService.findResponses(instance.id().get());
    System.out.println("===========Responses==========");
    System.out.println(responses);
    ImmutableSurveyQuestionResponse insertResponse = ImmutableSurveyQuestionResponse.builder().questionId(1L).comment("some comment").stringResponse("some response").build();
    surveyInstanceService.saveResponse(userName, instance.id().get(), insertResponse);
    System.out.println("===========Inserted Responses==========");
    System.out.println(surveyInstanceService.findResponses(instance.id().get()));
    ImmutableSurveyQuestionResponse updateResponse = insertResponse.withStringResponse("updated string response");
    surveyInstanceService.saveResponse(userName, instance.id().get(), updateResponse);
    System.out.println("===========Updated Responses==========");
    System.out.println(surveyInstanceService.findResponses(instance.id().get()));
    surveyInstanceService.updateStatus(userName, instance.id().get(), ImmutableSurveyInstanceStatusChangeCommand.builder().newStatus(SurveyInstanceStatus.IN_PROGRESS).build());
}
Also used : SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) SurveyInstanceService(com.khartec.waltz.service.survey.SurveyInstanceService)

Example 4 with SurveyQuestionService

use of com.khartec.waltz.service.survey.SurveyQuestionService 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)

Example 5 with SurveyQuestionService

use of com.khartec.waltz.service.survey.SurveyQuestionService in project waltz by khartec.

the class SurveyTemplateGenerator method main.

public static void main(String[] args) {
    try {
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
        DSLContext dsl = ctx.getBean(DSLContext.class);
        SurveyTemplateService surveyTemplateService = ctx.getBean(SurveyTemplateService.class);
        SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
        dsl.deleteFrom(SURVEY_TEMPLATE).execute();
        dsl.deleteFrom(SURVEY_QUESTION).execute();
        ReleaseLifecycleStatusChangeCommand statusChangeCommand = ImmutableReleaseLifecycleStatusChangeCommand.builder().newStatus(ReleaseLifecycleStatus.ACTIVE).build();
        SurveyTemplateChangeCommand appSurvey = mkAppSurvey();
        long aid = surveyTemplateService.create("admin", appSurvey);
        List<SurveyQuestion> appQs = mkAppQuestions(aid);
        appQs.forEach(surveyQuestionService::create);
        surveyTemplateService.updateStatus("admin", aid, statusChangeCommand);
        SurveyTemplateChangeCommand projectSurvey = mkProjectSurvey();
        long pid = surveyTemplateService.create("admin", projectSurvey);
        List<SurveyQuestion> projQs = mkProjQuestions(pid);
        projQs.forEach(surveyQuestionService::create);
        surveyTemplateService.updateStatus("admin", pid, statusChangeCommand);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SurveyQuestionService(com.khartec.waltz.service.survey.SurveyQuestionService) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ImmutableReleaseLifecycleStatusChangeCommand(com.khartec.waltz.model.ImmutableReleaseLifecycleStatusChangeCommand) ReleaseLifecycleStatusChangeCommand(com.khartec.waltz.model.ReleaseLifecycleStatusChangeCommand) DSLContext(org.jooq.DSLContext) SurveyTemplateService(com.khartec.waltz.service.survey.SurveyTemplateService)

Aggregations

SurveyQuestionService (com.khartec.waltz.service.survey.SurveyQuestionService)5 SurveyInstanceService (com.khartec.waltz.service.survey.SurveyInstanceService)2 SurveyRunService (com.khartec.waltz.service.survey.SurveyRunService)2 SurveyTemplateService (com.khartec.waltz.service.survey.SurveyTemplateService)2 DSLContext (org.jooq.DSLContext)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ArrayUtilities (com.khartec.waltz.common.ArrayUtilities)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 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 SurveyTemplateDao (com.khartec.waltz.data.survey.SurveyTemplateDao)1 EntityKind (com.khartec.waltz.model.EntityKind)1 HierarchyQueryScope (com.khartec.waltz.model.HierarchyQueryScope)1 ImmutableReleaseLifecycleStatusChangeCommand (com.khartec.waltz.model.ImmutableReleaseLifecycleStatusChangeCommand)1 ReleaseLifecycleStatusChangeCommand (com.khartec.waltz.model.ReleaseLifecycleStatusChangeCommand)1 AppGroup (com.khartec.waltz.model.app_group.AppGroup)1