use of org.finos.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();
ImmutableInstancesAndRecipientsCreateCommand createCmd = ImmutableInstancesAndRecipientsCreateCommand.builder().surveyRunId(surveyRunId).dueDate(toLocalDate(nowUtcTimestamp())).approvalDueDate(toLocalDate(nowUtcTimestamp())).excludedRecipients(emptySet()).build();
List<SurveyInstanceRecipient> surveyInstanceRecipients = surveyRunService.generateSurveyInstanceRecipients(createCmd);
surveyInstanceRecipients.forEach(r -> System.out.println(r.surveyInstance().surveyEntity().name().get() + " => " + r.person().email()));
System.out.println("Generated recipients count: " + surveyInstanceRecipients.size());
surveyRunService.createSurveyInstancesAndRecipients(createCmd);
}
use of org.finos.waltz.service.survey.SurveyQuestionService in project waltz by khartec.
the class SurveyBuilder method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
SurveyTemplateService surveyTemplateService = ctx.getBean(SurveyTemplateService.class);
SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
SurveyQuestionDropdownEntryService surveyQuestionDropdownEntryService = ctx.getBean(SurveyQuestionDropdownEntryService.class);
long templateId = storeTemplate(surveyTemplateService);
storeQuestions(surveyQuestionService, surveyQuestionDropdownEntryService, mkAllQs.apply(templateId));
}
use of org.finos.waltz.service.survey.SurveyQuestionService in project waltz by khartec.
the class SurveyRunGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
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.findAllActive();
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);
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());
ImmutableInstancesAndRecipientsCreateCommand createCmd = ImmutableInstancesAndRecipientsCreateCommand.builder().surveyRunId(surveyRunId).dueDate(toLocalDate(nowUtcTimestamp())).approvalDueDate(toLocalDate(nowUtcTimestamp())).excludedRecipients(emptySet()).build();
surveyRunService.createSurveyInstancesAndRecipients(createCmd);
List<SurveyInstanceQuestionResponse> surveyInstanceQuestionResponses = mkRandomSurveyRunResponses(surveyRunId, surveyInstanceService, surveyQuestionService);
Map<SurveyInstanceStatus, Set<Long>> surveyInstanceStatusMap = surveyInstanceQuestionResponses.stream().mapToLong(response -> response.surveyInstanceId()).distinct().mapToObj(id -> tuple(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(DateTimeUtilities.nowUtcTimestamp());
return record;
}).filter(Objects::nonNull).collect(toList())).execute();
if (SurveyRunStatus.valueOf(surveyRunRecord.getStatus()) == SurveyRunStatus.COMPLETED) {
surveyRunRecord.setStatus(SurveyRunStatus.COMPLETED.name());
surveyRunRecord.store();
surveyCompletedCount.incrementAndGet();
// update 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);
}
} 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());
return null;
}
use of org.finos.waltz.service.survey.SurveyQuestionService in project waltz by khartec.
the class SurveyTemplateGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
SurveyTemplateService surveyTemplateService = ctx.getBean(SurveyTemplateService.class);
SurveyQuestionService surveyQuestionService = ctx.getBean(SurveyQuestionService.class);
SurveyTemplateChangeCommand appSurvey = mkAppSurvey();
long aid = surveyTemplateService.create("admin", appSurvey);
List<SurveyQuestion> appQs = mkAppQuestions(aid);
appQs.forEach(surveyQuestionService::create);
SurveyTemplateChangeCommand projectSurvey = mkProjectSurvey();
long pid = surveyTemplateService.create("admin", projectSurvey);
List<SurveyQuestion> projQs = mkProjQuestions(pid);
projQs.forEach(surveyQuestionService::create);
surveyTemplateService.updateStatus("admin", aid, ImmutableReleaseLifecycleStatusChangeCommand.builder().newStatus(ReleaseLifecycleStatus.ACTIVE).build());
surveyTemplateService.updateStatus("admin", pid, ImmutableReleaseLifecycleStatusChangeCommand.builder().newStatus(ReleaseLifecycleStatus.ACTIVE).build());
return null;
}
use of org.finos.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);
}
Aggregations