Skip to content

Commit

Permalink
SEBSERV-594
Browse files Browse the repository at this point in the history
  • Loading branch information
anhefti committed Dec 4, 2024
1 parent fadcf31 commit ae481ef
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,18 @@
package ch.ethz.seb.sebserver.gbl.model.exam;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Objects;

import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.Entity;
import org.apache.commons.lang3.BooleanUtils;
import org.hibernate.validator.constraints.URL;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.model.Domain;
import org.joda.time.DateTime;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScreenProctoringSettings implements SPSAPIAccessData, Entity {
Expand All @@ -36,6 +34,7 @@ public class ScreenProctoringSettings implements SPSAPIAccessData, Entity {
public static final String ATTR_SPS_ACCOUNT_ID = "spsAccountId";
public static final String ATTR_SPS_ACCOUNT_PASSWORD = "spsAccountPassword";

public static final String ATT_SPS_DELETION_TIME = "spsDeletionTime";
public static final String ATTR_COLLECTING_STRATEGY = "spsCollectingStrategy";
public static final String ATTR_COLLECTING_GROUP_NAME = "spsCollectingGroupName";
public static final String ATTR_COLLECTING_GROUP_SIZE = "spsCollectingGroupSize";
Expand Down Expand Up @@ -66,6 +65,9 @@ public class ScreenProctoringSettings implements SPSAPIAccessData, Entity {
@JsonProperty(ATTR_SPS_ACCOUNT_PASSWORD)
public final CharSequence spsAccountPassword;

@JsonProperty(ATT_SPS_DELETION_TIME)
public final DateTime deletionTime;

@JsonProperty(ATTR_COLLECTING_STRATEGY)
public final CollectingStrategy collectingStrategy;

Expand All @@ -91,6 +93,7 @@ public ScreenProctoringSettings(
@JsonProperty(ATTR_SPS_API_SECRET) final CharSequence spsAPISecret,
@JsonProperty(ATTR_SPS_ACCOUNT_ID) final String spsAccountId,
@JsonProperty(ATTR_SPS_ACCOUNT_PASSWORD) final CharSequence spsAccountPassword,
@JsonProperty(ATT_SPS_DELETION_TIME) final DateTime deletionTime,
@JsonProperty(ATTR_COLLECTING_STRATEGY) final CollectingStrategy collectingStrategy,
@JsonProperty(ATTR_COLLECTING_GROUP_NAME) final String collectingGroupName,
@JsonProperty(ATTR_COLLECTING_GROUP_SIZE) final Integer collectingGroupSize,
Expand All @@ -104,6 +107,7 @@ public ScreenProctoringSettings(
this.spsAPISecret = spsAPISecret;
this.spsAccountId = spsAccountId;
this.spsAccountPassword = spsAccountPassword;
this.deletionTime = deletionTime;
this.collectingStrategy = collectingStrategy;
this.collectingGroupName = collectingGroupName;
this.collectingGroupSize = collectingGroupSize;
Expand All @@ -119,6 +123,7 @@ public ScreenProctoringSettings(
final CharSequence spsAPISecret,
final String spsAccountId,
final CharSequence spsAccountPassword,
final DateTime deletionTime,
final CollectingStrategy collectingStrategy,
final String collectingGroupName,
final Integer collectingGroupSize,
Expand All @@ -131,6 +136,7 @@ public ScreenProctoringSettings(
this.spsAPISecret = spsAPISecret;
this.spsAccountId = spsAccountId;
this.spsAccountPassword = spsAccountPassword;
this.deletionTime = deletionTime;
this.collectingStrategy = collectingStrategy;
this.collectingGroupName = collectingGroupName;
this.collectingGroupSize = collectingGroupSize;
Expand Down Expand Up @@ -181,6 +187,10 @@ public CharSequence getSpsAccountPassword() {
return this.spsAccountPassword;
}

public DateTime getDeletionTime() {
return deletionTime;
}

public CollectingStrategy getCollectingStrategy() {
return this.collectingStrategy;
}
Expand All @@ -205,7 +215,7 @@ public int hashCode() {
public boolean isBundled() {
return this.bundled;
}

@Override
public boolean equals(final Object obj) {
if (this == obj)
Expand All @@ -225,13 +235,15 @@ public String toString() {
", enableScreenProctoring=" + enableScreenProctoring +
", spsServiceURL='" + spsServiceURL + '\'' +
", spsAPIKey='" + spsAPIKey + '\'' +
", spsAPISecret=" + spsAPISecret +
", spsAccountId='" + spsAccountId + '\'' +
", spsAccountPassword=" + spsAccountPassword +
", deletionTime=" + deletionTime +
", collectingStrategy=" + collectingStrategy +
", collectingGroupName='" + collectingGroupName + '\'' +
", collectingGroupSize=" + collectingGroupSize +
", sebGroupsSelection='" + sebGroupsSelection + '\'' +
", bundled=" + bundled +
'}';
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class ScreenProctoringSettingsPopup {
private final static LocTextKey FORM_ACCOUNT_SECRET_SPS =
new LocTextKey("sebserver.exam.sps.form.accountSecret");

private final static LocTextKey FORM_COLLECTING_DELETION_TIME =
new LocTextKey("sebserver.exam.sps.form.collect.deletion.time");
private final static LocTextKey FORM_COLLECTING_STRATEGY =
new LocTextKey("sebserver.exam.sps.form.collect.strategy");
private final static LocTextKey FORM_GROUP_NAME =
Expand Down Expand Up @@ -172,6 +174,7 @@ private boolean doSaveSettings(
final String groupSizeString = form.getFieldValue(ScreenProctoringSettings.ATTR_COLLECTING_GROUP_SIZE);
final int groupSize = StringUtils.isNotBlank(groupSizeString) ? Integer.parseInt(groupSizeString) : 0;
final CollectingStrategy collectingStrategy = CollectingStrategy.valueOf(form.getFieldValue(ScreenProctoringSettings.ATTR_COLLECTING_STRATEGY));
final String deletionTimeString = form.getFieldValue(ScreenProctoringSettings.ATT_SPS_DELETION_TIME);

settings = new ScreenProctoringSettings(
Long.parseLong(entityKey.modelId),
Expand All @@ -181,6 +184,7 @@ private boolean doSaveSettings(
form.getFieldValue(ScreenProctoringSettings.ATTR_SPS_API_SECRET),
form.getFieldValue(ScreenProctoringSettings.ATTR_SPS_ACCOUNT_ID),
form.getFieldValue(ScreenProctoringSettings.ATTR_SPS_ACCOUNT_PASSWORD),
Utils.toDateTime(deletionTimeString),
collectingStrategy,
form.getFieldValue(ScreenProctoringSettings.ATTR_COLLECTING_GROUP_NAME),
groupSize,
Expand Down Expand Up @@ -387,6 +391,14 @@ private void buildFormForCollectingStrategy(
? String.valueOf(settings.spsAccountPassword)
: null))

.addField(FormBuilder.dateTime(
ScreenProctoringSettings.ATT_SPS_DELETION_TIME,
FORM_COLLECTING_DELETION_TIME,
settings.deletionTime != null
? settings.deletionTime
: Utils.toDateTimeUTC(Utils.getMillisecondsNow()).plusYears(2)
))

.addField(FormBuilder.singleSelection(
ScreenProctoringSettings.ATTR_COLLECTING_STRATEGY,
FORM_COLLECTING_STRATEGY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

public class DateTimeSelector extends Composite {

private DateTime date;
private DateTime time;
private Label timeZoneLabel;
private final DateTime date;
private final DateTime time;
private final DateTimeZone timeZone;
private final String testKey;

public DateTimeSelector(
final Composite parent,
Expand All @@ -26,7 +24,6 @@ public DateTimeSelector(

super(parent, SWT.NONE);
this.timeZone = timeZone;
this.testKey = testKey;

final GridLayout gridLayout = new GridLayout(3, false);
gridLayout.verticalSpacing = 5;
Expand All @@ -37,12 +34,8 @@ public DateTimeSelector(

this.date = widgetFactory.dateSelector(this, new LocTextKey(label), testKey);
this.time = widgetFactory.timeSelector(this, new LocTextKey(label), testKey);
this.timeZoneLabel = widgetFactory.label(this, timeZone.getID());
final Label timeZoneLabel = widgetFactory.label(this, timeZone.getID());

this.setValue(Utils.getMillisecondsNow());
}

public void setValue(final long timestamp) {
setDateTime(org.joda.time.DateTime.now(this.timeZone));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ private ScreenProctoringSettings getLegacyScreenProctoringSettings(final EntityK
screenProctoringServiceBundle.clientSecret.toString(),
screenProctoringServiceBundle.apiAccountName,
screenProctoringServiceBundle.apiAccountPassword.toString(),
null,
getScreenProctoringCollectingStrategy(mapping),
null,
getScreenProctoringCollectingSize(mapping),
Expand All @@ -343,6 +344,7 @@ private ScreenProctoringSettings getLegacyScreenProctoringSettings(final EntityK
getString(mapping, ScreenProctoringSettings.ATTR_SPS_API_SECRET),
getString(mapping, ScreenProctoringSettings.ATTR_SPS_ACCOUNT_ID),
getString(mapping, ScreenProctoringSettings.ATTR_SPS_ACCOUNT_PASSWORD),
null,
getScreenProctoringCollectingStrategy(mapping),
null,
getScreenProctoringCollectingSize(mapping),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ private ScreenProctoringSettings convertSPSTemplateSettings(
screenProctoringSettings.spsAPISecret,
screenProctoringSettings.spsAccountId,
screenProctoringSettings.spsAccountPassword,
screenProctoringSettings.deletionTime,
screenProctoringSettings.collectingStrategy,
screenProctoringSettings.collectingGroupName,
screenProctoringSettings.collectingGroupSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public Result<ScreenProctoringSettings> saveScreenProctoringSettings(
this.cryptor.decrypt(this.screenProctoringServiceBundle.clientSecret).getOrThrow(),
this.screenProctoringServiceBundle.apiAccountName,
this.cryptor.decrypt(this.screenProctoringServiceBundle.apiAccountPassword).getOrThrow(),
screenProctoringSettings.deletionTime,
screenProctoringSettings.collectingStrategy,
screenProctoringSettings.collectingGroupName,
screenProctoringSettings.collectingGroupSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.*;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
Expand Down Expand Up @@ -601,6 +602,9 @@ void updateExam(final Exam exam) {
try {
final SPSData spsData = this.getSPSData(exam.id);
final ScreenProctoringServiceOAuthTemplate apiTemplate = this.getAPITemplate(exam.id);
final ScreenProctoringSettings settings = this.proctoringSettingsDAO
.getScreenProctoringSettings(new EntityKey(exam.id, EntityType.EXAM))
.getOrThrow();

final String uri = UriComponentsBuilder
.fromUriString(apiTemplate.spsServiceURL)
Expand All @@ -617,7 +621,7 @@ void updateExam(final Exam exam) {
exam.getType().name(),
exam.startTime != null ? exam.startTime.getMillis() : null,
exam.endTime != null ? exam.endTime.getMillis() : null,
null, // TODO
settings.deletionTime != null ? settings.deletionTime.getMillis() : null,
supporterIds
);

Expand Down Expand Up @@ -1104,9 +1108,9 @@ private void createExam(
final String uuid = createExamUUID(exam);
final MultiValueMap<String, String> params = createExamCreationParams(
exam,
uuid,
null, // TODO settings.getDeletionTime
supporterIds);
uuid,
settings.deletionTime,
supporterIds);
final String paramsFormEncoded = Utils.toAppFormUrlEncodedBodyForSPService(params);

final ResponseEntity<String> exchange = apiTemplate.exchange(uri, paramsFormEncoded);
Expand Down Expand Up @@ -1140,7 +1144,7 @@ private void createExam(
private static MultiValueMap<String, String> createExamCreationParams(
final Exam exam,
final String uuid,
final Long deletionTime,
final DateTime deletionTime,
final List<String> supporterIds) {

final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
Expand All @@ -1161,7 +1165,7 @@ private static MultiValueMap<String, String> createExamCreationParams(
}

if (deletionTime != null) {
params.add(EXAM.ATTR_DELETION_TIME, java.lang.String.valueOf(deletionTime));
params.add(EXAM.ATTR_DELETION_TIME, java.lang.String.valueOf(deletionTime.getMillis()));
}
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public Result<ScreenProctoringSettings> testSettings(
this.cryptor.encrypt(screenProctoringSettings.spsAPISecret).getOrThrow(),
screenProctoringSettings.spsAccountId,
this.cryptor.encrypt(screenProctoringSettings.spsAccountPassword).getOrThrow(),
screenProctoringSettings.deletionTime,
screenProctoringSettings.collectingStrategy,
screenProctoringSettings.collectingGroupName,
screenProctoringSettings.collectingGroupSize,
Expand Down Expand Up @@ -257,6 +258,7 @@ public Result<Exam> applyScreenProctoringForExam(final EntityKey entityKey) {

this.examDAO.markUpdate(exam.id);
} else if (isEnabling) {
this.screenProctoringAPIBinding.updateExam(exam);
this.screenProctoringAPIBinding.synchronizeGroups(exam);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,8 @@ sebserver.exam.sps.form.accountSecret=Account Password
sebserver.exam.sps.form.accountSecret.tooltip=This is the secret/password for the above API account id
sebserver.exam.sps.form.collect.strategy=Grouping Strategy
sebserver.exam.sps.form.collect.strategy.tooltip=This specifies the strategy how connecting SEB clients are collected into screen proctoring groups
sebserver.exam.sps.form.collect.deletion.time=Deletion Date
sebserver.exam.sps.form.collect.deletion.time.tooltip=The date on when the Screen Proctoring data should automatically been deleted.
sebserver.exam.sps.form.saveSettings=Save Settings
sebserver.exam.sps.form.saveSettings.error=SEB Server is not able to connect to bundled Screen Proctoring service within the given Service URL.<br/>This probably relies on a incorrect SEB Server setup.<br/><br/>Please make sure your SEB Server setup uses the correct URL mappings or contact a system administrator.
sebserver.exam.test.run.enabled.note=Exam Test Run is currently enabled. To disable please use "Disable Test Run"
Expand Down

0 comments on commit ae481ef

Please sign in to comment.