From 15739de559b85635d2b116963671e41be7fed123 Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 4 Jul 2019 13:58:10 +0200 Subject: [PATCH] fix find-bugs issues --- .../ch/ethz/seb/sebserver/gbl/Constants.java | 9 ---- .../sebserver/gbl/api/ExamAPIDiscovery.java | 48 ++++++++++++++++++- .../seb/sebserver/gbl/api/POSTMapper.java | 7 +-- .../seb/sebserver/gbl/model/EntityKey.java | 4 +- .../gbl/model/EntityProcessingReport.java | 19 ++++++++ .../sebconfig/ConfigurationAttribute.java | 20 ++++++++ .../model/user/ExamineeAccountDetails.java | 2 +- .../sebconfig/impl/ExamConfigIO.java | 20 +++++--- .../session/ExamSessionService.java | 15 ++++++ .../session/impl/ExamSessionServiceImpl.java | 24 ++++++++++ src/main/resources/logback-spring.xml | 1 + 11 files changed, 143 insertions(+), 26 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java index a62b7948..920afd90 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/Constants.java @@ -11,8 +11,6 @@ package ch.ethz.seb.sebserver.gbl; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; -import ch.ethz.seb.sebserver.gbl.util.Utils; - /** Global Constants used in SEB Server web-service as well as in web-gui component */ public final class Constants { @@ -56,11 +54,4 @@ public final class Constants { public static final String XML_DICT_END = ""; - public static final byte[] XML_VERSION_HEADER_UTF_8 = Utils.toByteArray(XML_VERSION_HEADER); - public static final byte[] XML_DOCTYPE_HEADER_UTF_8 = Utils.toByteArray(XML_DOCTYPE_HEADER); - public static final byte[] XML_PLIST_START_V1_UTF_8 = Utils.toByteArray(XML_PLIST_START_V1); - public static final byte[] XML_PLIST_END_UTF_8 = Utils.toByteArray(XML_PLIST_END); - public static final byte[] XML_DICT_START_UTF_8 = Utils.toByteArray(XML_DICT_START); - public static final byte[] XML_DICT_END_UTF_8 = Utils.toByteArray(XML_DICT_END); - } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/ExamAPIDiscovery.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/ExamAPIDiscovery.java index 413230e7..994d730b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/ExamAPIDiscovery.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/ExamAPIDiscovery.java @@ -15,6 +15,8 @@ import java.util.Collections; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import ch.ethz.seb.sebserver.gbl.util.Utils; + public final class ExamAPIDiscovery { @JsonProperty("title") @@ -55,6 +57,22 @@ public final class ExamAPIDiscovery { (versions != null) ? Arrays.asList(versions) : Collections.emptyList()); } + public String getTitle() { + return this.title; + } + + public String getDescription() { + return this.description; + } + + public String getServerLocation() { + return this.serverLocation; + } + + public Collection getVersions() { + return this.versions; + } + public static final class ExamAPIVersion { @JsonProperty("name") @@ -69,7 +87,7 @@ public final class ExamAPIDiscovery { @JsonProperty("endpoints") final Collection endpoints) { this.name = name; - this.endpoints = endpoints; + this.endpoints = Utils.immutableCollectionOf(endpoints); } public ExamAPIVersion( @@ -77,8 +95,19 @@ public final class ExamAPIDiscovery { final Endpoint... endpoints) { this.name = name; - this.endpoints = (endpoints != null) ? Arrays.asList(endpoints) : Collections.emptyList(); + this.endpoints = (endpoints != null) + ? Utils.immutableCollectionOf(Arrays.asList(endpoints)) + : Collections.emptyList(); } + + public String getName() { + return this.name; + } + + public Collection getEndpoints() { + return this.endpoints; + } + } public static final class Endpoint { @@ -108,5 +137,20 @@ public final class ExamAPIDiscovery { this.authorization = authorization; } + public String getName() { + return this.name; + } + + public String getDescripiton() { + return this.descripiton; + } + + public String getLocation() { + return this.location; + } + + public String getAuthorization() { + return this.authorization; + } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java index 41eec2d0..0aae14bd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java @@ -55,12 +55,7 @@ public class POSTMapper { } public CharSequence getCharSequence(final String name) { - final char[] charArray = getCharArray(name); - if (charArray == null) { - return null; - } - - return CharBuffer.wrap(charArray); + return CharBuffer.wrap(getCharArray(name)); } public Long getLong(final String name) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java index 269f51b7..3bc7d405 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityKey.java @@ -53,8 +53,8 @@ public class EntityKey implements ModelIdAware, Serializable { final int prime = 31; int result = 1; - result = prime * result + ((this.entityType == null) ? 0 : this.entityType.hashCode()); - result = prime * result + ((this.modelId == null) ? 0 : this.modelId.hashCode()); + result = prime * result + this.entityType.hashCode(); + result = prime * result + this.modelId.hashCode(); this.hash = result; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityProcessingReport.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityProcessingReport.java index 48d13300..c92ed91d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityProcessingReport.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/EntityProcessingReport.java @@ -49,6 +49,18 @@ public class EntityProcessingReport { return null; } + public Set getSource() { + return this.source; + } + + public Set getDependencies() { + return this.dependencies; + } + + public Set getErrors() { + return this.errors; + } + public static final class ErrorEntry { public final EntityKey entityKey; @@ -63,6 +75,13 @@ public class EntityProcessingReport { this.errorMessage = errorMessage; } + public EntityKey getEntityKey() { + return this.entityKey; + } + + public APIMessage getErrorMessage() { + return this.errorMessage; + } } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationAttribute.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationAttribute.java index 6c195c93..0655aab8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationAttribute.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationAttribute.java @@ -166,6 +166,26 @@ public final class ConfigurationAttribute implements Entity, Comparable getConnectionData(String connectionToken); + + /** Get the collection of ClientConnectionData of all active SEB client connections + * of a running exam. + * + * @param examId The exam identifier + * @return collection of ClientConnectionData of all active SEB client connections + * of a running exam */ + Result> getConnectionData(Long examId); + } 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 3b6d3b5b..f28e55ff 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 @@ -23,6 +23,7 @@ import org.springframework.stereotype.Service; 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.ClientConnectionData; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ClientConnectionDAO; @@ -144,6 +145,29 @@ public class ExamSessionServiceImpl implements ExamSessionService { } } + @Override + public Result getConnectionData(final String connectionToken) { + final ClientConnectionDataInternal activeClientConnection = this.examSessionCacheService + .getActiveClientConnection(connectionToken); + + if (activeClientConnection == null) { + log.error("No active ClientConnection found for token: {}", connectionToken); + return Result.ofError(new IllegalArgumentException("No active ClientConnection found for token")); + } else { + return Result.of(activeClientConnection); + } + } + + @Override + public Result> getConnectionData(final Long examId) { + return this.clientConnectionDAO + .getConnectionTokens(examId) + .map(all -> all + .stream() + .map(this.examSessionCacheService::getActiveClientConnection) + .collect(Collectors.toList())); + } + private void flushCache(final Exam exam) { this.examSessionCacheService.evict(exam); this.examSessionCacheService.evictDefaultSebConfig(exam.id); diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 22630cd2..98ae07be 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -56,6 +56,7 @@ +