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
This commit is contained in:
anhefti 2020-12-02 09:01:12 +01:00
parent 9a9b04d1ec
commit 5258f2384b
7 changed files with 52 additions and 30 deletions

View file

@ -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. */

View file

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

View file

@ -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<IndicatorType, IndicatorData> indicatorMapping;
private final Map<Long, IndicatorData> indicatorMapping;
private final RestCall<ClientConnectionData>.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);

View file

@ -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<Collection<ClientConnectionData>>.RestCallBuilder restCallBuilder;
private final EnumMap<IndicatorType, IndicatorData> indicatorMapping;
private final Map<Long, IndicatorData> indicatorMapping;
private final Table table;
private final ColorData colorData;
private final EnumSet<ConnectionStatus> 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();

View file

@ -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<IndicatorType, IndicatorData> createFormIndicators(
static Map<Long, IndicatorData> createFormIndicators(
final Collection<Indicator> indicators,
final Display display,
final ColorData colorData,
final int tableIndexOffset) {
final EnumMap<IndicatorType, IndicatorData> indicatorMapping = new EnumMap<>(IndicatorType.class);
final Map<Long, IndicatorData> 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,

View file

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

View file

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