From 0cce03198caf0ad615e853a92a1147fb314e3349 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 27 Jun 2022 14:58:32 +0200 Subject: [PATCH] Code cleanup --- .../java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java | 4 ++-- .../ch/ethz/seb/sebserver/gbl/model/exam/Chapters.java | 8 ++++---- .../sebserver/gbl/model/sebconfig/SettingsPublished.java | 4 ++-- .../sebserver/gui/content/configs/SEBSettingsForm.java | 2 +- .../gui/content/exam/ExamSEBRestrictionSettings.java | 2 +- .../gui/service/examconfig/impl/TableFieldBuilder.java | 6 ++++++ .../examconfig/impl/rules/BrowserViewModeRule.java | 2 ++ .../sebserver/gui/service/page/impl/PageServiceImpl.java | 2 -- .../seb/sebserver/gui/widget/MultiSelectionCheckbox.java | 4 ++++ .../ch/ethz/seb/sebserver/webservice/CacheConfig.java | 4 +++- .../servicelayer/dao/impl/CertificateDAOImpl.java | 3 ++- 11 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java index 4cc325b2..857f19e9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java @@ -57,8 +57,7 @@ public class POSTMapper { // NOTE: this is a workaround since URI parameter are not automatically decoded in the HTTPServletRequest // while parameter from form-urlencoded body part are. - // I also tried to set application property: server.tomcat.uri-encoding=UTF-8 bit with no effect. - // TODO Didn't found a better solution for now but if there is some time, we should find a better solution + // I also tried to set application property: server.tomcat.uri-encoding=UTF-8 but with no effect. private void handleEncodedURIParams(final String uriQueryString) { final MultiValueMap override = new LinkedMultiValueMap<>(); this.params @@ -252,6 +251,7 @@ public class POSTMapper { try { val = Double.parseDouble(split[0]); } catch (final Exception e) { + log.error("Failed to parse double: ", e.getMessage()); } return new Threshold( val, diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Chapters.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Chapters.java index 923e3919..18ce1868 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Chapters.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/exam/Chapters.java @@ -26,24 +26,24 @@ public final class Chapters { public static final String ATTR_CHAPTERS = "chapters"; - public final List chapters; + public final List chapter_list; @JsonCreator public Chapters(@JsonProperty(ATTR_CHAPTERS) final Collection chapters) { final List c = (chapters != null) ? new ArrayList<>(chapters) : new ArrayList<>(); Collections.sort(c); - this.chapters = Utils.immutableListOf(c); + this.chapter_list = Utils.immutableListOf(c); } public Collection getChapters() { - return this.chapters; + return this.chapter_list; } @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("Chapters [chapters="); - builder.append(this.chapters); + builder.append(this.chapter_list); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SettingsPublished.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SettingsPublished.java index a797e678..219624d7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SettingsPublished.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/SettingsPublished.java @@ -21,11 +21,11 @@ public class SettingsPublished { @NotNull @JsonProperty(ATTR_SETTINGS_PUBLISHED) - public final Boolean settingsPublished; + public final Boolean pubished; @JsonCreator public SettingsPublished(@JsonProperty(ATTR_SETTINGS_PUBLISHED) final Boolean settingsPublished) { - this.settingsPublished = settingsPublished; + this.pubished = settingsPublished; } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBSettingsForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBSettingsForm.java index 2ae44a2b..b95ace8f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBSettingsForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/configs/SEBSettingsForm.java @@ -303,7 +303,7 @@ public class SEBSettingsForm implements TemplateComposer { .withURIVariable(API.PARAM_MODEL_ID, this.nodeId) .call() .onError(error -> log.warn("Failed to verify published settings. Cause: ", error.getMessage())) - .map(result -> result.settingsPublished) + .map(result -> result.pubished) .getOr(false); if (!settingsPublished) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSEBRestrictionSettings.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSEBRestrictionSettings.java index 4a6da27b..70cd080a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSEBRestrictionSettings.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/exam/ExamSEBRestrictionSettings.java @@ -278,7 +278,7 @@ public class ExamSEBRestrictionSettings { sebRestriction .getAdditionalProperties() .get(OpenEdxSEBRestriction.ATTR_BLACKLIST_CHAPTERS), - () -> chapters.chapters + () -> chapters.chapter_list .stream() .map(chapter -> new Tuple<>(chapter.id, chapter.name)) .collect(Collectors.toList()))) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableFieldBuilder.java index c65b4623..baac9047 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TableFieldBuilder.java @@ -20,6 +20,8 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -42,6 +44,8 @@ import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.ImageIcon; @GuiProfile public class TableFieldBuilder extends AbstractTableFieldBuilder { + private static final Logger log = LoggerFactory.getLogger(TableFieldBuilder.class); + private static final String TOOLTIP_SUFFIX = ".tooltip"; private static final String ADD_TOOLTIP_SUFFIX = ".add" + TOOLTIP_SUFFIX; private static final String REMOVE_TOOLTIP_SUFFIX = ".remove" + TOOLTIP_SUFFIX; @@ -159,6 +163,7 @@ public class TableFieldBuilder extends AbstractTableFieldBuilder { this.control.showSelection(); } catch (final Exception e) { // ignore auto selection error + log.warn("Failed to apply auto selection: {}", e.getMessage()); } // send new values to web-service this.tableContext @@ -184,6 +189,7 @@ public class TableFieldBuilder extends AbstractTableFieldBuilder { this.control.showSelection(); } catch (final Exception e) { // ignore auto selection error + log.warn("Failed to apply auto selection: {}", e.getMessage()); } // send new values to web-service this.tableContext.getValueChangeListener() diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/BrowserViewModeRule.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/BrowserViewModeRule.java index e1b29beb..ba69e689 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/BrowserViewModeRule.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/BrowserViewModeRule.java @@ -79,6 +79,8 @@ public class BrowserViewModeRule implements ValueChangeRule { break; } default: { + log.warn("Unexpected state"); + break; } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java index 8faf5b3b..3c4528e1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java @@ -331,8 +331,6 @@ public class PageServiceImpl implements PageService { } catch (final Exception e) { log.error("Failed to set current PageState: ", e); } - } else { - } callback.accept(result); }); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java index 2033c806..914ccd39 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCheckbox.java @@ -20,6 +20,8 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Listener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.util.Tuple; @@ -30,6 +32,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService; public final class MultiSelectionCheckbox extends Composite implements Selection { private static final long serialVersionUID = -8507565817745610126L; + private static final Logger log = LoggerFactory.getLogger(MultiSelectionCheckbox.class); private Listener listener = null; private final Map checkboxes; @@ -90,6 +93,7 @@ public final class MultiSelectionCheckbox extends Composite implements Selection } } catch (final Exception e) { // ignore + log.warn("Failed to get Tuple3: {}", e.getMessage()); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/CacheConfig.java b/src/main/java/ch/ethz/seb/sebserver/webservice/CacheConfig.java index 20923778..03efff94 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/CacheConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/CacheConfig.java @@ -45,7 +45,9 @@ public class CacheConfig extends JCacheConfigurerSupport { try { final CachingProvider cachingProvider = Caching.getCachingProvider(); final javax.cache.CacheManager cacheManager = - cachingProvider.getCacheManager(new URI(this.jCacheConfig), this.getClass().getClassLoader()); + cachingProvider.getCacheManager( + new URI(this.jCacheConfig), + Thread.currentThread().getContextClassLoader()); final CompositeCacheManager composite = new CompositeCacheManager(); composite.setCacheManagers(Arrays.asList( diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java index 88455581..104420a1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/CertificateDAOImpl.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.List; +import java.util.Locale; import java.util.NoSuchElementException; import java.util.Set; import java.util.stream.Collectors; @@ -236,7 +237,7 @@ public class CertificateDAOImpl implements CertificateDAO { if (StringUtils.isBlank(dn)) { return String.valueOf(certificate.getSerialNumber()); } else { - return dn.replace(" ", "_").toLowerCase(); + return dn.replace(" ", "_").toLowerCase(Locale.ENGLISH); } } catch (final CertificateEncodingException e) { log.warn("Error while trying to get alias from certificate subject name. Use serial number as alias");