From cf948d58277ecb0ae78ed449d3dc6311004117eb Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 2 Sep 2019 11:36:11 +0200 Subject: [PATCH] SEBSERV-89 implemented --- .../examconfig/impl/AbstractInputField.java | 5 +- .../dao/impl/ConfigurationValueDAOImpl.java | 46 +++++++++++++------ .../impl/converter/IntegerConverter.java | 4 +- src/main/resources/data-demo.sql | 2 + src/main/resources/data-prod.sql | 2 + src/main/resources/messages.properties | 12 +++++ .../exam/SebExamConfigurationRequestTest.java | 2 +- src/test/resources/data-test-additional.sql | 2 + 8 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java index d77a8a48..7e556dcd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractInputField.java @@ -117,7 +117,10 @@ public abstract class AbstractInputField implements InputFiel initValue(v.value, v.listIndex); return v; }) - .orElse(null); + .orElseGet(() -> { + initValue(this.attribute.defaultValue, 0); + return null; + }); } @Override diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java index 4019d9be..298e37b8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationValueDAOImpl.java @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; @@ -33,7 +34,6 @@ import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationTableValues.TableV import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile; import ch.ethz.seb.sebserver.gbl.util.Result; -import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationAttributeRecordDynamicSqlSupport; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationAttributeRecordMapper; import ch.ethz.seb.sebserver.webservice.datalayer.batis.mapper.ConfigurationRecordMapper; @@ -189,20 +189,19 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { final Long id; if (data.id == null) { - id = this.configurationValueRecordMapper.selectIdsByExample() - .where( - ConfigurationValueRecordDynamicSqlSupport.configurationId, - isEqualTo(data.configurationId)) - .and( - ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, - isEqualTo(data.attributeId)) - .and( - ConfigurationValueRecordDynamicSqlSupport.listIndex, - isEqualTo(data.listIndex)) - .build() - .execute() - .stream() - .collect(Utils.toSingleton()); + + id = getByProperties(data) + .orElseGet(() -> { + log.warn("Missing SEB exam configuration attrribute value for: {}", data); + log.info("Use self-healing strategy to recover from missing SEB exam configuration " + + "attrribute value\n**** Create new AttributeValue for: {}", + data); + + createNew(data); + return getByProperties(data) + .orElseThrow(); + + }); } else { id = data.id; } @@ -446,4 +445,21 @@ public class ConfigurationValueDAOImpl implements ConfigurationValueDAO { return data; } + private Optional getByProperties(final ConfigurationValue data) { + return this.configurationValueRecordMapper.selectIdsByExample() + .where( + ConfigurationValueRecordDynamicSqlSupport.configurationId, + isEqualTo(data.configurationId)) + .and( + ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId, + isEqualTo(data.attributeId)) + .and( + ConfigurationValueRecordDynamicSqlSupport.listIndex, + isEqualTo(data.listIndex)) + .build() + .execute() + .stream() + .findFirst(); + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java index 315f9f22..1848ba28 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/sebconfig/impl/converter/IntegerConverter.java @@ -79,7 +79,9 @@ public class IntegerConverter implements AttributeValueConverter { final ConfigurationValue value, final String template) throws IOException { - final String val = (value.value != null) ? value.value : attribute.getDefaultValue(); + final String val = (value != null && value.value != null) + ? value.value + : attribute.getDefaultValue(); int intVal = 0; try { diff --git a/src/main/resources/data-demo.sql b/src/main/resources/data-demo.sql index 2a8c5a0e..e28810d2 100644 --- a/src/main/resources/data-demo.sql +++ b/src/main/resources/data-demo.sql @@ -225,6 +225,7 @@ INSERT IGNORE INTO configuration_attribute VALUES (314, 'allowDisplayMirroring', 'CHECKBOX', null, null, null, null, 'false'), (315, 'allowedDisplaysMaxNumber', 'COMBO_SELECTION', null, '1,2,3', null, null, '1'), (316, 'allowedDisplayBuiltin', 'CHECKBOX', null, null, null, null, 'true'), + (317, 'logLevel', 'SINGLE_SELECTION', null, '0,1,2,3,4', null, null, '1'), (400, 'insideSebEnableSwitchUser', 'CHECKBOX', null, null, null, null, 'false'), (401, 'insideSebEnableLockThisComputer', 'CHECKBOX', null, null, null, null, 'false'), @@ -439,6 +440,7 @@ INSERT IGNORE INTO orientation VALUES (314, 314, 0, 9, 'macSettings', 7, 7, 5, 1, 'NONE'), (315, 315, 0, 9, 'macSettings', 7, 9, 5, 1, 'TOP'), (316, 316, 0, 9, 'macSettings', 7, 10, 5, 1, 'NONE'), + (317, 317, 0, 9, 'logging', 3, 11, 4, 1, 'LEFT_SPAN'), (400, 400, 0, 10, 'registry', 0, 1, 4, 1, 'NONE'), (401, 401, 0, 10, 'registry', 0, 2, 4, 1, 'NONE'), diff --git a/src/main/resources/data-prod.sql b/src/main/resources/data-prod.sql index a356599f..7227e4df 100644 --- a/src/main/resources/data-prod.sql +++ b/src/main/resources/data-prod.sql @@ -199,6 +199,7 @@ INSERT IGNORE INTO configuration_attribute VALUES (314, 'allowDisplayMirroring', 'CHECKBOX', null, null, null, null, 'false'), (315, 'allowedDisplaysMaxNumber', 'COMBO_SELECTION', null, '1,2,3', null, null, '1'), (316, 'allowedDisplayBuiltin', 'CHECKBOX', null, null, null, null, 'true'), + (317, 'logLevel', 'SINGLE_SELECTION', null, '0,1,2,3,4', null, null, '1'), (400, 'insideSebEnableSwitchUser', 'CHECKBOX', null, null, null, null, 'false'), (401, 'insideSebEnableLockThisComputer', 'CHECKBOX', null, null, null, null, 'false'), @@ -413,6 +414,7 @@ INSERT IGNORE INTO orientation VALUES (314, 314, 0, 9, 'macSettings', 7, 7, 5, 1, 'NONE'), (315, 315, 0, 9, 'macSettings', 7, 9, 5, 1, 'TOP'), (316, 316, 0, 9, 'macSettings', 7, 10, 5, 1, 'NONE'), + (317, 317, 0, 9, 'logging', 3, 11, 4, 1, 'LEFT_SPAN'), (400, 400, 0, 10, 'registry', 0, 1, 4, 1, 'NONE'), (401, 401, 0, 10, 'registry', 0, 2, 4, 1, 'NONE'), diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 1504f6be..b55b1671 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -840,6 +840,18 @@ sebserver.examconfig.props.label.allowedDisplaysMaxNumber=Maximum allowed number sebserver.examconfig.props.label.allowedDisplaysMaxNumber.tooltip=If more displays are connected, this are blanked with an orange full screen window sebserver.examconfig.props.label.allowedDisplayBuiltin=Use built-in display sebserver.examconfig.props.label.allowedDisplayBuiltin.tooltip=Use the built-in display (if available) when only one display is allowed or when switching off display mirroring +sebserver.examconfig.props.label.logLevel=Log Level +sebserver.examconfig.props.label.logLevel.tooltip=The log will contain the selected log level plus all levels with a lower value +sebserver.examconfig.props.label.logLevel.0=Error +sebserver.examconfig.props.label.logLevel.0.tooltip=Error includes fatal application and browser level errors +sebserver.examconfig.props.label.logLevel.1=Warning +sebserver.examconfig.props.label.logLevel.1.tooltip=Warning are non-fatal but non-expected or security affecting events +sebserver.examconfig.props.label.logLevel.2=Info +sebserver.examconfig.props.label.logLevel.2.tooltip=Info includes most user actions including all browser navigation actions +sebserver.examconfig.props.label.logLevel.3=Debug +sebserver.examconfig.props.label.logLevel.3.tooltip=Debug is reserved for information which is only necessary for in-deep program code debugging +sebserver.examconfig.props.label.logLevel.4=Verbose +sebserver.examconfig.props.label.logLevel.4.tooltip=Verbose level contains events of all levels sebserver.examconfig.props.group.registry=While running SEB sebserver.examconfig.props.group.registry.tooltip=Options in the Windows Security Screen invoked by Ctrl-Alt-Del diff --git a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java index c62dc8f2..fe37c657 100644 --- a/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java +++ b/src/test/java/ch/ethz/seb/sebserver/webservice/integration/api/exam/SebExamConfigurationRequestTest.java @@ -58,7 +58,7 @@ public class SebExamConfigurationRequestTest extends ExamAPIIntegrationTester { final String contentAsString = configResponse.getContentAsString(); assertEquals( - "allowAudioCaptureallowBrowsingBackForwardallowDictionaryLookupallowDisplayMirroringallowDownUploadsallowedDisplayBuiltinallowedDisplaysMaxNumber1allowFlashFullscreenallowPDFPlugInallowQuitallowScreenSharingallowSiriallowSpellCheckallowSpellCheckDictionaryda-DKen-AUen-GBen-USes-ESfr-FRpt-PTsv-SEsv-FIallowSwitchToApplicationsallowUserAppFolderInstallallowVideoCaptureallowVirtualMachineaudioControlEnabledaudioMuteaudioSetVolumeLevelaudioVolumeLevel25blockPopUpWindowsbrowserUserAgentbrowserUserAgentMac0browserUserAgentMacCustombrowserUserAgentWinDesktopMode0browserUserAgentWinDesktopModeCustombrowserUserAgentWinTouchMode0browserUserAgentWinTouchModeCustombrowserViewMode0browserWindowAllowReloadbrowserWindowTitleSuffixchooseFileToUploadPolicy0createNewDesktopdetectStoppedProcessdownloadAndOpenSebConfigdownloadDirectoryOSXdownloadDirectoryWindownloadPDFFilesenableAltEscenableAltF4enableAltMouseWheelenableAltTabenableAppSwitcherCheckenableBrowserWindowToolbarenableCtrlEscenableEscenableF1enableF10enableF11enableF12enableF2enableF3enableF4enableF5enableF6enableF7enableF8enableF9enableJavaenableJavaScriptenableLoggingenablePlugInsenablePrintScreenenablePrivateClipboardenableRightMouseenableSebBrowserenableStartMenuenableTouchExitenableZoomPageenableZoomTextexitKey12exitKey210exitKey35forceAppFolderInstallhashedAdminPasswordhashedQuitPasswordhideBrowserWindowToolbarignoreExitKeysinsideSebEnableChangeAPasswordinsideSebEnableEaseOfAccessinsideSebEnableLockThisComputerinsideSebEnableLogOffinsideSebEnableNetworkConnectionSelectorinsideSebEnableShutDowninsideSebEnableStartTaskManagerinsideSebEnableSwitchUserinsideSebEnableVmWareClientShadekillExplorerShelllogDirectoryOSX~/DocumentslogDirectoryWinmainBrowserWindowHeight100%mainBrowserWindowPositioning1mainBrowserWindowWidth100%minMacOSVersion0newBrowserWindowAllowReloadnewBrowserWindowByLinkBlockForeignnewBrowserWindowByLinkHeight100%newBrowserWindowByLinkPolicy2newBrowserWindowByLinkPositioning2newBrowserWindowByLinkWidth100%newBrowserWindowNavigationnewBrowserWindowShowReloadWarningopenDownloadsoriginatorVersionSEB_Server_0.3.0permittedProcessesprohibitedProcessesproxiesAutoConfigurationEnabledAutoConfigurationJavaScriptAutoConfigurationURLAutoDiscoveryEnabledExceptionsListExcludeSimpleHostnamesFTPEnableFTPPassiveFTPPasswordFTPPort21FTPProxyFTPRequiresPasswordFTPUsernameHTTPEnableHTTPPasswordHTTPPort80HTTPProxyHTTPRequiresPasswordHTTPSEnableHTTPSPasswordHTTPSPort443HTTPSProxyHTTPSRequiresPasswordHTTPSUsernameHTTPUsernameRTSPEnableRTSPPasswordRTSPPort1080RTSPProxyRTSPRequiresPasswordRTSPUsernameSOCKSEnableSOCKSPasswordSOCKSPort1080SOCKSProxySOCKSRequiresPasswordSOCKSUsernameproxySettingsPolicy0quitURLquitURLConfirmremoveBrowserProfileremoveLocalStoragerestartExamPasswordProtectedrestartExamTextrestartExamURLrestartExamUseStartURLsebConfigPurpose0sebServicePolicy2showInputLanguageshowMenuBarshowReloadButtonshowReloadWarningshowTaskBarshowTimetaskBarHeight40URLFilterEnableURLFilterEnableContentFilterURLFilterRuleszoomMode0", + "allowAudioCaptureallowBrowsingBackForwardallowDictionaryLookupallowDisplayMirroringallowDownUploadsallowedDisplayBuiltinallowedDisplaysMaxNumber1allowFlashFullscreenallowPDFPlugInallowQuitallowScreenSharingallowSiriallowSpellCheckallowSpellCheckDictionaryda-DKen-AUen-GBen-USes-ESfr-FRpt-PTsv-SEsv-FIallowSwitchToApplicationsallowUserAppFolderInstallallowVideoCaptureallowVirtualMachineaudioControlEnabledaudioMuteaudioSetVolumeLevelaudioVolumeLevel25blockPopUpWindowsbrowserUserAgentbrowserUserAgentMac0browserUserAgentMacCustombrowserUserAgentWinDesktopMode0browserUserAgentWinDesktopModeCustombrowserUserAgentWinTouchMode0browserUserAgentWinTouchModeCustombrowserViewMode0browserWindowAllowReloadbrowserWindowTitleSuffixchooseFileToUploadPolicy0createNewDesktopdetectStoppedProcessdownloadAndOpenSebConfigdownloadDirectoryOSXdownloadDirectoryWindownloadPDFFilesenableAltEscenableAltF4enableAltMouseWheelenableAltTabenableAppSwitcherCheckenableBrowserWindowToolbarenableCtrlEscenableEscenableF1enableF10enableF11enableF12enableF2enableF3enableF4enableF5enableF6enableF7enableF8enableF9enableJavaenableJavaScriptenableLoggingenablePlugInsenablePrintScreenenablePrivateClipboardenableRightMouseenableSebBrowserenableStartMenuenableTouchExitenableZoomPageenableZoomTextexitKey12exitKey210exitKey35forceAppFolderInstallhashedAdminPasswordhashedQuitPasswordhideBrowserWindowToolbarignoreExitKeysinsideSebEnableChangeAPasswordinsideSebEnableEaseOfAccessinsideSebEnableLockThisComputerinsideSebEnableLogOffinsideSebEnableNetworkConnectionSelectorinsideSebEnableShutDowninsideSebEnableStartTaskManagerinsideSebEnableSwitchUserinsideSebEnableVmWareClientShadekillExplorerShelllogDirectoryOSX~/DocumentslogDirectoryWinlogLevel1mainBrowserWindowHeight100%mainBrowserWindowPositioning1mainBrowserWindowWidth100%minMacOSVersion0newBrowserWindowAllowReloadnewBrowserWindowByLinkBlockForeignnewBrowserWindowByLinkHeight100%newBrowserWindowByLinkPolicy2newBrowserWindowByLinkPositioning2newBrowserWindowByLinkWidth100%newBrowserWindowNavigationnewBrowserWindowShowReloadWarningopenDownloadsoriginatorVersionSEB_Server_0.3.0permittedProcessesprohibitedProcessesproxiesAutoConfigurationEnabledAutoConfigurationJavaScriptAutoConfigurationURLAutoDiscoveryEnabledExceptionsListExcludeSimpleHostnamesFTPEnableFTPPassiveFTPPasswordFTPPort21FTPProxyFTPRequiresPasswordFTPUsernameHTTPEnableHTTPPasswordHTTPPort80HTTPProxyHTTPRequiresPasswordHTTPSEnableHTTPSPasswordHTTPSPort443HTTPSProxyHTTPSRequiresPasswordHTTPSUsernameHTTPUsernameRTSPEnableRTSPPasswordRTSPPort1080RTSPProxyRTSPRequiresPasswordRTSPUsernameSOCKSEnableSOCKSPasswordSOCKSPort1080SOCKSProxySOCKSRequiresPasswordSOCKSUsernameproxySettingsPolicy0quitURLquitURLConfirmremoveBrowserProfileremoveLocalStoragerestartExamPasswordProtectedrestartExamTextrestartExamURLrestartExamUseStartURLsebConfigPurpose0sebServicePolicy2showInputLanguageshowMenuBarshowReloadButtonshowReloadWarningshowTaskBarshowTimetaskBarHeight40URLFilterEnableURLFilterEnableContentFilterURLFilterRuleszoomMode0", contentAsString); // check cache diff --git a/src/test/resources/data-test-additional.sql b/src/test/resources/data-test-additional.sql index 4a2bdc7c..7380b851 100644 --- a/src/test/resources/data-test-additional.sql +++ b/src/test/resources/data-test-additional.sql @@ -206,6 +206,7 @@ INSERT IGNORE INTO configuration_attribute VALUES (314, 'allowDisplayMirroring', 'CHECKBOX', null, null, null, null, 'false'), (315, 'allowedDisplaysMaxNumber', 'COMBO_SELECTION', null, '1,2,3', null, null, '1'), (316, 'allowedDisplayBuiltin', 'CHECKBOX', null, null, null, null, 'true'), + (317, 'logLevel', 'SINGLE_SELECTION', null, '0,1,2,3,4', null, null, '1'), (400, 'insideSebEnableSwitchUser', 'CHECKBOX', null, null, null, null, 'false'), (401, 'insideSebEnableLockThisComputer', 'CHECKBOX', null, null, null, null, 'false'), @@ -420,6 +421,7 @@ INSERT IGNORE INTO orientation VALUES (314, 314, 0, 9, 'macSettings', 7, 7, 5, 1, 'NONE'), (315, 315, 0, 9, 'macSettings', 7, 9, 5, 1, 'TOP'), (316, 316, 0, 9, 'macSettings', 7, 10, 5, 1, 'NONE'), + (317, 317, 0, 9, 'logging', 3, 11, 4, 1, 'LEFT_SPAN'), (400, 400, 0, 10, 'registry', 0, 1, 4, 1, 'NONE'), (401, 401, 0, 10, 'registry', 0, 2, 4, 1, 'NONE'),