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 cafaf6ba..5e2c4aeb 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 java.util.function.Consumer; import org.apache.commons.lang3.BooleanUtils; @@ -22,7 +22,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; @@ -52,7 +51,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; @@ -167,7 +166,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 df601195..d91d7262 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; @@ -50,7 +50,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; @@ -68,6 +67,8 @@ public final class ClientConnectionTable { private static final Logger log = LoggerFactory.getLogger(ClientConnectionTable.class); + private static final int[] TABLE_PROPORTIONS = new int[] { 3, 1, 2, 1 }; + private static final int BOTTOM_PADDING = 20; private static final int NUMBER_OF_NONE_INDICATOR_COLUMNS = 3; private static final String USER_SESSION_STATUS_FILTER_ATTRIBUTE = "USER_SESSION_STATUS_FILTER_ATTRIBUTE"; @@ -91,7 +92,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; @@ -355,9 +356,22 @@ public final class ClientConnectionTable { private void adaptTableWidth() { final Rectangle area = this.table.getParent().getClientArea(); if (this.tableWidth != area.width) { - final int columnWidth = area.width / this.table.getColumnCount() - 5; - for (final TableColumn column : this.table.getColumns()) { - column.setWidth(columnWidth); + + // proportions size + final int pSize = TABLE_PROPORTIONS[0] + + TABLE_PROPORTIONS[1] + + TABLE_PROPORTIONS[2] + + TABLE_PROPORTIONS[3] * this.indicatorMapping.size(); + final int columnUnitSize = (pSize > 0) + ? area.width / pSize + : area.width / TABLE_PROPORTIONS.length - 1 + this.indicatorMapping.size(); + + final TableColumn[] columns = this.table.getColumns(); + for (int i = 0; i < columns.length; i++) { + final int proportionFactor = (i < TABLE_PROPORTIONS.length) + ? TABLE_PROPORTIONS[i] + : TABLE_PROPORTIONS[TABLE_PROPORTIONS.length - 1]; + columns[i].setWidth(proportionFactor * columnUnitSize); } this.tableWidth = area.width; } @@ -528,7 +542,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; } @@ -632,7 +646,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/indicator/AbstractClientIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java index baf30534..34c647ce 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractClientIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/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.examId = (indicatorDefinition != null) ? indicatorDefinition.examId : null; + this.indicatorId = (indicatorDefinition != null) ? indicatorDefinition.id : -1; + this.examId = (indicatorDefinition != null) ? indicatorDefinition.examId : -1; 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 87faf630..3412bdef 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 @@ -232,7 +232,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)); @@ -250,9 +250,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(), null, null), 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));