diff --git a/pom.xml b/pom.xml index 2d4c872368633f4bcfef57560534ede130f84605..f6446ebc0643685cdfe7476e87085debd3781f23 100644 --- a/pom.xml +++ b/pom.xml @@ -19,19 +19,6 @@ <version>2.3.2</version> </dependency> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-entitymanager</artifactId> - <version>6.0.0.Alpha7</version> - <type>pom</type> - </dependency> - - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-validator</artifactId> - <version>8.0.1.Final</version> - </dependency> - <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> diff --git a/src/main/java/com/soap/dao/DaoInterface.java b/src/main/java/com/soap/dao/DaoInterface.java deleted file mode 100644 index 081112cf9ad60e7bde92e427f0a8becbb6340664..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/dao/DaoInterface.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.soap.dao; - -import java.util.List; - -// Dao stands for Data Access Object -public interface DaoInterface<T> { - public T findById(int id); - public List<T> findAll(); - public void save(T t); - public void update(T t); - public void delete(T t); -} diff --git a/src/main/java/com/soap/exception/DaoException.java b/src/main/java/com/soap/exception/DaoException.java deleted file mode 100644 index 5874b11aa161ea7a05f4c3a544727a26445955ba..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/exception/DaoException.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.soap.exception; - -public class DaoException extends Exception { - public int code; - - public DaoException(String message, int code) { - super(message); - this.code = code; - } - - public DaoException(String message) { - this(message, 400); - } -} diff --git a/src/main/java/com/soap/exception/ServiceException.java b/src/main/java/com/soap/exception/ServiceException.java deleted file mode 100644 index 7c2d58885324ef90f2508c54f154d4a29ecc71ce..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/exception/ServiceException.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.soap.exception; -import javax.xml.ws.WebFault; - -@WebFault(name = "ServiceException") -public class ServiceException extends Exception{ - public int code = 400; - - public ServiceException(int code, String message) { - super(message); - this.code = code; - } - - public ServiceException(String message) { - this(400, message); - } -} diff --git a/src/main/java/com/soap/model/Author.java b/src/main/java/com/soap/model/Author.java deleted file mode 100644 index d9669ba0420e2ec021a13572b8105d06045a0606..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/Author.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.soap.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@Entity -@Table(name = "author") -public class Author { - @Id - @Column(name = "author_id") - private int authorId; -} diff --git a/src/main/java/com/soap/model/Book.java b/src/main/java/com/soap/model/Book.java deleted file mode 100644 index 57bd117072e57f8947dcf28027beb398488f5192..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/Book.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.soap.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@Entity -@Table(name = "book") -public class Book { - @Id - @Column(name = "book_id") - private int bookId; -} diff --git a/src/main/java/com/soap/model/BookCollection.java b/src/main/java/com/soap/model/BookCollection.java deleted file mode 100644 index d3aff82645f5053f452f51261e313f8af8f6b39f..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/BookCollection.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.soap.model; - -import java.sql.Timestamp; -import java.util.List; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@Entity -@Table(name = "book_collection") -public class BookCollection { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "collection_id") - private int collectionId; - - @Column(name = "created_by") - private User createdBy; - - @Column(name = "name") - private String name; - - @Column(name = "desc") - private String desc; - - @Column(name = "created_at") - private Timestamp createdAt; - - @Column(name = "updated_at") - private Timestamp updatedAt; - - @Column(name = "is_deleted") - private boolean isDeleted; - - @Column(name = "deleted_at") - private Timestamp deletedAt; - - private List<Book> books; - private List<User> subscribers; - - @Override - public String toString() { - return "BookCollection [collectionId=" + collectionId + ", createdBy=" + createdBy + ", name=" + name - + ", desc=" + desc + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", isDeleted=" - + isDeleted + ", deletedAt=" + deletedAt + "]"; - } -} diff --git a/src/main/java/com/soap/model/User.java b/src/main/java/com/soap/model/User.java deleted file mode 100644 index 80a3061c28c3e99d5430c41a20d1bb2f80fe41c5..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/User.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.soap.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -@AllArgsConstructor -@Entity -@Table(name = "user") -public class User { - @Id - @Column(name = "username") - private String username; -} diff --git a/src/main/java/com/soap/model/UserNotification.java b/src/main/java/com/soap/model/UserNotification.java deleted file mode 100644 index ed6476b0f6bc8b8dbeee4cd6d009a40ed0ef4a7f..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/UserNotification.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.soap.model; - -import java.sql.Timestamp; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -import com.soap.model.enums.NotificationStatus; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@Entity -@Table(name = "user_notification") -public class UserNotification { - public UserNotification(User user, String message, Timestamp createdAt, NotificationStatus status) { - this.user = user; - this.message = message; - this.createdAt = createdAt; - this.status = status; - } - - public UserNotification(String username, String message, Timestamp createdAt, NotificationStatus status) { - this.user = new User(username); - this.message = message; - this.createdAt = createdAt; - this.status = status; - } - - public UserNotification(User user, String message, NotificationStatus status) { - this(user, message, new Timestamp(System.currentTimeMillis()), status); - } - - public UserNotification(String username, String message, NotificationStatus status) { - this(username, message, new Timestamp(System.currentTimeMillis()), status); - } - - public UserNotification(User user, String message) { - this(user, message, NotificationStatus.UNREAD); - } - - public UserNotification(String username, String message) { - this(username, message, NotificationStatus.UNREAD); - } - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "notification_id") - private int notificationId; - - private User user; - - @Column(name = "message") - private String message; - - @Column(name = "created_at") - private Timestamp createdAt; - - @Enumerated(EnumType.STRING) - @Column(name = "status") - private NotificationStatus status; -} diff --git a/src/main/java/com/soap/model/enums/NotificationStatus.java b/src/main/java/com/soap/model/enums/NotificationStatus.java deleted file mode 100644 index 93f29249bf2fdde6a1a368d781792ec5b5d7b00b..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/model/enums/NotificationStatus.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.soap.model.enums; - -public enum NotificationStatus { - UNREAD, - READ, - ARCHIVED -} diff --git a/src/main/java/com/soap/util/HibernateUtil.java b/src/main/java/com/soap/util/HibernateUtil.java deleted file mode 100644 index 624c3374aed026a7867ff977af8a99cb16a7b6b9..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/util/HibernateUtil.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.soap.util; - -import java.io.File; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.w3c.dom.Document; - -import io.github.cdimascio.dotenv.Dotenv; - -public class HibernateUtil { - private static final String CONFIG_FILE_TEMPLATE = "/hibernate.cfg.template.xml"; - private static final String CONFIG_FILE = "/hibernate.cfg.xml"; - private static SessionFactory sessionFactory = buildSessionFactory(); - - private static SessionFactory buildSessionFactory() { - try { - Configuration conf = new Configuration().configure(makeConfigFile()); - return conf.buildSessionFactory(); - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - } - - private static String makeConfigFile() { - try { - File file = new File(CONFIG_FILE); - if (file.exists()) return CONFIG_FILE; - - // Load .env - Dotenv dotenv = Dotenv.load(); - - // Load XML file - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document doc = builder.parse(CONFIG_FILE_TEMPLATE); - - // Set the variables - doc.getElementsByTagName("property").item(0).setTextContent(dotenv.get("DB_HOST")); - doc.getElementsByTagName("property").item(1).setTextContent( - "jdbc:mysql://localhost:3306/" + dotenv.get("DB_NAME") - ); - doc.getElementsByTagName("property").item(2).setTextContent(dotenv.get("DB_USER")); - doc.getElementsByTagName("property").item(3).setTextContent(dotenv.get("DB_PASS")); - - // Save the file - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - Transformer transformer = transformerFactory.newTransformer(); - transformer.transform(new DOMSource(doc), new StreamResult(CONFIG_FILE)); - - return CONFIG_FILE; - } catch (Exception e) { - throw new ExceptionInInitializerError(e); - } - } - - public static SessionFactory getSessionFactory() { - return sessionFactory; - } - -} diff --git a/src/main/java/com/soap/util/hibernate.cfg.template.xml b/src/main/java/com/soap/util/hibernate.cfg.template.xml deleted file mode 100644 index 07b3a3a32805c0e84871ace7e44c5874e55316ca..0000000000000000000000000000000000000000 --- a/src/main/java/com/soap/util/hibernate.cfg.template.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> -<hibernate-configuration> - <session-factory> - <!-- Database connection settings --> - <property name="hibernate.connection.driver_class"></property> - <property name="hibernate.connection.url"></property> - <property name="hibernate.connection.username"></property> - <property name="hibernate.connection.password"></property> - - <!-- Dialect for your database --> - <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> - - <!-- Enable Hibernate's automatic session context management --> - <property name="hibernate.current_session_context_class">thread</property> - - <!-- Echo all executed SQL to stdout --> - <property name="hibernate.show_sql">true</property> - - <!-- Mapping file or annotated class --> - <!-- Add your entity classes or mapping files here --> - - </session-factory> -</hibernate-configuration> diff --git a/src/main/resources/db/migration/V1__init_db_shema.sql b/src/main/resources/db/migration/V1__init_db_shema.sql deleted file mode 100644 index 5f44083360d176f8cbe6089873f488980a117822..0000000000000000000000000000000000000000 --- a/src/main/resources/db/migration/V1__init_db_shema.sql +++ /dev/null @@ -1,57 +0,0 @@ -BEGIN; - -DROP TABLE IF EXISTS `book_collection`; -DROP TABLE IF EXISTS `in_collection`; -DROP TABLE IF EXISTS `collection_subscription`; -DROP TABLE IF EXISTS `author_subscription`; -DROP TABLE IF EXISTS `user_notification`; - -CREATE TABLE `book_collection` ( - `collection_id` int AUTO_INCREMENT PRIMARY KEY, - `created_by` varchar(25) NOT NULL, - `name` varchar(255) NOT NULL, - `desc` text NOT NULL, - `created_at` timestamp NOT NULL, - `updated_at` timestamp, - `is_deleted` BOOLEAN NOT NULL DEFAULT FALSE, - `deleted_at` timestamp -); - -CREATE TABLE `in_collection` ( - `collection_id` int, - `book_id` int, - PRIMARY KEY (`collection_id`, `book_id`) -); - -CREATE TABLE `collection_subscription` ( - `collection_id` int, - `username` varchar(25), - `subscribed_at` timestamp NOT NULL, - `is_unsubscribed` BOOLEAN NOT NULL DEFAULT FALSE, - `unsubscribed_at` timestamp, - PRIMARY KEY (`collection_id`, `username`) -); - -CREATE TABLE `author_subscription` ( - `author_id` int, - `username` varchar(25), - `subscribed_at` timestamp NOT NULL, - `is_unsubscribed` BOOLEAN NOT NULL DEFAULT FALSE, - `unsubscribed_at` timestamp, - PRIMARY KEY (`author_id`, `username`) -); - -CREATE TABLE `user_notification` ( - `notification_id` int AUTO_INCREMENT PRIMARY KEY, - `username` varchar(25), - `message` text NOT NULL, - `created_at` timestamp NOT NULL, - `status` ENUM('unread', 'read', 'archived') NOT NULL -); - -ALTER TABLE `in_collection` ADD FOREIGN KEY (`collection_id`) REFERENCES `book_collection` (`collection_id`); - -ALTER TABLE `collection_subscription` ADD FOREIGN KEY (`collection_id`) REFERENCES `book_collection` (`collection_id`); - -COMMIT; -``` \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__alter_notification_status.sql b/src/main/resources/db/migration/V2__alter_notification_status.sql deleted file mode 100644 index 2f88b6537e6ba6ce9ba9dd6839c2908b2bf93158..0000000000000000000000000000000000000000 --- a/src/main/resources/db/migration/V2__alter_notification_status.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `user_notification` -MODIFY COLUMN `status` enum('READ','UNREAD', 'ARCHIVED') NOT NULL; \ No newline at end of file diff --git a/src/main/resources/db/migration/V3__services_data_duplication.sql b/src/main/resources/db/migration/V3__services_data_duplication.sql deleted file mode 100644 index be6e134c43810527f205a5440e4748dee555eefd..0000000000000000000000000000000000000000 --- a/src/main/resources/db/migration/V3__services_data_duplication.sql +++ /dev/null @@ -1,40 +0,0 @@ -BEGIN; - --- This migration is made for synchronization purpose with PHP Service - -CREATE TABLE IF NOT EXISTS `user` ( - `username` varchar(32) PRIMARY KEY -); - -CREATE TABLE IF NOT EXISTS `book` ( - `book_id` integer PRIMARY KEY -); - -CREATE TABLE IF NOT EXISTS `author` ( - `author_id` integer PRIMARY KEY -); - -ALTER TABLE `book_collection` - ADD FOREIGN KEY (`created_by`) REFERENCES `user` (`username`) - ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE `in_collection` - ADD FOREIGN KEY (`book_id`) REFERENCES `book` (`book_id`) - ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE `collection_subscription` - ADD FOREIGN KEY (`username`) REFERENCES `user` (`username`) - ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE `author_subscription` - ADD FOREIGN KEY (`author_id`) REFERENCES `author` (`author_id`) - ON DELETE CASCADE ON UPDATE CASCADE; -ALTER TABLE `author_subscription` - ADD FOREIGN KEY (`username`) REFERENCES `user` (`username`) - ON DELETE CASCADE ON UPDATE CASCADE; - -ALTER TABLE `user_notification` - ADD FOREIGN KEY (`username`) REFERENCES `user` (`username`) - ON DELETE CASCADE ON UPDATE CASCADE;; - -COMMIT; \ No newline at end of file