From a0bb0db5edc3ef1cc8d00e81d8025bcd8acc48ad Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 24 Oct 2019 15:34:26 +0200 Subject: [PATCH] SEBSERV-73 exam config <-> exam attachment handling --- .../gui/content/SebExamConfigPropForm.java | 45 ++++++++++++++++--- .../gui/content/action/ActionDefinition.java | 2 +- .../gui/service/ResourceService.java | 12 +++-- .../gui/service/page/impl/PageAction.java | 2 + .../api/exam/GetExamConfigMappingNames.java | 2 +- .../examconfig/GetExamConfigNodeNames.java | 42 +++++++++++++++++ .../impl/ConfigurationDAOBatchService.java | 2 +- src/main/resources/messages.properties | 1 + 8 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetExamConfigNodeNames.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java index ecd53dfb..e102b894 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java @@ -8,6 +8,8 @@ package ch.ethz.seb.sebserver.gui.content; +import java.util.Arrays; +import java.util.HashSet; import java.util.function.Function; import org.eclipse.rap.rwt.RWT; @@ -22,6 +24,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import ch.ethz.seb.sebserver.gbl.api.API; +import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.exam.ExamConfigurationMap; @@ -38,6 +41,7 @@ import ch.ethz.seb.sebserver.gui.form.FormHandle; import ch.ethz.seb.sebserver.gui.service.ResourceService; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.service.page.PageMessageException; import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; @@ -90,6 +94,8 @@ public class SebExamConfigPropForm implements TemplateComposer { new LocTextKey("sebserver.examconfig.form.config-key.title"); static final LocTextKey FORM_IMPORT_CONFIRM_TEXT_KEY = new LocTextKey("sebserver.examconfig.action.import-config.confirm"); + static final LocTextKey FORM_ATTACHED_EXAMS_TITLE_TEXT_KEY = + new LocTextKey("sebserver.examconfig.form.attched-to"); static final LocTextKey FORM_COPY_TEXT_KEY = new LocTextKey("sebserver.examconfig.action.copy"); @@ -144,7 +150,7 @@ public class SebExamConfigPropForm implements TemplateComposer { final boolean writeGrant = entityGrant.w(); final boolean modifyGrant = entityGrant.m(); final boolean isReadonly = pageContext.isReadonly(); - final boolean isAttachedToExam = this.restService + final boolean isAttachedToExam = !isNew && this.restService .getBuilder(GetExamConfigMappingNames.class) .withQueryParam(ExamConfigurationMap.FILTER_ATTR_CONFIG_ID, examConfig.getModelId()) .call() @@ -264,6 +270,12 @@ public class SebExamConfigPropForm implements TemplateComposer { .publishIf(() -> !isReadonly); if (isAttachedToExam) { + + widgetFactory.labelLocalized( + content, + CustomVariant.TEXT_H3, + FORM_ATTACHED_EXAMS_TITLE_TEXT_KEY); + final EntityTable table = this.pageService.entityTableBuilder(this.restService.getRestCall(GetExamConfigMappingsPage.class)) .withRestCallAdapter(restCall -> restCall.withQueryParam( @@ -289,21 +301,42 @@ public class SebExamConfigPropForm implements TemplateComposer { ExamList.COLUMN_TITLE_TYPE_KEY, resourceService::localizedExamTypeName)) - .withDefaultAction(actionBuilder - .newAction(ActionDefinition.EXAM_VIEW_FROM_LIST) - .create()) + .withDefaultAction(this::showExamAction) .compose(pageContext.copyOf(content)); actionBuilder .newAction(ActionDefinition.EXAM_VIEW_FROM_LIST) - .withSelect(table::getSelection, PageAction::applySingleSelection, - ExamList.EMPTY_SELECTION_TEXT_KEY) + .withExec(pageAction -> { + final ExamConfigurationMap selectedExamMapping = getSelectedExamMapping(table); + return pageAction.withEntityKey( + new EntityKey(selectedExamMapping.examId, EntityType.EXAM)); + }) .publishIf(table::hasAnyContent); } } + private PageAction showExamAction(final EntityTable table) { + return this.pageService.pageActionBuilder(table.getPageContext()) + .newAction(ActionDefinition.EXAM_VIEW_FROM_LIST) + .withSelectionSupplier(() -> { + final ExamConfigurationMap selectedROWData = getSelectedExamMapping(table); + return new HashSet<>(Arrays.asList(new EntityKey(selectedROWData.examId, EntityType.EXAM))); + }) + .withExec(PageAction::applySingleSelection) + .create(); + } + + private ExamConfigurationMap getSelectedExamMapping(final EntityTable table) { + final ExamConfigurationMap selectedROWData = table.getSelectedROWData(); + + if (selectedROWData == null) { + throw new PageMessageException(ExamList.EMPTY_SELECTION_TEXT_KEY); + } + return selectedROWData; + } + private LocTextKey stateChangeConfirm( final boolean isAttachedToExam, final FormHandle formHandle) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index 935f65e1..31a6283e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -240,7 +240,7 @@ public enum ActionDefinition { EXAM_CONFIGURATION_EXAM_CONFIG_VIEW_PROP( new LocTextKey("sebserver.examconfig.action.view"), ImageIcon.SHOW, - PageStateDefinitionImpl.SEB_EXAM_CONFIG_VIEW, + PageStateDefinitionImpl.SEB_EXAM_CONFIG_PROP_VIEW, ActionCategory.EXAM_CONFIG_MAPPING_LIST), EXAM_CONFIGURATION_DELETE_FROM_LIST( new LocTextKey("sebserver.exam.configuration.action.list.delete"), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java index ce040086..dd8c08dc 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java @@ -57,11 +57,11 @@ import ch.ethz.seb.sebserver.gbl.util.Tuple; import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamConfigMappingNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExams; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutionNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.lmssetup.GetLmsSetupNames; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodeNames; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodes; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetViews; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccountNames; @@ -371,7 +371,13 @@ public class ResourceService { public List> examConfigStatusResources(final boolean isAttachedToExam) { return Arrays.asList(ConfigurationStatus.values()) .stream() - .filter(status -> !isAttachedToExam || status != ConfigurationStatus.READY_TO_USE) + .filter(status -> { + if (isAttachedToExam) { + return status != ConfigurationStatus.READY_TO_USE; + } else { + return status != ConfigurationStatus.IN_USE; + } + }) .map(type -> new Tuple<>( type.name(), this.i18nSupport.getText(EXAMCONFIG_STATUS_PREFIX + type.name()))) @@ -580,7 +586,7 @@ public class ResourceService { } private Result> getExamConfigurationSelection() { - return this.restService.getBuilder(GetExamConfigMappingNames.class) + return this.restService.getBuilder(GetExamConfigNodeNames.class) .withQueryParam( Entity.FILTER_ATTR_INSTITUTION, String.valueOf(this.currentUser.get().institutionId)) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java index e8ad94bf..76400665 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java @@ -121,6 +121,8 @@ public final class PageAction { confirm -> callback.accept((confirm) ? exec() : Result.ofRuntimeError("Confirm denied"))); + } else { + callback.accept(exec()); } } else { callback.accept(exec()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/GetExamConfigMappingNames.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/GetExamConfigMappingNames.java index 44e93674..9b717197 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/GetExamConfigMappingNames.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/GetExamConfigMappingNames.java @@ -36,7 +36,7 @@ public class GetExamConfigMappingNames extends RestCall> { }), HttpMethod.GET, MediaType.APPLICATION_FORM_URLENCODED, - API.CONFIGURATION_NODE_ENDPOINT + API.NAMES_PATH_SEGMENT); + API.EXAM_CONFIGURATION_MAP_ENDPOINT + API.NAMES_PATH_SEGMENT); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetExamConfigNodeNames.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetExamConfigNodeNames.java new file mode 100644 index 00000000..910ea51f --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetExamConfigNodeNames.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 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.seb.examconfig; + +import java.util.List; + +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.EntityName; +import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; + +@Lazy +@Component +@GuiProfile +public class GetExamConfigNodeNames extends RestCall> { + + public GetExamConfigNodeNames() { + super(new TypeKey<>( + CallType.GET_NAMES, + EntityType.CONFIGURATION_NODE, + new TypeReference>() { + }), + HttpMethod.GET, + MediaType.APPLICATION_FORM_URLENCODED, + API.CONFIGURATION_NODE_ENDPOINT + API.NAMES_PATH_SEGMENT); + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java index ed9c0644..edd6997e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java @@ -330,7 +330,7 @@ class ConfigurationDAOBatchService { .selectByPrimaryKey(copyInfo.configurationNodeId); if (!sourceNode.getInstitutionId().equals(institutionId)) { - new IllegalArgumentException("Institution integrity violation"); + throw new IllegalArgumentException("Institution integrity violation"); } return this.copyNodeRecord(sourceNode, newOwner, copyInfo); diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 15f9fad0..267661cf 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -467,6 +467,7 @@ sebserver.examconfig.form.with-history=With History sebserver.examconfig.form.template=From Template sebserver.examconfig.form.status=Status sebserver.examconfig.form.config-key.title=Config Key +sebserver.examconfig.form.attched-to=Attached To Exam sebserver.examconfig.status.CONSTRUCTION=Under Construction sebserver.examconfig.status.READY_TO_USE=Ready To Use