From 5258f2384b1635ad034d2474976b35f319e91a13 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 2 Dec 2020 09:01:12 +0100 Subject: [PATCH] SEBSERV-136 fixed bug with two indicator of the same type. The indicator mapping on GUI side is now done within the id not the type --- .../gbl/model/session/IndicatorValue.java | 7 ++++++ .../model/session/SimpleIndicatorValue.java | 17 ++++++++++---- .../session/ClientConnectionDetails.java | 11 ++++----- .../session/ClientConnectionTable.java | 9 ++++---- .../gui/service/session/IndicatorData.java | 23 ++++++++++--------- .../session/impl/AbstractClientIndicator.java | 7 ++++++ .../gbl/model/ModelObjectJSONGenerator.java | 8 +++---- 7 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/IndicatorValue.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/IndicatorValue.java index 2a19c939..1f2d12c0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/IndicatorValue.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/IndicatorValue.java @@ -14,6 +14,13 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; public interface IndicatorValue extends IndicatorValueHolder { + public static final String ATTR_INDICATOR_ID = "indicatorId"; + public static final String ATTR_INDICATOR_VALUE = "indicatorValue"; + public static final String ATTR_INDICATOR_TYPE = "indicatorType"; + + @JsonProperty(SimpleIndicatorValue.ATTR_INDICATOR_ID) + Long getIndicatorId(); + /** Use this to get the type of indicator this value was computed from. * * @return the type of indicator this value was computed from. */ diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/SimpleIndicatorValue.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/SimpleIndicatorValue.java index 5797dcbd..91c9e740 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/SimpleIndicatorValue.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/SimpleIndicatorValue.java @@ -15,9 +15,8 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; public final class SimpleIndicatorValue implements IndicatorValue { - public static final String ATTR_INDICATOR_VALUE = "indicatorValue"; - public static final String ATTR_INDICATOR_TYPE = "indicatorType"; - + @JsonProperty(ATTR_INDICATOR_ID) + public final Long indicatorId; @JsonProperty(ATTR_INDICATOR_TYPE) public final IndicatorType type; @JsonProperty(ATTR_INDICATOR_VALUE) @@ -25,13 +24,20 @@ public final class SimpleIndicatorValue implements IndicatorValue { @JsonCreator public SimpleIndicatorValue( + @JsonProperty(ATTR_INDICATOR_ID) final Long indicatorId, @JsonProperty(ATTR_INDICATOR_TYPE) final IndicatorType type, @JsonProperty(ATTR_INDICATOR_VALUE) final double value) { + this.indicatorId = indicatorId; this.type = type; this.value = value; } + @Override + public Long getIndicatorId() { + return this.indicatorId; + } + @Override public IndicatorType getType() { return this.type; @@ -45,11 +51,14 @@ public final class SimpleIndicatorValue implements IndicatorValue { @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append("IndicatorValue [type="); + builder.append("SimpleIndicatorValue [indicatorId="); + builder.append(this.indicatorId); + builder.append(", type="); builder.append(this.type); builder.append(", value="); builder.append(this.value); builder.append("]"); return builder.toString(); } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java index 5e831776..883fdbdd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionDetails.java @@ -9,7 +9,7 @@ package ch.ethz.seb.sebserver.gui.service.session; import java.util.Collection; -import java.util.EnumMap; +import java.util.Map; import org.apache.commons.lang3.BooleanUtils; import org.eclipse.swt.graphics.Color; @@ -21,7 +21,6 @@ import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; 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.QuizData; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; import ch.ethz.seb.sebserver.gbl.model.session.IndicatorValue; @@ -51,7 +50,7 @@ public class ClientConnectionDetails { private static final int NUMBER_OF_NONE_INDICATOR_ROWS = 3; private final ResourceService resourceService; - private final EnumMap indicatorMapping; + private final Map indicatorMapping; private final RestCall.RestCallBuilder restCallBuilder; private final FormHandle formHandle; private final ColorData colorData; @@ -123,8 +122,8 @@ public class ClientConnectionDetails { if (this.connectionData != null && connectionData != null) { this.statusChanged = this.connectionData.clientConnection.status != connectionData.clientConnection.status || - BooleanUtils.toBoolean(this.connectionData.missingPing) != - BooleanUtils.toBoolean(connectionData.missingPing); + BooleanUtils.toBoolean(this.connectionData.missingPing) != BooleanUtils + .toBoolean(connectionData.missingPing); } this.connectionData = connectionData; } @@ -157,7 +156,7 @@ public class ClientConnectionDetails { // update indicators this.connectionData.getIndicatorValues() .forEach(indValue -> { - final IndicatorData indData = this.indicatorMapping.get(indValue.getType()); + final IndicatorData indData = this.indicatorMapping.get(indValue.getIndicatorId()); final double value = indValue.getValue(); final String displayValue = IndicatorValue.getDisplayValue(indValue); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index f1232557..10c81dff 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -13,12 +13,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.EnumMap; import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.function.Consumer; @@ -48,7 +48,6 @@ import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; 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.session.ClientConnection; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; @@ -89,7 +88,7 @@ public final class ClientConnectionTable { private final ResourceService resourceService; private final Exam exam; private final RestCall>.RestCallBuilder restCallBuilder; - private final EnumMap indicatorMapping; + private final Map indicatorMapping; private final Table table; private final ColorData colorData; private final EnumSet statusFilter; @@ -509,7 +508,7 @@ public final class ClientConnectionTable { for (int i = 0; i < this.connectionData.indicatorValues.size(); i++) { final IndicatorValue indicatorValue = this.connectionData.indicatorValues.get(i); final IndicatorData indicatorData = - ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType()); + ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getIndicatorId()); if (indicatorData == null) { continue; } @@ -613,7 +612,7 @@ public final class ClientConnectionTable { for (int i = 0; i < connectionData.indicatorValues.size(); i++) { final IndicatorValue indicatorValue = connectionData.indicatorValues.get(i); final IndicatorData indicatorData = - ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType()); + ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getIndicatorId()); if (indicatorData != null) { final double value = indicatorValue.getValue(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java index bfd2225e..e60572e6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/IndicatorData.java @@ -8,17 +8,18 @@ package ch.ethz.seb.sebserver.gui.service.session; -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.util.Utils; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Display; - import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; -import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Display; + +import ch.ethz.seb.sebserver.gbl.model.exam.Indicator; +import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.Threshold; +import ch.ethz.seb.sebserver.gbl.util.Utils; final class IndicatorData { @@ -52,16 +53,16 @@ final class IndicatorData { } } - static EnumMap createFormIndicators( + static Map createFormIndicators( final Collection indicators, final Display display, final ColorData colorData, final int tableIndexOffset) { - final EnumMap indicatorMapping = new EnumMap<>(IndicatorType.class); + final Map indicatorMapping = new HashMap<>(); int i = 0; for (final Indicator indicator : indicators) { - indicatorMapping.put(indicator.type, new IndicatorData( + indicatorMapping.put(indicator.id, new IndicatorData( indicator, i, i + tableIndexOffset, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java index 87fba65b..b033c1de 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/AbstractClientIndicator.java @@ -16,6 +16,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.session.ClientIndicator; public abstract class AbstractClientIndicator implements ClientIndicator { + protected Long indicatorId; protected Long examId; protected Long connectionId; protected boolean cachingEnabled; @@ -28,11 +29,17 @@ public abstract class AbstractClientIndicator implements ClientIndicator { final Long connectionId, final boolean cachingEnabled) { + this.indicatorId = (indicatorDefinition != null) ? indicatorDefinition.id : -1; this.examId = (indicatorDefinition != null) ? indicatorDefinition.examId : null; this.connectionId = connectionId; this.cachingEnabled = cachingEnabled; } + @Override + public Long getIndicatorId() { + return this.indicatorId; + } + @Override public Long examId() { return this.examId; diff --git a/src/test/java/ch/ethz/seb/sebserver/gbl/model/ModelObjectJSONGenerator.java b/src/test/java/ch/ethz/seb/sebserver/gbl/model/ModelObjectJSONGenerator.java index 9ee92687..2642d9a5 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gbl/model/ModelObjectJSONGenerator.java +++ b/src/test/java/ch/ethz/seb/sebserver/gbl/model/ModelObjectJSONGenerator.java @@ -227,7 +227,7 @@ public class ModelObjectJSONGenerator { System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject)); domainObject = - new SimpleIndicatorValue(IndicatorType.LAST_PING, 1.0); + new SimpleIndicatorValue(1L, IndicatorType.LAST_PING, 1.0); System.out.println(domainObject.getClass().getSimpleName() + ":"); System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject)); @@ -244,9 +244,9 @@ public class ModelObjectJSONGenerator { 1L, 1L, 1L, ConnectionStatus.ACTIVE, UUID.randomUUID().toString(), "user-account-1", "86.119.30.213", "0.0.0.0", System.currentTimeMillis()), Arrays.asList( - new SimpleIndicatorValue(IndicatorType.LAST_PING, 1.0), - new SimpleIndicatorValue(IndicatorType.ERROR_COUNT, 2.0), - new SimpleIndicatorValue(IndicatorType.WARN_COUNT, 3.0))); + new SimpleIndicatorValue(1L, IndicatorType.LAST_PING, 1.0), + new SimpleIndicatorValue(2L, IndicatorType.ERROR_COUNT, 2.0), + new SimpleIndicatorValue(3L, IndicatorType.WARN_COUNT, 3.0))); System.out.println(domainObject.getClass().getSimpleName() + ":"); System.out.println(writerWithDefaultPrettyPrinter.writeValueAsString(domainObject));