diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java index 612d2ea6..6e3242fe 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java @@ -133,6 +133,7 @@ public final class Constants { public static final String XML_PLIST_STRING = "string"; public static final String XML_PLIST_DATA = "data"; public static final String XML_PLIST_INTEGER = "integer"; + public static final String XML_PLIST_REAL = "real"; public static final String OAUTH2_GRANT_TYPE_PASSWORD = "password"; public static final String OAUTH2_CLIENT_SECRET = "client_secret"; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java index de4b8f57..b4957ff1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBExamConfigForm.java @@ -417,15 +417,17 @@ public class SEBExamConfigForm implements TemplateComposer { } private PageAction deleteConfiguration(final PageAction action) { + final EntityKey entityKey = action.getEntityKey(); + final ConfigurationNode configNode = this.restService .getBuilder(GetExamConfigNode.class) - .withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) .call() .getOrThrow(); final Result call = this.restService .getBuilder(DeleteExamConfiguration.class) - .withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) .call(); final PageContext pageContext = action.pageContext(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java index 50079e64..b2fef43a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java @@ -204,15 +204,15 @@ public class EntityTable { this.table.addListener(SWT.MouseDoubleClick, event -> { // if the action has its own selection function, apply this EntityKey selection = defaultAction.getSingleSelection(); + if (selection == null) { // otherwise use current selection of this table selection = getSingleSelection(); } + if (selection != null) { this.pageService.executePageAction( defaultAction.withEntityKey(selection)); - } else { - this.pageService.executePageAction(defaultAction); } }); } 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 157f06c0..08d52120 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 @@ -81,7 +81,8 @@ public class ExamConfigXMLParser extends DefaultHandler { Constants.XML_PLIST_BOOLEAN_TRUE, Constants.XML_PLIST_STRING, Constants.XML_PLIST_DATA, - Constants.XML_PLIST_INTEGER)); + Constants.XML_PLIST_INTEGER, + Constants.XML_PLIST_REAL)); private static final Set KNOWN_INLINE_TABLES = Utils.immutableSetOf(Arrays.asList( "arguments")); @@ -162,6 +163,7 @@ public class ExamConfigXMLParser extends DefaultHandler { case VALUE_STRING: case VALUE_DATA: case VALUE_INTEGER: + case VALUE_REAL_NUMBER: startValueElement(type, top); break; } @@ -397,7 +399,7 @@ public class ExamConfigXMLParser extends DefaultHandler { } else { top.value += StringEscapeUtils.unescapeXml(value); } - } else if (top.type == Type.VALUE_INTEGER) { + } else if (top.type == Type.VALUE_INTEGER || top.type == Type.VALUE_REAL_NUMBER) { top.value = value; } else if (top.type == Type.KEY) { top.name = value; @@ -574,7 +576,8 @@ public class ExamConfigXMLParser extends DefaultHandler { VALUE_BOOLEAN_FALSE(true, Constants.XML_PLIST_BOOLEAN_FALSE), VALUE_STRING(true, Constants.XML_PLIST_STRING), VALUE_DATA(true, Constants.XML_PLIST_DATA), - VALUE_INTEGER(true, Constants.XML_PLIST_INTEGER); + VALUE_INTEGER(true, Constants.XML_PLIST_INTEGER), + VALUE_REAL_NUMBER(true, Constants.XML_PLIST_REAL); private final boolean isValueType; private final String typeName; 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 new file mode 100644 index 00000000..26031af5 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/RealNumberConverter.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2023 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.impl.converter; + +import java.io.IOException; +import java.io.OutputStream; +import java.text.DecimalFormat; +import java.util.Collections; +import java.util.Set; +import java.util.function.Function; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; +import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; +import ch.ethz.seb.sebserver.gbl.util.Utils; +import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.AttributeValueConverter; + +@Lazy +@Component +@WebServiceProfile +public class RealNumberConverter implements AttributeValueConverter { + + private static final Logger log = LoggerFactory.getLogger(IntegerConverter.class); + + public static final Set SUPPORTED_ATTR_NAMES = Utils.immutableSetOf( + "defaultPageZoomLevel", + "defaultTextZoomLevel"); + + private static final String XML_TEMPLATE = "%s%s"; + private static final String JSON_TEMPLATE = "\"%s\":%s"; + + private static final DecimalFormat FORMATTER = new DecimalFormat("0.##############"); + + @Override + public Set names() { + return SUPPORTED_ATTR_NAMES; + } + + @Override + public Set types() { + return Collections.emptySet(); + } + + @Override + public void convertToXML( + final OutputStream out, + final ConfigurationAttribute attribute, + final Function valueSupplier) throws IOException { + + convert(out, attribute, valueSupplier.apply(attribute), XML_TEMPLATE); + } + + @Override + public void convertToJSON( + final OutputStream out, + final ConfigurationAttribute attribute, + final Function valueSupplier) throws IOException { + + convert(out, attribute, valueSupplier.apply(attribute), JSON_TEMPLATE); + } + + private void convert( + final OutputStream out, + final ConfigurationAttribute attribute, + final ConfigurationValue value, + final String template) throws IOException { + + final String val = (value != null && value.value != null) + ? value.value + : attribute.getDefaultValue(); + + double realVal; + try { + realVal = Double.parseDouble(val); + } catch (final NumberFormatException nfe) { + log.error("Failed to convert SEB configuration attribute value of type real number: {}", val, nfe); + realVal = 0; + } + + out.write(Utils.toByteArray(String.format( + template, + AttributeValueConverter.extractName(attribute), + FORMATTER.format(realVal)))); + } + +} diff --git a/src/main/resources/config/sql/base/V20__fixes_v1_5.sql b/src/main/resources/config/sql/base/V20__fixes_v1_5.sql new file mode 100644 index 00000000..89b9e122 --- /dev/null +++ b/src/main/resources/config/sql/base/V20__fixes_v1_5.sql @@ -0,0 +1,7 @@ +-- ----------------------------------------------------------------- +-- Fix SEB Settings according to SEBSERV-329 +-- ----------------------------------------------------------------- + +UPDATE configuration_attribute SET default_value='1' WHERE id=1565; +UPDATE configuration_attribute SET default_value='1' WHERE id=1566; +UPDATE configuration_attribute SET parent_id=93 WHERE id=1577; \ No newline at end of file