Skip to content

Commit

Permalink
Merge pull request #11 from BLCK-B/dev
Browse files Browse the repository at this point in the history
merge from dev v7.1
  • Loading branch information
BLCK-B authored Nov 25, 2023
2 parents 87adf2f + 94858e8 commit 777560b
Show file tree
Hide file tree
Showing 20 changed files with 450 additions and 238 deletions.
2 changes: 1 addition & 1 deletion MRTinstallerScript.nsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; UI settings
!include "MUI2.nsh"
!define VERSION "7"
!define VERSION "7.1"
!define MUI_ABORTWARNING
!define MUI_ICON "MRTicon.ico"
!insertmacro MUI_PAGE_LICENSE "license.txt"
Expand Down
44 changes: 26 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
plugins {
id 'java'
id 'application'
id 'org.beryx.jlink' version '2.26.0'
// https://plugins.gradle.org/plugin/org.beryx.jlink
id("org.beryx.jlink") version "3.0.1"
// https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow
id "com.github.johnrengelman.shadow" version "8.1.1"
id 'org.springframework.boot' version '3.1.2'
id 'io.spring.dependency-management' version '1.1.2'
id 'org.graalvm.buildtools.native' version '0.9.27'
// https://plugins.gradle.org/plugin/org.springframework.boot
id("org.springframework.boot") version "3.2.0"
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id("io.spring.dependency-management") version "1.1.4"
// https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#_adding_the_plugin
id 'org.graalvm.buildtools.native' version '0.9.28'
}

group 'com.blck'
version '6'
version '7.1'

repositories {
mavenCentral()
Expand Down Expand Up @@ -46,14 +51,18 @@ application {

dependencies {
// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
implementation 'org.xerial:sqlite-jdbc:3.42.0.0'
implementation 'org.xerial:sqlite-jdbc:3.44.0.0'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation 'org.jsoup:jsoup:1.16.1'
implementation 'org.jsoup:jsoup:1.16.2'
// https://mvnrepository.com/artifact/com.typesafe/config
implementation 'com.typesafe:config:1.4.2'
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
testRuntimeOnly('org.junit.platform:junit-platform-launcher:1.9.2')
implementation 'com.typesafe:config:1.4.3'

// https://mvnrepository.com/artifact/org.junit/junit-bom
testImplementation(platform("org.junit:junit-bom:5.10.1"))
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.platform:junit-platform-launcher'

implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
Expand Down Expand Up @@ -103,13 +112,7 @@ tasks.jar {
shadowJar {
exclude 'org/sqlite/native/Linux-Musl/**'
exclude 'org/sqlite/native/Linux-Android/**'
exclude 'org/sqlite/native/FreeBSD/**'
exclude 'org/sqlite/native/Mac/**'
exclude 'org/sqlite/native/Linux/aarch64/**'
exclude 'org/sqlite/native/Linux/arm/**'
exclude 'org/sqlite/native/Linux/armv6/**'
exclude 'org/sqlite/native/Linux/ppc64/**'
exclude 'org/sqlite/native/Linux/x86/**'
exclude 'org/sqlite/native/Windows/aarch64/**'
exclude 'org/sqlite/native/Windows/x86/**'
configurations = [project.configurations.runtimeClasspath, project.configurations.shadow]
Expand All @@ -118,4 +121,9 @@ shadowJar {
attributes 'Main-Class': 'com.blck.MusicReleaseTracker.Main'
}
mergeServiceFiles()
}
}

test {
useJUnitPlatform()
}

18 changes: 5 additions & 13 deletions src/main/java/com/blck/MusicReleaseTracker/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,11 @@ public void clickScrape() {
sendRequest.clickScrape();
}

@PostMapping("/toggleFilter")
public void toggleFilter(@RequestParam String filter, @RequestParam Boolean value) {
sendRequest.toggleFilter(filter, value);
}
@PostMapping("/setTheme")
public void setTheme(@RequestBody Map<String, String> themeMap) {
String theme = themeMap.get("theme");
sendRequest.setTheme(theme);
@PostMapping("/setSetting")
public void setSetting(@RequestBody Map<String, String> params) {
String name = params.get("name");
String value = params.get("value");
sendRequest.setSetting(name, value);
}
@GetMapping("/getThemeConfig")
public Map<String,String> getThemeConfig() {
Expand All @@ -121,11 +118,6 @@ public boolean checkExistURL() {
return sendRequest.checkExistURL();
}

@PostMapping("/saveScrapeDate")
public void saveScrapeDate(@RequestBody String time) {
sendRequest.saveScrapeDate(time);
}

@GetMapping("/getScrapeDate")
public String getScrapeDate() {
return sendRequest.getScrapeDate();
Expand Down
23 changes: 19 additions & 4 deletions src/main/java/com/blck/MusicReleaseTracker/DBtools.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ private static void createDB(String path) {
e.printStackTrace();
}
}
private static Map<String, ArrayList<String>> getDBStructure(String path) {
public static Map<String, ArrayList<String>> getDBStructure(String path) {
HashMap<String, ArrayList<String>> tableMap = new HashMap<String, ArrayList<String>>();
try {
Connection conn = DriverManager.getConnection(path);
Expand Down Expand Up @@ -237,13 +237,26 @@ public static void readConfig(String option) {
String scrapeDate = config.getString("lastScrape");
settingsStore.setScrapeDate(scrapeDate);
}
case ("longTimeout") -> {
boolean longTimeout = config.getBoolean("longTimeout");
settingsStore.setLongTimeout(longTimeout);
}
case("isoDates") -> {
boolean isoDates = config.getBoolean("isoDates");
settingsStore.setIsoDates(isoDates);
}
}
config = null;
}
public static void writeSingleConfig(String name, String value) {
//save single option state in HOCON
//save single string option state in HOCON
Config config = ConfigFactory.parseFile(new File(DBtools.settingsStore.getConfigPath()));
config = config.withValue(name, ConfigValueFactory.fromAnyRef(value));
ConfigValue configValue;
if (value.equals("true") || value.equals("false"))
configValue = ConfigValueFactory.fromAnyRef(Boolean.parseBoolean(value));
else
configValue = ConfigValueFactory.fromAnyRef(value);
config = config.withValue(name, configValue);
ConfigRenderOptions renderOptions = ConfigRenderOptions.defaults().setOriginComments(false).setJson(false).setFormatted(true);
try (PrintWriter writer = new PrintWriter(new FileWriter(DBtools.settingsStore.getConfigPath()))) {
writer.write(config.root().render(renderOptions));
Expand Down Expand Up @@ -272,7 +285,9 @@ public static void updateSettings() {
"}\n" +
"theme=Black\n" +
"accent=Classic\n" +
"lastScrape=-\n";
"lastScrape=-\n" +
"longTimeout=false\n" +
"isoDates=false\n";

//create template file / overwrite templateContent
File templateFile = new File(configFolder + "/MRTsettingsTemplate.hocon");
Expand Down
86 changes: 30 additions & 56 deletions src/main/java/com/blck/MusicReleaseTracker/GUIController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.blck.MusicReleaseTracker;

import com.blck.MusicReleaseTracker.ModelsEnums.TableModel;
import com.typesafe.config.*;
import org.springframework.stereotype.Service;
import java.io.File;
import java.io.FileWriter;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -62,34 +59,25 @@ public void artistAddConfirm(String input) {
pstmt.close();
lastClickedArtist = null;
} catch (SQLException e) {
throw new RuntimeException(e);
System.out.println("artist already exists");
}
}
public void artistClickDelete() {
//delete last selected artist and all entries from artist
if (lastClickedArtist != null) {
try {
Map<String, ArrayList<String>> tableMap = DBtools.getDBStructure(DBtools.settingsStore.getDBpath());
Connection conn = DriverManager.getConnection(DBtools.settingsStore.getDBpath());
String sql = "DELETE FROM artists WHERE artistname = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM musicbrainz WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM beatport WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM junodownload WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
sql = "DELETE FROM youtube WHERE artist = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
String sql;
for (String tableName : tableMap.keySet()) {
if (tableName.equals("artists"))
sql = "DELETE FROM artists WHERE artistname = ?";
else
sql = "DELETE FROM " + tableName + " WHERE artist = ?";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lastClickedArtist);
pstmt.executeUpdate();
}
conn.close();
lastClickedArtist = null;
}
Expand Down Expand Up @@ -128,7 +116,7 @@ public void deleteUrl() {
}
}
public void cleanArtistSource() {
//clear artist entries from a source table
//clear artist entries from a source table, used by scrape preview
try {
Connection conn = DriverManager.getConnection(DBtools.settingsStore.getDBpath());
String sql = "DELETE FROM " + selectedSource + " WHERE artist = ?";
Expand All @@ -143,6 +131,7 @@ public void cleanArtistSource() {
}

public List<TableModel> artistListClick(String artist) {
//when artist and source selected, load respective table
lastClickedArtist = artist;
if (selectedSource.equals("combview")) {
try {
Expand All @@ -162,6 +151,7 @@ public List<TableModel> artistListClick(String artist) {
}

public List<TableModel> sourceTabClick(String source) {
//when source and artist selected, load respective table
selectedSource = source;
if (!selectedSource.equals("combview")) {
try {
Expand Down Expand Up @@ -219,7 +209,7 @@ public void loadCombviewTable() throws SQLException {
rs.close();
}
public void fillCombview() {
MainBackend.fillCombviewTable();
MainBackend.fillCombviewTable(null);
}

public void clickAddURL(String url) {
Expand Down Expand Up @@ -362,13 +352,14 @@ public boolean checkExistURL() {
}

public void clickScrape() {
//launch scraping in backend, then fill and load table
try {
MainBackend.scrapeData();
} catch (Exception e) {
e.printStackTrace();
}
try {
MainBackend.fillCombviewTable();
MainBackend.fillCombviewTable(null);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -389,7 +380,7 @@ public void cancelScrape() {
}

public HashMap<String, Boolean> settingsOpened() {
//gather all settings states and return them to frontend
//gather all settings states and return them to frontend when settings are opened
DBtools.readConfig("filters");
HashMap<String, Boolean> configData = new HashMap<>();

Expand All @@ -401,53 +392,36 @@ public HashMap<String, Boolean> settingsOpened() {
else
configData.put(filter, false);
}
DBtools.readConfig("longTimeout");
if (DBtools.settingsStore.getTimeout() > 20000)
configData.put("longTimeout", true);
else
configData.put("longTimeout", false);
DBtools.readConfig("isoDates");
configData.put("isoDates", DBtools.settingsStore.getIsoDates());

return configData;
}

public void toggleFilter(String filter, Boolean value) {
//change config filter state
Config config = ConfigFactory.parseFile(new File(DBtools.settingsStore.getConfigPath()));
config = config.withValue("filters." + filter, ConfigValueFactory.fromAnyRef(value));
ConfigRenderOptions renderOptions = ConfigRenderOptions.defaults().setOriginComments(false).setJson(false).setFormatted(true);

try (PrintWriter writer = new PrintWriter(new FileWriter(DBtools.settingsStore.getConfigPath()))) {
writer.write(config.root().render(renderOptions));
} catch (IOException e) {
System.out.println("could not save filter change");
e.printStackTrace();
}
}
public void setTheme(String theme) {
//change config theme/accent
if (theme.equals("Black") || theme.equals("Dark") || theme.equals("Light"))
DBtools.writeSingleConfig("theme", theme);
else
DBtools.writeSingleConfig("accent", theme);
public void setSetting(String name, String value) {
//write any setting in config, note: "name" = config name
DBtools.writeSingleConfig(name, value);
}
public Map<String,String> getThemeConfig() {
DBtools.readConfig("themes");
return DBtools.settingsStore.getThemes();
}

public void saveScrapeDate(String time) {
//change config lastScrape time
DBtools.writeSingleConfig("lastScrape", time);
}
public String getScrapeDate() {
DBtools.readConfig("lastScrape");
return DBtools.settingsStore.getScrapeDate();
}

public String getLastArtist() {
return lastClickedArtist;
}

public void resetSettings() {
DBtools.resetSettings();
}
public void resetDB() {
DBtools.resetDB();
}

}
Loading

0 comments on commit 777560b

Please sign in to comment.