From ca23a2e5819c44276ac935f11e6b6e55ca97d59c Mon Sep 17 00:00:00 2001 From: dmitrij Date: Mon, 5 Aug 2024 18:08:37 +0300 Subject: [PATCH] OD-19241 feat: allow all custom field types for survey forms --- .../function/DataCollectionFunctions.groovy | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/server/src/main/groovy/ish/oncourse/server/api/v1/function/DataCollectionFunctions.groovy b/server/src/main/groovy/ish/oncourse/server/api/v1/function/DataCollectionFunctions.groovy index 1c814e73172..69875b86c69 100644 --- a/server/src/main/groovy/ish/oncourse/server/api/v1/function/DataCollectionFunctions.groovy +++ b/server/src/main/groovy/ish/oncourse/server/api/v1/function/DataCollectionFunctions.groovy @@ -12,6 +12,7 @@ package ish.oncourse.server.api.v1.function import groovy.transform.CompileDynamic +import ish.oncourse.server.api.service.SurveyApiService import ish.oncourse.server.cayenne.ArticleFieldConfiguration import ish.oncourse.server.cayenne.Enrolment import ish.oncourse.server.cayenne.MembershipFieldConfiguration @@ -98,12 +99,7 @@ class DataCollectionFunctions { if (Survey.simpleName == formType) { - fieldTypes = ObjectSelect.query(CustomFieldType) - .where(CustomFieldType.ENTITY_IDENTIFIER.eq(Survey.class.simpleName)) - .and(CustomFieldType.DATA_TYPE.in(TEXT, LIST, MAP)) - .orderBy(CustomFieldType.SORT_ORDER.asc()) - .select(context) - .collect { new FieldTypeDTO(uniqueKey: "${CUSTOM_FIELD_PROPERTY_PATTERN}${it.entityIdentifier.toLowerCase()}.${it.key}", label: it.name) } + fieldTypes = getFieldTypes(context, Survey.class.simpleName) fieldTypes << new FieldTypeDTO(uniqueKey: NET_PROMOTER_SCORE.key, label: NET_PROMOTER_SCORE.displayName) fieldTypes << new FieldTypeDTO(uniqueKey: COURSE_SCORE.key, label: COURSE_SCORE.displayName) @@ -111,12 +107,7 @@ class DataCollectionFunctions { fieldTypes << new FieldTypeDTO(uniqueKey: TUTOR_SCORE.key, label: TUTOR_SCORE.displayName) fieldTypes << new FieldTypeDTO(uniqueKey: COMMENT.key, label: COMMENT.displayName) } else { - fieldTypes = ObjectSelect.query(CustomFieldType) - .where(CustomFieldType.ENTITY_IDENTIFIER.in(Contact.class.simpleName, formType == 'Product' ? 'Article' : formType)) - .orderBy(CustomFieldType.SORT_ORDER.asc()) - .select(context) - .collect { new FieldTypeDTO(uniqueKey: "${CUSTOM_FIELD_PROPERTY_PATTERN}${it.entityIdentifier.toLowerCase()}.${it.key}", label: it.name) } - + fieldTypes = getFieldTypes(context, Contact.class.simpleName, formType == 'Product' ? 'Article' : formType) fieldTypes += VISIBLE_FIELDS switch (formType) { @@ -131,6 +122,14 @@ class DataCollectionFunctions { return fieldTypes } + static List getFieldTypes(ObjectContext context, String... identifiers) { + ObjectSelect.query(CustomFieldType) + .where(CustomFieldType.ENTITY_IDENTIFIER.in(identifiers.toList())) + .orderBy(CustomFieldType.SORT_ORDER.asc()) + .select(context) + .collect { new FieldTypeDTO(uniqueKey: "${CUSTOM_FIELD_PROPERTY_PATTERN}${it.entityIdentifier.toLowerCase()}.${it.key}", label: it.name) } + } + static FieldConfiguration getFormByName(ObjectContext context, String name) { return ObjectSelect.query(FieldConfiguration).where(FieldConfiguration.NAME.eq(name)) .selectOne(context)