SEBSERV-347 start implementing
This commit is contained in:
parent
b5704dea95
commit
dbe50a69ff
5 changed files with 138 additions and 40 deletions
|
@ -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<Long> 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<Long> 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<Long> getGroups() {
|
||||||
|
return this.groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroups(final Set<Long> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -17,7 +17,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
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.ClientConnection.ConnectionStatus;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
|
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_STATUS_MAPPING = "statusMapping";
|
||||||
public static final String ATTR_CLIENT_GROUP_MAPPING = "clientGroupMapping";
|
public static final String ATTR_CLIENT_GROUP_MAPPING = "clientGroupMapping";
|
||||||
|
|
||||||
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_EXAM_ID)
|
|
||||||
public final Long examId;
|
|
||||||
@JsonProperty(ATTR_CONNECTIONS)
|
@JsonProperty(ATTR_CONNECTIONS)
|
||||||
public final Collection<ClientConnectionData> connections;
|
public final Collection<ClientConnectionData> connections;
|
||||||
@JsonProperty(ATTR_STATUS_MAPPING)
|
@JsonProperty(ATTR_STATUS_MAPPING)
|
||||||
|
@ -39,21 +36,15 @@ public class MonitoringSEBConnectionData {
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public MonitoringSEBConnectionData(
|
public MonitoringSEBConnectionData(
|
||||||
@JsonProperty(Domain.CLIENT_CONNECTION.ATTR_EXAM_ID) final Long examId,
|
|
||||||
@JsonProperty(ATTR_CONNECTIONS) final Collection<ClientConnectionData> connections,
|
@JsonProperty(ATTR_CONNECTIONS) final Collection<ClientConnectionData> connections,
|
||||||
@JsonProperty(ATTR_STATUS_MAPPING) final int[] connectionsPerStatus,
|
@JsonProperty(ATTR_STATUS_MAPPING) final int[] connectionsPerStatus,
|
||||||
@JsonProperty(ATTR_CLIENT_GROUP_MAPPING) final Map<Long, Integer> connectionsPerClientGroup) {
|
@JsonProperty(ATTR_CLIENT_GROUP_MAPPING) final Map<Long, Integer> connectionsPerClientGroup) {
|
||||||
|
|
||||||
this.examId = examId;
|
|
||||||
this.connections = connections;
|
this.connections = connections;
|
||||||
this.connectionsPerStatus = connectionsPerStatus;
|
this.connectionsPerStatus = connectionsPerStatus;
|
||||||
this.connectionsPerClientGroup = connectionsPerClientGroup;
|
this.connectionsPerClientGroup = connectionsPerClientGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getExamId() {
|
|
||||||
return this.examId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<ClientConnectionData> getConnections() {
|
public Collection<ClientConnectionData> getConnections() {
|
||||||
return this.connections;
|
return this.connections;
|
||||||
}
|
}
|
||||||
|
@ -78,40 +69,15 @@ public class MonitoringSEBConnectionData {
|
||||||
return this.connectionsPerClientGroup.get(clientGroupId);
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
builder.append("MonitoringSEBConnectionData [examId=");
|
builder.append("MonitoringSEBConnectionData [connections=");
|
||||||
builder.append(this.examId);
|
|
||||||
builder.append(", connections=");
|
|
||||||
builder.append(this.connections);
|
builder.append(this.connections);
|
||||||
builder.append(", connectionsPerStatus=");
|
builder.append(", connectionsPerStatus=");
|
||||||
builder.append(Arrays.toString(this.connectionsPerStatus));
|
builder.append(Arrays.toString(this.connectionsPerStatus));
|
||||||
|
builder.append(", connectionsPerClientGroup=");
|
||||||
|
builder.append(this.connectionsPerClientGroup);
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.exam.Exam;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection;
|
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.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.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.gbl.util.Result;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO;
|
||||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamDAO;
|
||||||
|
@ -235,4 +236,6 @@ public interface ExamSessionService {
|
||||||
return connection.clientConnection.status.clientActiveStatus;
|
return connection.clientConnection.status.clientActiveStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<Collection<StaticClientConnectionData>> getStaticClientConnectionInfo(String connecionTokens);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ package ch.ethz.seb.sebserver.webservice.servicelayer.session.impl;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -23,6 +24,7 @@ import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.BooleanUtils;
|
import org.apache.commons.lang3.BooleanUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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;
|
||||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnection.ConnectionStatus;
|
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.ClientConnectionData;
|
||||||
|
import ch.ethz.seb.sebserver.gbl.model.session.StaticClientConnectionData;
|
||||||
import ch.ethz.seb.sebserver.gbl.monitoring.MonitoringSEBConnectionData;
|
import ch.ethz.seb.sebserver.gbl.monitoring.MonitoringSEBConnectionData;
|
||||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||||
|
@ -435,7 +438,6 @@ public class ExamSessionServiceImpl implements ExamSessionService {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return new MonitoringSEBConnectionData(
|
return new MonitoringSEBConnectionData(
|
||||||
examId,
|
|
||||||
filteredConnections,
|
filteredConnections,
|
||||||
statusMapping,
|
statusMapping,
|
||||||
clientGroupMapping);
|
clientGroupMapping);
|
||||||
|
@ -586,4 +588,23 @@ public class ExamSessionServiceImpl implements ExamSessionService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Collection<StaticClientConnectionData>> 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());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class ExamMonitoringController {
|
||||||
method = RequestMethod.GET,
|
method = RequestMethod.GET,
|
||||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public MonitoringFullPageData getFullpageData(
|
public MonitoringFullPageData getFullMonitoringPageData(
|
||||||
@RequestParam(
|
@RequestParam(
|
||||||
name = API.PARAM_INSTITUTION_ID,
|
name = API.PARAM_INSTITUTION_ID,
|
||||||
required = true,
|
required = true,
|
||||||
|
|
Loading…
Reference in a new issue