fixed SEB Settings bugs
This commit is contained in:
parent
9800fdcd7c
commit
2062c3cddb
6 changed files with 118 additions and 7 deletions
|
@ -133,6 +133,7 @@ public final class Constants {
|
||||||
public static final String XML_PLIST_STRING = "string";
|
public static final String XML_PLIST_STRING = "string";
|
||||||
public static final String XML_PLIST_DATA = "data";
|
public static final String XML_PLIST_DATA = "data";
|
||||||
public static final String XML_PLIST_INTEGER = "integer";
|
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_GRANT_TYPE_PASSWORD = "password";
|
||||||
public static final String OAUTH2_CLIENT_SECRET = "client_secret";
|
public static final String OAUTH2_CLIENT_SECRET = "client_secret";
|
||||||
|
|
|
@ -417,15 +417,17 @@ public class SEBExamConfigForm implements TemplateComposer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private PageAction deleteConfiguration(final PageAction action) {
|
private PageAction deleteConfiguration(final PageAction action) {
|
||||||
|
final EntityKey entityKey = action.getEntityKey();
|
||||||
|
|
||||||
final ConfigurationNode configNode = this.restService
|
final ConfigurationNode configNode = this.restService
|
||||||
.getBuilder(GetExamConfigNode.class)
|
.getBuilder(GetExamConfigNode.class)
|
||||||
.withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId)
|
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
|
||||||
.call()
|
.call()
|
||||||
.getOrThrow();
|
.getOrThrow();
|
||||||
|
|
||||||
final Result<EntityProcessingReport> call = this.restService
|
final Result<EntityProcessingReport> call = this.restService
|
||||||
.getBuilder(DeleteExamConfiguration.class)
|
.getBuilder(DeleteExamConfiguration.class)
|
||||||
.withURIVariable(API.PARAM_MODEL_ID, action.getEntityKey().modelId)
|
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
final PageContext pageContext = action.pageContext();
|
final PageContext pageContext = action.pageContext();
|
||||||
|
|
|
@ -204,15 +204,15 @@ public class EntityTable<ROW extends ModelIdAware> {
|
||||||
this.table.addListener(SWT.MouseDoubleClick, event -> {
|
this.table.addListener(SWT.MouseDoubleClick, event -> {
|
||||||
// if the action has its own selection function, apply this
|
// if the action has its own selection function, apply this
|
||||||
EntityKey selection = defaultAction.getSingleSelection();
|
EntityKey selection = defaultAction.getSingleSelection();
|
||||||
|
|
||||||
if (selection == null) {
|
if (selection == null) {
|
||||||
// otherwise use current selection of this table
|
// otherwise use current selection of this table
|
||||||
selection = getSingleSelection();
|
selection = getSingleSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selection != null) {
|
if (selection != null) {
|
||||||
this.pageService.executePageAction(
|
this.pageService.executePageAction(
|
||||||
defaultAction.withEntityKey(selection));
|
defaultAction.withEntityKey(selection));
|
||||||
} else {
|
|
||||||
this.pageService.executePageAction(defaultAction);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ public class ExamConfigXMLParser extends DefaultHandler {
|
||||||
Constants.XML_PLIST_BOOLEAN_TRUE,
|
Constants.XML_PLIST_BOOLEAN_TRUE,
|
||||||
Constants.XML_PLIST_STRING,
|
Constants.XML_PLIST_STRING,
|
||||||
Constants.XML_PLIST_DATA,
|
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(
|
private static final Set<String> KNOWN_INLINE_TABLES = Utils.immutableSetOf(Arrays.asList(
|
||||||
"arguments"));
|
"arguments"));
|
||||||
|
@ -162,6 +163,7 @@ public class ExamConfigXMLParser extends DefaultHandler {
|
||||||
case VALUE_STRING:
|
case VALUE_STRING:
|
||||||
case VALUE_DATA:
|
case VALUE_DATA:
|
||||||
case VALUE_INTEGER:
|
case VALUE_INTEGER:
|
||||||
|
case VALUE_REAL_NUMBER:
|
||||||
startValueElement(type, top);
|
startValueElement(type, top);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -397,7 +399,7 @@ public class ExamConfigXMLParser extends DefaultHandler {
|
||||||
} else {
|
} else {
|
||||||
top.value += StringEscapeUtils.unescapeXml(value);
|
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;
|
top.value = value;
|
||||||
} else if (top.type == Type.KEY) {
|
} else if (top.type == Type.KEY) {
|
||||||
top.name = value;
|
top.name = value;
|
||||||
|
@ -574,7 +576,8 @@ public class ExamConfigXMLParser extends DefaultHandler {
|
||||||
VALUE_BOOLEAN_FALSE(true, Constants.XML_PLIST_BOOLEAN_FALSE),
|
VALUE_BOOLEAN_FALSE(true, Constants.XML_PLIST_BOOLEAN_FALSE),
|
||||||
VALUE_STRING(true, Constants.XML_PLIST_STRING),
|
VALUE_STRING(true, Constants.XML_PLIST_STRING),
|
||||||
VALUE_DATA(true, Constants.XML_PLIST_DATA),
|
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 boolean isValueType;
|
||||||
private final String typeName;
|
private final String typeName;
|
||||||
|
|
|
@ -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))));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
7
src/main/resources/config/sql/base/V20__fixes_v1_5.sql
Normal file
7
src/main/resources/config/sql/base/V20__fixes_v1_5.sql
Normal 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;
|
Loading…
Reference in a new issue