diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 24c7ba0..db80f3a 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,52 +1,19 @@ # docker-compose.yml version: '3.8' - # Define the services for our application stack services: - # PostgreSQL database service - postgres: - # Using the official PostgreSQL base image. - # 'postgres:16' is recommended for a stable, recent version. - # You can use 'postgres:latest' for the very newest, but versions like 13, 14, 15, 16 are common. - image: postgres:16 # Or postgres:latest, postgres:13-alpine, etc. - container_name: postgres_db # Assign a friendly name to the container - environment: - # --- CRITICAL: These settings will ONLY take effect if ./dbData directory is EMPTY on first run --- - POSTGRES_DB: horse # Your database name - POSTGRES_USER: postgres # Set to 'postgres', the default superuser for the official image - POSTGRES_PASSWORD: root # Your desired password for the 'postgres' user - # -------------------------------------------------------------------------------------------------- - ports: - - "5434:5432" # Map host port 5434 to container port 5432 - volumes: - # Using a bind mount. You MUST delete the ./dbData directory manually if you change user/pass/db. - # This directory MUST be empty when the container first starts to trigger initialization. - - ./dbData:/var/lib/postgresql/data # Persist PostgreSQL data to a local directory - # Added command for more verbose logging during startup (optional, but highly recommended here) - command: postgres -c log_statement=all - networks: - - app_network # Connect to our custom application network - # networks: - # - app_network # Connect to our custom application network spring: #image: mathewfrancisv/spring_back_postgres:v1.0.0 - image: mathewfrancisv/btc_cezen_backend:v1.0.2 + image: mathewfrancisv/btc_cezen_backend:v2.3.0 container_name: spring_app ports: - "8083:8080" environment: - # jdbc:postgresql://localhost:5432/horse - # SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/horse - SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/horse - SPRING_DATASOURCE_USERNAME: postgres # Ensure this matches POSTGRES_USER - SPRING_DATASOURCE_PASSWORD: root # Ensure this matches POSTGRES_PASSWORD SPRING_DATASOURCE_CORSIP: http://10.83.77.61:4200 #network_mode: host networks: - app_network - depends_on: - - postgres # Angular frontend application service angular-dev: @@ -56,9 +23,6 @@ services: volumes: - ../btc-UI:/app command: sh -c "npm install && npm run start" - # IMPORTANT: This service is explicitly part of the 'app_network' (bridge) - # Removing network_mode: host for this service - # network_mode: host ports: - "4200:4200" # REQUIRED to expose Angular to the host machine in bridge mode networks: @@ -66,20 +30,6 @@ services: depends_on: - spring # The 'spring' service might not be directly reachable by name here - # Optional Nginx service for Angular (if you were deploying production build) - # angular: - # image: nginx:alpine - # container_name: angular_app - # ports: - # - "80:80" - # volumes: - # - ./angular/dist/your-angular-app:/usr/share/nginx/html - # - ./nginx/default.conf:/etc/nginx/conf.d/default.conf - # networks: - # - app_network - # depends_on: - # - spring - # Define the custom bridge network for 'angular-dev' networks: app_network: diff --git a/springHorse/pom.xml b/springHorse/pom.xml index be8640a..af68995 100755 --- a/springHorse/pom.xml +++ b/springHorse/pom.xml @@ -30,10 +30,10 @@ 21 - - org.springframework.boot - spring-boot-starter-data-jpa - + + + + org.springframework.boot spring-boot-starter-web @@ -45,11 +45,11 @@ runtime true - - org.postgresql - postgresql - runtime - + + + + + diff --git a/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAO.java b/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAO.java index 7deb2e5..e4c24ae 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAO.java +++ b/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAO.java @@ -1,21 +1,21 @@ -package com.example.cezenBTC.DAO; - -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.entity.btc_entity.RaceNumber; -import com.example.cezenBTC.entity.btc_entity.RaceVenue; - -import java.time.LocalDate; -import java.util.List; - -public interface BtcOpsDAO { - - public ReturnStatus sentARaceVenue(RaceVenue raceVenue); - - public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRaces); - - public List getAllRaceVenue(); - - public List getALlRacesByVenueId(int raceVenueId); - - public List getAllRacesByDate(LocalDate date); -} +//package com.example.cezenBTC.DAO; +// +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.entity.btc_entity.RaceNumber; +//import com.example.cezenBTC.entity.btc_entity.RaceVenue; +// +//import java.time.LocalDate; +//import java.util.List; +// +//public interface BtcOpsDAO { +// +// public ReturnStatus sentARaceVenue(RaceVenue raceVenue); +// +// public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRaces); +// +// public List getAllRaceVenue(); +// +// public List getALlRacesByVenueId(int raceVenueId); +// +// public List getAllRacesByDate(LocalDate date); +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAOImpl.java b/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAOImpl.java index 8c4151e..80a1d05 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAOImpl.java +++ b/springHorse/src/main/java/com/example/cezenBTC/DAO/BtcOpsDAOImpl.java @@ -1,92 +1,92 @@ -package com.example.cezenBTC.DAO; - -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.entity.btc_entity.RaceNumber; -import com.example.cezenBTC.entity.btc_entity.RaceVenue; -import com.example.cezenBTC.entity.user.UserEntity; -import jakarta.persistence.EntityManager; -import jakarta.persistence.TypedQuery; -import jakarta.transaction.Transactional; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -import java.time.LocalDate; -import java.util.List; - -@Repository -public class BtcOpsDAOImpl implements BtcOpsDAO{ - - @Autowired - private EntityManager entityManager; - - @Override - @Transactional - public ReturnStatus sentARaceVenue(RaceVenue raceVenue) { - this.entityManager.persist(raceVenue); - return new ReturnStatus(true, "Venue added successfully", ""); - } - - @Override - @Transactional - public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace) { - - // find the venue if it exists - RaceVenue raceVenue = getRaceVenueById(raceVenueId); - - // find a race event - System.out.println("Race Venue is" + raceVenue.getVenue()); - // only if a race event exists then persist a race - System.out.println(raceVenue.getVenue()); - RaceNumber raceNumber = new RaceNumber(localDate, raceVenue, numberOfRace); - - this.entityManager.persist(raceNumber); - return new ReturnStatus(true, "raceNumber persisted", ""); - - } - - private RaceVenue getRaceVenueById(int raceVenueId){ - - TypedQuery query = this.entityManager - .createQuery("SELECT V FROM RaceVenue as V WHERE V.raceVenueId = :venueID", RaceVenue.class); - - query.setParameter("venueID", raceVenueId); - - return query.getSingleResult(); - } - - @Override - public List getAllRaceVenue() { - - TypedQuery query = this.entityManager - .createQuery("SELECT R FROM RaceVenue as R", RaceVenue.class); - - return query.getResultList(); - } - - @Override - public List getALlRacesByVenueId(int raceVenueId) { - - // get the race venue from the backend - RaceVenue raceVenue = this.getRaceVenueById(raceVenueId); - - TypedQuery query = this.entityManager - .createQuery("SELECT V FROM RaceNumber as V WHERE V.raceVenue = :venue", RaceNumber.class); - - query.setParameter("venue", raceVenue); - - return query.getResultList(); - } - - @Override - public List getAllRacesByDate(LocalDate date) { - - // get all races today - - TypedQuery query = this.entityManager - .createQuery("SELECT T FROM RaceNumber as T JOIN FETCH T.raceVenue WHERE T.sysDataOnly = :date", RaceNumber.class); - - query.setParameter("date", date); - - return query.getResultList(); - } -} +//package com.example.cezenBTC.DAO; +// +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.entity.btc_entity.RaceNumber; +//import com.example.cezenBTC.entity.btc_entity.RaceVenue; +//import com.example.cezenBTC.entity.user.UserEntity; +//import jakarta.persistence.EntityManager; +//import jakarta.persistence.TypedQuery; +//import jakarta.transaction.Transactional; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Repository; +// +//import java.time.LocalDate; +//import java.util.List; +// +//@Repository +//public class BtcOpsDAOImpl implements BtcOpsDAO{ +// +// @Autowired +// private EntityManager entityManager; +// +// @Override +// @Transactional +// public ReturnStatus sentARaceVenue(RaceVenue raceVenue) { +// this.entityManager.persist(raceVenue); +// return new ReturnStatus(true, "Venue added successfully", ""); +// } +// +// @Override +// @Transactional +// public ReturnStatus setRaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace) { +// +// // find the venue if it exists +// RaceVenue raceVenue = getRaceVenueById(raceVenueId); +// +// // find a race event +// System.out.println("Race Venue is" + raceVenue.getVenue()); +// // only if a race event exists then persist a race +// System.out.println(raceVenue.getVenue()); +// RaceNumber raceNumber = new RaceNumber(localDate, raceVenue, numberOfRace); +// +// this.entityManager.persist(raceNumber); +// return new ReturnStatus(true, "raceNumber persisted", ""); +// +// } +// +// private RaceVenue getRaceVenueById(int raceVenueId){ +// +// TypedQuery query = this.entityManager +// .createQuery("SELECT V FROM RaceVenue as V WHERE V.raceVenueId = :venueID", RaceVenue.class); +// +// query.setParameter("venueID", raceVenueId); +// +// return query.getSingleResult(); +// } +// +// @Override +// public List getAllRaceVenue() { +// +// TypedQuery query = this.entityManager +// .createQuery("SELECT R FROM RaceVenue as R", RaceVenue.class); +// +// return query.getResultList(); +// } +// +// @Override +// public List getALlRacesByVenueId(int raceVenueId) { +// +// // get the race venue from the backend +// RaceVenue raceVenue = this.getRaceVenueById(raceVenueId); +// +// TypedQuery query = this.entityManager +// .createQuery("SELECT V FROM RaceNumber as V WHERE V.raceVenue = :venue", RaceNumber.class); +// +// query.setParameter("venue", raceVenue); +// +// return query.getResultList(); +// } +// +// @Override +// public List getAllRacesByDate(LocalDate date) { +// +// // get all races today +// +// TypedQuery query = this.entityManager +// .createQuery("SELECT T FROM RaceNumber as T JOIN FETCH T.raceVenue WHERE T.sysDataOnly = :date", RaceNumber.class); +// +// query.setParameter("date", date); +// +// return query.getResultList(); +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAO.java b/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAO.java index a1c389e..da0a80b 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAO.java +++ b/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAO.java @@ -1,18 +1,18 @@ -package com.example.cezenBTC.DAO; - -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.entity.user.UserEntity; - -// TODO only one admin allowed ... once the admin creates an -// account they should not be able to make the account again -// admin login, logout and signup DAO operations -public interface UserOpsDAO { - - // check if user exists; - public boolean checkIfAdminExists(UserEntity userEntity) throws Exception; - - // admin login - public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity); - - public UserEntity getUserByUserStringId(String userName); -} +//package com.example.cezenBTC.DAO; +// +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.entity.user.UserEntity; +// +//// TODO only one admin allowed ... once the admin creates an +//// account they should not be able to make the account again +//// admin login, logout and signup DAO operations +//public interface UserOpsDAO { +// +// // check if user exists; +// public boolean checkIfAdminExists(UserEntity userEntity) throws Exception; +// +// // admin login +// public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity); +// +// public UserEntity getUserByUserStringId(String userName); +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAOImpl.java b/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAOImpl.java index ece772d..87fd040 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAOImpl.java +++ b/springHorse/src/main/java/com/example/cezenBTC/DAO/UserOpsDAOImpl.java @@ -1,105 +1,105 @@ -package com.example.cezenBTC.DAO; - -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.entity.user.Role; -import com.example.cezenBTC.entity.user.UserEntity; -import jakarta.persistence.EntityManager; -import jakarta.persistence.Query; -import jakarta.persistence.TypedQuery; -import jakarta.transaction.Transactional; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; - -@Repository -public class UserOpsDAOImpl implements UserOpsDAO{ - - private final String roleNameInDb = "ROLE_admin"; - - @Autowired - private EntityManager entityManager; - - @Override - public boolean checkIfAdminExists(UserEntity userEntity){ - // check if info exists in the database users table - // this enforces the fact that only one user can exist - Query query = entityManager.createQuery( - "SELECT COUNT(u) FROM UserEntity u JOIN u.roles r WHERE r.role = :roleName"); - query.setParameter("roleName", this.roleNameInDb); - Long count = (Long) query.getSingleResult(); - return count > 0; - - } - - //check if user already exists - private boolean checkIfUserExists(UserEntity userEntity){ - - try{ - TypedQuery query = this.entityManager.createQuery( - "SELECT U FROM UserEntity U where U.userName= :givenUserName",UserEntity.class ); - query.setParameter("givenUserName", userEntity.getUserName()); - System.out.println("Existing user "+ userEntity.getUserName()); - return query.getSingleResult() != null; - - }catch ( Exception e){ - return false; - } - } - - // get roles from the databasepbxUserService.adminSetUserNamePasswordSet("1234567890", "12345", "12345"); - - // Admin sets a username and password for the first time - @Override - @Transactional - public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity) { - - if(this.checkIfUserExists(userEntity)){ - return new ReturnStatus(false, "User already exists", ""); - } - - try { -// if (checkIfAdminExists(userEntity)) { -// return new ReturnStatus(false, "Admin already exists", ""); -// } - // Fetch existing ROLE_Admin from DB - TypedQuery query = entityManager.createQuery("FROM Role r WHERE r.role = :roleName", Role.class) - .setParameter("roleName", roleNameInDb); - - Role role = query.getSingleResult(); - System.out.println("Adding " + userEntity.getUserName()); - userEntity.setARole(role); - // Persist the user - entityManager.persist(userEntity); - return new ReturnStatus(true, "Admin created", ""); - } catch (Exception e) { - return new ReturnStatus(false, "Admin creation failed", e.getMessage()); - } - } - - // get user details by username - // throws an exception if the user doesn't exist - // exception is caught and returns null ... custom authentication provider must catch the exception - @Override - public UserEntity getUserByUserStringId(String userStringId) { - try{ - TypedQuery query = this.entityManager - .createQuery("SELECT u FROM UserEntity u JOIN FETCH u.roles AS r WHERE u.userIdNumber = :userStringId", UserEntity.class); - - query.setParameter("userStringId", userStringId); - - return query.getSingleResult(); - - }catch ( Exception e){ - System.out.println("User not found User exception"); - return null; - } - } - -// public UserEntity getUserByUserName(String userName){ -// TypedQuery query = this.entityManager -// .createQuery("SELECT u FROM UserEntity u WHERE u.userName = :userString", UserEntity.class); +//package com.example.cezenBTC.DAO; // -// query.setParameter("userString", userName); +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.entity.user.Role; +//import com.example.cezenBTC.entity.user.UserEntity; +//import jakarta.persistence.EntityManager; +//import jakarta.persistence.Query; +//import jakarta.persistence.TypedQuery; +//import jakarta.transaction.Transactional; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Repository; +// +//@Repository +//public class UserOpsDAOImpl implements UserOpsDAO{ +// +// private final String roleNameInDb = "ROLE_admin"; +// +// @Autowired +// private EntityManager entityManager; +// +// @Override +// public boolean checkIfAdminExists(UserEntity userEntity){ +// // check if info exists in the database users table +// // this enforces the fact that only one user can exist +// Query query = entityManager.createQuery( +// "SELECT COUNT(u) FROM UserEntity u JOIN u.roles r WHERE r.role = :roleName"); +// query.setParameter("roleName", this.roleNameInDb); +// Long count = (Long) query.getSingleResult(); +// return count > 0; // -// return query.getSingleResult(); // } -} +// +// //check if user already exists +// private boolean checkIfUserExists(UserEntity userEntity){ +// +// try{ +// TypedQuery query = this.entityManager.createQuery( +// "SELECT U FROM UserEntity U where U.userName= :givenUserName",UserEntity.class ); +// query.setParameter("givenUserName", userEntity.getUserName()); +// System.out.println("Existing user "+ userEntity.getUserName()); +// return query.getSingleResult() != null; +// +// }catch ( Exception e){ +// return false; +// } +// } +// +// // get roles from the databasepbxUserService.adminSetUserNamePasswordSet("1234567890", "12345", "12345"); +// +// // Admin sets a username and password for the first time +// @Override +// @Transactional +// public ReturnStatus adminSetUsernameAndPassword(UserEntity userEntity) { +// +// if(this.checkIfUserExists(userEntity)){ +// return new ReturnStatus(false, "User already exists", ""); +// } +// +// try { +//// if (checkIfAdminExists(userEntity)) { +//// return new ReturnStatus(false, "Admin already exists", ""); +//// } +// // Fetch existing ROLE_Admin from DB +// TypedQuery query = entityManager.createQuery("FROM Role r WHERE r.role = :roleName", Role.class) +// .setParameter("roleName", roleNameInDb); +// +// Role role = query.getSingleResult(); +// System.out.println("Adding " + userEntity.getUserName()); +// userEntity.setARole(role); +// // Persist the user +// entityManager.persist(userEntity); +// return new ReturnStatus(true, "Admin created", ""); +// } catch (Exception e) { +// return new ReturnStatus(false, "Admin creation failed", e.getMessage()); +// } +// } +// +// // get user details by username +// // throws an exception if the user doesn't exist +// // exception is caught and returns null ... custom authentication provider must catch the exception +// @Override +// public UserEntity getUserByUserStringId(String userStringId) { +// try{ +// TypedQuery query = this.entityManager +// .createQuery("SELECT u FROM UserEntity u JOIN FETCH u.roles AS r WHERE u.userIdNumber = :userStringId", UserEntity.class); +// +// query.setParameter("userStringId", userStringId); +// +// return query.getSingleResult(); +// +// }catch ( Exception e){ +// System.out.println("User not found User exception"); +// return null; +// } +// } +// +//// public UserEntity getUserByUserName(String userName){ +//// TypedQuery query = this.entityManager +//// .createQuery("SELECT u FROM UserEntity u WHERE u.userName = :userString", UserEntity.class); +//// +//// query.setParameter("userString", userName); +//// +//// return query.getSingleResult(); +//// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/HorseBTC.java b/springHorse/src/main/java/com/example/cezenBTC/HorseBTC.java index 6422985..761cd77 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/HorseBTC.java +++ b/springHorse/src/main/java/com/example/cezenBTC/HorseBTC.java @@ -1,7 +1,7 @@ package com.example.cezenBTC; -import com.example.cezenBTC.service.BtcRaceService; -import com.example.cezenBTC.service.BtcUserService; +//import com.example.cezenBTC.service.BtcRaceService; +//import com.example.cezenBTC.service.BtcUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -20,37 +20,37 @@ public class HorseBTC { @Bean - CommandLineRunner runner(@Autowired BtcUserService btcUserService, @Autowired BtcRaceService btcRaceService) { + CommandLineRunner runner(/*@Autowired BtcUserService btcUserService, @Autowired BtcRaceService btcRaceService*/) { return (args) -> { - btcUserService.adminSetUserNamePasswordSet("123412341234", "John Dow", "1234567"); - btcUserService.adminSetUserNamePasswordSet("432143214321", "John Dow 1", "1231234"); - btcUserService.adminSetUserNamePasswordSet("567856785678", "John Dow 2", "1234567"); - btcUserService.adminSetUserNamePasswordSet("876587658765", "John Dow 3", "1234567"); - btcUserService.adminSetUserNamePasswordSet("098709870987", "John Dow 4", "2222222"); - btcUserService.adminSetUserNamePasswordSet("789078907890", "John Dow 5", "4444444"); - btcUserService.adminSetUserNamePasswordSet("231120230065", "Gowathami v", "1111111"); - - btcRaceService.addARaceVenue("BNG"); - btcRaceService.addARaceVenue("MYS"); - - - //add a few venue races - //LocalDate.of(2025, 6, 29) year month day - btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 29), 1, 4); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 2); - btcRaceService.addARaceNumber(LocalDate.of(2025, 8, 29), 1, 4); - btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 1, 4); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 4); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 1, 4); - - - - btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 2); - btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6); - btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 1); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 3); - btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 2, 3); +// btcUserService.adminSetUserNamePasswordSet("123412341234", "John Dow", "1234567"); +// btcUserService.adminSetUserNamePasswordSet("432143214321", "John Dow 1", "1231234"); +// btcUserService.adminSetUserNamePasswordSet("567856785678", "John Dow 2", "1234567"); +// btcUserService.adminSetUserNamePasswordSet("876587658765", "John Dow 3", "1234567"); +// btcUserService.adminSetUserNamePasswordSet("098709870987", "John Dow 4", "2222222"); +// btcUserService.adminSetUserNamePasswordSet("789078907890", "John Dow 5", "4444444"); +// btcUserService.adminSetUserNamePasswordSet("231120230065", "Gowathami v", "1111111"); +// +// btcRaceService.addARaceVenue("BNG"); +// btcRaceService.addARaceVenue("MYS"); +// +// +// //add a few venue races +// //LocalDate.of(2025, 6, 29) year month day +// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 29), 1, 4); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 2); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 8, 29), 1, 4); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 1, 4); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 1, 4); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 1, 4); +// +// +// +// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 2); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 6, 30), 2, 6); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 1); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 1), 2, 3); +// btcRaceService.addARaceNumber(LocalDate.of(2025, 7, 7), 2, 3); }; } diff --git a/springHorse/src/main/java/com/example/cezenBTC/absbridge/model/LoginRequest.java b/springHorse/src/main/java/com/example/cezenBTC/absbridge/model/LoginRequest.java index 70e1b4c..5690eb4 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/absbridge/model/LoginRequest.java +++ b/springHorse/src/main/java/com/example/cezenBTC/absbridge/model/LoginRequest.java @@ -19,6 +19,54 @@ public class LoginRequest { this.btMake = btMake; } + public String getOpCard() { + return opCard; + } + + public void setOpCard(String opCard) { + this.opCard = opCard; + } + + public String getBtId() { + return btId; + } + + public void setBtId(String btId) { + this.btId = btId; + } + + public String getUsrId() { + return usrId; + } + + public void setUsrId(String usrId) { + this.usrId = usrId; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getPasswordEnc() { + return passwordEnc; + } + + public void setPasswordEnc(String passwordEnc) { + this.passwordEnc = passwordEnc; + } + + public Object getBtMake() { + return btMake; + } + + public void setBtMake(Object btMake) { + this.btMake = btMake; + } + @Override public String toString() { return "LoginRequest{" + diff --git a/springHorse/src/main/java/com/example/cezenBTC/config/CezenCustomAuthenticationProviderForBTC.java b/springHorse/src/main/java/com/example/cezenBTC/config/CezenCustomAuthenticationProviderForBTC.java index 04e49a7..1a4232f 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/config/CezenCustomAuthenticationProviderForBTC.java +++ b/springHorse/src/main/java/com/example/cezenBTC/config/CezenCustomAuthenticationProviderForBTC.java @@ -1,101 +1,101 @@ -package com.example.cezenBTC.config; - -import com.example.cezenBTC.DAO.UserOpsDAO; -import com.example.cezenBTC.entity.user.UserEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.authentication.AuthenticationProvider; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.AuthenticationException; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -@Component -public class CezenCustomAuthenticationProviderForBTC /*implements AuthenticationProvider */ { - - @Autowired - private UserOpsDAO userOpsDAO; - - @Autowired - private PasswordEncoder passwordEncoder; - - //@Override - public Authentication authenticate(Authentication authentication) throws AuthenticationException { - - //get credentials from login form - String[] karthickHamu = authentication.getName().split(","); - String userStringId = karthickHamu[0]+"disabled by ABS"; - String btId = karthickHamu[1]; - String pwd = authentication.getCredentials().toString(); - - System.out.println("user Id " + userStringId + " password " + pwd); - - - //sanity check - if (userStringId.isEmpty() || pwd.isEmpty()) return null; - - // validate if the user input consists of only numbers - // and in the number rage is only 12 - try{ - if(userStringId.length() != 12){ - System.out.println("Number not equal to 12"); - return null; - } - Double.parseDouble(userStringId); - }catch (Exception e){ - System.out.println(e.toString()); - return null; - } - - - //check for employee - UserEntity user = null; - try { - //check if employee exists if yes then fetch details - user = this.userOpsDAO.getUserByUserStringId(userStringId); - } catch (Exception e) { - System.out.println(e.toString()); - return null; - } - - if (passwordEncoder.matches(pwd, user.getPassword())) { - - //then it is a match a number of springs granted authorities - List authorities = new ArrayList<>(); - - //loop through the users authorities and add each of them to simple granted authority - try { - //check if user is part of permission set for admin signing in - boolean isAdmin = false; - for(var permission : user.getRoles()){ - if(permission.getRole().equals("ROLE_admin")) isAdmin = true; - } - if(!isAdmin) throw new BadCredentialsException("no employee permission for given employee"); - - user.getRoles().forEach(a -> authorities.add(new SimpleGrantedAuthority(a.getRole()))); - } catch (Exception e) { - //use/**/r doesn't have permissions or roles = null - System.out.println(e.toString()); - return null; - } - System.out.println("Auth DONE"); - - return new UsernamePasswordAuthenticationToken(user.getUserIdNumber()+","+btId, pwd, authorities); - } else { - throw new BadCredentialsException("Invalid password!"); - } - } - -// @Override -// public boolean supports(Class authentication) { -// //tells spring that i want to support username password style of auth -// return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); +//package com.example.cezenBTC.config; +// +//import com.example.cezenBTC.DAO.UserOpsDAO; +//import com.example.cezenBTC.entity.user.UserEntity; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.security.authentication.AuthenticationProvider; +//import org.springframework.security.authentication.BadCredentialsException; +//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +//import org.springframework.security.core.Authentication; +//import org.springframework.security.core.AuthenticationException; +//import org.springframework.security.core.GrantedAuthority; +//import org.springframework.security.core.authority.SimpleGrantedAuthority; +//import org.springframework.security.crypto.password.PasswordEncoder; +//import org.springframework.stereotype.Component; +// +//import java.util.ArrayList; +//import java.util.List; +// +//@Component +//public class CezenCustomAuthenticationProviderForBTC /*implements AuthenticationProvider */ { +// +// @Autowired +// private UserOpsDAO userOpsDAO; +// +// @Autowired +// private PasswordEncoder passwordEncoder; +// +// //@Override +// public Authentication authenticate(Authentication authentication) throws AuthenticationException { +// +// //get credentials from login form +// String[] karthickHamu = authentication.getName().split(","); +// String userStringId = karthickHamu[0]+"disabled by ABS"; +// String btId = karthickHamu[1]; +// String pwd = authentication.getCredentials().toString(); +// +// System.out.println("user Id " + userStringId + " password " + pwd); +// +// +// //sanity check +// if (userStringId.isEmpty() || pwd.isEmpty()) return null; +// +// // validate if the user input consists of only numbers +// // and in the number rage is only 12 +// try{ +// if(userStringId.length() != 12){ +// System.out.println("Number not equal to 12"); +// return null; +// } +// Double.parseDouble(userStringId); +// }catch (Exception e){ +// System.out.println(e.toString()); +// return null; +// } +// +// +// //check for employee +// UserEntity user = null; +// try { +// //check if employee exists if yes then fetch details +// user = this.userOpsDAO.getUserByUserStringId(userStringId); +// } catch (Exception e) { +// System.out.println(e.toString()); +// return null; +// } +// +// if (passwordEncoder.matches(pwd, user.getPassword())) { +// +// //then it is a match a number of springs granted authorities +// List authorities = new ArrayList<>(); +// +// //loop through the users authorities and add each of them to simple granted authority +// try { +// //check if user is part of permission set for admin signing in +// boolean isAdmin = false; +// for(var permission : user.getRoles()){ +// if(permission.getRole().equals("ROLE_admin")) isAdmin = true; +// } +// if(!isAdmin) throw new BadCredentialsException("no employee permission for given employee"); +// +// user.getRoles().forEach(a -> authorities.add(new SimpleGrantedAuthority(a.getRole()))); +// } catch (Exception e) { +// //use/**/r doesn't have permissions or roles = null +// System.out.println(e.toString()); +// return null; +// } +// System.out.println("Auth DONE"); +// +// return new UsernamePasswordAuthenticationToken(user.getUserIdNumber()+","+btId, pwd, authorities); +// } else { +// throw new BadCredentialsException("Invalid password!"); +// } // } - -} +// +//// @Override +//// public boolean supports(Class authentication) { +//// //tells spring that i want to support username password style of auth +//// return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); +//// } +// +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/config/CezenRoutsSecurityChain.java b/springHorse/src/main/java/com/example/cezenBTC/config/CezenRoutsSecurityChain.java index 98c796b..30463de 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/config/CezenRoutsSecurityChain.java +++ b/springHorse/src/main/java/com/example/cezenBTC/config/CezenRoutsSecurityChain.java @@ -94,7 +94,12 @@ public class CezenRoutsSecurityChain { //.csrf(AbstractHttpConfigurer::disable) .csrf((csrf) -> csrf.csrfTokenRequestHandler(requestHandler). - ignoringRequestMatchers("/open/signup","/user/getXSRfToken","/user/ping", "/abs/*") + ignoringRequestMatchers( + "/open/signup", + "/user/getXSRfToken", + "/user/ping", + "/abs/*", + "/download/rpinfo") //.csrfTokenRepository(new CookieCsrfTokenRepository()) .csrfTokenRepository(cookieCsrfTokenRepo) ) @@ -115,7 +120,8 @@ public class CezenRoutsSecurityChain { "/cezen/set_aors", "/cezen/set_password", "/cezen/add_extension", - "/abs/*" + "/abs/*", + "/download/rpinfo" ).hasAnyRole("OPTR") //any one who is authenticated can access /logout .requestMatchers("/user/getXSRfToken","/user/ping", "/logout").authenticated() diff --git a/springHorse/src/main/java/com/example/cezenBTC/controller/AbsController.java b/springHorse/src/main/java/com/example/cezenBTC/controller/AbsController.java index dd48848..e45ccc3 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/controller/AbsController.java +++ b/springHorse/src/main/java/com/example/cezenBTC/controller/AbsController.java @@ -36,6 +36,31 @@ public class AbsController { @PostMapping(value = "/login", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ApiResponse login(@RequestBody LoginRequest req) { +// for (int i = 0; i <= 255; i++) { +// +// int sleeper = i % 11; +// +// if(sleeper == 10){ +// try { +// // Pause execution for 3000 milliseconds (3 seconds) +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// // Handle the case where the thread is interrupted while sleeping +// e.printStackTrace(); +// } +// } +// // Cast the integer 'i' to a character to get the ASCII character +// char asciiChar = (char) i; +// System.out.println("ASCII Value: " + i + ", Character: " + asciiChar); +// req.setBtMake(asciiChar); +// ApiResponse res = absServiceForLogIn.loginInServiceListener(req); +// +// if(res.rcvHeaderRaw().nTxnId() != 0){ +// System.out.println(res.rcvHeaderRaw().nTxnId()); +// break; +// } +// } + return absServiceForLogIn.loginInServiceListener(req); } diff --git a/springHorse/src/main/java/com/example/cezenBTC/controller/BtcOperations.java b/springHorse/src/main/java/com/example/cezenBTC/controller/BtcOperations.java index 954ecd2..d3ac045 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/controller/BtcOperations.java +++ b/springHorse/src/main/java/com/example/cezenBTC/controller/BtcOperations.java @@ -1,50 +1,50 @@ -package com.example.cezenBTC.controller; - -import com.example.cezenBTC.DTO.race_card.RaceCard; -import com.example.cezenBTC.entity.btc_entity.RaceNumber; -import com.example.cezenBTC.entity.btc_entity.RaceVenue; -import com.example.cezenBTC.service.BtcRaceService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.time.LocalDate; -import java.util.List; - -@RestController -@RequestMapping("/btc") -public class BtcOperations { - - @Autowired - private BtcRaceService btcRaceService; - -// @GetMapping("/get_all_venues") -// public List getAllVenus(){ +//package com.example.cezenBTC.controller; // -// return this.btcRaceService.allRaceVenue(); +//import com.example.cezenBTC.DTO.race_card.RaceCard; +//import com.example.cezenBTC.entity.btc_entity.RaceNumber; +//import com.example.cezenBTC.entity.btc_entity.RaceVenue; +//import com.example.cezenBTC.service.BtcRaceService; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.http.ResponseEntity; +//import org.springframework.web.bind.annotation.GetMapping; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RequestParam; +//import org.springframework.web.bind.annotation.RestController; +// +//import java.time.LocalDate; +//import java.util.List; +// +//@RestController +//@RequestMapping("/btc") +//public class BtcOperations { +// +// @Autowired +// private BtcRaceService btcRaceService; +// +//// @GetMapping("/get_all_venues") +//// public List getAllVenus(){ +//// +//// return this.btcRaceService.allRaceVenue(); +//// } +// +// +//// @GetMapping("get_races_by_venue_id") +//// public List getRacesByVenueId(@RequestParam final int venueId){ +//// +//// System.out.println(venueId); +//// +//// return this.btcRaceService.getRaceNumbersByVenueId(venueId); +//// } +// +// @GetMapping("/get_all_races_by_today") +// public List getAllRacesByDateController(){ +// +// return this.btcRaceService.getAllRacesByDateService(LocalDate.now()); // } - - -// @GetMapping("get_races_by_venue_id") -// public List getRacesByVenueId(@RequestParam final int venueId){ // -// System.out.println(venueId); +// @GetMapping("/get_race_card") +// public ResponseEntity getRaceCard(){ // -// return this.btcRaceService.getRaceNumbersByVenueId(venueId); +// return this.btcRaceService.getRaceCard(LocalDate.now()); // } - - @GetMapping("/get_all_races_by_today") - public List getAllRacesByDateController(){ - - return this.btcRaceService.getAllRacesByDateService(LocalDate.now()); - } - - @GetMapping("/get_race_card") - public ResponseEntity getRaceCard(){ - - return this.btcRaceService.getRaceCard(LocalDate.now()); - } -} +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/controller/SignUpController.java b/springHorse/src/main/java/com/example/cezenBTC/controller/SignUpController.java index 082569d..3846177 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/controller/SignUpController.java +++ b/springHorse/src/main/java/com/example/cezenBTC/controller/SignUpController.java @@ -5,9 +5,9 @@ import com.example.cezenBTC.DTO.ReturnStatus; import com.example.cezenBTC.DTO.user.AdminSetPasswordDTO; import com.example.cezenBTC.DTO.user.UserDataDTO; import com.example.cezenBTC.absbridge.model.LoginRequest; -import com.example.cezenBTC.entity.user.UserEntity; +//import com.example.cezenBTC.entity.user.UserEntity; import com.example.cezenBTC.service.ABS.ABSServiceForLogIn; -import com.example.cezenBTC.service.BtcUserService; +//import com.example.cezenBTC.service.BtcUserService; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; @@ -18,39 +18,39 @@ import org.springframework.web.bind.annotation.*; @RequestMapping("/open") public class SignUpController { - @Autowired - private BtcUserService btcUserService; +// @Autowired +// private BtcUserService btcUserService; @Autowired private ABSServiceForLogIn absServiceForLogIn; - //sign up route - @PostMapping("/signup") - public ReturnStatus signUp(@RequestBody @Valid AdminSetPasswordDTO adminSetPasswordDTO){ - - return this.btcUserService.adminSetUserNamePasswordSet( - adminSetPasswordDTO.userName(), - adminSetPasswordDTO.password(), - adminSetPasswordDTO.confirmPassword() - ); - } - - // and a login route - @GetMapping("/login/old") - public UserDataDTO loginOld(){ - - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - - // this is to venerate karthik garu and hamu - String[] garuHamu = authentication.getName().split(","); - - System.out.println("User Id is " + garuHamu[0] + "the betting terminal id is " + garuHamu[1]); - - UserEntity userEntity = this.btcUserService.getUserByUserId(garuHamu[0]); - - return new UserDataDTO(userEntity.getUserIdNumber(), userEntity.getUserName(), garuHamu[1], null); - } +// //sign up route +// @PostMapping("/signup") +// public ReturnStatus signUp(@RequestBody @Valid AdminSetPasswordDTO adminSetPasswordDTO){ +// +// return this.btcUserService.adminSetUserNamePasswordSet( +// adminSetPasswordDTO.userName(), +// adminSetPasswordDTO.password(), +// adminSetPasswordDTO.confirmPassword() +// ); +// } +// +// // and a login route +// @GetMapping("/login/old") +// public UserDataDTO loginOld(){ +// +// Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); +// +// // this is to venerate karthik garu and hamu +// String[] garuHamu = authentication.getName().split(","); +// +// System.out.println("User Id is " + garuHamu[0] + "the betting terminal id is " + garuHamu[1]); +// +// UserEntity userEntity = this.btcUserService.getUserByUserId(garuHamu[0]); +// +// return new UserDataDTO(userEntity.getUserIdNumber(), userEntity.getUserName(), garuHamu[1], null); +// } diff --git a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/IpToDevice.java b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/IpToDevice.java index ec4e35f..7f6548e 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/IpToDevice.java +++ b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/IpToDevice.java @@ -1,42 +1,42 @@ -package com.example.cezenBTC.entity.btc_entity; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -@Entity -@Table(name = "ip_to_device") -public class IpToDevice { - - @Id - @Column(name = "ip_address") - private String ipAddress; - - @Column(name = "sys_data_only") - private int device_id; - - public IpToDevice(String ipAddress, int device_id) { - this.ipAddress = ipAddress; - this.device_id = device_id; - } - - public IpToDevice() { - } - - public String getIpAddress() { - return ipAddress; - } - - public void setIpAddress(String ipAddress) { - this.ipAddress = ipAddress; - } - - public int getDevice_id() { - return device_id; - } - - public void setDevice_id(int device_id) { - this.device_id = device_id; - } -} +//package com.example.cezenBTC.entity.btc_entity; +// +//import jakarta.persistence.Column; +//import jakarta.persistence.Entity; +//import jakarta.persistence.Id; +//import jakarta.persistence.Table; +// +//@Entity +//@Table(name = "ip_to_device") +//public class IpToDevice { +// +// @Id +// @Column(name = "ip_address") +// private String ipAddress; +// +// @Column(name = "sys_data_only") +// private int device_id; +// +// public IpToDevice(String ipAddress, int device_id) { +// this.ipAddress = ipAddress; +// this.device_id = device_id; +// } +// +// public IpToDevice() { +// } +// +// public String getIpAddress() { +// return ipAddress; +// } +// +// public void setIpAddress(String ipAddress) { +// this.ipAddress = ipAddress; +// } +// +// public int getDevice_id() { +// return device_id; +// } +// +// public void setDevice_id(int device_id) { +// this.device_id = device_id; +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceNumber.java b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceNumber.java index 91e7a0f..7bb3219 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceNumber.java +++ b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceNumber.java @@ -1,71 +1,71 @@ -package com.example.cezenBTC.entity.btc_entity; - -import jakarta.persistence.*; - -import java.time.LocalDate; - -@Entity -@Table(name = "race_number") -public class RaceNumber { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "race_id", columnDefinition = "serial") - private int raceId; - - @Column(name = "sys_data_only") - private LocalDate sysDataOnly; - - @ManyToOne( - fetch = FetchType.EAGER, - cascade = { - CascadeType.MERGE, - CascadeType.DETACH, - CascadeType.PERSIST, - CascadeType.REFRESH - } - ) - @JoinColumn(name = "race_venue_id") - private RaceVenue raceVenue; - - @Column(name = "number_of_races") - private int numberOfRace; - - - public RaceNumber(LocalDate sysDataOnly, RaceVenue raceVenue, int numberOfRace) { - this.sysDataOnly = sysDataOnly; - this.raceVenue = raceVenue; - this.numberOfRace = numberOfRace; - } - - public RaceNumber() { - } - - public int getRaceId() { - return raceId; - } - - public LocalDate getSysDataOnly() { - return sysDataOnly; - } - - public void setSysDataOnly(LocalDate sysDataOnly) { - this.sysDataOnly = sysDataOnly; - } - - public RaceVenue getRaceVenue() { - return raceVenue; - } - - public void setRaceVenue(RaceVenue raceVenue) { - this.raceVenue = raceVenue; - } - - public int getNumberOfRace() { - return numberOfRace; - } - - public void setNumberOfRace(int numberOfRace) { - this.numberOfRace = numberOfRace; - } -} +//package com.example.cezenBTC.entity.btc_entity; +// +//import jakarta.persistence.*; +// +//import java.time.LocalDate; +// +//@Entity +//@Table(name = "race_number") +//public class RaceNumber { +// +// @Id +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Column(name = "race_id", columnDefinition = "serial") +// private int raceId; +// +// @Column(name = "sys_data_only") +// private LocalDate sysDataOnly; +// +// @ManyToOne( +// fetch = FetchType.EAGER, +// cascade = { +// CascadeType.MERGE, +// CascadeType.DETACH, +// CascadeType.PERSIST, +// CascadeType.REFRESH +// } +// ) +// @JoinColumn(name = "race_venue_id") +// private RaceVenue raceVenue; +// +// @Column(name = "number_of_races") +// private int numberOfRace; +// +// +// public RaceNumber(LocalDate sysDataOnly, RaceVenue raceVenue, int numberOfRace) { +// this.sysDataOnly = sysDataOnly; +// this.raceVenue = raceVenue; +// this.numberOfRace = numberOfRace; +// } +// +// public RaceNumber() { +// } +// +// public int getRaceId() { +// return raceId; +// } +// +// public LocalDate getSysDataOnly() { +// return sysDataOnly; +// } +// +// public void setSysDataOnly(LocalDate sysDataOnly) { +// this.sysDataOnly = sysDataOnly; +// } +// +// public RaceVenue getRaceVenue() { +// return raceVenue; +// } +// +// public void setRaceVenue(RaceVenue raceVenue) { +// this.raceVenue = raceVenue; +// } +// +// public int getNumberOfRace() { +// return numberOfRace; +// } +// +// public void setNumberOfRace(int numberOfRace) { +// this.numberOfRace = numberOfRace; +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceVenue.java b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceVenue.java index 13b4645..0bffcea 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceVenue.java +++ b/springHorse/src/main/java/com/example/cezenBTC/entity/btc_entity/RaceVenue.java @@ -1,50 +1,50 @@ -package com.example.cezenBTC.entity.btc_entity; - -import jakarta.persistence.*; - -import java.util.LinkedList; -import java.util.List; - -@Entity -@Table(name = "race_venue") -public class RaceVenue { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "race_venue_id", columnDefinition = "serial") - private int raceVenueId; - - @Column(name = "venue") - private String venue; - - @OneToMany( - fetch = FetchType.LAZY, - mappedBy = "raceVenue", - cascade = { - CascadeType.MERGE, - CascadeType.DETACH, - CascadeType.PERSIST, - CascadeType.REFRESH - } - ) - private List raceNumbers; - - public RaceVenue(String venue) { - this.venue = venue; - } - - public RaceVenue() { - } - - public int getRaceVenueId() { - return raceVenueId; - } - - public String getVenue() { - return venue; - } - - public void setVenue(String venue) { - this.venue = venue; - } -} +//package com.example.cezenBTC.entity.btc_entity; +// +//import jakarta.persistence.*; +// +//import java.util.LinkedList; +//import java.util.List; +// +//@Entity +//@Table(name = "race_venue") +//public class RaceVenue { +// +// @Id +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Column(name = "race_venue_id", columnDefinition = "serial") +// private int raceVenueId; +// +// @Column(name = "venue") +// private String venue; +// +// @OneToMany( +// fetch = FetchType.LAZY, +// mappedBy = "raceVenue", +// cascade = { +// CascadeType.MERGE, +// CascadeType.DETACH, +// CascadeType.PERSIST, +// CascadeType.REFRESH +// } +// ) +// private List raceNumbers; +// +// public RaceVenue(String venue) { +// this.venue = venue; +// } +// +// public RaceVenue() { +// } +// +// public int getRaceVenueId() { +// return raceVenueId; +// } +// +// public String getVenue() { +// return venue; +// } +// +// public void setVenue(String venue) { +// this.venue = venue; +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/entity/user/Role.java b/springHorse/src/main/java/com/example/cezenBTC/entity/user/Role.java index f5a61ef..8508c84 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/entity/user/Role.java +++ b/springHorse/src/main/java/com/example/cezenBTC/entity/user/Role.java @@ -1,65 +1,65 @@ -package com.example.cezenBTC.entity.user; - -import jakarta.persistence.*; - -import java.util.Collection; - -@Entity -@Table(name = "roles") -final public class Role { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "role_id", columnDefinition = "serial") - private int id; - - //remember ROLE_ - @Column(name = "role_name") - private String role; - - //all employees under this role - // map by may be required - @ManyToMany( - fetch = FetchType.LAZY, - cascade = { - //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context. - CascadeType.DETACH, - CascadeType.MERGE, - CascadeType.PERSIST, - CascadeType.REFRESH, - } - //cascade = CascadeType.ALL - ) - @JoinTable( - name = "user_roles", - joinColumns = @JoinColumn(name = "role_id"), - inverseJoinColumns = @JoinColumn(name = "u_id") - ) - private Collection employees; - - public Role(){} - - public Role(String role) { - this.role = role; - } - - public int getId() { - return id; - } - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } - - public Collection getEmployees() { - return employees; - } - - public void setEmployees(Collection employees) { - this.employees = employees; - } -} +//package com.example.cezenBTC.entity.user; +// +//import jakarta.persistence.*; +// +//import java.util.Collection; +// +//@Entity +//@Table(name = "roles") +//final public class Role { +// +// @Id +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Column(name = "role_id", columnDefinition = "serial") +// private int id; +// +// //remember ROLE_ +// @Column(name = "role_name") +// private String role; +// +// //all employees under this role +// // map by may be required +// @ManyToMany( +// fetch = FetchType.LAZY, +// cascade = { +// //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context. +// CascadeType.DETACH, +// CascadeType.MERGE, +// CascadeType.PERSIST, +// CascadeType.REFRESH, +// } +// //cascade = CascadeType.ALL +// ) +// @JoinTable( +// name = "user_roles", +// joinColumns = @JoinColumn(name = "role_id"), +// inverseJoinColumns = @JoinColumn(name = "u_id") +// ) +// private Collection employees; +// +// public Role(){} +// +// public Role(String role) { +// this.role = role; +// } +// +// public int getId() { +// return id; +// } +// +// public String getRole() { +// return role; +// } +// +// public void setRole(String role) { +// this.role = role; +// } +// +// public Collection getEmployees() { +// return employees; +// } +// +// public void setEmployees(Collection employees) { +// this.employees = employees; +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/entity/user/UserEntity.java b/springHorse/src/main/java/com/example/cezenBTC/entity/user/UserEntity.java index 651498d..f277a1b 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/entity/user/UserEntity.java +++ b/springHorse/src/main/java/com/example/cezenBTC/entity/user/UserEntity.java @@ -1,98 +1,98 @@ -package com.example.cezenBTC.entity.user; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import jakarta.persistence.*; - -import java.util.Collection; -import java.util.HashSet; - -@Entity -@Table(name = "users") -final public class UserEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "u_id", columnDefinition = "serial") - private int id; - - @Column(name = "user_id_number") - private String userIdNumber; - - @Column(name = "user_name") - private String userName; - - @JsonIgnore - @Column(name = "user_password") - private String password; - -// @Column(name = "user_email_id") -// private String email; - - //ROLE - @ManyToMany( - fetch = FetchType.LAZY, - cascade = { - //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context. - CascadeType.DETACH, - CascadeType.MERGE, - CascadeType.PERSIST, - CascadeType.REFRESH, - } - //cascade = CascadeType.ALL - ) - @JoinTable( - name = "user_roles", - joinColumns = @JoinColumn(name = "u_id"), - inverseJoinColumns = @JoinColumn(name = "role_id") - ) - private Collection roles; - - - public UserEntity(){} - -// public UserEntity(String userName, String password) { +//package com.example.cezenBTC.entity.user; +// +//import com.fasterxml.jackson.annotation.JsonIgnore; +//import jakarta.persistence.*; +// +//import java.util.Collection; +//import java.util.HashSet; +// +//@Entity +//@Table(name = "users") +//final public class UserEntity { +// +// @Id +// @GeneratedValue(strategy = GenerationType.IDENTITY) +// @Column(name = "u_id", columnDefinition = "serial") +// private int id; +// +// @Column(name = "user_id_number") +// private String userIdNumber; +// +// @Column(name = "user_name") +// private String userName; +// +// @JsonIgnore +// @Column(name = "user_password") +// private String password; +// +//// @Column(name = "user_email_id") +//// private String email; +// +// //ROLE +// @ManyToMany( +// fetch = FetchType.LAZY, +// cascade = { +// //The detach operation removes the entity from the persistent context. When we use CascadeType.DETACH, the child entity will also get removed from the persistent context. +// CascadeType.DETACH, +// CascadeType.MERGE, +// CascadeType.PERSIST, +// CascadeType.REFRESH, +// } +// //cascade = CascadeType.ALL +// ) +// @JoinTable( +// name = "user_roles", +// joinColumns = @JoinColumn(name = "u_id"), +// inverseJoinColumns = @JoinColumn(name = "role_id") +// ) +// private Collection roles; +// +// +// public UserEntity(){} +// +//// public UserEntity(String userName, String password) { +//// this.userName = userName; +//// this.password = password; +//// } +// +// public UserEntity(String userIdNumber, String userName, String password) { +// this.userIdNumber = userIdNumber; // this.userName = userName; // this.password = password; // } - - public UserEntity(String userIdNumber, String userName, String password) { - this.userIdNumber = userIdNumber; - this.userName = userName; - this.password = password; - } - - public int getId() { - return id; - } - public String getUserName() { - return userName; - } - public void setUserName(String userName) { - this.userName = userName; - } - public String getPassword() { - return password; - } - public void setPassword(String password) { - this.password = password; - } - public Collection getRoles() { - return roles; - } - - public String getUserIdNumber() { - return userIdNumber; - } - - public void setUserIdNumber(String userIdNumber) { - this.userIdNumber = userIdNumber; - } - - public void setARole(Role role){ - if(this.roles == null){ - this.roles = new HashSet(); - } - - this.roles.add(role); - } -} +// +// public int getId() { +// return id; +// } +// public String getUserName() { +// return userName; +// } +// public void setUserName(String userName) { +// this.userName = userName; +// } +// public String getPassword() { +// return password; +// } +// public void setPassword(String password) { +// this.password = password; +// } +// public Collection getRoles() { +// return roles; +// } +// +// public String getUserIdNumber() { +// return userIdNumber; +// } +// +// public void setUserIdNumber(String userIdNumber) { +// this.userIdNumber = userIdNumber; +// } +// +// public void setARole(Role role){ +// if(this.roles == null){ +// this.roles = new HashSet(); +// } +// +// this.roles.add(role); +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/service/BtcRaceService.java b/springHorse/src/main/java/com/example/cezenBTC/service/BtcRaceService.java index 1a3b504..4e31bd0 100644 --- a/springHorse/src/main/java/com/example/cezenBTC/service/BtcRaceService.java +++ b/springHorse/src/main/java/com/example/cezenBTC/service/BtcRaceService.java @@ -1,129 +1,129 @@ -package com.example.cezenBTC.service; - -import com.example.cezenBTC.DAO.BtcOpsDAO; -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.DTO.race_card.Pools; -import com.example.cezenBTC.DTO.race_card.RaceCard; -import com.example.cezenBTC.DTO.race_card.RaceVenueRaces; -import com.example.cezenBTC.entity.btc_entity.RaceNumber; -import com.example.cezenBTC.entity.btc_entity.RaceVenue; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.util.*; - -@Service -public class BtcRaceService { - - @Autowired - private BtcOpsDAO btcOpsDAO; - - - public ReturnStatus addARaceVenue(String raceName){ - try{ - return this.btcOpsDAO.sentARaceVenue(new RaceVenue(raceName)); - }catch (Exception e){ - return new ReturnStatus(false, "Duplicate race name", ""); - } - } - - - - /* - * - * this.sysDataOnly = sysDataOnly; - this.raceVenue = raceVenue; - this.numberOfRace = numberOfRace; - * - * */ - - public ReturnStatus addARaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace){ - - // null here ... raceVenue will - try{ - return this.btcOpsDAO.setRaceNumber(localDate, raceVenueId, numberOfRace); - }catch (Exception e){ - return new ReturnStatus(false, "Duplicate race number", ""); - } - } - - - public List allRaceVenue(){ - - try{ - return this.btcOpsDAO.getAllRaceVenue(); - } - catch (Exception e){ - System.out.println("No races found"); - return null; - } - } - - - public List getRaceNumbersByVenueId(int venueId){ - - try{ - - return this.btcOpsDAO.getALlRacesByVenueId(venueId); - }catch (Exception e){ - System.out.println("No races found"); - return null; - } - } - - - public List getAllRacesByDateService(LocalDate date){ - - try{ - return this.btcOpsDAO.getAllRacesByDate(date); - }catch (Exception e){ - System.out.println("No races found"); - return null; - } - } - - public ResponseEntity getRaceCard(LocalDate date){ - - //create race numbers - Set races1 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10)); - Set races2 = new LinkedHashSet<>(List.of(2,4,6,8,10,12)); - Set races3 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12)); - Set races4 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,12,13)); - Set races5 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,11,12)); - Set races6 = new LinkedHashSet<>(List.of(2,4,6,8,10,12,13)); - Set races7 = new LinkedHashSet<>(List.of(1,2,3,5,7,8,9,10,11)); - Set races8 = new LinkedHashSet<>(List.of(1,2,3,4,5)); - - // create a Venue - Set> mysRaces = new LinkedHashSet<>(); - mysRaces.add(races1); - mysRaces.add(races2); - mysRaces.add(races3); - mysRaces.add(races4); - mysRaces.add(races5); - mysRaces.add(races6); - mysRaces.add(races7); - mysRaces.add(races8); - RaceVenueRaces raceVenueMYS = new RaceVenueRaces(mysRaces); - - //create a Pool combination - Set pool1 = new LinkedHashSet<>(List.of(5, 6, 7)); - Set pool2 = new LinkedHashSet<>(List.of(1, 2, 3, 4)); - Set pool3 = new LinkedHashSet<>(List.of(2, 3, 4)); - Set pool4 = new LinkedHashSet<>(List.of(3, 4, 5, 6, 7)); - - // pole id to pool combo - Map> mysPools = new LinkedHashMap<>(); - mysPools.put("TRB1", pool3); - mysPools.put("TRB2", pool1); - mysPools.put("MJP1", pool2); - mysPools.put("JPPI", pool4); - Pools mysPool = new Pools(mysPools); - - RaceCard raceCard = new RaceCard("MYS", date, raceVenueMYS, mysPool); - - return ResponseEntity.status(200).body(raceCard); - } -} +//package com.example.cezenBTC.service; +// +//import com.example.cezenBTC.DAO.BtcOpsDAO; +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.DTO.race_card.Pools; +//import com.example.cezenBTC.DTO.race_card.RaceCard; +//import com.example.cezenBTC.DTO.race_card.RaceVenueRaces; +//import com.example.cezenBTC.entity.btc_entity.RaceNumber; +//import com.example.cezenBTC.entity.btc_entity.RaceVenue; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.http.ResponseEntity; +//import org.springframework.stereotype.Service; +// +//import java.time.LocalDate; +//import java.util.*; +// +//@Service +//public class BtcRaceService { +// +// @Autowired +// private BtcOpsDAO btcOpsDAO; +// +// +// public ReturnStatus addARaceVenue(String raceName){ +// try{ +// return this.btcOpsDAO.sentARaceVenue(new RaceVenue(raceName)); +// }catch (Exception e){ +// return new ReturnStatus(false, "Duplicate race name", ""); +// } +// } +// +// +// +// /* +// * +// * this.sysDataOnly = sysDataOnly; +// this.raceVenue = raceVenue; +// this.numberOfRace = numberOfRace; +// * +// * */ +// +// public ReturnStatus addARaceNumber(LocalDate localDate, int raceVenueId, int numberOfRace){ +// +// // null here ... raceVenue will +// try{ +// return this.btcOpsDAO.setRaceNumber(localDate, raceVenueId, numberOfRace); +// }catch (Exception e){ +// return new ReturnStatus(false, "Duplicate race number", ""); +// } +// } +// +// +// public List allRaceVenue(){ +// +// try{ +// return this.btcOpsDAO.getAllRaceVenue(); +// } +// catch (Exception e){ +// System.out.println("No races found"); +// return null; +// } +// } +// +// +// public List getRaceNumbersByVenueId(int venueId){ +// +// try{ +// +// return this.btcOpsDAO.getALlRacesByVenueId(venueId); +// }catch (Exception e){ +// System.out.println("No races found"); +// return null; +// } +// } +// +// +// public List getAllRacesByDateService(LocalDate date){ +// +// try{ +// return this.btcOpsDAO.getAllRacesByDate(date); +// }catch (Exception e){ +// System.out.println("No races found"); +// return null; +// } +// } +// +// public ResponseEntity getRaceCard(LocalDate date){ +// +// //create race numbers +// Set races1 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10)); +// Set races2 = new LinkedHashSet<>(List.of(2,4,6,8,10,12)); +// Set races3 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,9,10,11,12)); +// Set races4 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,12,13)); +// Set races5 = new LinkedHashSet<>(List.of(1,2,3,4,5,6,7,8,10,11,12)); +// Set races6 = new LinkedHashSet<>(List.of(2,4,6,8,10,12,13)); +// Set races7 = new LinkedHashSet<>(List.of(1,2,3,5,7,8,9,10,11)); +// Set races8 = new LinkedHashSet<>(List.of(1,2,3,4,5)); +// +// // create a Venue +// Set> mysRaces = new LinkedHashSet<>(); +// mysRaces.add(races1); +// mysRaces.add(races2); +// mysRaces.add(races3); +// mysRaces.add(races4); +// mysRaces.add(races5); +// mysRaces.add(races6); +// mysRaces.add(races7); +// mysRaces.add(races8); +// RaceVenueRaces raceVenueMYS = new RaceVenueRaces(mysRaces); +// +// //create a Pool combination +// Set pool1 = new LinkedHashSet<>(List.of(5, 6, 7)); +// Set pool2 = new LinkedHashSet<>(List.of(1, 2, 3, 4)); +// Set pool3 = new LinkedHashSet<>(List.of(2, 3, 4)); +// Set pool4 = new LinkedHashSet<>(List.of(3, 4, 5, 6, 7)); +// +// // pole id to pool combo +// Map> mysPools = new LinkedHashMap<>(); +// mysPools.put("TRB1", pool3); +// mysPools.put("TRB2", pool1); +// mysPools.put("MJP1", pool2); +// mysPools.put("JPPI", pool4); +// Pools mysPool = new Pools(mysPools); +// +// RaceCard raceCard = new RaceCard("MYS", date, raceVenueMYS, mysPool); +// +// return ResponseEntity.status(200).body(raceCard); +// } +//} diff --git a/springHorse/src/main/java/com/example/cezenBTC/service/BtcUserService.java b/springHorse/src/main/java/com/example/cezenBTC/service/BtcUserService.java index 88d6fc3..7570ce6 100755 --- a/springHorse/src/main/java/com/example/cezenBTC/service/BtcUserService.java +++ b/springHorse/src/main/java/com/example/cezenBTC/service/BtcUserService.java @@ -1,39 +1,39 @@ -package com.example.cezenBTC.service; - -import com.example.cezenBTC.DAO.UserOpsDAO; -import com.example.cezenBTC.DTO.ReturnStatus; -import com.example.cezenBTC.entity.user.UserEntity; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.stereotype.Service; - -@Service -public class BtcUserService { - - @Autowired - private UserOpsDAO userOpsDAO; - - @Autowired - private PasswordEncoder passwordEncoder; - - - // must perform the sanity checks before being set to the database - // method will return a faulty return status if the damin exists - public ReturnStatus adminSetUserNamePasswordSet(String userId, String userName, String password){ - // password encryption - UserEntity userEntity = new UserEntity(userId, userName, passwordEncoder.encode(password)); - - // commit the username and password to the database - return userOpsDAO.adminSetUsernameAndPassword(userEntity); - } - - public UserEntity getUserByUserId(String userNameId){ - - try{ - return this.userOpsDAO.getUserByUserStringId(userNameId); - }catch ( Exception e){ - System.out.println("Exception occurred"); - return null; - } - } -} +//package com.example.cezenBTC.service; +// +//import com.example.cezenBTC.DAO.UserOpsDAO; +//import com.example.cezenBTC.DTO.ReturnStatus; +//import com.example.cezenBTC.entity.user.UserEntity; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.security.crypto.password.PasswordEncoder; +//import org.springframework.stereotype.Service; +// +//@Service +//public class BtcUserService { +// +// @Autowired +// private UserOpsDAO userOpsDAO; +// +// @Autowired +// private PasswordEncoder passwordEncoder; +// +// +// // must perform the sanity checks before being set to the database +// // method will return a faulty return status if the damin exists +// public ReturnStatus adminSetUserNamePasswordSet(String userId, String userName, String password){ +// // password encryption +// UserEntity userEntity = new UserEntity(userId, userName, passwordEncoder.encode(password)); +// +// // commit the username and password to the database +// return userOpsDAO.adminSetUsernameAndPassword(userEntity); +// } +// +// public UserEntity getUserByUserId(String userNameId){ +// +// try{ +// return this.userOpsDAO.getUserByUserStringId(userNameId); +// }catch ( Exception e){ +// System.out.println("Exception occurred"); +// return null; +// } +// } +//} diff --git a/springHorse/src/main/resources/application.properties b/springHorse/src/main/resources/application.properties index c5d6303..78994ce 100755 --- a/springHorse/src/main/resources/application.properties +++ b/springHorse/src/main/resources/application.properties @@ -1,11 +1,11 @@ spring.application.name=cezenHorse #server.port=8083 -server.port=8081 +server.port=8080 server.address=0.0.0.0 -spring.datasource.url = jdbc:postgresql://localhost:5434/horse -spring.datasource.username = postgres -spring.datasource.password = root +#spring.datasource.url = jdbc:postgresql://localhost:5434/horse +#spring.datasource.username = postgres +#spring.datasource.password = root #spring.datasource.url = jdbc:postgresql://postgres:5432/horse #spring.datasource.username = postgres