fix find-bugs issues
This commit is contained in:
parent
70094a5a60
commit
15739de559
11 changed files with 143 additions and 26 deletions
|
@ -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 =
|
||||
"</dict>";
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ExamAPIVersion> getVersions() {
|
||||
return this.versions;
|
||||
}
|
||||
|
||||
public static final class ExamAPIVersion {
|
||||
|
||||
@JsonProperty("name")
|
||||
|
@ -69,7 +87,7 @@ public final class ExamAPIDiscovery {
|
|||
@JsonProperty("endpoints") final Collection<Endpoint> 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<Endpoint> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,18 @@ public class EntityProcessingReport {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Set<EntityKey> getSource() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public Set<EntityKey> getDependencies() {
|
||||
return this.dependencies;
|
||||
}
|
||||
|
||||
public Set<ErrorEntry> 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
|
||||
|
|
|
@ -166,6 +166,26 @@ public final class ConfigurationAttribute implements Entity, Comparable<Configur
|
|||
return this.name.compareToIgnoreCase(attribute.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.name == null) ? 0 : this.name.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 ConfigurationAttribute other = (ConfigurationAttribute) obj;
|
||||
return this.compareTo(other) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ExamineeAccountDetails {
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import ch.ethz.seb.sebserver.gbl.async.AsyncServiceSpringConfig;
|
|||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
|
||||
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationAttributeDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationValueDAO;
|
||||
|
@ -40,6 +41,13 @@ public class ExamConfigIO {
|
|||
|
||||
private static final Logger log = LoggerFactory.getLogger(ExamConfigIO.class);
|
||||
|
||||
private static final byte[] XML_VERSION_HEADER_UTF_8 = Utils.toByteArray(Constants.XML_VERSION_HEADER);
|
||||
private static final byte[] XML_DOCTYPE_HEADER_UTF_8 = Utils.toByteArray(Constants.XML_DOCTYPE_HEADER);
|
||||
private static final byte[] XML_PLIST_START_V1_UTF_8 = Utils.toByteArray(Constants.XML_PLIST_START_V1);
|
||||
private static final byte[] XML_PLIST_END_UTF_8 = Utils.toByteArray(Constants.XML_PLIST_END);
|
||||
private static final byte[] XML_DICT_START_UTF_8 = Utils.toByteArray(Constants.XML_DICT_START);
|
||||
private static final byte[] XML_DICT_END_UTF_8 = Utils.toByteArray(Constants.XML_DICT_END);
|
||||
|
||||
private final ConfigurationAttributeDAO configurationAttributeDAO;
|
||||
private final ConfigurationValueDAO configurationValueDAO;
|
||||
private final ConfigurationDAO configurationDAO;
|
||||
|
@ -93,12 +101,12 @@ public class ExamConfigIO {
|
|||
|
||||
try {
|
||||
// write headers
|
||||
out.write(Constants.XML_VERSION_HEADER_UTF_8);
|
||||
out.write(Constants.XML_DOCTYPE_HEADER_UTF_8);
|
||||
out.write(XML_VERSION_HEADER_UTF_8);
|
||||
out.write(XML_DOCTYPE_HEADER_UTF_8);
|
||||
|
||||
// plist open
|
||||
out.write(Constants.XML_PLIST_START_V1_UTF_8);
|
||||
out.write(Constants.XML_DICT_START_UTF_8);
|
||||
out.write(XML_PLIST_START_V1_UTF_8);
|
||||
out.write(XML_DICT_START_UTF_8);
|
||||
|
||||
// write attributes
|
||||
for (final ConfigurationAttribute attribute : sortedAttributes) {
|
||||
|
@ -112,8 +120,8 @@ public class ExamConfigIO {
|
|||
}
|
||||
|
||||
// plist close
|
||||
out.write(Constants.XML_DICT_END_UTF_8);
|
||||
out.write(Constants.XML_PLIST_END_UTF_8);
|
||||
out.write(XML_DICT_END_UTF_8);
|
||||
out.write(XML_PLIST_END_UTF_8);
|
||||
out.flush();
|
||||
|
||||
} catch (final Exception e) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import java.io.OutputStream;
|
|||
import java.util.Collection;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.Exam;
|
||||
import ch.ethz.seb.sebserver.gbl.model.session.ClientConnectionData;
|
||||
import ch.ethz.seb.sebserver.gbl.util.Result;
|
||||
|
||||
/** A Service to handle running exam sessions */
|
||||
|
@ -45,4 +46,18 @@ public interface ExamSessionService {
|
|||
* @param out The OutputStream to stream the data to */
|
||||
void streamDefaultExamConfig(String connectionToken, OutputStream out);
|
||||
|
||||
/** Get current ClientConnectionData for a specified active SEB client connection.
|
||||
*
|
||||
* @param connectionToken the connection token of the active SEB client connection
|
||||
* @return */
|
||||
Result<ClientConnectionData> 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<Collection<ClientConnectionData>> getConnectionData(Long examId);
|
||||
|
||||
}
|
||||
|
|
|
@ -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<ClientConnectionData> 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<Collection<ClientConnectionData>> 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);
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
|
||||
<root level="INFO" additivity="true">
|
||||
<appender-ref ref="STDOUT" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
</springProfile>
|
||||
|
|
Loading…
Reference in a new issue