Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some SonarCloud issues from the complete code analysis #49

Merged
merged 53 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
cd537d6
Fixed some SonarCloud issues;
JonasSchaub Mar 4, 2024
37f3ea7
Fixed string concatenation, cannot do anything about duplications now;
JonasSchaub Mar 4, 2024
59c1836
Same as before;
JonasSchaub Mar 4, 2024
df0fda7
Fixed SonarCloud complaints;
JonasSchaub Mar 4, 2024
bea1219
introduced a configuration properties file and changed a few things a…
JonasSchaub Mar 5, 2024
ef17d27
Fixed import of resource files via configurations class, also works f…
JonasSchaub Mar 6, 2024
8910e4e
All resource files are imported via paths and file names in configura…
JonasSchaub Mar 6, 2024
73111a1
Removed unused imports;
JonasSchaub Mar 6, 2024
d3d0f7f
No more exceptions when a configurations instance is passed as param …
JonasSchaub Mar 6, 2024
202c390
Moved some folder names from BasicDefinitions to Configuration
JonasSchaub Mar 6, 2024
71d9a78
Removed unused param according to https://github.com/FelixBaensch/MOR…
JonasSchaub Mar 7, 2024
0ba77f2
Made sure all buttons have the same sizes;
JonasSchaub Mar 7, 2024
6203b4c
Defined general font size;
JonasSchaub Mar 7, 2024
5843c12
Merge branch 'production' into sonar-issues-fix
JonasSchaub Mar 11, 2024
51a1379
Abbreviated export button labels and exchanged histogram button label…
JonasSchaub Mar 11, 2024
26d9b3d
Renamed and restructured method to get items of active tab;
JonasSchaub Mar 11, 2024
62548b5
Encapsulated the custom pagination with suitable page count creation …
JonasSchaub Mar 11, 2024
2c29323
Separated overview view setting for first structure highlight and jum…
JonasSchaub Mar 11, 2024
e5638b8
Mainly merged some if statements;
JonasSchaub Mar 11, 2024
39ecbc7
More SonarCloud issues fixes, i.a. throwing specific exceptions in Vi…
JonasSchaub Mar 12, 2024
a2dc5fd
Reversed exchanging [0-9] by \d in regex patterns for better readabil…
JonasSchaub Mar 13, 2024
0c911c6
SimpleEnumConstantnamePropertyTest overhaul, added assertions, remove…
JonasSchaub Mar 13, 2024
8f3702a
Added check for successful initialization of Configuration to MainApp…
JonasSchaub Mar 13, 2024
4590260
Refer to interfaces instead of specific class for HashMap in Molecule…
JonasSchaub Mar 13, 2024
dd2f0a3
Fixed bug that items tab was not sortable by name (unmodifiable list …
JonasSchaub Mar 14, 2024
89094bc
Documenting and linting; refactored depictBufferedImageWithZoom method;
JonasSchaub Mar 14, 2024
52f0d09
Linting and fixing some sonar issues in FragmentationService mostly; …
JonasSchaub Mar 14, 2024
5ca25e7
Fixing sonar complaints and linting in FragmentationTask and all frag…
JonasSchaub Mar 15, 2024
04961c0
Fix EFGF instance instantiated too late in the constructor;
JonasSchaub Mar 15, 2024
6eaba95
Overhaul of exporter, mostly exception treatment (more is passed on t…
JonasSchaub Mar 18, 2024
bdc12be
Fixed bug in items tab PDF export, number of fragments in header was …
JonasSchaub Mar 19, 2024
3224b7c
A few changes and additions in headers of exported files;
JonasSchaub Mar 19, 2024
a45bb63
Fix spotless complaint;
JonasSchaub Mar 19, 2024
c0fc480
Changed CSV export separator char from being set directly to an enum …
JonasSchaub Mar 19, 2024
b944857
Overhaul of importer;
JonasSchaub Mar 19, 2024
9b61c2d
Overhaul of SettingsContainer;
JonasSchaub Mar 19, 2024
9daa33f
Replacing some string concatenations with string.format calls;
JonasSchaub Mar 19, 2024
7ae13f9
Overhaul of some util classes;
JonasSchaub Mar 19, 2024
493d861
Introduced separate display names for settings (general and for fragm…
JonasSchaub Mar 20, 2024
c18817e
Defined fixed size for combo boxes in the settings views;
JonasSchaub Mar 20, 2024
4af7a03
Started working on a new custom property to wrap the language-specifi…
JonasSchaub Mar 20, 2024
d8f1847
Added SimpleIDisplayEnumConstantProperty as new JavaFX property that …
JonasSchaub Mar 21, 2024
e494708
Replaced all SimpleEnumConstantNameProperty settings with SimpleIDisp…
JonasSchaub Mar 22, 2024
9a3d613
Updated spotless; moved openFilePathInExplorer() to FileUtil; overhau…
JonasSchaub Mar 25, 2024
11c812d
make constructors protected;
JonasSchaub Mar 25, 2024
2efc444
Final clean-up, mostly linting; added a MORTARException class but end…
JonasSchaub Mar 26, 2024
2e8f5e3
Trying to reduce duplications;
JonasSchaub Mar 26, 2024
ef799ef
Final clean-up, mostly linting; fixed possible eternal loop in Prefer…
JonasSchaub Mar 27, 2024
09047af
Reduced duplication by moving translation of preferences to propertie…
JonasSchaub Mar 27, 2024
7f42944
Added separate display name to fragmenters but not used yet; added no…
JonasSchaub Mar 28, 2024
26a7a3c
Changed integer filter of settings view integer text fields to positi…
JonasSchaub Mar 28, 2024
481184a
Changed double filter of settings view double text fields to positive…
JonasSchaub Mar 28, 2024
095a146
Separated usage of algorithm name for internal use and algorithm disp…
JonasSchaub Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* MORTAR - MOlecule fRagmenTAtion fRamework
* Copyright (C) 2024 Felix Baensch, Jonas Schaub (felix.baensch@w-hs.de, jonas.schaub@uni-jena.de)
*
* Source code is available at <https://github.com/FelixBaensch/MORTAR>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.unijena.cheminf.mortar.configuration;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.MissingResourceException;
import java.util.Properties;

/**
* Thread-safe singleton class for reading configuration properties file, e.g. for paths to resource folders.
*
* @author Jonas Schaub
* @version 1.0.0.0
*/
public class Configuration implements IConfiguration {
/**
* Single instance of this class.
*/
private static Configuration instance;
//
/**
* Properties imported and cached from the configuration properties file.
*/
private final Properties properties;
//
/**
* Path to the configuration properties file to read.
*/
private static final String PROPERTIES_FILE_PATH = "de/unijena/cheminf/mortar/configuration/MORTAR_configuration.properties";
//
/**
* Private constructor that creates the single instance.
*
* @throws IOException if the properties file is not found or if an error occurs when reading from the input stream
*/
private Configuration() throws IOException {
this.properties = new Properties();
try (InputStream tmpInputStream = this.getClass().getClassLoader().getResourceAsStream(Configuration.PROPERTIES_FILE_PATH)) {
if (tmpInputStream != null) {
//throws IOException if an error occurs when reading from the input stream
this.properties.load(tmpInputStream);
} else {
//extends IOException
throw new FileNotFoundException(String.format("property file '%s' not found in the classpath", Configuration.PROPERTIES_FILE_PATH));
}
}
}
//
/**
* Returns the single instance of this class.
*
* @return instance of this class
* @throws IOException if the properties file is not found or if an error occurs when reading from the input stream
*/
public static synchronized Configuration getInstance() throws IOException {
if (Configuration.instance == null) {
Configuration.instance = new Configuration();
}
return Configuration.instance;
}
//
@Override
public String getProperty(String aKey) throws MissingResourceException {
String tmpProperty = this.properties.getProperty(aKey).trim();
if (tmpProperty == null) {
throw new MissingResourceException(String.format("Property '%s' not found", aKey), Configuration.class.getName(), aKey);
} else {
return tmpProperty;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* MORTAR - MOlecule fRagmenTAtion fRamework
* Copyright (C) 2024 Felix Baensch, Jonas Schaub (felix.baensch@w-hs.de, jonas.schaub@uni-jena.de)
*
* Source code is available at <https://github.com/FelixBaensch/MORTAR>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.unijena.cheminf.mortar.configuration;

import java.util.MissingResourceException;

/**
* Interface for classes reading configuration properties files, e.g. for paths to resource folders.
*
* @author Jonas Schaub
* @version 1.0.0.0
*/
public interface IConfiguration {
/**
* Returns the string value associated with the key in the configurations properties file.
*
* @param aKey key defined in the configuration properties file
* @return property value associated with the given key
* @throws MissingResourceException if no associated value could be found for the given key
*/
public String getProperty(String aKey) throws MissingResourceException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

package de.unijena.cheminf.mortar.controller;

import de.unijena.cheminf.mortar.configuration.IConfiguration;
import de.unijena.cheminf.mortar.gui.util.ExternalTool;
import de.unijena.cheminf.mortar.gui.util.GuiDefinitions;
import de.unijena.cheminf.mortar.gui.util.GuiUtil;
import de.unijena.cheminf.mortar.gui.views.AboutView;
import de.unijena.cheminf.mortar.message.Message;
import de.unijena.cheminf.mortar.model.util.BasicDefinitions;
import de.unijena.cheminf.mortar.model.util.LogUtil;

import javafx.application.Platform;
Expand Down Expand Up @@ -59,7 +59,6 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Objects;
Expand All @@ -73,28 +72,27 @@
* @version 1.0.0.0
*/
public class AboutViewController {

//<editor-fold desc="private class variables" defaultstate="collapsed">
/**
* Main Stage / parent Stage
*/
private Stage mainStage;
/**
* View to controll
* View to control
*/
private AboutView aboutView;
/**
* Stage to show AboutView
*/
private Stage aboutViewStage;
/**
* path to xml file which contains information about external tools
*/
private String toolsXmlFileName = "de/unijena/cheminf/mortar/descriptions/tools_description.xml";
/**
* ObservableList to show properties of ExternalTools
*/
private ObservableList<ExternalTool> toolObservableList;
/**
* Configuration class to read resource file paths from.
*/
private final IConfiguration configuration;
//</editor-fold>
//
//<editor-fold desc="private static final class variables" defaultstate="collapsed">
Expand All @@ -105,13 +103,15 @@ public class AboutViewController {
//</editor-fold>
//
/**
* Constructor
* Constructor.
*
* @param aStage Stage
* @param aConfiguration configuration class reading from properties file
*/
public AboutViewController(Stage aStage){
public AboutViewController(Stage aStage, IConfiguration aConfiguration) {
this.mainStage = aStage;
this.toolObservableList = FXCollections.observableArrayList();
this.configuration = aConfiguration;
this.showAboutView();
}
//
Expand All @@ -121,7 +121,7 @@ public AboutViewController(Stage aStage){
*/
private void showAboutView(){
if(this.aboutView == null){
this.aboutView = new AboutView();
this.aboutView = new AboutView(this.configuration);
}
this.aboutViewStage = new Stage();
Scene tmpScene = new Scene(this.aboutView, GuiDefinitions.GUI_MAIN_VIEW_WIDTH_VALUE, GuiDefinitions.GUI_MAIN_VIEW_HEIGHT_VALUE);
Expand All @@ -131,8 +131,9 @@ private void showAboutView(){
this.aboutViewStage.setTitle(Message.get("AboutView.title.text"));
this.aboutViewStage.setMinHeight(GuiDefinitions.GUI_MAIN_VIEW_HEIGHT_VALUE);
this.aboutViewStage.setMinWidth(GuiDefinitions.GUI_MAIN_VIEW_WIDTH_VALUE);
InputStream tmpImageInputStream = AboutViewController.class.getResourceAsStream("/de/unijena/cheminf/mortar/images/Mortar_Logo_Icon1.png");
this.aboutViewStage.getIcons().add(new Image(tmpImageInputStream));
String tmpIconURL = this.getClass().getClassLoader().getResource(
this.configuration.getProperty("mortar.imagesFolder") + this.configuration.getProperty("mortar.logo.icon.name")).toExternalForm();
this.aboutViewStage.getIcons().add(new Image(tmpIconURL));
Platform.runLater(()->{
this.addListeners();
this.getExternalToolInfosFromXml();
Expand Down Expand Up @@ -182,7 +183,7 @@ else if (tmpOS.contains("NUX") || tmpOS.contains("NIX") || tmpOS.contains("AIX")
else
throw new SecurityException("OS name " + tmpOS + " unknown.");
} catch (IOException anException) {
LOGGER.log(Level.SEVERE, anException.toString(), anException);
AboutViewController.LOGGER.log(Level.SEVERE, anException.toString(), anException);
throw new SecurityException("Could not open directory path");
}
}
Expand All @@ -194,9 +195,9 @@ else if (tmpOS.contains("NUX") || tmpOS.contains("NIX") || tmpOS.contains("AIX")
*/
private void openGitHubRepositoryInDefaultBrowser(){
try{
Desktop.getDesktop().browse(new URI(BasicDefinitions.GITHUB_REPOSITORY_URL));
Desktop.getDesktop().browse(new URI(this.configuration.getProperty("mortar.github.repository.url")));
} catch (IOException | URISyntaxException anException) {
LOGGER.log(Level.SEVERE, anException.toString(), anException);
AboutViewController.LOGGER.log(Level.SEVERE, anException.toString(), anException);
throw new SecurityException("Could not open directory path");
}
}
Expand All @@ -207,14 +208,14 @@ private void openGitHubRepositoryInDefaultBrowser(){
private void openTutorialInDefaultPdfViewer() {
//Note: Does not work when started from IDE, only in built version started from JAR
try {
Desktop.getDesktop().open(new File(BasicDefinitions.MORTAR_TUTORIAL_RELATIVE_FILE_PATH));
Desktop.getDesktop().open(new File(this.configuration.getProperty("mortar.tutorial.relativeFilePath")));
} catch (IOException | IllegalArgumentException anException) {
LOGGER.log(Level.SEVERE, anException.toString(), anException);
Hyperlink tmpLinkToTutorial = new Hyperlink(Message.get("AboutView.tutorialButton.alert.hyperlink.text"));
tmpLinkToTutorial.setTooltip(new Tooltip(BasicDefinitions.MORTAR_TUTORIAL_URL));
tmpLinkToTutorial.setTooltip(new Tooltip(this.configuration.getProperty("mortar.tutorial.url")));
tmpLinkToTutorial.setOnAction(event -> {
try {
Desktop.getDesktop().browse(new URI(BasicDefinitions.MORTAR_TUTORIAL_URL));
Desktop.getDesktop().browse(new URI(this.configuration.getProperty("mortar.tutorial.url")));
} catch (IOException | URISyntaxException e) {
LOGGER.log(Level.SEVERE, anException.toString(), anException);
throw new SecurityException("Could not open URI");
Expand All @@ -226,7 +227,7 @@ private void openTutorialInDefaultPdfViewer() {
}
//
/**
* Reads xml file (tools_description.xml in resources) which contains information about the used external tools
* Reads xml file (tools_description.xml in resources) which contains information about the used external tools.
*/
private void getExternalToolInfosFromXml(){
DocumentBuilderFactory tmpDocumentBuilderFactory = DocumentBuilderFactory.newInstance();
Expand All @@ -235,9 +236,11 @@ private void getExternalToolInfosFromXml(){
// process XML securely, avoid attacks like XML External Entities (XXE)
tmpDocumentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder tmpDocBuilder = tmpDocumentBuilderFactory.newDocumentBuilder();
Document tmpDoc = tmpDocBuilder.parse(getClass().getClassLoader().getResourceAsStream(this.toolsXmlFileName));
if(tmpDoc == null){
throw new FileNotFoundException("File not found " + this.toolsXmlFileName);
Document tmpDoc = tmpDocBuilder.parse(this.getClass().getClassLoader().getResource(
this.configuration.getProperty("mortar.descriptionsFolder")
+ this.configuration.getProperty("mortar.tools.description.name")).toExternalForm());
if (tmpDoc == null) {
throw new FileNotFoundException("Tools description XML file not found.");
}
// optional, but recommended
// http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package de.unijena.cheminf.mortar.controller;

import de.unijena.cheminf.mortar.configuration.IConfiguration;
import de.unijena.cheminf.mortar.gui.util.GuiDefinitions;
import de.unijena.cheminf.mortar.gui.views.SettingsView;
import de.unijena.cheminf.mortar.message.Message;
Expand All @@ -38,7 +39,6 @@
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
Expand All @@ -51,7 +51,6 @@
* @version 1.0.0.0
*/
public class FragmentationSettingsViewController {

//<editor-fold desc="private and private final class variables">
/**
* Main stage object of the application
Expand All @@ -77,24 +76,29 @@ public class FragmentationSettingsViewController {
* Name of the selected fragmentation algorithm
*/
private String selectedFragmenterName;
/**
* Configuration class to read resource file paths from.
*/
private final IConfiguration configuration;
/**
* Logger
*/
private static final Logger LOGGER = Logger.getLogger(FragmentationSettingsViewController.class.getName());
//</editor-fold>

/**
* Constructor
*
* @param aStage Stage
* @param anArrayOfFragmenters IMoleculeFragmenter[]
* @param aSelectedFragmenterAlgorithmName String
* @param aConfiguration configuration instance to read resource file paths from
*/
public FragmentationSettingsViewController(Stage aStage, IMoleculeFragmenter[] anArrayOfFragmenters, String aSelectedFragmenterAlgorithmName){
public FragmentationSettingsViewController(Stage aStage, IMoleculeFragmenter[] anArrayOfFragmenters, String aSelectedFragmenterAlgorithmName, IConfiguration aConfiguration){
this.mainStage = aStage;
this.recentProperties = new HashMap<>(CollectionUtil.calculateInitialHashCollectionCapacity(anArrayOfFragmenters.length));
this.fragmenters = anArrayOfFragmenters;
this.selectedFragmenterName = aSelectedFragmenterAlgorithmName;
this.configuration = aConfiguration;
this.openFragmentationSettingsView();
}
//
Expand All @@ -113,8 +117,10 @@ private void openFragmentationSettingsView(){
this.fragmentationSettingsViewStage.setTitle(Message.get("FragmentationSettingsView.title.text"));
this.fragmentationSettingsViewStage.setMinHeight(GuiDefinitions.GUI_MAIN_VIEW_HEIGHT_VALUE);
this.fragmentationSettingsViewStage.setMinWidth(GuiDefinitions.GUI_MAIN_VIEW_WIDTH_VALUE);
InputStream tmpImageInputStream = FragmentationSettingsViewController.class.getResourceAsStream("/de/unijena/cheminf/mortar/images/Mortar_Logo_Icon1.png");
this.fragmentationSettingsViewStage.getIcons().add(new Image(tmpImageInputStream));
String tmpIconURL = this.getClass().getClassLoader().getResource(
this.configuration.getProperty("mortar.imagesFolder")
+ this.configuration.getProperty("mortar.logo.icon.name")).toExternalForm();
this.fragmentationSettingsViewStage.getIcons().add(new Image(tmpIconURL));
//
this.addListener();
for (IMoleculeFragmenter tmpFragmenter : this.fragmenters) {
Expand Down Expand Up @@ -169,7 +175,7 @@ private void addListener(){
* @param aFragmenter IMoleculeFragmenter
* @param aRecentPropertiesMap Map
*/
private void setRecentProperties(IMoleculeFragmenter aFragmenter, Map aRecentPropertiesMap){
private void setRecentProperties(IMoleculeFragmenter aFragmenter, Map<String, Object> aRecentPropertiesMap){
for (Property tmpProperty : aFragmenter.settingsProperties()) {
if(aRecentPropertiesMap.containsKey(tmpProperty.getName())){
tmpProperty.setValue(aRecentPropertiesMap.get(tmpProperty.getName()));
Expand Down
Loading
Loading