diff --git a/docker-compose.yaml b/docker-compose.yaml index 59d9ec3daf95e96af98607a7f23f84f9097c6b2b..c8f62f47ca07a689db789715deff0b3e17a96030 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,32 +1,11 @@ version: '3.3' services: - mysql: - image: mysql:8 - restart: always - environment: - MYSQL_ROOT_PASSWORD: ${API_ROOT} - MYSQL_DATABASE: api - MYSQL_ROOT_HOST: '%' - volumes: - - "${WORKING_DIR}/storage/mysql:/var/lib/mysql" - networks: - - netMySQL - ports: - - "3306:3306" playwall: - image: jtobisan/playwall-server:latest + image: registry.thecodelabs.de/tobisan/playwall-server:latest restart: always volumes: - - "${WORKING_DIR}/deploy_docker:/root/deploy" - "${WORKING_DIR}/download:/root/download" expose: - "8080" ports: - "8090:8080" - networks: - - netMySQL - depends_on: - - mysql -networks: - netMySQL: - driver: bridge diff --git a/pom.xml b/pom.xml index 435ebd9ac84241cb82e558e7c99d50819f78a49a..f7afa1b7ab3b591dc311b725239848119513f49b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,251 +1,43 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>de.tobias</groupId> - <artifactId>playwall-server</artifactId> - <version>1.0-SNAPSHOT</version> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <project.main>de.tobias.playpad.PlayPadServer</project.main> - <java.version>1.8</java.version> - - <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> - <scala-maven-plugin.version>3.4.4</scala-maven-plugin.version> - <maven-jar-plugin.version>2.3.1</maven-jar-plugin.version> - - <scala-library.version>[2.13.0,)</scala-library.version> - - <spark-core.version>[2.9.0,)</spark-core.version> - - <ormlite-jdbc.version>5.1</ormlite-jdbc.version> - <ormlite-core.version>5.1</ormlite-core.version> - - <junit.version>4.12</junit.version> - </properties> - - <dependencyManagement> - <dependencies> - <dependency> - <groupId>de.thecodelabs</groupId> - <artifactId>jlibs</artifactId> - <version>2.0.5</version> - <scope>import</scope> - <type>pom</type> - </dependency> - </dependencies> - </dependencyManagement> - - <dependencies> - <dependency> - <groupId>org.scala-lang</groupId> - <artifactId>scala-library</artifactId> - <version>${scala-library.version}</version> - </dependency> - - <dependency> - <groupId>io.github.classgraph</groupId> - <artifactId>classgraph</artifactId> - <version>4.8.43</version> - </dependency> - - <dependency> - <groupId>de.thecodelabs</groupId> - <artifactId>libUtils</artifactId> - </dependency> - - <dependency> - <groupId>com.sparkjava</groupId> - <artifactId>spark-core</artifactId> - <version>${spark-core.version}</version> - </dependency> - <dependency> - <groupId>de.thecodelabs</groupId> - <artifactId>libLogger-slf4j</artifactId> - </dependency> - - <dependency> - <groupId>com.j256.ormlite</groupId> - <artifactId>ormlite-core</artifactId> - <version>${ormlite-core.version}</version> - </dependency> - <dependency> - <groupId>com.j256.ormlite</groupId> - <artifactId>ormlite-jdbc</artifactId> - <version>${ormlite-jdbc.version}</version> - </dependency> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>8.0.17</version> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - <version>[2.8.5,)</version> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>${junit.version}</version> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <!-- <finalName>PlayWallServer</finalName>--> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>${maven-compiler-plugin.version}</version> - <configuration> - <source>${java.version}</source> - <target>${java.version}</target> - </configuration> - </plugin> - - <plugin> - <groupId>net.alchim31.maven</groupId> - <artifactId>scala-maven-plugin</artifactId> - <version>${scala-maven-plugin.version}</version> - <executions> - <execution> - <id>scala-compile-first</id> - <phase>process-resources</phase> - <goals> - <goal>add-source</goal> - <goal>compile</goal> - </goals> - </execution> - <execution> - <id>scala-test-compile</id> - <phase>process-test-resources</phase> - <goals> - <goal>testCompile</goal> - </goals> - </execution> - </executions> - <configuration> - <args> - <arg>-deprecation</arg> - </args> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-assembly-plugin</artifactId> - <configuration> - <outputDirectory>build/${project.version}</outputDirectory> - <finalName>${project.artifactId}</finalName> - <appendAssemblyId>false</appendAssemblyId> - <archive> - <manifest> - <mainClass>${project.main}</mainClass> - </manifest> - </archive> - <descriptorRefs> - <descriptorRef>jar-with-dependencies</descriptorRef> - </descriptorRefs> - </configuration> - <executions> - <execution> - <id>make-assembly</id> <!-- this is used for inheritance merges --> - <phase>package</phase> <!-- bind to the packaging phase --> - <goals> - <goal>single</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <distributionManagement> - <repository> - <id>release</id> - <name>TheCodeLabs-releases</name> - <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-release</url> - </repository> - <snapshotRepository> - <id>snapshots</id> - <name>TheCodeLabs-snapshots</name> - <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-snapshots</url> - </snapshotRepository> - </distributionManagement> - - <pluginRepositories> - <pluginRepository> - <id>scala</id> - <name>Scala Tools</name> - <url>http://scala-tools.org/repo-releases/</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </pluginRepository> - <pluginRepository> - <id>release</id> - <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-plugins-release</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </pluginRepository> - <pluginRepository> - <id>snapshots</id> - <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-plugins-snapshots</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </pluginRepository> - </pluginRepositories> - - - <repositories> - <repository> - <id>scala</id> - <name>Scala Tools</name> - <url>http://scala-tools.org/repo-releases/</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - - <repository> - <id>release</id> - <url>https://maven.thecodelabs.de/artifactory/Releases</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>false</enabled> - </snapshots> - </repository> - <repository> - <id>snapshots</id> - <url>https://maven.thecodelabs.de/artifactory/TheCodeLabs-snapshots</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> -</project> \ No newline at end of file +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-parent</artifactId> + <version>3.1.5</version> + </parent> + <groupId>de.tobias</groupId> + <artifactId>playwall-server</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>playwall-server</name> + <description>PlayWall Server</description> + <properties> + <java.version>17</java.version> + </properties> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.graalvm.buildtools</groupId> + <artifactId>native-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> +</project> diff --git a/src/main/java/de/tobias/playpad/server/project/sync/SyncListener.java b/src/main/java/de/tobias/playpad/server/project/sync/SyncListener.java deleted file mode 100644 index f08a8ad41313e1a4f2a805a2807b04d10c3e5856..0000000000000000000000000000000000000000 --- a/src/main/java/de/tobias/playpad/server/project/sync/SyncListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.tobias.playpad.server.project.sync; - -public @interface SyncListener { - String value(); -} diff --git a/src/main/java/de/tobias/playpad/utils/json/JsonCollection.java b/src/main/java/de/tobias/playpad/utils/json/JsonCollection.java deleted file mode 100644 index 28370c8f3a8978f4c3501811b08d20ba01e789d9..0000000000000000000000000000000000000000 --- a/src/main/java/de/tobias/playpad/utils/json/JsonCollection.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.tobias.playpad.utils.json; - -import java.lang.annotation.*; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface JsonCollection -{ - - /** - * Name of the field for the json. - * - * @return name - */ - String value(); - - Class type(); -} diff --git a/src/main/java/de/tobias/playpad/utils/json/JsonName.java b/src/main/java/de/tobias/playpad/utils/json/JsonName.java deleted file mode 100644 index 368a53dae633ef822a381994aea3844fb99c12a2..0000000000000000000000000000000000000000 --- a/src/main/java/de/tobias/playpad/utils/json/JsonName.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.tobias.playpad.utils.json; - -import java.lang.annotation.*; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface JsonName -{ - - /** - * Name of the field for the json. - * - * @return name - */ - String value(); - - Class<? extends SerializerHandler> handler() default StringSerializerHandler.class; -} diff --git a/src/main/java/de/tobias/playpad/utils/json/JsonObj.java b/src/main/java/de/tobias/playpad/utils/json/JsonObj.java deleted file mode 100644 index 32e10fbef4f0637de8610d389cf4104e149be4e5..0000000000000000000000000000000000000000 --- a/src/main/java/de/tobias/playpad/utils/json/JsonObj.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.tobias.playpad.utils.json; - -import java.lang.annotation.*; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface JsonObj -{ - - /** - * Name of the field for the json. - * - * @return name - */ - String value(); - -} diff --git a/src/main/java/de/tobias/playpad/utils/json/JsonParent.java b/src/main/java/de/tobias/playpad/utils/json/JsonParent.java deleted file mode 100644 index ae62d2453c48eb06e1dbbcb1c5217504a77b6f69..0000000000000000000000000000000000000000 --- a/src/main/java/de/tobias/playpad/utils/json/JsonParent.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.tobias.playpad.utils.json; - -import java.lang.annotation.*; - -@Target(ElementType.FIELD) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface JsonParent -{ -} diff --git a/src/main/java/de/tobias/playwall/PlaywallServerApplication.java b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..dbdf3b8f5caf4c7a12215ed45ffe200e9473d619 --- /dev/null +++ b/src/main/java/de/tobias/playwall/PlaywallServerApplication.java @@ -0,0 +1,15 @@ +package de.tobias.playwall; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PlaywallServerApplication +{ + + public static void main(String[] args) + { + SpringApplication.run(PlaywallServerApplication.class, args); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml deleted file mode 100644 index d592fee4394c346c3c78ecf42cd008e54f43e920..0000000000000000000000000000000000000000 --- a/src/main/resources/config/application.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: "PlayWallServer" -version: "1.0.0" -build: 1 -identifier: "de.tobias.playpad-server" -date: "2019-07-24" - -main: "de.tobias.playpad.server.PlayPadServer" -author: "Tobias Ullerich" - -basePath: "PlayWall" \ No newline at end of file diff --git a/src/main/resources/config/libLogger.yml b/src/main/resources/config/libLogger.yml deleted file mode 100644 index 90d50b09a449a7c0afda6c28508ac4ae48c8bed6..0000000000000000000000000000000000000000 --- a/src/main/resources/config/libLogger.yml +++ /dev/null @@ -1,20 +0,0 @@ -color: - enable: true - info: "GREEN" - warn: "YELLOW" - error: "RED" - time: "BLUE" - detail: "CYAN" - message: "RESET" - -dateFormatterPattern: "dd.MM.YY HH:mm:ss" - -defaultOutLevel: "DEBUG" -defaultErrLevel: "ERROR" - -showShortPackageName: true -showClassName: true -showMethodName: true -showLineNumber: true - -ignoreStandardStream: false diff --git a/src/main/resources/messages.json b/src/main/resources/messages.json deleted file mode 100644 index 43c4f86714cfae2c05a023e0c6ec1c2eb260d821..0000000000000000000000000000000000000000 --- a/src/main/resources/messages.json +++ /dev/null @@ -1,31 +0,0 @@ -Simple Property { - class name - object id - - field name - field value - field type - - operation = update -} - -Collection Add { - class name parent - class name child - - object id parent - object id child - - data [ - field name - field value - field type - ] - - operation add -} - -Collection Remove { - class name child - object id child -} \ No newline at end of file diff --git a/src/main/resources/protocol.txt b/src/main/resources/protocol.txt deleted file mode 100644 index 6bdea08cf9b123ac72fdb2443dfaf32226020ccf..0000000000000000000000000000000000000000 --- a/src/main/resources/protocol.txt +++ /dev/null @@ -1,23 +0,0 @@ -=================================== -Project Add: -=================================== -{ - id - name -} - -=================================== -Project Update: -=================================== -{ - id - field (name) - value -} - -=================================== -Project Remove: -=================================== -{ - id -} \ No newline at end of file diff --git a/src/main/scala/de/tobias/playpad/PlayPadServer.scala b/src/main/scala/de/tobias/playpad/PlayPadServer.scala deleted file mode 100644 index 9ad6938fa8ccb7e3a8886ffde6f39b35e972185f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/PlayPadServer.scala +++ /dev/null @@ -1,126 +0,0 @@ -package de.tobias.playpad - -import java.nio.file.{Files, Path, Paths} -import java.sql.{Connection, DriverManager} - -import com.j256.ormlite.dao.{Dao, DaoManager} -import com.j256.ormlite.jdbc.JdbcConnectionSource -import com.j256.ormlite.table.TableUtils -import de.thecodelabs.logger.{FileOutputOption, LogLevelFilter, Logger, Slf4JLoggerAdapter} -import de.thecodelabs.utils.application.ApplicationUtils -import de.thecodelabs.utils.application.container.PathType -import de.tobias.playpad.model.account.{Account, Session} -import de.tobias.playpad.model.plugin.Plugin -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.account._ -import de.tobias.playpad.server.plugin.{PluginGet, PluginList, PluginRawGet} -import de.tobias.playpad.server.project.sync.ProjectSyncHandler -import de.tobias.playpad.server.project.{ProjectDelete, ProjectGet, ProjectList, ProjectPost} -import de.tobias.playpad.transformer.JsonTransformer -import de.tobias.playpad.utils.settings.{Settings, SettingsHandler, SettingsLoader} -import de.tobias.playpad.utils.sql.SqlBackgroundRunner -import spark.Spark._ - -/** - * Created by tobias on 29.01.17. - */ -object PlayPadServer extends App { - - private var settingsLoader: SettingsLoader = _ - private var settingsPath: Path = _ - private var settings: Settings = _ - - private var databaseUrl: String = _ - private var connectionSource: JdbcConnectionSource = _ - private var databaseConnection: Connection = _ - private var databaseBackgroundThread: Thread = _ - - try { - val app = ApplicationUtils.registerMainApplication(getClass) - ApplicationUtils.addAppListener(_ => { - Logger.init(app.getPath(PathType.LOG)) - Slf4JLoggerAdapter.disableSlf4jDebugPrints() - Logger.setLevelFilter(LogLevelFilter.DEBUG) - Logger.setFileOutput(FileOutputOption.COMBINED) - }) - app.start(args) - - // Load Config - settingsLoader = SettingsHandler.loader - settingsPath = Paths.get("deploy/settings.properties") - - if (Files.notExists(settingsPath)) { - SettingsHandler.saver.default(settingsPath) - } - - settings = settingsLoader.load(settingsPath) - - databaseUrl = s"jdbc:mysql://${settings.db_host}:${settings.db_port}/${settings.db_database}?" + - s"autoReconnect=true&wait_timeout=86400&serverTimezone=Europe/Berlin" - connectionSource = new JdbcConnectionSource(databaseUrl) - connectionSource.setUsername(settings.db_username) - connectionSource.setPassword(settings.db_password) - - databaseConnection = DriverManager.getConnection(databaseUrl, settings.db_username, settings.db_password) - - val pluginDao: Dao[Plugin, Int] = DaoManager.createDao(connectionSource, classOf[Plugin]) - val accountDao: Dao[Account, Int] = DaoManager.createDao(connectionSource, classOf[Account]) - val sessionDao: Dao[Session, Int] = DaoManager.createDao(connectionSource, classOf[Session]) - - // Management Tables - TableUtils.createTableIfNotExists(connectionSource, classOf[Plugin]) - TableUtils.createTableIfNotExists(connectionSource, classOf[Account]) - TableUtils.createTableIfNotExists(connectionSource, classOf[Session]) - SqlHelper.createTables(databaseConnection) - - val runner = new SqlBackgroundRunner(databaseConnection) - databaseBackgroundThread = new Thread(runner) - databaseBackgroundThread.start() - - - // Setup Http Server - port(settings.server_port) - threadPool(8, 2, 60 * 60 * 1000) - - if (settings.server_secure) { - secure(settings.server_keystore_path, settings.server_keystore_password, null, null) - } - - // PlayWall Cloud - webSocket("/project", new ProjectSyncHandler(sessionDao, databaseConnection)) - - // Project - val transformer = new JsonTransformer - - get("/projects/:id", new ProjectGet(databaseConnection, sessionDao), transformer) - get("/projects", new ProjectList(databaseConnection, sessionDao), transformer) - post("/projects", new ProjectPost(databaseConnection, sessionDao), transformer) - delete("/projects", new ProjectDelete(databaseConnection, sessionDao), transformer) - - // Plugins - get("/plugins/:id", new PluginGet(pluginDao), transformer) - get("/plugins/raw/:id", new PluginRawGet(pluginDao, settings)) - get("/plugins", new PluginList(pluginDao), transformer) - - // Account - post("/accounts", new AccountPost(accountDao), transformer) - put("/accounts", new AccountPut(accountDao), transformer) - - post("/sessions", new SessionPost(accountDao), transformer) - delete("/sessions", new SessionDelete(accountDao), transformer) - get("/sessions", new SessionGet(accountDao), transformer) - - SettingsHandler.saver.save(settings, settingsPath) - - Runtime.getRuntime.addShutdownHook(new Thread(() => { - databaseBackgroundThread.interrupt() - - databaseConnection.close() - connectionSource.close() - - stop() - })) - } catch { - case e: Exception => e.printStackTrace() - } -} diff --git a/src/main/scala/de/tobias/playpad/model/account/Account.scala b/src/main/scala/de/tobias/playpad/model/account/Account.scala deleted file mode 100644 index c0a3a55de5e23521a8e5bf01650dec8a9a7b24c5..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/account/Account.scala +++ /dev/null @@ -1,51 +0,0 @@ -package de.tobias.playpad.model.account - -import com.j256.ormlite.dao.{Dao, ForeignCollection} -import com.j256.ormlite.field.{DatabaseField, ForeignCollectionField} -import com.j256.ormlite.table.DatabaseTable - -/** - * Created by tobias on 15.02.17. - */ -@DatabaseTable(tableName = "Account") class Account() { - - @DatabaseField(generatedId = true) val id: Int = 0 - @DatabaseField(unique = true) var username: String = _ // Mail Address - @DatabaseField var password: String = _ - @ForeignCollectionField var sessions: ForeignCollection[Session] = _ - - def this(username: String, password: String) { - this() - this.username = username - this.password = password - } - - def getId: Int = id - - def canEqual(other: Any): Boolean = other.isInstanceOf[Account] - - override def equals(other: Any): Boolean = other match { - case that: Account => - (that canEqual this) && - id == that.id - case _ => false - } - - override def hashCode(): Int = { - val state = Seq(id) - state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b) - } - -} - -object Account { - def getAccount(username: String, accountDao: Dao[Account, Int]): Option[Account] = { - val accountList = accountDao.queryForEq("username", username) - if (accountList.size() == 1) { - return Some(accountList.get(0)) - } - None - } -} - - diff --git a/src/main/scala/de/tobias/playpad/model/account/Session.scala b/src/main/scala/de/tobias/playpad/model/account/Session.scala deleted file mode 100644 index f812e5170337b5282fea82724d87afe10f74b857..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/account/Session.scala +++ /dev/null @@ -1,63 +0,0 @@ -package de.tobias.playpad.model.account - -import java.sql.Date - -import com.j256.ormlite.dao.Dao -import com.j256.ormlite.field.DatabaseField -import com.j256.ormlite.table.DatabaseTable - -import scala.util.Random - -/** - * Created by tobias on 15.02.17. - */ -@DatabaseTable(tableName = "Session") class Session() { - - @DatabaseField(generatedId = true) private val id: Int = 0 - @DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true) private var account: Account = _ - @DatabaseField var key: String = _ - @DatabaseField var createDate: Date = _ - - def this(account: Account, key: String) { - this() - this.account = account - this.key = key - this.createDate = new Date(System.currentTimeMillis) - } - - def getId: Int = id - - def getAccount: Account = account - - - def canEqual(other: Any): Boolean = other.isInstanceOf[Session] - - override def equals(other: Any): Boolean = other match { - case that: Session => - (that canEqual this) && - id == that.id && - key == that.key - case _ => false - } - - override def hashCode(): Int = { - val state = Seq(id, key) - state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b) - } -} - -object Session { - private val length = 100 - - val alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - - def generateKey(): String = (1 to length).map(_ => alpha(Random.nextInt.abs % alpha.length())).mkString - - def getSession(sessionKey: String, sessionDao: Dao[Session, Int]): Option[Session] = { - val sessionList = sessionDao.queryForEq("key", sessionKey) - if (sessionList.size() == 1) { - return Some(sessionList.get(0)) - } - None - } -} diff --git a/src/main/scala/de/tobias/playpad/model/plugin/Plugin.scala b/src/main/scala/de/tobias/playpad/model/plugin/Plugin.scala deleted file mode 100644 index b1b477b8bf48eec2002260b663a18237a18620bc..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/plugin/Plugin.scala +++ /dev/null @@ -1,31 +0,0 @@ -package de.tobias.playpad.model.plugin - -import com.j256.ormlite.field.DatabaseField -import com.j256.ormlite.table.DatabaseTable - -/** - * Created by tobias on 31.01.17. - */ -@DatabaseTable(tableName = "Plugin") class Plugin() { - @DatabaseField(generatedId = true) private val id: Int = 0 - @DatabaseField var name: String = _ - @DatabaseField var displayName: String = _ - @DatabaseField var description: String = _ - @DatabaseField var version: String = _ - @DatabaseField var build: Int = _ - @DatabaseField var icon: String = _ - @DatabaseField var category: String = _ - - def this(name: String, displayName: String, description: String, version: String, build: Int, icon: String, category: String) { - this() - this.name = name - this.displayName = displayName - this.description = description - this.version = version - this.build = build - this.icon = icon - this.category = category - } - - def getId: Int = id -} \ No newline at end of file diff --git a/src/main/scala/de/tobias/playpad/model/project/Design.scala b/src/main/scala/de/tobias/playpad/model/project/Design.scala deleted file mode 100644 index 1e521eb9a8279134a1f9ce001405c2ca32a83d3c..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/Design.scala +++ /dev/null @@ -1,21 +0,0 @@ -package de.tobias.playpad.model.project - -import java.util.UUID - -import de.tobias.playpad.utils.json.{JsonName, JsonParent, UUIDSerializerHandler} - -/** - * Created by tobias on 23.02.17. - */ -class Design { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - @JsonName("background_color") - var backgroundColor: String = _ - @JsonName("play_color") - var playColor: String = _ - - @JsonParent - var pad: Pad = _ -} diff --git a/src/main/scala/de/tobias/playpad/model/project/Pad.scala b/src/main/scala/de/tobias/playpad/model/project/Pad.scala deleted file mode 100644 index 7308410551895a8582c8ee336a89c978bcff753e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/Pad.scala +++ /dev/null @@ -1,34 +0,0 @@ -package de.tobias.playpad.model.project - -import java.util.UUID - -import de.tobias.playpad.model.project.settings.PadSettings -import de.tobias.playpad.utils.json._ - -/** - * Created by tobias on 17.02.17. - */ -class Pad() { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - - @JsonName("name") - var name: String = _ - @JsonName(value = "position", handler = classOf[IntSerializerHandler]) - var position: Int = _ - - @JsonName("contentType") - var contentType: String = _ - @JsonCollection(value = "paths", `type` = classOf[Path]) - var paths: List[Path] = List() - - @JsonObj("settings") - var padSettings: PadSettings = _ - - @JsonParent - var page: Page = _ - - - override def toString = s"Pad($id, $name, $position, $contentType, $paths, $padSettings, $page)" -} diff --git a/src/main/scala/de/tobias/playpad/model/project/Page.scala b/src/main/scala/de/tobias/playpad/model/project/Page.scala deleted file mode 100644 index 5d98784a2fbcaeeaac03a88c99d58059295858b3..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/Page.scala +++ /dev/null @@ -1,25 +0,0 @@ -package de.tobias.playpad.model.project - -import java.util.UUID - -import de.tobias.playpad.utils.json._ - -/** - * Created by tobias on 17.02.17. - */ -class Page { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - @JsonName("name") - var name: String = _ - - @JsonName(value = "position", handler = classOf[IntSerializerHandler]) - var position: Int = _ - - @JsonCollection(value = "pads", `type` = classOf[Pad]) - var pads: List[Pad] = List() - - @JsonParent - var project: Project = _ // FOREIGN KEY -} diff --git a/src/main/scala/de/tobias/playpad/model/project/Path.scala b/src/main/scala/de/tobias/playpad/model/project/Path.scala deleted file mode 100644 index 3ea785f3746e0ac9e8fbefdf5abda3cbfcf98c5e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/Path.scala +++ /dev/null @@ -1,19 +0,0 @@ -package de.tobias.playpad.model.project - -import java.util.UUID - -import de.tobias.playpad.utils.json.{JsonName, JsonParent, UUIDSerializerHandler} - -/** - * Created by tobias on 20.02.17. - */ -class Path { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - @JsonName("filename") - var filename: String = _ - - @JsonParent - var pad: Pad = _ -} diff --git a/src/main/scala/de/tobias/playpad/model/project/Project.scala b/src/main/scala/de/tobias/playpad/model/project/Project.scala deleted file mode 100644 index 91d9573e6fbed9b37a5ab9c63db6f5288b4e972e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/Project.scala +++ /dev/null @@ -1,24 +0,0 @@ -package de.tobias.playpad.model.project - -import java.util.UUID - -import de.tobias.playpad.utils.json.{JsonCollection, JsonName, UUIDSerializerHandler} - -/** - * Created by tobias on 17.02.17. - */ -class Project { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - @JsonName("name") - var name: String = _ - - var accountId: Int = _ // Account that own this project - var lastModified: Long = _ - var session: String = _ - - @JsonCollection(value = "pages", `type` = classOf[Page]) - var pages: List[Page] = List() - -} diff --git a/src/main/scala/de/tobias/playpad/model/project/settings/Fade.scala b/src/main/scala/de/tobias/playpad/model/project/settings/Fade.scala deleted file mode 100644 index a1ca1fe5dd086038cd2c6f19494c528b722a9b8e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/settings/Fade.scala +++ /dev/null @@ -1,29 +0,0 @@ -package de.tobias.playpad.model.project.settings - -import java.time.Duration -import java.util.UUID - -import de.tobias.playpad.utils.json._ - -class Fade { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - - @JsonName(value = "fadeIn", handler = classOf[DurationSerializerHandler]) - var fadeIn: Duration = _ - @JsonName(value = "fadeOut", handler = classOf[DurationSerializerHandler]) - var fadeOut: Duration = _ - - @JsonName(value = "fadeInStart", handler = classOf[BooleanSerializerHandler]) - var fadeInStart: Boolean = _ - @JsonName(value = "fadeInPause", handler = classOf[BooleanSerializerHandler]) - var fadeInPause: Boolean = _ - @JsonName(value = "fadeOutPause", handler = classOf[BooleanSerializerHandler]) - var fadeOutPause: Boolean = _ - @JsonName(value = "fadeOutStop", handler = classOf[BooleanSerializerHandler]) - var fadeOutStop: Boolean = _ - - @JsonParent - var padSettings: PadSettings = _ -} \ No newline at end of file diff --git a/src/main/scala/de/tobias/playpad/model/project/settings/PadSettings.scala b/src/main/scala/de/tobias/playpad/model/project/settings/PadSettings.scala deleted file mode 100644 index f645c562f4bb5f51b124e09ca790a46ed4b8797f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/model/project/settings/PadSettings.scala +++ /dev/null @@ -1,32 +0,0 @@ -package de.tobias.playpad.model.project.settings - -import java.time.Duration -import java.util.UUID - -import de.tobias.playpad.model.project.{Design, Pad} -import de.tobias.playpad.utils.json._ - -class PadSettings { - - @JsonName(value = "id", handler = classOf[UUIDSerializerHandler]) - var id: UUID = UUID.randomUUID() - - @JsonName(value = "volume", handler = classOf[DoubleSerializerHandler]) - var volume: Double = _ - @JsonName(value = "loop", handler = classOf[BooleanSerializerHandler]) - var loop: Boolean = _ - - @JsonName("timeMode") - var timeMode: String = _ // In PlayWallDesktop ENUM - - @JsonObj("fade") - var fade: Fade = _ - @JsonName(value = "warning", handler = classOf[DurationSerializerHandler]) - var warning: Duration = _ - - @JsonObj("design") - var design: Design = _ - - @JsonParent - var pad: Pad = _ -} diff --git a/src/main/scala/de/tobias/playpad/server/Result.scala b/src/main/scala/de/tobias/playpad/server/Result.scala deleted file mode 100644 index cdf9de7beb921c249c2c66a5cf8026597d018bd5..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/Result.scala +++ /dev/null @@ -1,16 +0,0 @@ -package de.tobias.playpad.server - -/** - * Created by tobias on 16.02.17. - */ -class Result { - - var status: String = _ - var message: String = _ - - def this(status: Status.Value, message: String = "") { - this() - this.status = status.toString - this.message = message - } -} diff --git a/src/main/scala/de/tobias/playpad/server/SqlHelper.scala b/src/main/scala/de/tobias/playpad/server/SqlHelper.scala deleted file mode 100644 index 366f568915fc331607f286f34006ac78f115e002..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/SqlHelper.scala +++ /dev/null @@ -1,166 +0,0 @@ -package de.tobias.playpad.server - -import java.sql.Types.NULL -import java.sql.{Connection, PreparedStatement} -import java.util.UUID - -/** - * Created by tobias on 17.02.17. - */ -object SqlHelper { - - def insertOrUpdate[T](connection: Connection, table: String, idValue: Int, field: String, value: T): Unit = { - val preparedStatement = createQuery(connection, table, field, value) - preparedStatement.setInt(1, idValue) - preparedStatement.execute() - preparedStatement.close() - } - - def insertOrUpdate[T](connection: Connection, table: String, idValue: UUID, field: String, value: T): Unit = { - val preparedStatement = createQuery(connection, table, field, value) - preparedStatement.setString(1, idValue.toString) - preparedStatement.execute() - preparedStatement.close() - } - - private def createQuery[T](connection: Connection, table: String, field: String, value: T): PreparedStatement = { - val sql = s"INSERT INTO $table (id, $field) VALUES(?, ?) ON DUPLICATE KEY UPDATE $field=?" - val preparedStatement = connection.prepareStatement(sql) - - value match { - case value: String => - preparedStatement.setString(2, value) - preparedStatement.setString(3, value) - case value: Boolean => - val v = if (value) { - 1 - } else { - 0 - } - preparedStatement.setInt(2, v) - preparedStatement.setInt(3, v) - case value: Int => - preparedStatement.setInt(2, value) - preparedStatement.setInt(3, value) - case value: Long => - preparedStatement.setLong(2, value) - preparedStatement.setLong(3, value) - case value: Double => - preparedStatement.setDouble(2, value) - preparedStatement.setDouble(3, value) - case value: UUID => - preparedStatement.setString(2, value.toString) - preparedStatement.setString(3, value.toString) - case null => - preparedStatement.setNull(2, NULL) - preparedStatement.setNull(3, NULL) - - } - preparedStatement - } - - def delete(connection: Connection, table: String, id: Int): Unit = { - val sql = s"DELETE FROM $table WHERE id = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setInt(1, id) - preparedStatement.execute() - preparedStatement.close() - } - - def delete(connection: Connection, table: String, uuid: UUID): Unit = { - val sql = s"DELETE FROM $table WHERE id = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, uuid.toString) - preparedStatement.execute() - preparedStatement.close() - } - - def createTables(connection: Connection): Unit = { - def createTable(sql: String): Unit = { - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.execute() - preparedStatement.close() - } - - createTable( - """CREATE TABLE IF NOT EXISTS `Project` ( - | `id` varchar(48) NOT NULL DEFAULT '', - | `name` varchar(255) DEFAULT NULL, - | `account_id` int(11) DEFAULT NULL, - | `last_modified` bigint(11) DEFAULT NULL, - | `session_key` varchar(255) DEFAULT NULL, - | PRIMARY KEY (`id`), - | UNIQUE KEY `id` (`id`) - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - createTable( - """CREATE TABLE IF NOT EXISTS `Page` ( - | `id` varchar(48) NOT NULL DEFAULT '', - | `name` varchar(255) DEFAULT NULL, - | `position` int(11) DEFAULT NULL, - | `project_id` varchar(48) DEFAULT NULL, - | PRIMARY KEY (`id`), - | UNIQUE KEY `id` (`id`), - | KEY `project_id` (`project_id`), - | CONSTRAINT `Page_ibfk_1` FOREIGN KEY (`project_id`) REFERENCES `Project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - - createTable( - """CREATE TABLE IF NOT EXISTS `Pad` ( - | `id` varchar(48) NOT NULL DEFAULT '', - | `name` varchar(255) DEFAULT NULL, - | `position` int(11) DEFAULT NULL, - | `content_type` varchar(100) DEFAULT NULL, - | `page_id` varchar(48) DEFAULT NULL, - | PRIMARY KEY (`id`), - | UNIQUE KEY `id` (`id`), - | KEY `Pad_ibfk_1` (`page_id`), - | CONSTRAINT `Pad_ibfk_1` FOREIGN KEY (`page_id`) REFERENCES `Page` (`id`) ON DELETE CASCADE ON UPDATE CASCADE - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - createTable( - """CREATE TABLE IF NOT EXISTS `Path` ( - | `id` varchar(40) NOT NULL DEFAULT '', - | `filename` text, - | `pad_id` varchar(40) DEFAULT NULL, - | PRIMARY KEY (`id`), - | KEY `pad_id` (`pad_id`), - | CONSTRAINT `Path_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - - createTable( - """CREATE TABLE IF NOT EXISTS `PadSettings` ( - | `id` varchar(48) NOT NULL DEFAULT '', - | `volume` double DEFAULT NULL, - | `loop` tinyint(1) DEFAULT NULL, - | `timeMode` varchar(20) DEFAULT NULL, - | `warning` int(11) DEFAULT NULL, - | `pad_id` varchar(48) DEFAULT NULL, - | PRIMARY KEY (`id`), - | KEY `pad_id` (`pad_id`), - | CONSTRAINT `PadSettings_ibfk_1` FOREIGN KEY (`pad_id`) REFERENCES `Pad` (`id`) ON DELETE CASCADE ON UPDATE CASCADE - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - createTable( - """CREATE TABLE IF NOT EXISTS `Design` ( - | `id` varchar(40) NOT NULL DEFAULT '', - | `background_color` varchar(20) DEFAULT NULL, - | `play_color` varchar(20) DEFAULT NULL, - | `settings_id` varchar(48) DEFAULT NULL, - | PRIMARY KEY (`id`), - | KEY `settings_id` (`settings_id`), - | CONSTRAINT `Design_ibfk_1` FOREIGN KEY (`settings_id`) REFERENCES `PadSettings` (`id`) ON DELETE CASCADE ON UPDATE CASCADE - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - createTable( - """CREATE TABLE IF NOT EXISTS `Fade` ( - | `id` varchar(48) NOT NULL DEFAULT '', - | `fadeIn` int(11) DEFAULT NULL, - | `fadeOut` int(11) DEFAULT NULL, - | `fadeInStart` tinyint(1) DEFAULT NULL, - | `fadeInPause` tinyint(1) DEFAULT NULL, - | `fadeOutPause` tinyint(1) DEFAULT NULL, - | `fadeOutStop` tinyint(1) DEFAULT NULL, - | `padSettings_id` varchar(48) DEFAULT NULL, - | PRIMARY KEY (`id`), - | KEY `padSettings_id` (`padSettings_id`), - | CONSTRAINT `Fade_ibfk_1` FOREIGN KEY (`padSettings_id`) REFERENCES `PadSettings` (`id`) - |) ENGINE=InnoDB DEFAULT CHARSET=latin1;""".stripMargin) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/Status.scala b/src/main/scala/de/tobias/playpad/server/Status.scala deleted file mode 100644 index 53e4c04fddb55b2cd193c6230b664564e442e2bd..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/Status.scala +++ /dev/null @@ -1,8 +0,0 @@ -package de.tobias.playpad.server - -/** - * Created by tobias on 16.02.17. - */ -object Status extends Enumeration { - val OK, ERROR = Value -} diff --git a/src/main/scala/de/tobias/playpad/server/account/AccountPost.scala b/src/main/scala/de/tobias/playpad/server/account/AccountPost.scala deleted file mode 100644 index ce2f66144e64e613dee35347c9ae2a210b0eb500..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/account/AccountPost.scala +++ /dev/null @@ -1,29 +0,0 @@ -package de.tobias.playpad.server.account - -import java.sql.SQLException - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Account -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 15.02.17. - */ -class AccountPost(accountDao: Dao[Account, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val username = request.queryMap().get("username").value - val password = request.queryMap().get("password").value - - val account = new Account(username, password) - try { - accountDao.create(account) - } catch { - case e: SQLException => return new Result(Status.ERROR) - } - - new Result(Status.OK, "created") - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/account/AccountPut.scala b/src/main/scala/de/tobias/playpad/server/account/AccountPut.scala deleted file mode 100644 index e6be26d699eef8d07bc74017ad3bac2ccd96f9f0..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/account/AccountPut.scala +++ /dev/null @@ -1,41 +0,0 @@ -package de.tobias.playpad.server.account - -import java.sql.SQLException - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Account -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 15.02.17. - */ -class AccountPut(accountDao: Dao[Account, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - try { - print(request.queryParams()) - val username = request.queryMap().get("username").value - val oldPassword = request.queryMap().get("old_password").value - val newPassword = request.queryMap().get("new_password").value - - val account = Account.getAccount(username, accountDao) - account match { - case Some(a) => - if (a.password.equals(oldPassword)) { - a.password = newPassword - accountDao.update(a) - return new Result(Status.OK) - } - new Result(Status.ERROR, "Password invalid") - case None => - new Result(Status.ERROR, "Account invalid") - } - } catch { - case e: SQLException => return new Result(Status.ERROR) - } - - new Result(Status.ERROR) - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/account/SessionDelete.scala b/src/main/scala/de/tobias/playpad/server/account/SessionDelete.scala deleted file mode 100644 index c569de782867cdb1d393c6e239316bba5298e82d..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/account/SessionDelete.scala +++ /dev/null @@ -1,34 +0,0 @@ -package de.tobias.playpad.server.account - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Account -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 15.02.17. - */ -class SessionDelete(accountDao: Dao[Account, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val username = request.queryParams("username") - val password = request.queryParams("password") - val key = request.queryParams("key") - - val account = Account.getAccount(username, accountDao) - - account match { - case Some(a) => - if (a.password.equals(password)) { - a.sessions.removeIf(s => s.key.equals(key)) - accountDao.update(a) - return new Result(Status.OK, "deleted") - } - new Result(Status.ERROR, "Password invalid") - case None => - new Result(Status.ERROR, "Account invalid") - - } - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/account/SessionGet.scala b/src/main/scala/de/tobias/playpad/server/account/SessionGet.scala deleted file mode 100644 index 12d73f53ca2fa720df25a741010ea83bb014f184..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/account/SessionGet.scala +++ /dev/null @@ -1,37 +0,0 @@ -package de.tobias.playpad.server.account - -import com.google.gson.{JsonArray, JsonObject} -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Account -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 15.02.17. - */ -class SessionGet(accountDao: Dao[Account, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val username = request.queryParams("username") - val password = request.queryParams("password") - - val account = Account.getAccount(username, accountDao) - - account match { - case Some(a) => - if (a.password.equals(password)) { - val array = new JsonArray - a.sessions.forEach(session => { - val jsonObj = new JsonObject - jsonObj.addProperty("key", session.key) - jsonObj.addProperty("createDate", session.createDate.getTime) - array.add(jsonObj) - }) - return array - } - new Result(Status.ERROR, "Password invalid") - case None => - new Result(Status.ERROR, "Account invalid") - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/account/SessionPost.scala b/src/main/scala/de/tobias/playpad/server/account/SessionPost.scala deleted file mode 100644 index 8e9e0a39b9d9d298e762ce172840decacf15183f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/account/SessionPost.scala +++ /dev/null @@ -1,47 +0,0 @@ -package de.tobias.playpad.server.account - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.{Account, Session} -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 15.02.17. - */ -class SessionPost(accountDao: Dao[Account, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val username = request.queryParams("username") - val password = request.queryParams("password") - - val account = Account.getAccount(username, accountDao) - - account match { - case Some(a) => - if (a.password.equals(password)) { - - val randomKey = Session.generateKey() - val session = new Session(a, randomKey) - - a.sessions.add(session) - accountDao.update(a) - return new SessionPostResult(Status.OK, randomKey) - } - new Result(Status.ERROR, "Password invalid") - case None => - new Result(Status.ERROR, "Account invalid") - } - } - - private class SessionPostResult extends Result { - var key: String = _ - - def this(status: Status.Value, key: String, message: String = "") { - this() - this.status = status.toString - this.message = message - this.key = key - } - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/plugin/PluginGet.scala b/src/main/scala/de/tobias/playpad/server/plugin/PluginGet.scala deleted file mode 100644 index 5772d2da6bb79ce32eb3167ff79f0f2593b97c15..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/plugin/PluginGet.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.plugin - -import com.google.gson.Gson -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.plugin.Plugin -import de.tobias.playpad.server.{Result, Status} -import spark.{Request, Response, Route} - -/** - * Created by tobias on 05.02.17. - */ -class PluginGet(dao: Dao[Plugin, Int]) extends Route { - - val gson = new Gson() - - override def handle(request: Request, response: Response): AnyRef = { - val plugin = dao.queryForId(request.params(":id").toInt) - if (plugin == null) { - return new Result(Status.ERROR, "Bad request") - } - plugin - } -} diff --git a/src/main/scala/de/tobias/playpad/server/plugin/PluginList.scala b/src/main/scala/de/tobias/playpad/server/plugin/PluginList.scala deleted file mode 100644 index a071fc3b779ffcc29621a7576c9d9b72349e0422..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/plugin/PluginList.scala +++ /dev/null @@ -1,19 +0,0 @@ -package de.tobias.playpad.server.plugin - -import com.google.gson.Gson -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.plugin.Plugin -import spark.{Request, Response, Route} - -/** - * Created by tobias on 05.02.17. - */ -class PluginList(val dao: Dao[Plugin, Int]) extends Route { - - val gson = new Gson() - - override def handle(request: Request, response: Response): AnyRef = { - val plugins = dao.queryForAll() - plugins - } -} diff --git a/src/main/scala/de/tobias/playpad/server/plugin/PluginRawGet.scala b/src/main/scala/de/tobias/playpad/server/plugin/PluginRawGet.scala deleted file mode 100644 index 209bddcd41cb3b109977a53b9ad164743c22a785..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/plugin/PluginRawGet.scala +++ /dev/null @@ -1,24 +0,0 @@ -package de.tobias.playpad.server.plugin - -import java.net.URL - -import com.j256.ormlite.dao.Dao -import de.thecodelabs.utils.io.IOUtils -import de.tobias.playpad.model.plugin.Plugin -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.utils.settings.Settings -import spark.{Request, Response, Route} - -/** - * Created by tobias on 05.02.17. - */ -class PluginRawGet(dao: Dao[Plugin, Int], settings: Settings) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val plugin = dao.queryForId(request.params(":id").toInt) - if (plugin == null) { - return new Result(Status.ERROR, "Bad request") - } - IOUtils.urlToByteArray(new URL(s"${settings.plugin_source}/${plugin.name}/${plugin.version}/${plugin.name}-${plugin.version}.jar")) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/ProjectDelete.scala b/src/main/scala/de/tobias/playpad/server/project/ProjectDelete.scala deleted file mode 100644 index e7ad292802e348e1b016725b527dce0c6dc726e5..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/ProjectDelete.scala +++ /dev/null @@ -1,38 +0,0 @@ -package de.tobias.playpad.server.project - -import java.sql.Connection -import java.util.UUID - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.sql.loader.ProjectLoader -import de.tobias.playpad.sql.saver.ProjectSaver -import spark.{Request, Response, Route} - -/** - * Created by tobias on 17.02.17. - */ -class ProjectDelete(connection: Connection, sessionDao: Dao[Session, Int]) extends Route { - override def handle(request: Request, response: Response): AnyRef = { - val sessionKey = request.queryParams("session") - val session = Session.getSession(sessionKey, sessionDao) - session match { - case Some(s) => - val projectId = UUID.fromString(request.queryParams("project")) - - val projectLoader = new ProjectLoader(connection) - val account_id = projectLoader.getAccountId(projectId) - - if (account_id == s.getAccount.id) { - val projectSaver = new ProjectSaver(connection) - projectSaver.delete(projectId) - - return new Result(Status.OK, "added project") - } - new Result(Status.ERROR, "session mismatch") - case None => - new Result(Status.ERROR, "session invalid") - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/ProjectGet.scala b/src/main/scala/de/tobias/playpad/server/project/ProjectGet.scala deleted file mode 100644 index f61efee8fc1d94333c57c0c40974251a583e9e0e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/ProjectGet.scala +++ /dev/null @@ -1,41 +0,0 @@ -package de.tobias.playpad.server.project - -import java.sql.Connection -import java.util.UUID - -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.sql.loader.ProjectLoader -import de.tobias.playpad.utils.json.JsonSerializer -import spark.{Request, Response, Route} - -/** - * Created by tobias on 17.02.17. - */ -class ProjectGet(connection: Connection, sessionDao: Dao[Session, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val sessionKey = request.queryParams("session") - val projectId = request.params(":id") - - val session = Session.getSession(sessionKey, sessionDao) - - session match { - case Some(s) => - val projectLoader = new ProjectLoader(connection) - val projects = projectLoader.load(UUID.fromString(projectId)) - - if (projects.size == 1) { - val project = projects.head - if (project.accountId == s.getAccount.id) { - return new JsonSerializer().serialize(project) - } - } - new Result(Status.ERROR, "Project invalid") - case None => - new Result(Status.ERROR, "Session invalid") - } - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/project/ProjectList.scala b/src/main/scala/de/tobias/playpad/server/project/ProjectList.scala deleted file mode 100644 index bbc89a1c5a236554ab5b09af50d7ac6353a49a08..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/ProjectList.scala +++ /dev/null @@ -1,41 +0,0 @@ -package de.tobias.playpad.server.project - -import java.sql.Connection - -import com.google.gson.{JsonArray, JsonObject} -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.sql.loader.ProjectLoader -import spark.{Request, Response, Route} - -/** - * Created by tobias on 17.02.17. - */ -class ProjectList(connection: Connection, sessionDao: Dao[Session, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val sessionKey = request.queryParams("session") - - val session = Session.getSession(sessionKey, sessionDao) - - session match { - case Some(s) => - val projectLoader = new ProjectLoader(connection) - val projects = projectLoader.list(s.getAccount.id) - - val array = new JsonArray() - projects.foreach(project => { - val json = new JsonObject() - json.addProperty("uuid", project.id.toString) - json.addProperty("name", project.name) - array.add(json) - }) - - array - case None => - new Result(Status.ERROR, "Session invalid") - } - } - -} diff --git a/src/main/scala/de/tobias/playpad/server/project/ProjectModificationGet.scala b/src/main/scala/de/tobias/playpad/server/project/ProjectModificationGet.scala deleted file mode 100644 index 112570b819b41eb660513ed0c0d8c7ca4076291f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/ProjectModificationGet.scala +++ /dev/null @@ -1,42 +0,0 @@ -package de.tobias.playpad.server.project - -import java.sql.Connection - -import com.google.gson.{JsonArray, JsonObject} -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.sql.loader.ProjectLoader -import spark.{Request, Response, Route} - -/** - * Created by tobias on 01.03.17. - */ -class ProjectModificationGet(connection: Connection, sessionDao: Dao[Session, Int]) extends Route { - - override def handle(request: Request, response: Response): AnyRef = { - val sessionKey = request.queryParams("session") - - val session = Session.getSession(sessionKey, sessionDao) - - session match { - case Some(s) => - val projectLoader = new ProjectLoader(connection) - val projects = projectLoader.list(s.getAccount.id) - - val array = new JsonArray() - projects.foreach(projectReference => { - val json = new JsonObject() - json.addProperty("uuid", projectReference.id.toString) - json.addProperty("name", projectReference.name) - json.addProperty("last_modification", projectReference.lastModified) - json.addProperty("session", projectReference.session) - array.add(json) - }) - - array - case None => - new Result(Status.ERROR, "Session invalid") - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/ProjectPost.scala b/src/main/scala/de/tobias/playpad/server/project/ProjectPost.scala deleted file mode 100644 index 2c82068f8276d95032b0e8dbf508f5b735a8b571..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/ProjectPost.scala +++ /dev/null @@ -1,39 +0,0 @@ -package de.tobias.playpad.server.project - -import java.sql.Connection - -import com.google.gson.JsonParser -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.model.project.Project -import de.tobias.playpad.server.{Result, Status} -import de.tobias.playpad.sql.saver.ProjectSaver -import de.tobias.playpad.utils.json.JsonSerializer -import spark.{Request, Response, Route} - -/** - * Created by tobias on 17.02.17. - */ -class ProjectPost(connection: Connection, sessionDao: Dao[Session, Int]) extends Route { - override def handle(request: Request, response: Response): AnyRef = { - val sessionKey = request.queryParams("session") - val session = Session.getSession(sessionKey, sessionDao) - session match { - case Some(s) => - val projectParam = request.body() - - val json = new JsonParser().parse(projectParam).getAsJsonObject - - val project = new JsonSerializer().deserialize(json, classOf[Project]) - - project.accountId = s.getAccount.id - - val projectSaver = new ProjectSaver(connection) - projectSaver.save(project) - - new Result(Status.OK, "added project") - case None => - new Result(Status.ERROR, "session error") - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/ProjectSyncHandler.scala b/src/main/scala/de/tobias/playpad/server/project/sync/ProjectSyncHandler.scala deleted file mode 100644 index f808c7e6a23f838a8fe86c24d2f7700e1b9b686c..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/ProjectSyncHandler.scala +++ /dev/null @@ -1,126 +0,0 @@ -package de.tobias.playpad.server.project.sync - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.{JsonObject, JsonParser} -import com.j256.ormlite.dao.Dao -import de.tobias.playpad.model.account -import de.tobias.playpad.model.account.Account -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef -import io.github.classgraph.ClassGraph -import org.eclipse.jetty.websocket.api.Session -import org.eclipse.jetty.websocket.api.annotations.{OnWebSocketClose, OnWebSocketConnect, OnWebSocketMessage, WebSocket} - -import scala.collection.{Map, mutable} -import scala.jdk.CollectionConverters._ - -/** - * Created by tobias on 19.02.17. - */ -@WebSocket -class ProjectSyncHandler(sessionDao: Dao[account.Session, Int], connection: Connection) { - - val SESSION_KEY_HEADER = "key" - - private var sessions: Map[Account, mutable.HashSet[Session]] = new mutable.HashMap[Account, mutable.HashSet[Session]]() - - private val listeners = { - val packageName = "de.tobias.playpad.server.server.project.sync.listener" - val scanResult = new ClassGraph() - .enableAllInfo() - .whitelistPackages(packageName) - .scan() - - val annotationName = "de.tobias.playpad.server.server.project.sync.SyncListener" - scanResult.getClassesWithAnnotation(annotationName) - .asScala - .map(annotation => { - val info = annotation.getAnnotationInfo(annotationName) - val value = info.getParameterValues.getValue("value") - val instance = annotation.loadClass().newInstance().asInstanceOf[Listener] - value -> instance - }).toMap - } - - @OnWebSocketConnect - def onConnect(serverSession: Session): Unit = { - val key = serverSession.getUpgradeRequest.getHeader(SESSION_KEY_HEADER) - if (key == null) { - serverSession.close(500, "Invalid Key") - } - - val session = account.Session.getSession(key, sessionDao) - session match { - case Some(s) => - if (!this.sessions.contains(s.getAccount)) { - this.sessions += (s.getAccount -> new mutable.HashSet[Session]()) - } - this.sessions(s.getAccount) += serverSession - case None => serverSession.disconnect() - } - } - - @OnWebSocketClose - def onClose(serverSession: Session, status: Int, reason: String): Unit = { - val key = serverSession.getUpgradeRequest.getHeader(SESSION_KEY_HEADER) - if (key == null) { - serverSession.close(500, "Invalid Key") - } - - val session = account.Session.getSession(key, sessionDao) - session match { - case Some(s) => this.sessions(s.getAccount) -= serverSession - case None => serverSession.close(500, "Invalid Key") - } - } - - @OnWebSocketMessage - def onMessage(serverSession: Session, text: String): Unit = { - println(text) - // Store in Database - try { - val key = serverSession.getUpgradeRequest.getHeader(SESSION_KEY_HEADER) - val session = account.Session.getSession(key, sessionDao) - - if (key != null) { - val parser = new JsonParser() - val json = parser.parse(text) - json match { - case json: JsonObject => - session match { - case Some(s) => - // Write last modification to project table - val timeStamp = json.get("time").getAsLong - val projectRef = UUID.fromString(json.get("project").getAsString) - SqlHelper.insertOrUpdate(connection, SqlDef.PROJECT, projectRef, SqlDef.PROJECT_LAST_MODIFIED, timeStamp) - SqlHelper.insertOrUpdate(connection, SqlDef.PROJECT, projectRef, SqlDef.PROJECT_SESSION_KEY, s.key) - - val cmd = json.get("cmd").getAsString - if (listeners.contains(cmd)) { - listeners(cmd).onChange(json, connection, s) - } - - case None => serverSession.close(500, "Invalid Session") - } - case _ => serverSession.close(500, "Invalid Data") - } - } else { - serverSession.close(500, "Invalid Key") - } - - // Push to clients - session match { - case Some(s) => - this.sessions(s.getAccount) - .filter(s => s != serverSession) - .foreach(s => s.getRemote.sendStringByFuture(text)) - case None => serverSession.close(500, "Invalid Key") - } - } catch { - case e: Exception => e.printStackTrace() - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/Listener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/Listener.scala deleted file mode 100644 index 700907abacabac765c22a693d72bc087b1ff3d12..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/Listener.scala +++ /dev/null @@ -1,14 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener - -import java.sql.Connection - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session - -/** - * Created by tobias on 18.02.17. - */ -trait Listener { - - def onChange(json: JsonObject, connection: Connection, session: Session): Unit -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignAddListener.scala deleted file mode 100644 index a8bf32733c129af094a8e9da471477ba635452e7..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignAddListener.scala +++ /dev/null @@ -1,28 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.design - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("design-add") -class DesignAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val designId = UUID.fromString(json.get("id").getAsString) - val padSettingsId = UUID.fromString(json.get("pad_settings").getAsString) - val backgroundColor = json.get("background_color").getAsString - val playColor = json.get("play_color").getAsString - - SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_PAD_REF, padSettingsId) - SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_BACKGROUND_COLOR, backgroundColor) - SqlHelper.insertOrUpdate(connection, SqlDef.DESIGN, designId, SqlDef.DESIGN_PLAY_COLOR, playColor) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignUpdateListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignUpdateListener.scala deleted file mode 100644 index 6e212aa00e7f23541cd12cdeaf6ea6fcecf7eb6f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/design/DesignUpdateListener.scala +++ /dev/null @@ -1,30 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.design - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("design-update") -class DesignUpdateListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val designId = UUID.fromString(json.get("id").getAsString) - val padSettingsId = UUID.fromString(json.get("pad_settings").getAsString) - val field = json.get("field").getAsString - - SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PAD_REF, padSettingsId) - - field match { - case "background_color" => SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_BACKGROUND_COLOR, json.get("value").getAsString) - case "play_color" => SqlHelper.insertOrUpdate(connection, DESIGN, designId, DESIGN_PLAY_COLOR, json.get("value").getAsString) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadAddListener.scala deleted file mode 100644 index 4e4d9e8b32c0d562e859cf1c7f1507c6d6902963..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadAddListener.scala +++ /dev/null @@ -1,33 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pad-add") -class PadAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val padId = UUID.fromString(json.get("id").getAsString) - val pageId = UUID.fromString(json.get("page").getAsString) - val padName = json.get("name").getAsString - val padPosition = json.get("position").getAsInt - - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padId, SqlDef.PAD_PAGE_REF, pageId) - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padId, SqlDef.PAD_NAME, padName) - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padId, SqlDef.PAD_POSITION, padPosition) - - if (!json.get("contentType").isJsonNull) { - val contentType = json.get("contentType").getAsString - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padId, SqlDef.PAD_CONTENT_TYPE, contentType) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadClearListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadClearListener.scala deleted file mode 100644 index 7e3eb0b20a399c248958f18f68348b98231c8211..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadClearListener.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pad-clear") -class PadClearListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - - SqlHelper.delete(connection, SqlDef.PAGE, pageId) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadRemoveListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadRemoveListener.scala deleted file mode 100644 index 6710aef2343b49cfc464ca5f299356fd80828f9e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadRemoveListener.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pad-rm") -class PadRemoveListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - - SqlHelper.delete(connection, SqlDef.PAD, pageId) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadUpdateListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadUpdateListener.scala deleted file mode 100644 index 9e949555ed51dd34e0851076beddca88c7eddb1e..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/PadUpdateListener.scala +++ /dev/null @@ -1,35 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pad-update") -class PadUpdateListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val padID = UUID.fromString(json.get("id").getAsString) - val pageId = UUID.fromString(json.get("page").getAsString) - val field = json.get("field").getAsString - - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padID, SqlDef.PAD_PAGE_REF, pageId) - - field match { - case "name" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padID, SqlDef.PAD_NAME, json.get("value").getAsString) - case "position" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padID, SqlDef.PAD_POSITION, json.get("value").getAsInt) - case "contentType" => if (!json.get("value").isJsonNull) { - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padID, SqlDef.PAD_CONTENT_TYPE, json.get("value").getAsString) - } else { - SqlHelper.insertOrUpdate(connection, SqlDef.PAD, padID, SqlDef.PAD_CONTENT_TYPE, null) - } - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsAddListener.scala deleted file mode 100644 index 6b0b29c73292fd79222c325660836bb27b26c8d6..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsAddListener.scala +++ /dev/null @@ -1,35 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad.settings - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -@SyncListener("pad-settings-add") -class PadSettingsAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val padSettingsId = UUID.fromString(json.get("id").getAsString) - val padId = UUID.fromString(json.get("pad_id").getAsString) - val volume = json.get("volume").getAsDouble - val loop = json.get("loop").getAsBoolean - - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_PAD_REF, padId) - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_VOLUME, volume) - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_LOOP, loop) - - if (json.get("time_mode") != null) { - val timeMode = json.get("time_mode").getAsString - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_TIME_MODE, timeMode) - } - - if (json.get("warning") != null) { - val warning = json.get("warning").getAsInt - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, padSettingsId, SqlDef.PAD_SETTINGS_WARNING, warning) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsUpdateListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsUpdateListener.scala deleted file mode 100644 index 159c8fbdff40fb52fee28cd01dd3455c5544eada..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/pad/settings/PadSettingsUpdateListener.scala +++ /dev/null @@ -1,41 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.pad.settings - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -@SyncListener("pad-settings-update") -class PadSettingsUpdateListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val settingsId = UUID.fromString(json.get("id").getAsString) - val padId = UUID.fromString(json.get("pad_id").getAsString) - val field = json.get("field").getAsString - - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_PAD_REF, padId) - - field match { - case "volume" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_VOLUME, json.get("value").getAsDouble) - case "loop" => SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_LOOP, json.get("value").getAsBoolean) - case "time_mode" => - val value = if (!json.get("value").isJsonNull) { - json.get("value").getAsString - } else { - null - } - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_TIME_MODE, value) - case "warning" => - val value = if (!json.get("value").isJsonNull) { - json.get("value").getAsInt - } else { - null - } - SqlHelper.insertOrUpdate(connection, SqlDef.PAD_SETTINGS, settingsId, SqlDef.PAD_SETTINGS_WARNING, value) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageAddListener.scala deleted file mode 100644 index 6788aef48a8dd302af8371045639b1d57cedfa09..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageAddListener.scala +++ /dev/null @@ -1,28 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.page - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("page-add") -class PageAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - val projectId = UUID.fromString(json.get("project").getAsString) - val pageName = json.get("name").getAsString - val pagePosition = json.get("position").getAsInt - - SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_PROJECT_REF, projectId) - SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_NAME, pageName) - SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_POSITION, pagePosition) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageRemoveListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageRemoveListener.scala deleted file mode 100644 index ac7512fe67599001de0bced5b6ab577aac4b6c1f..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageRemoveListener.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.page - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("page-rm") -class PageRemoveListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - - SqlHelper.delete(connection, SqlDef.PAGE, pageId) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageUpdateListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageUpdateListener.scala deleted file mode 100644 index 26dba32e66af5693bb9f18818a526f6f1b8573fc..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/page/PageUpdateListener.scala +++ /dev/null @@ -1,30 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.page - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("page-update") -class PageUpdateListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - val projectId = UUID.fromString(json.get("project").getAsString) - val field = json.get("field").getAsString - - SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_PROJECT_REF, projectId) - - field match { - case "name" => SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_NAME, json.get("value").getAsString) - case "position" => SqlHelper.insertOrUpdate(connection, SqlDef.PAGE, pageId, SqlDef.PAGE_POSITION, json.get("value").getAsInt) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathAddListener.scala deleted file mode 100644 index 1b14ce5cd84826886077c98c6cd6b34eb1429e90..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathAddListener.scala +++ /dev/null @@ -1,29 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.path - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("path-add") -class PathAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pathId = UUID.fromString(json.get("id").getAsString) - val padId = UUID.fromString(json.get("pad").getAsString) - - SqlHelper.insertOrUpdate(connection, SqlDef.PATH, pathId, SqlDef.PATH_PAD_REF, padId) - - if (json.get("filename") != null) { - val path = json.get("filename").getAsString - SqlHelper.insertOrUpdate(connection, SqlDef.PATH, pathId, SqlDef.PATH_NAME, path) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathRemoveListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathRemoveListener.scala deleted file mode 100644 index 43b91df0cb98bdb94dd9a70bc6c4b1a2075c4457..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/path/PathRemoveListener.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.path - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("path-rm") -class PathRemoveListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val pageId = UUID.fromString(json.get("id").getAsString) - - SqlHelper.delete(connection, SqlDef.PATH, pageId) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectAddListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectAddListener.scala deleted file mode 100644 index 900217b138113ecf0cf02ef3574fe9570b42778b..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectAddListener.scala +++ /dev/null @@ -1,25 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.project - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pro-add") -class ProjectAddListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val projectId = UUID.fromString(json.get("id").getAsString) - val projectName = json.get("name").getAsString - - SqlHelper.insertOrUpdate(connection, SqlDef.PROJECT, projectId, SqlDef.PROJECT_NAME, projectName) - SqlHelper.insertOrUpdate(connection, SqlDef.PROJECT, projectId, SqlDef.PROJECT_ACCOUNT_ID, session.getAccount.id) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectRemoveListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectRemoveListener.scala deleted file mode 100644 index 72cf2baa55b8b598aa54f2a42186ee6409ccfa85..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectRemoveListener.scala +++ /dev/null @@ -1,23 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.project - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pro-rm") -class ProjectRemoveListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val projectId = UUID.fromString(json.get("id").getAsString) - - SqlHelper.delete(connection, SqlDef.PROJECT, projectId) - } -} diff --git a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectUpdateListener.scala b/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectUpdateListener.scala deleted file mode 100644 index bbb7bbbc04a7da3c890bc43b6a525d162ae18c96..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/server/project/sync/listener/project/ProjectUpdateListener.scala +++ /dev/null @@ -1,26 +0,0 @@ -package de.tobias.playpad.server.project.sync.listener.project - -import java.sql.Connection -import java.util.UUID - -import com.google.gson.JsonObject -import de.tobias.playpad.model.account.Session -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.server.project.sync.SyncListener -import de.tobias.playpad.server.project.sync.listener.Listener -import de.tobias.playpad.sql.SqlDef - -/** - * Created by tobias on 19.02.17. - */ -@SyncListener("pro-update") -class ProjectUpdateListener extends Listener { - override def onChange(json: JsonObject, connection: Connection, session: Session): Unit = { - val projectId = UUID.fromString(json.get("id").getAsString) - val field = json.get("field").getAsString - - field match { - case "name" => SqlHelper.insertOrUpdate(connection, SqlDef.PROJECT, projectId, SqlDef.PROJECT_NAME, json.get("value").getAsString) - } - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/SqlDef.scala b/src/main/scala/de/tobias/playpad/sql/SqlDef.scala deleted file mode 100644 index a0fe5d4ac41a991be94513afa732d41c40d544ee..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/SqlDef.scala +++ /dev/null @@ -1,45 +0,0 @@ -package de.tobias.playpad.sql - -/** - * Created by tobias on 17.02.17. - */ -object SqlDef { - - val PROJECT = "Project" - val PROJECT_ID = "id" - val PROJECT_NAME = "name" - val PROJECT_ACCOUNT_ID = "account_id" - val PROJECT_LAST_MODIFIED = "last_modified" - val PROJECT_SESSION_KEY = "session_key" - - val PAGE = "Page" - val PAGE_ID = "id" - val PAGE_NAME = "name" - val PAGE_POSITION = "position" - val PAGE_PROJECT_REF = "project_id" - - val PAD = "Pad" - val PAD_ID = "id" - val PAD_NAME = "name" - val PAD_POSITION = "position" - val PAD_CONTENT_TYPE = "content_type" - val PAD_PAGE_REF = "page_id" - - val PATH = "Path" - val PATH_ID = "id" - val PATH_NAME = "filename" - val PATH_PAD_REF = "pad_id" - - val DESIGN = "Design" - val DESIGN_ID = "id" - val DESIGN_PAD_REF = "settings_id" - val DESIGN_BACKGROUND_COLOR = "background_color" - val DESIGN_PLAY_COLOR = "play_color" - - val PAD_SETTINGS = "PadSettings" - val PAD_SETTINGS_PAD_REF = "pad_id" - val PAD_SETTINGS_VOLUME = "volume" - val PAD_SETTINGS_LOOP = "looping" - val PAD_SETTINGS_TIME_MODE = "timemode" - val PAD_SETTINGS_WARNING = "warning" -} diff --git a/src/main/scala/de/tobias/playpad/sql/loader/DesignLoader.scala b/src/main/scala/de/tobias/playpad/sql/loader/DesignLoader.scala deleted file mode 100644 index f8ed41d5643e549e655061aa08f897176f03b986..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/loader/DesignLoader.scala +++ /dev/null @@ -1,34 +0,0 @@ -package de.tobias.playpad.sql.loader - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.{Design, Pad} -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 23.02.17. - */ -class DesignLoader(val connection: Connection) { - def load(pad: Pad): Design = { - val sql = s"SELECT * FROM $DESIGN WHERE $DESIGN_PAD_REF = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, pad.id.toString) - val result = preparedStatement.executeQuery() - - while (result.next()) { - val design = new Design - design.id = UUID.fromString(result.getString(DESIGN_ID)) - design.backgroundColor = result.getString(DESIGN_BACKGROUND_COLOR) - design.playColor = result.getString(DESIGN_PLAY_COLOR) - design.pad = pad - - result.close() - preparedStatement.close() - - return design - } - - null - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/loader/PadLoader.scala b/src/main/scala/de/tobias/playpad/sql/loader/PadLoader.scala deleted file mode 100644 index 9f41024f1b4f87184e0671e13122d634653c5a21..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/loader/PadLoader.scala +++ /dev/null @@ -1,43 +0,0 @@ -package de.tobias.playpad.sql.loader - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.{Pad, Page} -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class PadLoader(val connection: Connection) { - def load(page: Page): List[Pad] = { - val sql = s"SELECT * FROM $PAD WHERE $PAD_PAGE_REF = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, page.id.toString) - val result = preparedStatement.executeQuery() - - var pads: List[Pad] = List() - - while (result.next()) { - val pad = new Pad() - pad.id = UUID.fromString(result.getString(PAD_ID)) - pad.name = result.getString(PAD_NAME) - pad.position = result.getInt(PAD_POSITION) - pad.contentType = result.getString(PAD_CONTENT_TYPE) - - val pathLoader = new PathLoader(connection) - pad.paths = pathLoader.load(pad) - - val designLoader = new DesignLoader(connection) - // pad.design = designLoader.load(pad) TODO - - pad.page = page - pads = pad :: pads - } - - result.close() - preparedStatement.close() - - pads - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/loader/PageLoader.scala b/src/main/scala/de/tobias/playpad/sql/loader/PageLoader.scala deleted file mode 100644 index c7444ca6b9e623735dda999c89cac0237ddab3ee..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/loader/PageLoader.scala +++ /dev/null @@ -1,38 +0,0 @@ -package de.tobias.playpad.sql.loader - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.{Page, Project} -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class PageLoader(val connection: Connection) { - def load(project: Project): List[Page] = { - val sql = s"SELECT * FROM $PAGE WHERE $PAGE_PROJECT_REF = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, project.id.toString) - val result = preparedStatement.executeQuery() - - var pages: List[Page] = List() - - while (result.next()) { - val page = new Page() - page.id = UUID.fromString(result.getString(PAGE_ID)) - page.name = result.getString(PAGE_NAME) - - val padLoader = new PadLoader(connection) - page.pads = padLoader.load(page) - - page.project = project - pages = page :: pages - } - - result.close() - preparedStatement.close() - - pages - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/loader/PathLoader.scala b/src/main/scala/de/tobias/playpad/sql/loader/PathLoader.scala deleted file mode 100644 index 2f2a926a3f3840189b9d7ba7b2b5090043016835..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/loader/PathLoader.scala +++ /dev/null @@ -1,35 +0,0 @@ -package de.tobias.playpad.sql.loader - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.{Pad, Path} -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 20.02.17. - */ -class PathLoader(val connection: Connection) { - def load(pad: Pad): List[Path] = { - val sql = s"SELECT * FROM $PATH WHERE $PATH_PAD_REF = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, pad.id.toString) - val result = preparedStatement.executeQuery() - - var paths: List[Path] = List() - - while (result.next()) { - val path = new Path() - path.id = UUID.fromString(result.getString(PATH_ID)) - path.filename = result.getString(PATH_NAME) - - path.pad = pad - paths = path :: paths - } - - result.close() - preparedStatement.close() - - paths - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/loader/ProjectLoader.scala b/src/main/scala/de/tobias/playpad/sql/loader/ProjectLoader.scala deleted file mode 100644 index f64fa0b698f61c2f0121f38d96942af156ca6c81..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/loader/ProjectLoader.scala +++ /dev/null @@ -1,88 +0,0 @@ -package de.tobias.playpad.sql.loader - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.Project -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class ProjectLoader(val connection: Connection) { - def load(id: UUID): List[Project] = { - val sql = s"SELECT * FROM $PROJECT WHERE $PROJECT_ID = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, id.toString) - val result = preparedStatement.executeQuery() - - var projects: List[Project] = List() - - while (result.next()) { - val project = new Project() - project.id = UUID.fromString(result.getString(PROJECT_ID)) - project.name = result.getString(PROJECT_NAME) - project.accountId = result.getInt(PROJECT_ACCOUNT_ID) - project.lastModified = result.getLong(PROJECT_LAST_MODIFIED) - project.session = result.getString(PROJECT_SESSION_KEY) - - val pageLoader = new PageLoader(connection) - project.pages = pageLoader.load(project) - - projects = project :: projects - } - - result.close() - preparedStatement.close() - - projects - } - - def list(accountId: Int): List[Project] = { - val sql = s"SELECT * FROM $PROJECT WHERE $PROJECT_ACCOUNT_ID = ?" - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setInt(1, accountId) - val result = preparedStatement.executeQuery() - - var projects: List[Project] = List() - - while (result.next()) { - val project = new Project() - - project.id = UUID.fromString(result.getString(PROJECT_ID)) - project.name = result.getString(PROJECT_NAME) - project.accountId = result.getInt(PROJECT_ACCOUNT_ID) - project.lastModified = result.getLong(PROJECT_LAST_MODIFIED) - project.session = result.getString(PROJECT_SESSION_KEY) - - projects = project :: projects - } - - result.close() - preparedStatement.close() - - projects - } - - def getAccountId(id: UUID): Int = { - val sql = s"SELECT account_id FROM $PROJECT WHERE $PROJECT_ID = ?" - - val preparedStatement = connection.prepareStatement(sql) - preparedStatement.setString(1, id.toString) - val result = preparedStatement.executeQuery() - - while (result.next()) { - val account_id = result.getInt(PROJECT_ACCOUNT_ID) - - result.close() - preparedStatement.close() - - return account_id - } - - result.close() - preparedStatement.close() - - -1 - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/saver/DesignSaver.scala b/src/main/scala/de/tobias/playpad/sql/saver/DesignSaver.scala deleted file mode 100644 index 9eb0593d521f3b6c282036e1465810fefd5c6f46..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/saver/DesignSaver.scala +++ /dev/null @@ -1,18 +0,0 @@ -package de.tobias.playpad.sql.saver - -import java.sql.Connection - -import de.tobias.playpad.model.project.Design -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 23.02.17. - */ -class DesignSaver(val connection: Connection) { - def save(design: Design): Unit = { - SqlHelper.insertOrUpdate(connection, DESIGN, design.id, DESIGN_BACKGROUND_COLOR, design.backgroundColor) - SqlHelper.insertOrUpdate(connection, DESIGN, design.id, DESIGN_PLAY_COLOR, design.playColor) - SqlHelper.insertOrUpdate(connection, DESIGN, design.id, DESIGN_PAD_REF, design.pad.id) - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/saver/PadSaver.scala b/src/main/scala/de/tobias/playpad/sql/saver/PadSaver.scala deleted file mode 100644 index 78461a3fa0ddbef01fdc81bdb14d90bada848f16..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/saver/PadSaver.scala +++ /dev/null @@ -1,27 +0,0 @@ -package de.tobias.playpad.sql.saver - -import java.sql.Connection - -import de.tobias.playpad.model.project.Pad -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class PadSaver(val connection: Connection) { - def save(pad: Pad): Unit = { - SqlHelper.insertOrUpdate(connection, PAD, pad.id, PAD_NAME, pad.name) - SqlHelper.insertOrUpdate(connection, PAD, pad.id, PAD_POSITION, pad.position) - SqlHelper.insertOrUpdate(connection, PAD, pad.id, PAD_CONTENT_TYPE, pad.contentType) - SqlHelper.insertOrUpdate(connection, PAD, pad.id, PAD_PAGE_REF, pad.page.id) - - val pathSaver = new PathSaver(connection) - pad.paths.foreach(pathSaver.save) - - // if (pad.design != null) { - // val designSaver = new DesignSaver(connection) - // designSaver.save(pad.design) - // } TODO - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/saver/PageSaver.scala b/src/main/scala/de/tobias/playpad/sql/saver/PageSaver.scala deleted file mode 100644 index 1b963a697414e575a22411d55243139001181c2b..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/saver/PageSaver.scala +++ /dev/null @@ -1,21 +0,0 @@ -package de.tobias.playpad.sql.saver - -import java.sql.Connection - -import de.tobias.playpad.model.project.Page -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class PageSaver(connection: Connection) { - def save(page: Page): Unit = { - SqlHelper.insertOrUpdate(connection, PAGE, page.id, PAGE_NAME, page.name) - SqlHelper.insertOrUpdate(connection, PAGE, page.id, PAGE_POSITION, page.position) - SqlHelper.insertOrUpdate(connection, PAGE, page.id, PAGE_PROJECT_REF, page.project.id) - - val padSaver = new PadSaver(connection) - page.pads.foreach(padSaver.save) - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/saver/PathSaver.scala b/src/main/scala/de/tobias/playpad/sql/saver/PathSaver.scala deleted file mode 100644 index ef4192a7dfa6014abc7977156f1a569f15e27d21..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/saver/PathSaver.scala +++ /dev/null @@ -1,18 +0,0 @@ -package de.tobias.playpad.sql.saver - -import java.sql.Connection - -import de.tobias.playpad.model.project.Path -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 20.02.17. - */ -class PathSaver(val connection: Connection) { - def save(path: Path): Unit = { - SqlHelper.insertOrUpdate(connection, PATH, path.id, PATH_PAD_REF, path.pad.id) - SqlHelper.insertOrUpdate(connection, PATH, path.id, PATH_NAME, path.filename) - - } -} diff --git a/src/main/scala/de/tobias/playpad/sql/saver/ProjectSaver.scala b/src/main/scala/de/tobias/playpad/sql/saver/ProjectSaver.scala deleted file mode 100644 index 351d807ac40d93045faf411e12654d4c5a46b4c9..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/sql/saver/ProjectSaver.scala +++ /dev/null @@ -1,25 +0,0 @@ -package de.tobias.playpad.sql.saver - -import java.sql.Connection -import java.util.UUID - -import de.tobias.playpad.model.project.Project -import de.tobias.playpad.server.SqlHelper -import de.tobias.playpad.sql.SqlDef._ - -/** - * Created by tobias on 17.02.17. - */ -class ProjectSaver(val connection: Connection) { - def save(project: Project): Unit = { - SqlHelper.insertOrUpdate(connection, PROJECT, project.id, PROJECT_NAME, project.name) - SqlHelper.insertOrUpdate(connection, PROJECT, project.id, PROJECT_ACCOUNT_ID, project.accountId) - - val pageSaver = new PageSaver(connection) - project.pages.foreach(pageSaver.save) - } - - def delete(project: UUID): Unit = { - SqlHelper.delete(connection, PROJECT, project) - } -} diff --git a/src/main/scala/de/tobias/playpad/transformer/JsonTransformer.scala b/src/main/scala/de/tobias/playpad/transformer/JsonTransformer.scala deleted file mode 100644 index 2563e092311551c139892cd5015ca9ae3f686406..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/transformer/JsonTransformer.scala +++ /dev/null @@ -1,20 +0,0 @@ -package de.tobias.playpad.transformer - -import com.google.gson.{Gson, JsonObject} -import spark.ResponseTransformer - -/** - * Created by tobias on 05.02.17. - */ -class JsonTransformer extends ResponseTransformer { - - val gson = new Gson() - - override def render(o: scala.Any): String = { - if (!o.isInstanceOf[JsonObject]) { - gson.toJson(o) - } else { - o.toString - } - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/BooleanSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/BooleanSerializerHandler.scala deleted file mode 100644 index da4625a68a16ca05c6acd8489c1eddb9f6b0aa21..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/BooleanSerializerHandler.scala +++ /dev/null @@ -1,15 +0,0 @@ -package de.tobias.playpad.utils.json - -import com.google.gson.{JsonElement, JsonPrimitive} - -class BooleanSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case bool: Boolean => new JsonPrimitive(bool) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): Boolean = jsonElement match { - case jsonPrimitive: JsonPrimitive => jsonPrimitive.getAsBoolean - case _ => false - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/DoubleSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/DoubleSerializerHandler.scala deleted file mode 100644 index d2a12c0c4762f5f38e68938e535609857240f6d9..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/DoubleSerializerHandler.scala +++ /dev/null @@ -1,15 +0,0 @@ -package de.tobias.playpad.utils.json - -import com.google.gson.{JsonElement, JsonPrimitive} - -class DoubleSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case number: Number => new JsonPrimitive(number) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): Double = jsonElement match { - case jsonPrimitive: JsonPrimitive => jsonPrimitive.getAsDouble - case _ => 0 - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/DurationSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/DurationSerializerHandler.scala deleted file mode 100644 index b840a3eccec581cc600e5c9dc45579e3d42f60e4..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/DurationSerializerHandler.scala +++ /dev/null @@ -1,17 +0,0 @@ -package de.tobias.playpad.utils.json - -import java.time.Duration - -import com.google.gson.{JsonElement, JsonPrimitive} - -class DurationSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case duration: Duration => new JsonPrimitive(duration.toMillis) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): Duration = jsonElement match { - case jsonPrimitive: JsonPrimitive => Duration.ofMillis(jsonPrimitive.getAsInt) - case _ => Duration.ZERO - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/IntSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/IntSerializerHandler.scala deleted file mode 100644 index fe7d0846514350f28f946a48b83249799baa7803..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/IntSerializerHandler.scala +++ /dev/null @@ -1,15 +0,0 @@ -package de.tobias.playpad.utils.json - -import com.google.gson.{JsonElement, JsonPrimitive} - -class IntSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case number: Number => new JsonPrimitive(number) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): Int = jsonElement match { - case jsonPrimitive: JsonPrimitive => jsonPrimitive.getAsInt - case _ => 0 - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/JsonSerializer.scala b/src/main/scala/de/tobias/playpad/utils/json/JsonSerializer.scala deleted file mode 100644 index 30310414eb1fd221c9df67194f830beb9b63de5b..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/JsonSerializer.scala +++ /dev/null @@ -1,112 +0,0 @@ -package de.tobias.playpad.utils.json - -import java.util - -import com.google.gson.{JsonArray, JsonObject} - -class JsonSerializer { - - def serialize(o: Any): JsonObject = { - val jsonObject = new JsonObject - o.getClass.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonName])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonName]) - val value = f.get(o) - if (value != null) { - jsonObject.add(annotation.value(), annotation.handler().newInstance().serialize(value)) - } - }) - - o.getClass.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonObj])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonObj]) - val value = f.get(o) - if (value != null) { - jsonObject.add(annotation.value(), serialize(value)) - } - }) - - o.getClass.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonCollection])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonCollection]) - val value = f.get(o) - - val jsonValues = value match { - case seq: Seq[_] => seq.map(serialize) - } - val jsonArray = new JsonArray(jsonValues.size) - jsonValues.foreach(jsonArray.add) - jsonObject.add(annotation.value(), jsonArray) - }) - - jsonObject - } - - def deserialize[T](jsonObject: JsonObject, clazz: Class[T]): T = { - val obj = clazz.newInstance() - - clazz.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonName])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonName]) - val value = jsonObject.get(annotation.value()) - f.set(obj, annotation.handler().newInstance().deserialize(value)) - }) - - - clazz.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonObj])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonObj]) - val jsonObj = jsonObject.getAsJsonObject(annotation.value()) - val value = if (jsonObj != null) { - val value = deserialize(jsonObj, f.getType) - setParent(value, obj) - value - } else { - null - } - f.set(obj, value) - }) - - clazz.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonCollection])) - .foreach(f => { - f.setAccessible(true) - val annotation = f.getAnnotation(classOf[JsonCollection]) - val jsonArray = jsonObject.getAsJsonArray(annotation.value()) - - val tempList = new util.ArrayList[Any]() - jsonArray.forEach(elem => { - val value = deserialize(elem.getAsJsonObject, annotation.`type`()) - setParent(value, obj) - tempList.add(value) - }) - - var col = f.get(obj) - col match { - case _: List[_] => tempList.forEach(e => col = e :: col.asInstanceOf[List[_]]) - } - f.set(obj, col) - }) - - obj - } - - private def setParent(value: Any, parent: Any): Unit = { - value.getClass.getDeclaredFields - .filter(f => f.isAnnotationPresent(classOf[JsonParent])) - .foreach(f => { - f.setAccessible(true) - f.set(value, parent) - }) - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/SerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/SerializerHandler.scala deleted file mode 100644 index 5357fe23958ca41238b53bfa79a44208463a0131..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/SerializerHandler.scala +++ /dev/null @@ -1,9 +0,0 @@ -package de.tobias.playpad.utils.json - -import com.google.gson.{JsonElement, JsonPrimitive} - -trait SerializerHandler { - def serialize(value: Any): JsonPrimitive - - def deserialize(jsonElement: JsonElement): Any -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/StringSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/StringSerializerHandler.scala deleted file mode 100644 index 2dfa25fb4467a571cdbabc718c732e0f5ba36655..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/StringSerializerHandler.scala +++ /dev/null @@ -1,15 +0,0 @@ -package de.tobias.playpad.utils.json - -import com.google.gson.{JsonElement, JsonPrimitive} - -class StringSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case str: String => new JsonPrimitive(str) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): String = jsonElement match { - case jsonPrimitive: JsonPrimitive => jsonPrimitive.getAsString - case _ => null - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/json/UUIDSerializerHandler.scala b/src/main/scala/de/tobias/playpad/utils/json/UUIDSerializerHandler.scala deleted file mode 100644 index be1b8be83cd048508dc6b998567a65b01857dbe7..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/json/UUIDSerializerHandler.scala +++ /dev/null @@ -1,17 +0,0 @@ -package de.tobias.playpad.utils.json - -import java.util.UUID - -import com.google.gson.{JsonElement, JsonPrimitive} - -class UUIDSerializerHandler extends SerializerHandler { - override def serialize(value: Any): JsonPrimitive = value match { - case uuid: UUID => new JsonPrimitive(uuid.toString) - case _ => null - } - - override def deserialize(jsonElement: JsonElement): UUID = jsonElement match { - case jsonPrimitive: JsonPrimitive => UUID.fromString(jsonPrimitive.getAsString) - case _ => null - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/settings/PropertiesSettingsHandler.scala b/src/main/scala/de/tobias/playpad/utils/settings/PropertiesSettingsHandler.scala deleted file mode 100644 index 4a88b7bb2d363b82c0078ce2ed8b1854467d0bb7..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/settings/PropertiesSettingsHandler.scala +++ /dev/null @@ -1,48 +0,0 @@ -package de.tobias.playpad.utils.settings - -import java.io.IOException -import java.lang.reflect.Modifier -import java.nio.file.{Files, Path} -import java.util.Properties - -/** - * Created by tobias on 05.02.17. - */ -class PropertiesSettingsHandler extends SettingsLoader with SettingsSaver { - - @throws[IOException] - override def load(path: Path): Settings = { - val properties = new Properties() - properties.load(Files.newBufferedReader(path)) - - val settings = new Settings() - classOf[Settings].getDeclaredFields - .filter(f => !Modifier.isTransient(f.getModifiers)) - .filter(f => properties.containsKey(f.getName)) - .foreach(f => { - f.setAccessible(true) - if (f.getType == Integer.TYPE) { - f.setInt(settings, properties.getProperty(f.getName).toInt) - } else if (f.getType == classOf[Boolean]) { - f.setBoolean(settings, properties.getProperty(f.getName).toBoolean) - } else { - f.set(settings, properties.getProperty(f.getName)) - } - }) - settings - } - - @throws[IOException] - override def save(settings: Settings, path: Path): Unit = { - val properties = new Properties() - - classOf[Settings].getDeclaredFields - .filter(f => !Modifier.isTransient(f.getModifiers)) - .foreach(f => { - f.setAccessible(true) - properties.setProperty(f.getName, f.get(settings).toString) - }) - - properties.store(Files.newOutputStream(path), "Settings") - } -} diff --git a/src/main/scala/de/tobias/playpad/utils/settings/Settings.scala b/src/main/scala/de/tobias/playpad/utils/settings/Settings.scala deleted file mode 100644 index 7a83d8744a82c294529c2a621c125ba9dfc2e8f2..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/settings/Settings.scala +++ /dev/null @@ -1,20 +0,0 @@ -package de.tobias.playpad.utils.settings - -/** - * Created by tobias on 05.02.17. - */ -class Settings { - - var server_port: Int = 8080 - var server_secure: Boolean = false - var server_keystore_path: String = "" - var server_keystore_password: String = "" - - var db_host: String = "localhost" - var db_port: Int = 3306 - var db_username: String = "root" - var db_password: String = "password" - var db_database: String = "PlayWall" - - var plugin_source: String = "https://maven.thecodelabs.de/artifactory/TheCodeLabs-release/de/tobias/playpad/" -} diff --git a/src/main/scala/de/tobias/playpad/utils/settings/SettingsHandler.scala b/src/main/scala/de/tobias/playpad/utils/settings/SettingsHandler.scala deleted file mode 100644 index eaa6168cc98526ed385acb502b43c25fcb49933a..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/settings/SettingsHandler.scala +++ /dev/null @@ -1,12 +0,0 @@ -package de.tobias.playpad.utils.settings - -/** - * Created by tobias on 05.02.17. - */ -object SettingsHandler { - - def loader = new PropertiesSettingsHandler() - - def saver = new PropertiesSettingsHandler() - -} diff --git a/src/main/scala/de/tobias/playpad/utils/settings/SettingsLoader.scala b/src/main/scala/de/tobias/playpad/utils/settings/SettingsLoader.scala deleted file mode 100644 index c0433f8976f2a63f468faee6aeee5072a9c185af..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/settings/SettingsLoader.scala +++ /dev/null @@ -1,13 +0,0 @@ -package de.tobias.playpad.utils.settings - -import java.io.IOException -import java.nio.file.Path - -/** - * Created by tobias on 05.02.17. - */ -trait SettingsLoader { - - @throws[IOException] - def load(path: Path): Settings -} diff --git a/src/main/scala/de/tobias/playpad/utils/settings/SettingsSaver.scala b/src/main/scala/de/tobias/playpad/utils/settings/SettingsSaver.scala deleted file mode 100644 index 8c7392b9941338305a719b96c5b99f7d3cc1ce73..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/settings/SettingsSaver.scala +++ /dev/null @@ -1,15 +0,0 @@ -package de.tobias.playpad.utils.settings - -import java.io.IOException -import java.nio.file.Path - -/** - * Created by tobias on 05.02.17. - */ -trait SettingsSaver { - - @throws[IOException] - def save(settings: Settings, path: Path): Unit - - def default(path: Path): Unit = save(new Settings(), path) -} diff --git a/src/main/scala/de/tobias/playpad/utils/sql/SqlBackgroundRunner.scala b/src/main/scala/de/tobias/playpad/utils/sql/SqlBackgroundRunner.scala deleted file mode 100644 index 947d8ec040b8a5bd2074dec6f4d0e0f02ff6e8ba..0000000000000000000000000000000000000000 --- a/src/main/scala/de/tobias/playpad/utils/sql/SqlBackgroundRunner.scala +++ /dev/null @@ -1,24 +0,0 @@ -package de.tobias.playpad.utils.sql - -import java.sql.Connection - -class SqlBackgroundRunner(connection: Connection) extends Runnable { - - private val SLEEP = 5 * 60 * 1000 - - override def run(): Unit = { - while (!Thread.interrupted()) { - val statement = connection.prepareStatement("SHOW TABLES;") - val resultSet = statement.executeQuery() - - resultSet.close() - statement.close() - - try { - Thread.sleep(SLEEP) - } catch { - case _: InterruptedException => return - } - } - } -} diff --git a/src/test/java/ClientTest.java b/src/test/java/ClientTest.java deleted file mode 100644 index 92f77bdb0a74e7a29f39f9396330c8a4fd0a0abc..0000000000000000000000000000000000000000 --- a/src/test/java/ClientTest.java +++ /dev/null @@ -1,47 +0,0 @@ -import javax.net.ssl.*; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; - -/** - * Created by tobias on 26.01.17. - */ -public class ClientTest { - public static void main(String[] args) throws IOException, KeyManagementException, NoSuchAlgorithmException { - // Create a trust manager that does not validate certificate chains - TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted(X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted(X509Certificate[] certs, String authType) { - } - }}; - - // Install the all-trusting trust manager - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - HttpsURLConnection.setDefaultHostnameVerifier((hostname, sslSession) -> true); - - URL url = new URL("https://localhost:8090/plugins"); - URLConnection conn = url.openConnection(); - - InputStream stream = conn.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); - - String line; - while ((line = reader.readLine()) != null) { - System.out.println(line); - } - } -} diff --git a/src/test/java/de/tobias/playwall/PlaywallServerApplicationTests.java b/src/test/java/de/tobias/playwall/PlaywallServerApplicationTests.java new file mode 100644 index 0000000000000000000000000000000000000000..db268fe3687673247ccbfa7223dcc2f21e801e9b --- /dev/null +++ b/src/test/java/de/tobias/playwall/PlaywallServerApplicationTests.java @@ -0,0 +1,15 @@ +package de.tobias.playwall; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class PlaywallServerApplicationTests +{ + + @Test + void contextLoads() + { + } + +}