SEBSERV-153 fixes
This commit is contained in:
parent
a9acb1b915
commit
4cb6c6d7d8
6 changed files with 89 additions and 9 deletions
|
@ -228,5 +228,6 @@ public final class API {
|
|||
|
||||
public static final String EXAM_TEMPLATE_ENDPOINT = "/exam-template";
|
||||
public static final String EXAM_TEMPLATE_INDICATOR_PATH_SEGMENT = "/indicator";
|
||||
public static final String EXAM_TEMPLATE_DEFAULT_PATH_SEGMENT = "/default";
|
||||
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError;
|
|||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.CheckExamConsistency;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.CheckSEBRestriction;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetDefaultExamTemplate;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExam;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamTemplate;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetProctoringSettings;
|
||||
|
@ -351,7 +352,9 @@ public class ExamForm implements TemplateComposer {
|
|||
.addField(FormBuilder.singleSelection(
|
||||
Domain.EXAM.ATTR_EXAM_TEMPLATE_ID,
|
||||
FORM_EXAM_TEMPLATE_TEXT_KEY,
|
||||
(exam.examTemplateId == null) ? null : String.valueOf(exam.examTemplateId),
|
||||
(exam.examTemplateId == null)
|
||||
? getDefaultExamTemplateId()
|
||||
: String.valueOf(exam.examTemplateId),
|
||||
this.resourceService::examTemplateResources)
|
||||
.withSelectionListener(form -> this.processTemplateSelection(form, formContext))
|
||||
.withLabelSpan(2)
|
||||
|
@ -382,6 +385,10 @@ public class ExamForm implements TemplateComposer {
|
|||
? this.restService.getRestCall(ImportAsExam.class)
|
||||
: this.restService.getRestCall(SaveExam.class));
|
||||
|
||||
if (importFromQuizData) {
|
||||
this.processTemplateSelection(formHandle.getForm(), formContext);
|
||||
}
|
||||
|
||||
final boolean proctoringEnabled = importFromQuizData ? false : this.restService
|
||||
.getBuilder(GetProctoringSettings.class)
|
||||
.withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId)
|
||||
|
@ -478,6 +485,14 @@ public class ExamForm implements TemplateComposer {
|
|||
}
|
||||
}
|
||||
|
||||
private String getDefaultExamTemplateId() {
|
||||
return this.restService.getBuilder(GetDefaultExamTemplate.class)
|
||||
.call()
|
||||
.map(ExamTemplate::getId)
|
||||
.map(Object::toString)
|
||||
.getOr(StringUtils.EMPTY);
|
||||
}
|
||||
|
||||
private void processTemplateSelection(final Form form, final PageContext context) {
|
||||
try {
|
||||
final String templateId = form.getFieldValue(Domain.EXAM.ATTR_EXAM_TEMPLATE_ID);
|
||||
|
|
|
@ -147,6 +147,7 @@ public class ResourceService {
|
|||
public static final String SEB_CONNECTION_STATUS_KEY_PREFIX = "sebserver.monitoring.exam.connection.status.";
|
||||
public static final LocTextKey ACTIVE_TEXT_KEY = new LocTextKey("sebserver.overall.status.active");
|
||||
public static final LocTextKey INACTIVE_TEXT_KEY = new LocTextKey("sebserver.overall.status.inactive");
|
||||
public static final LocTextKey NO_SELECTION = new LocTextKey("sebserver.overall.action.select.none");
|
||||
|
||||
private final I18nSupport i18nSupport;
|
||||
private final RestService restService;
|
||||
|
@ -310,7 +311,8 @@ public class ResourceService {
|
|||
|
||||
public List<Tuple<String>> lmsSetupResource() {
|
||||
final boolean isSEBAdmin = this.currentUser.get().hasRole(UserRole.SEB_SERVER_ADMIN);
|
||||
final String institutionId = (isSEBAdmin) ? "" : String.valueOf(this.currentUser.get().institutionId);
|
||||
final String institutionId =
|
||||
(isSEBAdmin) ? StringUtils.EMPTY : String.valueOf(this.currentUser.get().institutionId);
|
||||
return this.restService.getBuilder(GetLmsSetupNames.class)
|
||||
.withQueryParam(Entity.FILTER_ATTR_INSTITUTION, institutionId)
|
||||
.withQueryParam(Entity.FILTER_ATTR_ACTIVE, Constants.TRUE_STRING)
|
||||
|
@ -324,7 +326,8 @@ public class ResourceService {
|
|||
|
||||
public Function<String, String> getLmsSetupNameFunction() {
|
||||
final boolean isSEBAdmin = this.currentUser.get().hasRole(UserRole.SEB_SERVER_ADMIN);
|
||||
final String institutionId = (isSEBAdmin) ? "" : String.valueOf(this.currentUser.get().institutionId);
|
||||
final String institutionId =
|
||||
(isSEBAdmin) ? StringUtils.EMPTY : String.valueOf(this.currentUser.get().institutionId);
|
||||
final Map<String, String> idNameMap = this.restService.getBuilder(GetLmsSetupNames.class)
|
||||
.withQueryParam(Entity.FILTER_ATTR_INSTITUTION, institutionId)
|
||||
.withQueryParam(Entity.FILTER_ATTR_ACTIVE, Constants.TRUE_STRING)
|
||||
|
@ -732,7 +735,7 @@ public class ResourceService {
|
|||
.map(node -> new Tuple<>(node.getModelId(), node.name))
|
||||
.sorted(RESOURCE_COMPARATOR)
|
||||
.collect(Collectors.toList());
|
||||
collect.add(0, new Tuple<>(null, ""));
|
||||
collect.add(0, new Tuple<>(null, StringUtils.EMPTY));
|
||||
return collect;
|
||||
}
|
||||
|
||||
|
@ -788,7 +791,7 @@ public class ResourceService {
|
|||
|
||||
public List<Tuple<String>> identityCertificatesResources() {
|
||||
return Stream.concat(
|
||||
Stream.of(new EntityName("", EntityType.CERTIFICATE, "")),
|
||||
Stream.of(new EntityName(StringUtils.EMPTY, EntityType.CERTIFICATE, StringUtils.EMPTY)),
|
||||
this.restService.getBuilder(GetCertificateNames.class)
|
||||
.withQueryParam(
|
||||
CertificateInfo.FILTER_ATTR_TYPE,
|
||||
|
@ -802,8 +805,10 @@ public class ResourceService {
|
|||
}
|
||||
|
||||
public List<Tuple<String>> examTemplateResources() {
|
||||
|
||||
return Stream.concat(
|
||||
Stream.of(new EntityName("", EntityType.EXAM_TEMPLATE, "")),
|
||||
Stream.of(new EntityName(StringUtils.EMPTY, EntityType.EXAM_TEMPLATE,
|
||||
this.i18nSupport.getText(NO_SELECTION))),
|
||||
this.restService.getBuilder(GetExamTemplateNames.class)
|
||||
.call()
|
||||
.onError(error -> log.warn("Failed to get exam template names: {}", error.getMessage()))
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.gui.service.remote.webservice.api.exam;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import ch.ethz.seb.sebserver.gbl.api.API;
|
||||
import ch.ethz.seb.sebserver.gbl.api.EntityType;
|
||||
import ch.ethz.seb.sebserver.gbl.model.exam.ExamTemplate;
|
||||
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall;
|
||||
|
||||
@Lazy
|
||||
@Component
|
||||
@GuiProfile
|
||||
public class GetDefaultExamTemplate extends RestCall<ExamTemplate> {
|
||||
|
||||
public GetDefaultExamTemplate() {
|
||||
super(new TypeKey<>(
|
||||
CallType.GET_SINGLE,
|
||||
EntityType.EXAM_TEMPLATE,
|
||||
new TypeReference<ExamTemplate>() {
|
||||
}),
|
||||
HttpMethod.GET,
|
||||
MediaType.APPLICATION_FORM_URLENCODED,
|
||||
API.EXAM_TEMPLATE_ENDPOINT + API.EXAM_TEMPLATE_DEFAULT_PATH_SEGMENT);
|
||||
}
|
||||
|
||||
}
|
|
@ -49,6 +49,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.Authorization
|
|||
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.EntityDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ExamTemplateDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ResourceNotFoundException;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
|
||||
import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService;
|
||||
|
@ -77,6 +78,23 @@ public class ExamTemplateController extends EntityController<ExamTemplate, ExamT
|
|||
beanValidationService);
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.EXAM_TEMPLATE_DEFAULT_PATH_SEGMENT,
|
||||
method = RequestMethod.GET,
|
||||
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ExamTemplate getDefault() {
|
||||
final Long institutionId = super.authorization
|
||||
.getUserService()
|
||||
.getCurrentUser()
|
||||
.institutionId();
|
||||
|
||||
return ((ExamTemplateDAO) this.entityDAO)
|
||||
.getInstitutionalDefault(institutionId)
|
||||
.flatMap(this::checkReadAccess)
|
||||
.getOrThrow();
|
||||
}
|
||||
|
||||
@RequestMapping(
|
||||
path = API.MODEL_ID_VAR_PATH_SEGMENT
|
||||
+ API.EXAM_TEMPLATE_INDICATOR_PATH_SEGMENT,
|
||||
|
|
|
@ -34,6 +34,7 @@ sebserver.overall.date.to=To
|
|||
|
||||
sebserver.overall.action.remove=Remove
|
||||
sebserver.overall.action.select=Please Select
|
||||
sebserver.overall.action.select.none=[No Selection]
|
||||
sebserver.overall.action.toggle-activity=Switch Status
|
||||
|
||||
sebserver.overall.types.activityType.REGISTER=Register new Account
|
||||
|
@ -1686,9 +1687,9 @@ sebserver.examtemplate.indicator.list.pleaseSelect=At first please select an ind
|
|||
|
||||
sebserver.examtemplate.indicator.action.save=Save Indicator Template
|
||||
sebserver.examtemplate.indicator.list.actions=
|
||||
sebserver.examtemplate.indicator.action.list.new=Add Indicator Template
|
||||
sebserver.examtemplate.indicator.action.list.modify=Edit Indicator Template
|
||||
sebserver.examtemplate.indicator.action.list.delete=Delete Indicator Template
|
||||
sebserver.examtemplate.indicator.action.list.new=Add Indicator
|
||||
sebserver.examtemplate.indicator.action.list.modify=Edit Indicator
|
||||
sebserver.examtemplate.indicator.action.list.delete=Delete Indicator
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue