diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java index 5aa3c0e7..be21cd87 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Indicator.java @@ -17,7 +17,6 @@ import javax.validation.constraints.Size; import org.apache.commons.lang3.StringUtils; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -35,14 +34,15 @@ public final class Indicator implements Entity { public static final String FILTER_ATTR_EXAM_ID = "examId"; public enum IndicatorType { - LAST_PING(Names.LAST_PING, true, true, false, false), - ERROR_COUNT(Names.ERROR_COUNT, true, false, true, false), - WARN_COUNT(Names.WARN_COUNT, true, false, true, false), - INFO_COUNT(Names.INFO_COUNT, true, false, true, false), - BATTERY_STATUS(Names.BATTERY_STATUS, true, true, true, true), - WLAN_STATUS(Names.WLAN_STATUS, true, true, true, true); + LAST_PING(Names.LAST_PING, false, true, true, false, false), + ERROR_COUNT(Names.ERROR_COUNT, false, true, false, true, false), + WARN_COUNT(Names.WARN_COUNT, false, true, false, true, false), + INFO_COUNT(Names.INFO_COUNT, false, true, false, true, false), + BATTERY_STATUS(Names.BATTERY_STATUS, true, true, true, true, true), + WLAN_STATUS(Names.WLAN_STATUS, true, true, true, true, true); public final String name; + public final boolean inverse; public final boolean integerValue; public final boolean showOnlyInActiveState; public final boolean tags; @@ -50,12 +50,14 @@ public final class Indicator implements Entity { IndicatorType( final String name, + final boolean inverse, final boolean integerValue, final boolean showOnlyInActiveState, final boolean tags, final boolean tagsReadonly) { this.name = name; + this.inverse = inverse; this.integerValue = integerValue; this.showOnlyInActiveState = showOnlyInActiveState; this.tags = tags; @@ -176,11 +178,6 @@ public final class Indicator implements Entity { return this.tags; } - @JsonIgnore - public boolean hasTags() { - return this.type != IndicatorType.LAST_PING; - } - public Collection getThresholds() { return this.thresholds; } 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 1f2d12c0..b0e0f78d 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 @@ -10,6 +10,7 @@ package ch.ethz.seb.sebserver.gbl.model.session; import com.fasterxml.jackson.annotation.JsonProperty; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; public interface IndicatorValue extends IndicatorValueHolder { @@ -33,6 +34,9 @@ public interface IndicatorValue extends IndicatorValueHolder { * @param indicatorValue The indicator value instance * @return the display value of the given IndicatorValue */ static String getDisplayValue(final IndicatorValue indicatorValue) { + if (Double.isNaN(indicatorValue.getValue())) { + return Constants.EMPTY_NOTE; + } if (indicatorValue.getType().integerValue) { return String.valueOf((int) indicatorValue.getValue()); } else { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java index b93624f1..9f140275 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java @@ -8,7 +8,7 @@ package ch.ethz.seb.sebserver.gui.content; -import org.eclipse.swt.SWT; +import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.widgets.Composite; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -39,9 +39,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.NewIndicator; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.SaveIndicator; -import ch.ethz.seb.sebserver.gui.widget.Selection; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; -import io.micrometer.core.instrument.util.StringUtils; @Lazy @Component @@ -174,7 +172,7 @@ public class IndicatorForm implements TemplateComposer { Domain.INDICATOR.ATTR_TAGS, FORM_TAGS_TEXT_KEY, indicator.tags) - .visibleIf(indicator.hasTags())) + .visibleIf(indicator.type != null && indicator.type.tags && !indicator.type.tagsReadonly)) .addField(FormBuilder.thresholdList( Domain.THRESHOLD.REFERENCE_NAME, FORM_THRESHOLDS_TEXT_KEY, @@ -184,14 +182,6 @@ public class IndicatorForm implements TemplateComposer { ? restService.getRestCall(NewIndicator.class) : restService.getRestCall(SaveIndicator.class)); - formHandle.getForm().getFieldInput(Domain.INDICATOR.ATTR_TYPE) - .addListener(SWT.Selection, event -> formHandle.process( - name -> Domain.INDICATOR.ATTR_TAGS.equals(name), - ffa -> { - final String stringValue = ((Selection) event.widget).getSelectionValue(); - ffa.setVisible(stringValue == null || !stringValue.equals(IndicatorType.LAST_PING.name)); - })); - // propagate content actions to action-pane this.pageService.pageActionBuilder(formContext.clearEntityKeys()) @@ -214,6 +204,11 @@ public class IndicatorForm implements TemplateComposer { form.setFieldValue( TYPE_DESCRIPTION_FIELD_NAME, this.i18nSupport.getText(INDICATOR_TYPE_DESC_PREFIX + typeValue)); + final IndicatorType type = IndicatorType.valueOf(typeValue); + form.setFieldVisible(type.tags && !type.tagsReadonly, Domain.INDICATOR.ATTR_TAGS); + if (!type.tags || type.tagsReadonly) { + form.setFieldValue(Domain.INDICATOR.ATTR_TAGS, StringUtils.EMPTY); + } } else { form.setFieldValue(TYPE_DESCRIPTION_FIELD_NAME, Constants.EMPTY_NOTE); } 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 d91d7262..116707f4 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 @@ -571,7 +571,8 @@ public final class ClientConnectionTable { @Override public int compareTo(final UpdatableTableItem other) { - return Comparator.comparingInt(UpdatableTableItem::statusWeight) + return Comparator.comparingInt(UpdatableTableItem::notificationWeight) + .thenComparingInt(UpdatableTableItem::statusWeight) .thenComparingInt(UpdatableTableItem::thresholdsWeight) .thenComparing(UpdatableTableItem::getConnectionIdentifier) .compare(this, other); @@ -600,6 +601,10 @@ public final class ClientConnectionTable { return compareTo(other) == 0; } + int notificationWeight() { + return BooleanUtils.isTrue(this.connectionData.pendingNotification) ? -1 : 0; + } + int statusWeight() { return ClientConnectionTable.this.colorData.statusWeight(this.connectionData); } @@ -653,9 +658,15 @@ public final class ClientConnectionTable { final int indicatorWeight = IndicatorData.getWeight(indicatorData, value); if (this.indicatorWeights[indicatorData.index] != indicatorWeight) { ClientConnectionTable.this.needsSort = true; - this.thresholdsWeight -= this.indicatorWeights[indicatorData.index]; + this.thresholdsWeight -= (indicatorData.indicator.type.inverse) + ? indicatorData.indicator.thresholds.size() + - this.indicatorWeights[indicatorData.index] + : this.indicatorWeights[indicatorData.index]; this.indicatorWeights[indicatorData.index] = indicatorWeight; - this.thresholdsWeight += this.indicatorWeights[indicatorData.index]; + this.thresholdsWeight += (indicatorData.indicator.type.inverse) + ? indicatorData.indicator.thresholds.size() + - this.indicatorWeights[indicatorData.index] + : this.indicatorWeights[indicatorData.index]; } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogIndicator.java index d4de0281..04e8d804 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogIndicator.java @@ -39,7 +39,7 @@ public abstract class AbstractLogIndicator extends AbstractClientIndicator { @Override public void init(final Indicator indicatorDefinition, final Long connectionId, final boolean cachingEnabled) { super.init(indicatorDefinition, connectionId, cachingEnabled); - if (indicatorDefinition == null || indicatorDefinition.tags == null) { + if (indicatorDefinition == null || StringUtils.isBlank(indicatorDefinition.tags)) { this.tags = null; } else { this.tags = StringUtils.split(indicatorDefinition.tags, Constants.COMMA); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java index 9e5eb7d1..80f3ad40 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/indicator/AbstractLogNumberIndicator.java @@ -59,10 +59,14 @@ public abstract class AbstractLogNumberIndicator extends AbstractLogIndicator { ClientEventRecordDynamicSqlSupport.text, isLikeWhenPresent(getfirstTagSQL()), getSubTagSQL()) - .orderBy(ClientEventRecordDynamicSqlSupport.serverTime.descending()) + .orderBy(ClientEventRecordDynamicSqlSupport.serverTime) .build() .execute(); + if (execute == null || execute.isEmpty()) { + return this.currentValue; + } + return execute.get(execute.size() - 1).getNumericValue().doubleValue(); } catch (final Exception e) { log.error("Failed to get indicator number from persistent storage: ", e); diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/services/ClientEventServiceTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/services/ClientEventServiceTest.java index 99036399..865910cc 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/services/ClientEventServiceTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/services/ClientEventServiceTest.java @@ -183,7 +183,7 @@ public class ClientEventServiceTest extends AdministrationAPIIntegrationTester { assertTrue(findFirst.isPresent()); final IndicatorValue clientIndicator = findFirst.get(); - assertEquals("0", IndicatorValue.getDisplayValue(clientIndicator)); + assertEquals("--", IndicatorValue.getDisplayValue(clientIndicator)); this.sebClientConnectionService.notifyClientEvent( "token3", @@ -193,7 +193,7 @@ public class ClientEventServiceTest extends AdministrationAPIIntegrationTester { "token3", new ClientEvent(null, connection.id, EventType.INFO_LOG, 1L, 1L, 1.0, " some info other")); - assertEquals("0", IndicatorValue.getDisplayValue(clientIndicator)); + assertEquals("--", IndicatorValue.getDisplayValue(clientIndicator)); this.sebClientConnectionService.notifyClientEvent( "token3",