fixes in indicator threshold validation

This commit is contained in:
anhefti 2019-11-28 16:20:32 +01:00
parent 646cc51d3e
commit 6f9c84969f
6 changed files with 49 additions and 26 deletions

View file

@ -14,11 +14,12 @@ import java.util.List;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.api.POSTMapper;
import ch.ethz.seb.sebserver.gbl.model.Domain;
@ -163,11 +164,11 @@ public final class Indicator implements Entity {
return new Indicator(null, exam.id, null, null, null, null);
}
public static String getDisplayValue(final Indicator indicator, final Double value) {
if (value == null) {
return Constants.EMPTY_NOTE;
public static String getDisplayValue(final IndicatorType indicatorType, final Double value) {
if (value == null || indicatorType == null) {
return StringUtils.EMPTY;
}
if (indicator.getType().integerValue) {
if (indicatorType.integerValue) {
return String.valueOf(value.intValue());
} else {
return String.valueOf(value.floatValue());

View file

@ -740,7 +740,7 @@ public class ExamForm implements TemplateComposer {
? "color: #4a4a4a; "
: "color: #FFFFFF;")
.append("'>")
.append(Indicator.getDisplayValue(indicator, threshold.value))
.append(Indicator.getDisplayValue(indicator.type, threshold.value))
.append(" (")
.append(threshold.color)
.append(")")

View file

@ -260,7 +260,10 @@ public class FormBuilder {
final LocTextKey label,
final Indicator indicator) {
return new ThresholdListBuilder(name, label, indicator);
return new ThresholdListBuilder(
name,
label,
indicator.thresholds);
}
public static ImageUploadFieldBuilder imageUpload(final String name, final LocTextKey label, final String value) {

View file

@ -19,22 +19,22 @@ import org.eclipse.swt.widgets.Label;
import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.Domain;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.widget.ThresholdList;
public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
private final Indicator indicator;
private final Collection<Threshold> thresholds;
protected ThresholdListBuilder(
final String name,
final LocTextKey label,
final Indicator indicator) {
final Collection<Threshold> thresholds) {
super(name, label, indicator.getThresholds());
this.indicator = indicator;
super(name, label, thresholds);
this.thresholds = thresholds;
}
@Override
@ -46,15 +46,24 @@ public class ThresholdListBuilder extends FieldBuilder<Collection<Threshold>> {
this.spanLabel);
if (builder.readonly || this.readonly) {
// TODO do we need a read-only view for this?
// No read-only view needed for this so far?
return;
} else {
final Composite fieldGrid = Form.createFieldGrid(builder.formParent, this.spanInput);
final ThresholdList thresholdList = builder.widgetFactory.thresholdList(
fieldGrid,
fieldGrid.getParent().getParent(),
this.indicator);
this.thresholds,
() -> {
try {
final String fieldValue = builder.form.getFieldValue(Domain.INDICATOR.ATTR_TYPE);
return IndicatorType.valueOf(fieldValue);
} catch (final Exception e) {
return null;
}
});
final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
thresholdList.setLayoutData(gridData);

View file

@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.gui.widget;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
@ -25,6 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
@ -45,7 +47,7 @@ public final class ThresholdList extends Composite {
private static final LocTextKey REMOVE_TEXT_KEY = new LocTextKey("sebserver.exam.indicator.thresholds.list.remove");
private final WidgetFactory widgetFactory;
private final Indicator indicator;
private final Supplier<IndicatorType> indicatorTypeSupplier;
private final List<Entry> thresholds = new ArrayList<>();
private final GridData valueCell;
@ -54,13 +56,13 @@ public final class ThresholdList extends Composite {
private final Composite updateAnchor;
ThresholdList(
final Indicator indicator,
final Composite parent,
final Composite updateAnchor,
final WidgetFactory widgetFactory) {
final WidgetFactory widgetFactory,
final Supplier<IndicatorType> indicatorTypeSupplier) {
super(parent, SWT.NONE);
this.indicator = indicator;
this.indicatorTypeSupplier = indicatorTypeSupplier;
this.updateAnchor = updateAnchor;
this.widgetFactory = widgetFactory;
super.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@ -137,7 +139,7 @@ public final class ThresholdList extends Composite {
private void addThreshold(final Threshold threshold) {
final Text valueInput = this.widgetFactory.numberInput(
this, s -> {
if (this.indicator.getType().integerValue) {
if (this.indicatorTypeSupplier.get().integerValue) {
Integer.parseInt(s);
} else {
Double.parseDouble(s);
@ -163,7 +165,9 @@ public final class ThresholdList extends Composite {
if (threshold != null) {
if (threshold.value != null) {
valueInput.setText(Indicator.getDisplayValue(this.indicator, threshold.value));
valueInput.setText(Indicator.getDisplayValue(
this.indicatorTypeSupplier.get(),
threshold.value));
}
if (threshold.color != null) {
selector.select(threshold.color);

View file

@ -40,7 +40,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType;
import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gbl.util.Tuple;
import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition;
@ -58,7 +59,7 @@ public class WidgetFactory {
private static final Logger log = LoggerFactory.getLogger(WidgetFactory.class);
public static final int TEXT_AREA_INPUT_MIN_HEIGHT = 50;
public static final int TEXT_AREA_INPUT_MIN_HEIGHT = 100;
public static final int TEXT_INPUT_MIN_HEIGHT = 24;
public enum ImageIcon {
@ -605,11 +606,16 @@ public class WidgetFactory {
public ThresholdList thresholdList(
final Composite parent,
final Composite updateAnchor,
final Indicator indicator) {
final Collection<Threshold> thresholds,
final Supplier<IndicatorType> indicatorTypeSupplier) {
final ThresholdList thresholdList = new ThresholdList(indicator, parent, updateAnchor, this);
if (indicator.thresholds != null) {
thresholdList.setThresholds(indicator.thresholds);
final ThresholdList thresholdList = new ThresholdList(
parent,
updateAnchor,
this,
indicatorTypeSupplier);
if (thresholds != null) {
thresholdList.setThresholds(thresholds);
}
return thresholdList;
}