use of org.finos.waltz.schema.Tables.SURVEY_QUESTION_LIST_RESPONSE in project waltz by khartec.
the class SurveyQuestionResponseDao method saveGenericListResponse.
private <T> void saveGenericListResponse(DSLContext txDsl, Long instanceId, Long questionId, List<T> list, BiConsumer<T, SurveyQuestionListResponseRecord> recordUpdater) {
txDsl.deleteFrom(SURVEY_QUESTION_LIST_RESPONSE).where(SURVEY_QUESTION_LIST_RESPONSE.SURVEY_INSTANCE_ID.eq(instanceId)).and(SURVEY_QUESTION_LIST_RESPONSE.QUESTION_ID.eq(questionId)).execute();
if (!list.isEmpty()) {
AtomicInteger counter = new AtomicInteger(0);
List<SurveyQuestionListResponseRecord> listResponses = list.stream().map(lr -> {
SurveyQuestionListResponseRecord rec = new SurveyQuestionListResponseRecord();
rec.setSurveyInstanceId(instanceId);
rec.setQuestionId(questionId);
rec.setPosition(counter.incrementAndGet());
recordUpdater.accept(lr, rec);
return rec;
}).collect(toList());
txDsl.batchInsert(listResponses).execute();
}
}
Aggregations