Skip to content

Commit

Permalink
Bug fixes (#32)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
outbreaker authored Jan 10, 2021
1 parent 20b0856 commit efdade0
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 59 deletions.
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
63 changes: 24 additions & 39 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <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.
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 <https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>

[homepage]: https://www.contributor-covenant.org
[homepage]: <https://www.contributor-covenant.org>

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
<https://www.contributor-covenant.org/faq>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/de/gematik/demis/control/ConfigurationLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -85,21 +86,23 @@ public boolean checkPath(String dir) {
boolean config = false;
boolean client = false;
boolean data = false;

try (Stream<Path> stream1 = Files.walk(Paths.get(dir), 1);
Stream<Path> stream2 = Files.walk(Paths.get(dir), 1);
Stream<Path> stream3 = Files.walk(Paths.get(dir), 1)) {
try (Stream<Path> stream1 =
Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), 1);
Stream<Path> stream2 =
Files.walk(Paths.get(FilenameUtils.getFullPath(dir + File.separator)), 1);
Stream<Path> 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);
Expand All @@ -108,7 +111,8 @@ public boolean checkPath(String dir) {
}

public Set<Path> listFilesUsingFileWalk(String dir, int depth) throws IOException {
try (Stream<Path> stream = Files.walk(Paths.get(dir), depth)) {
try (Stream<Path> 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"))
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/de/gematik/demis/ui/PropertiesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 -> {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/MessagesBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
6 changes: 5 additions & 1 deletion src/main/resources/MessagesBundle_de_DE.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void getSetValueWrong() {
() -> {
portEditor.setValue("-1");
});
portEditor.setValue("100");
Assertions.assertEquals("100", portEditor.getValue());
portEditor.setValue("");
Assertions.assertEquals("", portEditor.getValue());
}

@Test
Expand Down

0 comments on commit efdade0

Please sign in to comment.