From efdade0e6f8d4a1fbe34fba2bdacd9b1d11dc882 Mon Sep 17 00:00:00 2001 From: outbreaker Date: Sun, 10 Jan 2021 17:40:20 +0100 Subject: [PATCH] Bug fixes (#32) * add handling of empty port values for PortEditor * add Warning Popup if value not correct set to fields * reset to default values if values for numbers are wrong * change Error-Message to general number failures Message * fix PATH_TRAVERSAL_IN * fix code smell in Markdown Code of Conduct * fix code smells in Markdown Bug-Report * add check fileType --- .github/ISSUE_TEMPLATE/bug_report.md | 14 ++--- CODE_OF_CONDUCT.md | 63 +++++++------------ build.gradle | 3 +- .../demis/control/ConfigurationLoader.java | 20 +++--- .../de/gematik/demis/ui/PropertiesView.java | 34 +++++++++- .../ui/actions/DemisMenuActionListener.java | 6 +- .../demis/ui/value/editor/PortEditor.java | 4 ++ src/main/resources/MessagesBundle.properties | 6 +- .../resources/MessagesBundle_de_DE.properties | 6 +- .../demis/ui/value/editor/PortEditorTest.java | 4 ++ 10 files changed, 101 insertions(+), 59 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..3f3b5ce 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,15 +24,15 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] +- OS: \[e.g. iOS\] +- Browser \[e.g. chrome, safari\] +- Version \[e.g. 22\] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] +- Device: \[e.g. iPhone6\] +- OS: \[e.g. iOS8.1\] +- Browser \[e.g. stock browser, safari\] +- Version \[e.g. 22\] **Additional context** Add any other context about the problem here. diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 38679c7..b58ce95 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,17 +2,14 @@ ## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, sex characteristics, gender identity and expression, -level of experience, education, socio-economic status, nationality, personal -appearance, race, religion, or sexual identity and orientation. +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and +expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and +orientation. ## Our Standards -Examples of behavior that contributes to creating a positive environment -include: +Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences @@ -22,55 +19,43 @@ include: Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or - advances +* The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective +action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples +of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an +appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at https://gematik-ext.atlassian.net/wiki/spaces/DSKB. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team +at . All complaints will be reviewed and investigated and will result in a response that is deemed +necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by +other members of the project's leadership. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available +at -[homepage]: https://www.contributor-covenant.org +[homepage]: For answers to common questions about this code of conduct, see -https://www.contributor-covenant.org/faq + diff --git a/build.gradle b/build.gradle index 20f2fa9..a6f84d5 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,8 @@ dependencies { implementation 'org.assertj:assertj-swing-jide:3.17.1' implementation 'org.assertj:assertj-swing-junit-4.5:1.2.0' - + + implementation 'org.apache.commons:commons-io:1.3.2' implementation group: 'commons-validator', name: 'commons-validator', version: '1.7' implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' implementation group: 'com.formdev', name: 'flatlaf', version: '0.43' diff --git a/src/main/java/de/gematik/demis/control/ConfigurationLoader.java b/src/main/java/de/gematik/demis/control/ConfigurationLoader.java index d98e45d..8c7021e 100644 --- a/src/main/java/de/gematik/demis/control/ConfigurationLoader.java +++ b/src/main/java/de/gematik/demis/control/ConfigurationLoader.java @@ -19,6 +19,7 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -85,21 +86,23 @@ public boolean checkPath(String dir) { boolean config = false; boolean client = false; boolean data = false; - - try (Stream stream1 = Files.walk(Paths.get(dir), 1); - Stream stream2 = Files.walk(Paths.get(dir), 1); - Stream stream3 = Files.walk(Paths.get(dir), 1)) { + try (Stream stream1 = + Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), 1); + Stream stream2 = + Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), 1); + Stream stream3 = + Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), 1)) { config = stream1 - .filter(file -> Files.isDirectory(file)) + .filter(Files::isDirectory) .anyMatch(f -> f.toFile().getAbsolutePath().toLowerCase().endsWith("config")); client = stream2 - .filter(file -> Files.isDirectory(file)) + .filter(Files::isDirectory) .anyMatch(f -> f.toFile().getAbsolutePath().toLowerCase().endsWith("client")); data = stream3 - .filter(file -> Files.isDirectory(file)) + .filter(Files::isDirectory) .anyMatch(f -> f.toFile().getAbsolutePath().toLowerCase().endsWith("data")); } catch (Exception e) { LOG.error("Failed to check folder", e); @@ -108,7 +111,8 @@ public boolean checkPath(String dir) { } public Set listFilesUsingFileWalk(String dir, int depth) throws IOException { - try (Stream stream = Files.walk(Paths.get(dir), depth)) { + try (Stream stream = + Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), depth)) { return stream .filter(file -> !Files.isDirectory(file)) .filter(file -> !file.toFile().getAbsolutePath().toLowerCase().contains("\\jre")) diff --git a/src/main/java/de/gematik/demis/ui/PropertiesView.java b/src/main/java/de/gematik/demis/ui/PropertiesView.java index 3540694..1b9ac55 100644 --- a/src/main/java/de/gematik/demis/ui/PropertiesView.java +++ b/src/main/java/de/gematik/demis/ui/PropertiesView.java @@ -23,6 +23,7 @@ import java.util.ResourceBundle; import javax.swing.JCheckBox; import javax.swing.JLabel; +import javax.swing.JOptionPane; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +101,14 @@ private void initComponents(File file) { + e.getKey() + "\" has no Value!"); } else { - editor.setValue(property); + try { + editor.setValue(property); + } catch (NumberFormatException exception) { + editor.setValue(e.getDefaultValue()); + handleSetValueException(exception, property, e.getKey()); + } catch (Exception exception) { + handleSetValueException(exception, property, e.getKey()); + } } editor.addChangeListener( s -> { @@ -113,6 +121,30 @@ private void initComponents(File file) { this.repaint(); } + private void handleSetValueException(Exception exception, String value, String property) { + ResourceBundle messages = ResourceBundle.getBundle("MessagesBundle", Locale.getDefault()); + if (exception instanceof NumberFormatException) { + JOptionPane.showMessageDialog( + MainView.getInstance().getMainComponent(), + messages + .getString("ERROR_SET_VALUE_AS_NUMBER") + .replace("##VALUE##", value) + .replace("##PROPERTY##", property), + messages.getString("ERROR_SET_VALUE_AS_NUMBER_TITLE"), + JOptionPane.WARNING_MESSAGE); + } else { + JOptionPane.showMessageDialog( + MainView.getInstance().getMainComponent(), + messages + .getString("ERROR_SET_VALUE") + .replace("##VALUE##", value) + .replace("##PROPERTY##", property), + messages.getString("ERROR_SET_VALUE_TITLE"), + JOptionPane.WARNING_MESSAGE); + } + setUnsaved(); + } + private void convertProxyFromSinglelineToMultiline(Properties prop) { String proxyKey = ADAPTER_Properties.IDP_LAB_PROXY.getKey(); String proxy = prop.getProperty(proxyKey); diff --git a/src/main/java/de/gematik/demis/ui/actions/DemisMenuActionListener.java b/src/main/java/de/gematik/demis/ui/actions/DemisMenuActionListener.java index 492aacd..041540c 100644 --- a/src/main/java/de/gematik/demis/ui/actions/DemisMenuActionListener.java +++ b/src/main/java/de/gematik/demis/ui/actions/DemisMenuActionListener.java @@ -26,6 +26,7 @@ import javax.swing.JOptionPane; import javax.swing.JToggleButton; import javax.swing.filechooser.FileFilter; +import org.apache.commons.io.FilenameUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,7 +186,10 @@ private Path checkPath( == JFileChooser.APPROVE_OPTION) { File folderToLoad = universalFileChooser.getSelectedFile(); if (!folderToLoad.getAbsolutePath().toLowerCase().endsWith("." + fileType)) { - lastPath = new File(folderToLoad.getAbsolutePath() + "." + fileType); + lastPath = + new File( + FilenameUtils.getPath( + folderToLoad.getAbsolutePath() + "." + FilenameUtils.getName(fileType))); } else { lastPath = folderToLoad.getAbsoluteFile(); } diff --git a/src/main/java/de/gematik/demis/ui/value/editor/PortEditor.java b/src/main/java/de/gematik/demis/ui/value/editor/PortEditor.java index 8139d96..b67ce5a 100644 --- a/src/main/java/de/gematik/demis/ui/value/editor/PortEditor.java +++ b/src/main/java/de/gematik/demis/ui/value/editor/PortEditor.java @@ -44,6 +44,10 @@ public String getValue() { @Override public void setValue(String value) { + if (value.isEmpty()) { + field.setValue(null); + return; + } field.setValue(Integer.valueOf(value)); try { field.commitEdit(); diff --git a/src/main/resources/MessagesBundle.properties b/src/main/resources/MessagesBundle.properties index c38bba4..792205f 100644 --- a/src/main/resources/MessagesBundle.properties +++ b/src/main/resources/MessagesBundle.properties @@ -40,4 +40,8 @@ OPEN_NEW_CONFIG_BUT_OPEN=Before you can open a new adapter configuration, the cu OPEN_NEW_CONFIG_BUT_OPEN_TITLE=Close Configuration? OPEN_NEW_CONFIG=Please select DEMIS Adapter mainfolder including the folders client, config, data, linux and windows. NEW_LAB=New Laboratoryconfiguration -NEW_PROPS=New Configuration \ No newline at end of file +NEW_PROPS=New Configuration +ERROR_SET_VALUE_AS_NUMBER=The Value "##VALUE##" is not a valid Number for "##PROPERTY##" and is changed to default value. +ERROR_SET_VALUE_AS_NUMBER_TITLE=Wrong Number value +ERROR_SET_VALUE=The Value "##VALUE##" is not valid for "##PROPERTY##" and is not set. +ERROR_SET_VALUE_TITLE=Wrong value \ No newline at end of file diff --git a/src/main/resources/MessagesBundle_de_DE.properties b/src/main/resources/MessagesBundle_de_DE.properties index 10ea256..fb29f10 100644 --- a/src/main/resources/MessagesBundle_de_DE.properties +++ b/src/main/resources/MessagesBundle_de_DE.properties @@ -40,4 +40,8 @@ OPEN_NEW_CONFIG_BUT_OPEN=Bevor Sie eine neue Adapter-Konfiguration OPEN_NEW_CONFIG_BUT_OPEN_TITLE=Konfiguration schließen? OPEN_NEW_CONFIG=Bitte wählen Sie den Hauptordner des DEMIS-Adapters aus, sodass Sie die einzelnen Unterverzeichnisse client, config, data, linux und windows sehen. NEW_LAB=Neue Laborkonfiguration -NEW_PROPS=Neue Konfiguration \ No newline at end of file +NEW_PROPS=Neue Konfiguration +ERROR_SET_VALUE_AS_NUMBER=Der Wert "##VALUE##" ist kein gültiger Zahlenwert für "##PROPERTY##" und wurde auf den Standardwert zurückgesetzt. +ERROR_SET_VALUE_AS_NUMBER_TITLE=Falscher Zahlenwert +ERROR_SET_VALUE=Der Wert "##VALUE##" ist kein gültiger Wert für "##PROPERTY##" und kann nicht genutzt werden. +ERROR_SET_VALUE_TITLE=Falscher Property Wert \ No newline at end of file diff --git a/src/test/java/de/gematik/demis/ui/value/editor/PortEditorTest.java b/src/test/java/de/gematik/demis/ui/value/editor/PortEditorTest.java index 29f4724..94a6a1c 100644 --- a/src/test/java/de/gematik/demis/ui/value/editor/PortEditorTest.java +++ b/src/test/java/de/gematik/demis/ui/value/editor/PortEditorTest.java @@ -38,6 +38,10 @@ void getSetValueWrong() { () -> { portEditor.setValue("-1"); }); + portEditor.setValue("100"); + Assertions.assertEquals("100", portEditor.getValue()); + portEditor.setValue(""); + Assertions.assertEquals("", portEditor.getValue()); } @Test