fixed SEB Settings bugs

This commit is contained in:
anhefti 2023-02-01 16:35:52 +01:00
parent 9800fdcd7c
commit 2062c3cddb
6 changed files with 118 additions and 7 deletions

View file

@ -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";

View file

@ -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<EntityProcessingReport> 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();

View file

@ -204,15 +204,15 @@ public class EntityTable<ROW extends ModelIdAware> {
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);
}
});
}

View file

@ -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<String> 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;

View file

@ -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<String> SUPPORTED_ATTR_NAMES = Utils.immutableSetOf(
"defaultPageZoomLevel",
"defaultTextZoomLevel");
private static final String XML_TEMPLATE = "<key>%s</key><real>%s</real>";
private static final String JSON_TEMPLATE = "\"%s\":%s";
private static final DecimalFormat FORMATTER = new DecimalFormat("0.##############");
@Override
public Set<String> names() {
return SUPPORTED_ATTR_NAMES;
}
@Override
public Set<AttributeType> types() {
return Collections.emptySet();
}
@Override
public void convertToXML(
final OutputStream out,
final ConfigurationAttribute attribute,
final Function<ConfigurationAttribute, ConfigurationValue> valueSupplier) throws IOException {
convert(out, attribute, valueSupplier.apply(attribute), XML_TEMPLATE);
}
@Override
public void convertToJSON(
final OutputStream out,
final ConfigurationAttribute attribute,
final Function<ConfigurationAttribute, ConfigurationValue> 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))));
}
}

View file

@ -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;