Search in sources :

Example 1 with SurveyQuestionListResponseRecord

use of org.finos.waltz.schema.tables.records.SurveyQuestionListResponseRecord 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();
    }
}
Also used : StringUtilities.join(org.finos.waltz.common.StringUtilities.join) DSL(org.jooq.impl.DSL) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SURVEY_INSTANCE(org.finos.waltz.schema.tables.SurveyInstance.SURVEY_INSTANCE) Checks.checkTrue(org.finos.waltz.common.Checks.checkTrue) BigDecimal(java.math.BigDecimal) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) SURVEY_QUESTION_LIST_RESPONSE(org.finos.waltz.schema.Tables.SURVEY_QUESTION_LIST_RESPONSE) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.jooq(org.jooq) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Repository(org.springframework.stereotype.Repository) SURVEY_QUESTION_RESPONSE(org.finos.waltz.schema.tables.SurveyQuestionResponse.SURVEY_QUESTION_RESPONSE) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) StringUtilities.ifEmpty(org.finos.waltz.common.StringUtilities.ifEmpty) org.finos.waltz.model.survey(org.finos.waltz.model.survey) SurveyQuestionListResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionListResponseRecord) Optional.ofNullable(java.util.Optional.ofNullable) ListUtilities.isEmpty(org.finos.waltz.common.ListUtilities.isEmpty) Timestamp(java.sql.Timestamp) Set(java.util.Set) Collectors(java.util.stream.Collectors) Date(java.sql.Date) SURVEY_RUN(org.finos.waltz.schema.Tables.SURVEY_RUN) SurveyQuestionResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionResponseRecord) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) InlineSelectFieldFactory(org.finos.waltz.data.InlineSelectFieldFactory) EntityReference(org.finos.waltz.model.EntityReference) Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SurveyQuestionListResponseRecord(org.finos.waltz.schema.tables.records.SurveyQuestionListResponseRecord)

Aggregations

BigDecimal (java.math.BigDecimal)1 Date (java.sql.Date)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 Checks.checkTrue (org.finos.waltz.common.Checks.checkTrue)1 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 ListUtilities.isEmpty (org.finos.waltz.common.ListUtilities.isEmpty)1 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)1 SetUtilities.map (org.finos.waltz.common.SetUtilities.map)1 StringUtilities.ifEmpty (org.finos.waltz.common.StringUtilities.ifEmpty)1 StringUtilities.join (org.finos.waltz.common.StringUtilities.join)1