From 1c48526fcefa81dc500f2da4b0a8f97f482c162f Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 29 Mar 2022 11:32:02 +0200 Subject: [PATCH] SEBSERV-240 finished --- .../gui/content/monitoring/FinishedExam.java | 8 ++- .../api/ClientConnectionController.java | 70 +++++-------------- 2 files changed, 24 insertions(+), 54 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/FinishedExam.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/FinishedExam.java index d25a1aae..9839d159 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/FinishedExam.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/monitoring/FinishedExam.java @@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.EntityKey; @@ -156,10 +157,11 @@ public class FinishedExam implements TemplateComposer { if (indicator.type == IndicatorType.LAST_PING || indicator.type == IndicatorType.NONE) { return; } - tableBuilder.withColumn(new ColumnDefinition<>( - indicator.name, + tableBuilder.withColumn(new ColumnDefinition( + ClientConnectionData.ATTR_INDICATOR_VALUE + Constants.UNDERLINE + indicator.id, new LocTextKey(indicator.name), - cc -> cc.getIndicatorDisplayValue(indicator))); + cc -> cc.getIndicatorDisplayValue(indicator)) + .sortable()); }); final EntityTable table = tableBuilder.compose(pageContext.copyOf(content)); diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ClientConnectionController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ClientConnectionController.java index daef8596..bed39fc5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ClientConnectionController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ClientConnectionController.java @@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.API.BulkActionType; import ch.ethz.seb.sebserver.gbl.api.EntityType; @@ -82,34 +83,6 @@ public class ClientConnectionController extends ReadonlyEntityController - * GET /{api}/{domain-entity-name} - *

- * For example for the "exam" domain-entity - * GET /admin-api/v1/exam - * GET /admin-api/v1/exam?page_number=2&page_size=10&sort=-name - * GET /admin-api/v1/exam?name=seb&active=true - *

- * Sorting: the sort parameter to sort the list of entities before paging - * the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for - * descending sort order. Note that not all entity-model attribute are suited for sorting while the most - * are. - *

- * Filter: The filter attributes accepted by this API depend on the actual entity model (domain object) - * and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually - * filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing - * a given text-snippet. - * - * @param institutionId The institution identifier of the request. - * Default is the institution identifier of the institution of the current user - * @param pageNumber the number of the page that is requested - * @param pageSize the size of the page that is requested - * @param sort the sort parameter to sort the list of entities before paging - * the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for - * descending sort order. - * @param allRequestParams a MultiValueMap of all request parameter that is used for filtering. - * @return Page of domain-model-entities of specified type */ @Override @RequestMapping( method = RequestMethod.GET, @@ -299,12 +272,8 @@ public class ClientConnectionController extends ReadonlyEntityController getClientConnectionDataFilter(final FilterMap filterMap) { - final String infoFilter = filterMap.getString(ClientConnection.FILTER_ATTR_INFO); - Predicate filter = Utils.truePredicate(); - if (StringUtils.isNotBlank(infoFilter)) { - filter = c -> c.clientConnection.getInfo() == null || c.clientConnection.getInfo().contains(infoFilter); - } - return filter; + final Predicate clientConnectionFilter = getClientConnectionFilter(filterMap); + return ccd -> clientConnectionFilter.test(ccd.clientConnection); } private static final class ClientConnectionComparator implements Comparator { @@ -338,30 +307,29 @@ public class ClientConnectionController extends ReadonlyEntityController { - final String sortColumn; - final boolean descending; + final ClientConnectionComparator clientConnectionComparator; ClientConnectionDataComparator(final String sort) { - this.sortColumn = PageSortOrder.decode(sort); - this.descending = PageSortOrder.getSortOrder(sort) == PageSortOrder.DESCENDING; + this.clientConnectionComparator = new ClientConnectionComparator(sort); } @Override public int compare(final ClientConnectionData cc1, final ClientConnectionData cc2) { - int result = 0; - if (Domain.CLIENT_CONNECTION.ATTR_EXAM_USER_SESSION_ID.equals(this.sortColumn)) { - result = cc1.clientConnection.userSessionId - .compareTo(cc2.clientConnection.userSessionId); - } else if (ClientConnection.ATTR_INFO.equals(this.sortColumn)) { - result = cc1.clientConnection.getInfo().compareTo(cc2.clientConnection.getInfo()); - } else if (Domain.CLIENT_CONNECTION.ATTR_STATUS.equals(this.sortColumn)) { - result = cc1.clientConnection.getStatus() - .compareTo(cc2.clientConnection.getStatus()); - } else { - result = cc1.clientConnection.userSessionId - .compareTo(cc2.clientConnection.userSessionId); + if (this.clientConnectionComparator.sortColumn.startsWith(ClientConnectionData.ATTR_INDICATOR_VALUE)) { + try { + final Long iValuePK = Long.valueOf(StringUtils.split( + this.clientConnectionComparator.sortColumn, + Constants.UNDERLINE)[1]); + final Double indicatorValue1 = cc1.getIndicatorValue(iValuePK); + final Double indicatorValue2 = cc2.getIndicatorValue(iValuePK); + final int result = indicatorValue1.compareTo(indicatorValue2); + return (this.clientConnectionComparator.descending) ? -result : result; + } catch (final Exception e) { + this.clientConnectionComparator.compare(cc1.clientConnection, cc2.clientConnection); + } } - return (this.descending) ? -result : result; + + return this.clientConnectionComparator.compare(cc1.clientConnection, cc2.clientConnection); } } }