From 8c29d7e8f24df397a600d57d1e7d440dff12c412 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 17 Feb 2021 11:34:56 +0100 Subject: [PATCH] fixed import settings and tests --- .../gui/content/SEBExamConfigImportPopup.java | 52 ++++++++++++------- .../gui/content/SEBExamConfigList.java | 2 +- .../gui/content/SEBSettingsForm.java | 12 +++-- .../gui/integration/GuiIntegrationTest.java | 8 +++ .../api/exam/ExamAPIIntegrationTester.java | 7 +++ 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java index 1b52f458..a717dcae 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigImportPopup.java @@ -68,9 +68,19 @@ public class SEBExamConfigImportPopup { this.pageService = pageService; } - public Function importFunction(final boolean newConfig) { + public Function importFunction() { + return importFunction(null); + } + + public Function importFunction(final Supplier tabSelectionSupplier) { return action -> { + final boolean newConfig = tabSelectionSupplier == null || tabSelectionSupplier.get() == null; + final PageContext context = (tabSelectionSupplier != null) + ? action.pageContext() + .withAttribute(SEBSettingsForm.ATTR_VIEW_INDEX, tabSelectionSupplier.get()) + : action.pageContext(); + final ModalInputDialog> dialog = new ModalInputDialog>( action.pageContext().getParent().getShell(), @@ -79,7 +89,7 @@ public class SEBExamConfigImportPopup { final ImportFormContext importFormContext = new ImportFormContext( this.pageService, - action.pageContext(), + context, newConfig); dialog.open( @@ -147,18 +157,6 @@ public class SEBExamConfigImportPopup { if (!configuration.hasError()) { context.publishInfo(SEBExamConfigForm.FORM_IMPORT_CONFIRM_TEXT_KEY); - final PageAction action = (newConfig) - ? this.pageService.pageActionBuilder(context) - .newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG) - .create() - : this.pageService.pageActionBuilder(context) - .newAction(ActionDefinition.SEB_EXAM_CONFIG_MODIFY) - .create(); - - this.pageService.firePageEvent( - new ActionEvent(action), - action.pageContext()); - } else { final Exception error = configuration.getError(); if (error instanceof RestCallError) { @@ -177,14 +175,15 @@ public class SEBExamConfigImportPopup { .notifyImportError(EntityType.CONFIGURATION_NODE, error); } }); - return true; + + } else { + formHandle.getContext().notifyError( + SEBExamConfigForm.FORM_TITLE, + configuration.getError()); } - formHandle.getContext().notifyError( - SEBExamConfigForm.FORM_TITLE, - configuration.getError()); - } + reloadPage(newConfig, context); return true; } else { formHandle.getContext().publishPageMessage( @@ -194,11 +193,26 @@ public class SEBExamConfigImportPopup { return false; } catch (final Exception e) { + reloadPage(newConfig, formHandle.getContext()); formHandle.getContext().notifyError(SEBExamConfigForm.FORM_TITLE, e); return true; } } + private void reloadPage(final boolean newConfig, final PageContext context) { + final PageAction action = (newConfig) + ? this.pageService.pageActionBuilder(context) + .newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG) + .create() + : this.pageService.pageActionBuilder(context) + .newAction(ActionDefinition.SEB_EXAM_CONFIG_MODIFY) + .create(); + + this.pageService.firePageEvent( + new ActionEvent(action), + action.pageContext()); + } + private boolean checkInput(final FormHandle formHandle, final boolean newConfig, final Form form) { if (newConfig) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigList.java index d5eef79b..a549a49e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBExamConfigList.java @@ -170,7 +170,7 @@ public class SEBExamConfigList implements TemplateComposer { .newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_NEW_CONFIG) .withSelect( configTable.getGrantedSelection(this.currentUser, NO_MODIFY_PRIVILEGE_ON_OTHER_INSTITUTION), - this.sebExamConfigImportPopup.importFunction(true), + this.sebExamConfigImportPopup.importFunction(), EMPTY_SELECTION_TEXT_KEY) .noEventPropagation() .publishIf(examConfigGrant::im); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java index f4c2f96f..75509107 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SEBSettingsForm.java @@ -69,6 +69,8 @@ public class SEBSettingsForm implements TemplateComposer { private static final Logger log = LoggerFactory.getLogger(SEBSettingsForm.class); + public static final String ATTR_VIEW_INDEX = "VIEW_INDEX"; + private static final String VIEW_TEXT_KEY_PREFIX = "sebserver.examconfig.props.form.views."; private static final String KEY_SAVE_TO_HISTORY_SUCCESS = @@ -194,7 +196,7 @@ public class SEBSettingsForm implements TemplateComposer { } // set selection if available - final String viewIndex = pageContext.getAttribute("VIEW_INDEX"); + final String viewIndex = pageContext.getAttribute(ATTR_VIEW_INDEX); if (StringUtils.isNotBlank(viewIndex)) { try { tabFolder.setSelection(Integer.parseInt(viewIndex)); @@ -217,7 +219,7 @@ public class SEBSettingsForm implements TemplateComposer { .call() .onError(t -> notifyErrorOnSave(t, pageContext)); return action.withAttribute( - "VIEW_INDEX", + ATTR_VIEW_INDEX, String.valueOf(tabFolder.getSelectionIndex())); }) .withSuccess(KEY_SAVE_TO_HISTORY_SUCCESS) @@ -232,7 +234,7 @@ public class SEBSettingsForm implements TemplateComposer { .call() .getOrThrow(); return action.withAttribute( - "VIEW_INDEX", + ATTR_VIEW_INDEX, String.valueOf(tabFolder.getSelectionIndex())); }) .withSuccess(KEY_UNDO_SUCCESS) @@ -254,7 +256,9 @@ public class SEBSettingsForm implements TemplateComposer { .newAction(ActionDefinition.SEB_EXAM_CONFIG_IMPORT_TO_EXISTING_CONFIG) .withEntityKey(entityKey) - .withExec(this.sebExamConfigImportPopup.importFunction(false)) + .withExec(this.sebExamConfigImportPopup.importFunction( + () -> String.valueOf(tabFolder.getSelectionIndex()))) + .noEventPropagation() .publishIf(() -> examConfigGrant.iw() && !readonly && !isAttachedToExam) .newAction(ActionDefinition.SEB_EXAM_CONFIG_VIEW_PROP) diff --git a/src/test/java/ch/ethz/seb/sebserver/gui/integration/GuiIntegrationTest.java b/src/test/java/ch/ethz/seb/sebserver/gui/integration/GuiIntegrationTest.java index 4bc87b44..5ff8dada 100644 --- a/src/test/java/ch/ethz/seb/sebserver/gui/integration/GuiIntegrationTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/gui/integration/GuiIntegrationTest.java @@ -36,6 +36,8 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestServiceImpl; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.OAuth2AuthorizationContextHolder; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.SEBServerAuthorizationContext; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.WebserviceURIService; +import ch.ethz.seb.sebserver.webservice.WebserviceInfo; +import ch.ethz.seb.sebserver.webservice.servicelayer.dao.WebserviceInfoDAO; @RunWith(SpringRunner.class) @SpringBootTest( @@ -59,13 +61,19 @@ public abstract class GuiIntegrationTest { protected JSONMapper jsonMapper; @Autowired protected FilterChainProxy springSecurityFilterChain; + @Autowired + private WebserviceInfoDAO webserviceInfoDAO; + @Autowired + private WebserviceInfo webserviceInfo; protected MockMvc mockMvc; @Before public void setup() { + this.webserviceInfoDAO.unregister(this.webserviceInfo.getWebserviceUUID()); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) .addFilter(this.springSecurityFilterChain).build(); + } protected OAuth2AuthorizationContextHolder getAuthorizationContextHolder() { diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/ExamAPIIntegrationTester.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/ExamAPIIntegrationTester.java index 1757b7f0..e53e9d4e 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/ExamAPIIntegrationTester.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/ExamAPIIntegrationTester.java @@ -53,6 +53,8 @@ import ch.ethz.seb.sebserver.SEBServer; import ch.ethz.seb.sebserver.WebSecurityConfig; import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.JSONMapper; +import ch.ethz.seb.sebserver.webservice.WebserviceInfo; +import ch.ethz.seb.sebserver.webservice.servicelayer.dao.WebserviceInfoDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ClientConfigService; import ch.ethz.seb.sebserver.webservice.weblayer.oauth.AdminAPIClientDetails; import ch.ethz.seb.sebserver.webservice.weblayer.oauth.WebClientDetailsService; @@ -77,6 +79,10 @@ public abstract class ExamAPIIntegrationTester { protected JSONMapper jsonMapper; @Autowired protected FilterChainProxy springSecurityFilterChain; + @Autowired + private WebserviceInfoDAO webserviceInfoDAO; + @Autowired + private WebserviceInfo webserviceInfo; protected MockMvc mockMvc; @@ -88,6 +94,7 @@ public abstract class ExamAPIIntegrationTester { @Before public void setup() { + this.webserviceInfoDAO.unregister(this.webserviceInfo.getWebserviceUUID()); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac) .addFilter(this.springSecurityFilterChain).build(); Mockito.when(this.webClientDetailsService.loadClientByClientId(Mockito.anyString())).thenReturn(