From 4b675bc7174a2a44a84241da2be38c5aa2d7ba0a Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 2 May 2024 12:52:57 +0200 Subject: [PATCH] SEBSERV-527 --- .../sebconfig/impl/ExamConfigXMLParser.java | 35 +++++++++++++++++-- .../impl/converter/RealNumberConverter.java | 7 ++-- .../sql/base/V28__migration_task1_v2_0.sql | 8 ++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigXMLParser.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigXMLParser.java index 89ef5274..57c63ec0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigXMLParser.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/ExamConfigXMLParser.java @@ -76,6 +76,11 @@ public class ExamConfigXMLParser extends DefaultHandler { "whitelistURLFilter", "URLFilterIgnoreList")); + private static final Set DECIMAL_TYPES = Utils.immutableSetOf(Arrays.asList( + "defaultPageZoomLevel", + "defaultTextZoomLevel", + "screenProctoringImageDownscale")); + private static final Set VALUE_ELEMENTS = Utils.immutableSetOf(Arrays.asList( Constants.XML_PLIST_BOOLEAN_FALSE, Constants.XML_PLIST_BOOLEAN_TRUE, @@ -456,8 +461,7 @@ public class ExamConfigXMLParser extends DefaultHandler { } } case INTEGER: - case RADIO_SELECTION: - case SINGLE_SELECTION: { + case RADIO_SELECTION: { try { Integer.parseInt(value); return value; @@ -470,6 +474,33 @@ public class ExamConfigXMLParser extends DefaultHandler { return attribute.defaultValue; } } + case SINGLE_SELECTION: { + if (DECIMAL_TYPES.contains(attribute.name)) { + try { + Double.parseDouble(value); + return value; + } catch (final Exception e) { + log.warn( + "Invalid attribute value detected. Name: {} type: {} value: {} : import with default value for this attribute", + attribute.name, + attribute.type, + value); + return attribute.defaultValue; + } + } else { + try { + Integer.parseInt(value); + return value; + } catch (final Exception e) { + log.warn( + "Invalid attribute value detected. Name: {} type: {} value: {} : import with default value for this attribute", + attribute.name, + attribute.type, + value); + return attribute.defaultValue; + } + } + } case DECIMAL: { try { Double.parseDouble(value); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/RealNumberConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/RealNumberConverter.java index 275ef83b..f5d5dead 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/RealNumberConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/RealNumberConverter.java @@ -90,9 +90,10 @@ public class RealNumberConverter implements AttributeValueConverter { realVal = 0; } - // NOTE: this is a special case for screenProctoringImageDownscale selector to get the selected real value - // from the selection-index instead using the index. See SEBSERV-527 - if ("screenProctoringImageDownscale".equals(attribute.name)) { + // NOTE: this is a special case for screenProctoringImageDownscale legacy data. See SEBSERV-527 + // Legacy data do not affect production data but only testing data so far. + // TODO this can be removed after release of 2.0 + if ("screenProctoringImageDownscale".equals(attribute.name) && realVal > 2.0) { realVal = realVal / 10.0 + 1.0; } diff --git a/src/main/resources/config/sql/base/V28__migration_task1_v2_0.sql b/src/main/resources/config/sql/base/V28__migration_task1_v2_0.sql index c110570d..a55b2118 100644 --- a/src/main/resources/config/sql/base/V28__migration_task1_v2_0.sql +++ b/src/main/resources/config/sql/base/V28__migration_task1_v2_0.sql @@ -27,4 +27,10 @@ ADD COLUMN IF NOT EXISTS `client_configuration_id` BIGINT NULL; -- ---------------------------------------------------------------- UPDATE orientation SET y_position=21 WHERE config_attribute_id=1578 AND template_id=0; INSERT IGNORE INTO orientation (config_attribute_id, template_id, view_id, group_id, x_position, y_position, width, height, title) VALUES - (1201, 0, 9, 'clipboardPolicy', 7, 18, 5, 2, 'NONE'); \ No newline at end of file + (1201, 0, 9, 'clipboardPolicy', 7, 18, 5, 2, 'NONE'); + +-- ---------------------------------------------------------------- +-- Fix SEBSERV-527 +-- ---------------------------------------------------------------- + +UPDATE configuration_attribute SET resources='1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0', default_value='1.0' WHERE name='screenProctoringImageDownscale'; \ No newline at end of file