diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/StaticClientConnectionData.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/StaticClientConnectionData.java new file mode 100644 index 00000000..ca042de4 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/session/StaticClientConnectionData.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gbl.model.session; + +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import ch.ethz.seb.sebserver.gbl.api.EntityType; +import ch.ethz.seb.sebserver.gbl.model.Domain; +import ch.ethz.seb.sebserver.gbl.model.Entity; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class StaticClientConnectionData implements Entity { + + @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID) + public final Long id; + @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_CONNECTION_TOKEN) + public final String connectionToken; + @JsonProperty(ClientConnection.ATTR_INFO) + public final String info; + @JsonProperty(ClientConnectionData.ATTR_CLIENT_GROUPS) + public Set groups = null; + + @JsonCreator + public StaticClientConnectionData( + @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_ID) final Long id, + @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_CONNECTION_TOKEN) final String connectionToken, + @JsonProperty(ClientConnection.ATTR_INFO) final String info, + @JsonProperty(ClientConnectionData.ATTR_CLIENT_GROUPS) final Set groups) { + + this.id = id; + this.connectionToken = connectionToken; + this.info = info; + this.groups = groups; + } + + @Override + public String getModelId() { + return (this.id != null) + ? String.valueOf(this.id) + : null; + } + + @Override + public EntityType entityType() { + return EntityType.CLIENT_CONNECTION; + } + + @Override + public String getName() { + return this.connectionToken; + } + + public Set getGroups() { + return this.groups; + } + + public void setGroups(final Set groups) { + this.groups = groups; + } + + public Long getId() { + return this.id; + } + + public String getConnectionToken() { + return this.connectionToken; + } + + public String getInfo() { + return this.info; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final StaticClientConnectionData other = (StaticClientConnectionData) obj; + if (this.id == null) { + if (other.id != null) + return false; + } else if (!this.id.equals(other.id)) + return false; + return true; + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/monitoring/MonitoringSEBConnectionData.java b/src/main/java/ch/ethz/seb/sebserver/gbl/monitoring/MonitoringSEBConnectionData.java index 832b3cc3..decf4191 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/monitoring/MonitoringSEBConnectionData.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/monitoring/MonitoringSEBConnectionData.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; @@ -28,8 +27,6 @@ public class MonitoringSEBConnectionData { public static final String ATTR_STATUS_MAPPING = "statusMapping"; public static final String ATTR_CLIENT_GROUP_MAPPING = "clientGroupMapping"; - @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_EXAM_ID) - public final Long examId; @JsonProperty(ATTR_CONNECTIONS) public final Collection connections; @JsonProperty(ATTR_STATUS_MAPPING) @@ -39,21 +36,15 @@ public class MonitoringSEBConnectionData { @JsonCreator public MonitoringSEBConnectionData( - @JsonProperty(Domain.CLIENT_CONNECTION.ATTR_EXAM_ID) final Long examId, @JsonProperty(ATTR_CONNECTIONS) final Collection connections, @JsonProperty(ATTR_STATUS_MAPPING) final int[] connectionsPerStatus, @JsonProperty(ATTR_CLIENT_GROUP_MAPPING) final Map connectionsPerClientGroup) { - this.examId = examId; this.connections = connections; this.connectionsPerStatus = connectionsPerStatus; this.connectionsPerClientGroup = connectionsPerClientGroup; } - public Long getExamId() { - return this.examId; - } - public Collection getConnections() { return this.connections; } @@ -78,40 +69,15 @@ public class MonitoringSEBConnectionData { return this.connectionsPerClientGroup.get(clientGroupId); } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((this.examId == null) ? 0 : this.examId.hashCode()); - return result; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final MonitoringSEBConnectionData other = (MonitoringSEBConnectionData) obj; - if (this.examId == null) { - if (other.examId != null) - return false; - } else if (!this.examId.equals(other.examId)) - return false; - return true; - } - @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append("MonitoringSEBConnectionData [examId="); - builder.append(this.examId); - builder.append(", connections="); + builder.append("MonitoringSEBConnectionData [connections="); builder.append(this.connections); builder.append(", connectionsPerStatus="); builder.append(Arrays.toString(this.connectionsPerStatus)); + builder.append(", connectionsPerClientGroup="); + builder.append(this.connectionsPerClientGroup); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java index 87ba1c8b..4266558c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/ExamSessionService.java @@ -18,8 +18,9 @@ import ch.ethz.seb.sebserver.gbl.api.APIMessage; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; 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.monitoring.MonitoringSEBConnectionData; import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData; +import ch.ethz.seb.sebserver.gbl.model.session.StaticClientConnectionData; +import ch.ethz.seb.sebserver.gbl.monitoring.MonitoringSEBConnectionData; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO; @@ -235,4 +236,6 @@ public interface ExamSessionService { return connection.clientConnection.status.clientActiveStatus; } + Result> getStaticClientConnectionInfo(String connecionTokens); + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java index 40c44d9a..41578b84 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/ExamSessionServiceImpl.java @@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -23,6 +24,7 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -42,6 +44,7 @@ import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamStatus; 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; +import ch.ethz.seb.sebserver.gbl.model.session.StaticClientConnectionData; import ch.ethz.seb.sebserver.gbl.monitoring.MonitoringSEBConnectionData; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; @@ -435,7 +438,6 @@ public class ExamSessionServiceImpl implements ExamSessionService { .collect(Collectors.toList()); return new MonitoringSEBConnectionData( - examId, filteredConnections, statusMapping, clientGroupMapping); @@ -586,4 +588,23 @@ public class ExamSessionServiceImpl implements ExamSessionService { }); } + @Override + public Result> getStaticClientConnectionInfo(final String connecionTokens) { + return Result.tryCatch(() -> { + if (StringUtils.isBlank(connecionTokens)) { + return Collections.emptyList(); + } + + return Arrays.asList(StringUtils.split(connecionTokens, Constants.LIST_SEPARATOR)) + .stream() + .map(this.examSessionCacheService::getClientConnection) + .map(cc -> new StaticClientConnectionData( + cc.clientConnection.id, + cc.clientConnection.connectionToken, + cc.clientConnection.info, + cc.groups)) + .collect(Collectors.toList()); + }); + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java index 31b5a4b0..b33e80e6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamMonitoringController.java @@ -270,7 +270,7 @@ public class ExamMonitoringController { method = RequestMethod.GET, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public MonitoringFullPageData getFullpageData( + public MonitoringFullPageData getFullMonitoringPageData( @RequestParam( name = API.PARAM_INSTITUTION_ID, required = true,