diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..9f970225ad --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..262ce78997 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive", + "java.compile.nullAnalysis.mode": "disabled", + "java.configuration.runtimes": [], + "debug.javascript.defaultRuntimeExecutable": { + "pwa-node": "node" + } +} \ No newline at end of file diff --git a/Poseiden-skeleton/doc/data.sql b/Poseiden-skeleton/doc/data.sql index 569bdeb432..cfd4770da7 100644 --- a/Poseiden-skeleton/doc/data.sql +++ b/Poseiden-skeleton/doc/data.sql @@ -53,28 +53,27 @@ CREATE TABLE Trade ( ) CREATE TABLE CurvePoint ( - Id tinyint(4) NOT NULL AUTO_INCREMENT, + CurvePointId tinyint(4) NOT NULL AUTO_INCREMENT, CurveId tinyint, asOfDate TIMESTAMP, term DOUBLE , value DOUBLE , - creationDate TIMESTAMP , - - PRIMARY KEY (Id) + creationDate TIMESTAMP, + PRIMARY KEY(CurvePointId) ) CREATE TABLE Rating ( - Id tinyint(4) NOT NULL AUTO_INCREMENT, + RatingId tinyint(4) NOT NULL AUTO_INCREMENT, moodysRating VARCHAR(125), sandPRating VARCHAR(125), fitchRating VARCHAR(125), orderNumber tinyint, - PRIMARY KEY (Id) + PRIMARY KEY (RatingId) ) CREATE TABLE RuleName ( - Id tinyint(4) NOT NULL AUTO_INCREMENT, + RuleNameId tinyint(4) NOT NULL AUTO_INCREMENT, name VARCHAR(125), description VARCHAR(125), json VARCHAR(125), @@ -82,18 +81,18 @@ CREATE TABLE RuleName ( sqlStr VARCHAR(125), sqlPart VARCHAR(125), - PRIMARY KEY (Id) + PRIMARY KEY (RuleNameId) ) CREATE TABLE Users ( - Id tinyint(4) NOT NULL AUTO_INCREMENT, + UsersId tinyint(4) NOT NULL AUTO_INCREMENT, username VARCHAR(125), password VARCHAR(125), fullname VARCHAR(125), role VARCHAR(125), - PRIMARY KEY (Id) + PRIMARY KEY (UsersId) ) -insert into Users(fullname, username, password, role) values("Administrator", "admin", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "ADMIN") -insert into Users(fullname, username, password, role) values("User", "user", "$2a$10$pBV8ILO/s/nao4wVnGLrh.sa/rnr5pDpbeC4E.KNzQWoy8obFZdaa", "USER") \ No newline at end of file +insert into Users(fullname, username, password, role) values("Administrator", "admin", "$2a$10$6n4h0PROT81sEhthIcc5R.y6BonwFkdIgrKvrHY60oPfPpO040KyW", "ADMIN") +insert into Users(fullname, username, password, role) values("User", "user", "$2a$10$K1eHIGsrBTjgtJpv/zAxeeAxz0iua92iY7g/gN0YlxNVZusUb.lD.", "USER") \ No newline at end of file diff --git a/Poseiden-skeleton/pom.xml b/Poseiden-skeleton/pom.xml index 255c20c118..c2135c5169 100644 --- a/Poseiden-skeleton/pom.xml +++ b/Poseiden-skeleton/pom.xml @@ -12,59 +12,74 @@ spring-boot-skeleton Demo project for Spring Boot - - org.springframework.boot - spring-boot-starter-parent - 3.1.0 - - UTF-8 UTF-8 - 17 + 21 org.springframework.boot spring-boot-starter-test - 3.1.0 + 3.3.2 test + - org.springframework.boot - spring-boot-starter-data-jpa - 3.1.0 + org.springframework.boot + spring-boot-starter-data-jpa + 3.3.2 + + + - org.springframework.boot - spring-boot-starter-web - 3.1.0 + org.springframework.boot + spring-boot-starter-validation + 3.3.2 + + + + + org.projectlombok + lombok + 1.18.34 + provided + + + + org.springframework.boot + spring-boot-starter-web + 3.3.2 org.springframework.boot spring-boot-starter-thymeleaf + 3.3.2 org.springframework.boot spring-boot-starter-security - 3.1.0 + 3.3.2 org.springframework.boot spring-boot-devtools true - 3.1.0 - - - mysql - mysql-connector-java + 3.3.2 + com.h2database h2 + 2.3.230 + + diff --git a/Poseiden-skeleton/spring-boot-skeleton.iml b/Poseiden-skeleton/spring-boot-skeleton.iml deleted file mode 100644 index bac7aedc30..0000000000 --- a/Poseiden-skeleton/spring-boot-skeleton.iml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SecurityConfiguration.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SecurityConfiguration.java new file mode 100644 index 0000000000..fa2105fd1b --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/configurations/SecurityConfiguration.java @@ -0,0 +1,79 @@ +package com.nnk.springboot.configurations; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.ProviderManager; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; + +import com.nnk.springboot.domain.User; +import com.nnk.springboot.repositories.UserRepository; +import com.nnk.springboot.services.UserService; + +@Configuration +@EnableWebSecurity +public class SecurityConfiguration { + + private UserRepository userRepository; + //securing routes by authority + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http + + .csrf(csrf->csrf.disable()) + .authorizeHttpRequests(req->req + .requestMatchers("/admin/**").hasAuthority("ADMIN") + .requestMatchers("/bidList/list").hasAnyAuthority("ADMIN","USER") + .requestMatchers("/user/**").hasAnyAuthority("ADMIN") + .requestMatchers("/bidList/**").hasAuthority("USER") + .requestMatchers("/curvePoint/**").hasAuthority("USER") + .requestMatchers("/rating/**").hasAuthority("USER") + .requestMatchers("/ruleName/**").hasAuthority("USER") + .requestMatchers("/trade/**").hasAuthority("USER") + .requestMatchers("/css/**").permitAll() + .requestMatchers("/").hasAuthority("USER") + .anyRequest().denyAll()).formLogin(login->login.loginPage("/user/loginPage").permitAll() + .loginProcessingUrl("/login").usernameParameter("username").defaultSuccessUrl("/")) + .logout(logout->logout.logoutUrl("/app-logout").logoutSuccessUrl("/user/loginPage")) + .authenticationManager(authenticationProvider()); + return http.build(); + } + //configuring password encoder + @Bean + public PasswordEncoder passwordEncoder() { + + return new BCryptPasswordEncoder(); + } + //configuring authentication settings + @Bean + public ProviderManager authenticationProvider() { + + List authenticationProviderList = new ArrayList<>(); + DaoAuthenticationProvider daoAuthenticationProvider=new DaoAuthenticationProvider(); + daoAuthenticationProvider.setPasswordEncoder(passwordEncoder()); + daoAuthenticationProvider.setUserDetailsService(userService(userRepository)); + authenticationProviderList.add(daoAuthenticationProvider); + ProviderManager providerManager = new ProviderManager(authenticationProviderList); + return providerManager; + } + //adding initial admin user + //only admin can manage users + @Bean + public UserService userService(UserRepository userRepository) { + User user = new User(); + user.setFullname("Admin"); + user.setUsername("admin"); + user.setPassword("AbC45678"); + user.setRole("ADMIN"); + userRepository.save(user); + return new UserService(userRepository,user); + } +} diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java index a31b9b53ca..859e5c66cb 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/BidListController.java @@ -1,7 +1,15 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.BidList; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.BidListService; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; +import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.GetMapping; @@ -9,47 +17,106 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; - - +/** + * @author Nguyen Kim Anh + * @since 08/08/2023 + * @version 1.0 + */ @Controller +@RequestMapping("/bidList") +@RequiredArgsConstructor public class BidListController { - // TODO: Inject Bid service - @RequestMapping("/bidList/list") - public String home(Model model) - { - // TODO: call service find all bids to show to the view + /** + * Inject Bid service + */ + private final BidListService bidListService; + + /** + * Home page + * @param model + * @param user + * @return + */ + @GetMapping("/list") + public String home(Model model,@AuthenticationPrincipal User user) { + model.addAttribute("remoteUser", user.getUsername()); + model.addAttribute("bidLists", bidListService.findAll()); return "bidList/list"; } - @GetMapping("/bidList/add") + /** + * Add bid form + * @param bid + * @return + */ + @GetMapping("/add") public String addBidForm(BidList bid) { return "bidList/add"; } - @PostMapping("/bidList/validate") + /** + * Validate bid + * @param bid + * @param result + * @param model + * @return + */ + @PostMapping("/validate") public String validate(@Valid BidList bid, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return bid list + if (!result.hasErrors()) { + bidListService.addBidList(bid); + } return "bidList/add"; } - @GetMapping("/bidList/update/{id}") + /** + * Update bid form + * @param id + * @param model + * @return + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Bid by Id and to model then show to the form + try { + BidList bidList = bidListService.findById(id); + model.addAttribute("bidList", bidList); + } catch (RequestedObjectNotFoundException e) { + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } return "bidList/update"; } - @PostMapping("/bidList/update/{id}") + /** + * Update bid + * @param id + * @param bidList + * @param result + * @param model + * @return + */ + @PostMapping("/update/{id}") public String updateBid(@PathVariable("id") Integer id, @Valid BidList bidList, - BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Bid and return list Bid + BindingResult result, Model model) { + if (!result.hasErrors()) { + bidList.setBidlistid(id); + bidListService.addBidList(bidList); + } return "redirect:/bidList/list"; } - @GetMapping("/bidList/delete/{id}") + /** + * Delete bid + * @param id + * @param model + * @return + */ + @GetMapping("/delete/{id}") + @Transactional public String deleteBid(@PathVariable("id") Integer id, Model model) { - // TODO: Find Bid by Id and delete the bid, return to Bid list + bidListService.deleteBidList(id); return "redirect:/bidList/list"; } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java index db69caf549..83393722ac 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/CurveController.java @@ -1,6 +1,14 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.CurvePoint; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.CurvePointService; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -9,46 +17,106 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; + @Controller +@RequestMapping("/curvePoint") +@RequiredArgsConstructor public class CurveController { - // TODO: Inject Curve Point service + // Inject Curve Point service + private final CurvePointService curvePointService; - @RequestMapping("/curvePoint/list") - public String home(Model model) + /** + * Find all Curve Point, add to model + * @param model + * @param user + * @return + */ + @GetMapping("/list") + public String home(Model model,@AuthenticationPrincipal User user) { - // TODO: find all Curve Point, add to model + model.addAttribute("remoteUser", user.getUsername()); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoint()); return "curvePoint/list"; } - @GetMapping("/curvePoint/add") + /** + * Add new curve point + * @param bid + * @return + */ + @GetMapping("/add") public String addBidForm(CurvePoint bid) { return "curvePoint/add"; } - @PostMapping("/curvePoint/validate") + /** + * Validate curve point + * @param curvePoint + * @param result + * @param model + * @return + */ + @PostMapping("/validate") public String validate(@Valid CurvePoint curvePoint, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Curve list + // Check data valid and save to db, after saving return Curve list + if (!result.hasErrors()) { + curvePointService.saveCurvePoint(curvePoint); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoint()); + } return "curvePoint/add"; } - @GetMapping("/curvePoint/update/{id}") + /** + * Show form to update curve point + * @param id + * @param model + * @return + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get CurvePoint by Id and to model then show to the form + // Get CurvePoint by Id and to model then show to the form + try { + CurvePoint curvePoint = curvePointService.findCurvePointById(id); + curvePoint.setCurveId(id); + model.addAttribute("curvePoint", curvePoint); + } catch (RequestedObjectNotFoundException e) { + // Handle exception + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } return "curvePoint/update"; } - @PostMapping("/curvePoint/update/{id}") + /** + * Update curve point + * @param id + * @param curvePoint + * @param result + * @param model + * @return + */ + @PostMapping("/update/{id}") public String updateBid(@PathVariable("id") Integer id, @Valid CurvePoint curvePoint, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Curve and return Curve list + // Check required fields, if valid call service to update Curve and return Curve list + if (!result.hasErrors()) { + curvePointService.saveCurvePoint(curvePoint); + model.addAttribute("curvePoints", curvePointService.findAllCurvePoint()); + } return "redirect:/curvePoint/list"; } - @GetMapping("/curvePoint/delete/{id}") - public String deleteBid(@PathVariable("id") Integer id, Model model) { - // TODO: Find Curve by Id and delete the Curve, return to Curve list + /** + * Delete curve point + * @param id + * @param model + * @return + */ + @GetMapping("/delete/{id}") + public String deleteByid(@PathVariable("id") Integer id, Model model) { + curvePointService.deleteCurvePoint(id); return "redirect:/curvePoint/list"; } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/HomeController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/HomeController.java index 50685b213f..e826ccff81 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/HomeController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/HomeController.java @@ -1,16 +1,21 @@ package com.nnk.springboot.controllers; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import com.nnk.springboot.domain.User; + @Controller -public class HomeController -{ +public class HomeController{ @RequestMapping("/") - public String home(Model model) + public String home(Model model,@AuthenticationPrincipal User user) { - return "home"; + if(user.getRole().equals("ADMIN")) + return "redirect:/admin/home"; + else + return "home"; } @RequestMapping("/admin/home") diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java index ef0c657c72..26325ba687 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/LoginController.java @@ -1,7 +1,9 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.repositories.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; + +import lombok.RequiredArgsConstructor; + import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -9,15 +11,15 @@ @Controller @RequestMapping("app") +@RequiredArgsConstructor public class LoginController { - @Autowired - private UserRepository userRepository; + private final UserRepository userRepository; @GetMapping("login") public ModelAndView login() { ModelAndView mav = new ModelAndView(); - mav.setViewName("login"); + mav.setViewName("loginPage"); return mav; } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java index 5e15e68fbc..c2d8c4a63d 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RatingController.java @@ -1,6 +1,14 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.Rating; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.RatingService; + +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -9,46 +17,102 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; - +/** + * RatingController class + */ @Controller +@RequestMapping("/rating") +@RequiredArgsConstructor public class RatingController { - // TODO: Inject Rating service - @RequestMapping("/rating/list") - public String home(Model model) - { - // TODO: find all Rating, add to model + /** + * Rating service + */ + private final RatingService ratingService; + + /** + * list all Ratings + * @param model + * @param user + * @return + */ + @GetMapping("/list") + public String home(Model model,@AuthenticationPrincipal User user) { + model.addAttribute("remoteUser", user.getUsername()); + model.addAttribute("ratings", ratingService.getRatings()); return "rating/list"; } - @GetMapping("/rating/add") + /** + * show add new form + * @return + */ + @GetMapping("/add") public String addRatingForm(Rating rating) { return "rating/add"; } - @PostMapping("/rating/validate") + /** + * validate input data and save to db + * @param rating + * @param result + * @param model + * @return + */ + @PostMapping("/validate") public String validate(@Valid Rating rating, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Rating list + if(!result.hasErrors()) { + ratingService.saveRating(rating); + model.addAttribute("ratings", ratingService.getRatings()); + } return "rating/add"; } - @GetMapping("/rating/update/{id}") + /** + * show update form + * @param id + * @param model + * @return + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Rating by Id and to model then show to the form + try { + model.addAttribute("rating", ratingService.getRatingById(id)); + } catch (RequestedObjectNotFoundException e) { + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } return "rating/update"; } - @PostMapping("/rating/update/{id}") + /** + * update rating + * @param id + * @param rating + * @param result + * @param model + * @return + */ + @PostMapping("/update/{id}") public String updateRating(@PathVariable("id") Integer id, @Valid Rating rating, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Rating and return Rating list + if(!result.hasErrors()) { + rating.setRatingid(id); + ratingService.saveRating(rating); + } return "redirect:/rating/list"; } - @GetMapping("/rating/delete/{id}") + /** + * delete rating + * @param id + * @param model + * @return + */ + @GetMapping("/delete/{id}") public String deleteRating(@PathVariable("id") Integer id, Model model) { - // TODO: Find Rating by Id and delete the Rating, return to Rating list + ratingService.deleteRating(id); return "redirect:/rating/list"; } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java index b9e72b1ba6..5703d5e528 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/RuleNameController.java @@ -1,6 +1,11 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.RuleName; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.RuleNameService; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -9,46 +14,106 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +/** + * Controller for ruleName. + */ @Controller +@RequestMapping("/ruleName") +@RequiredArgsConstructor public class RuleNameController { - // TODO: Inject RuleName service - @RequestMapping("/ruleName/list") - public String home(Model model) - { - // TODO: find all RuleName, add to model + /** + * Rule name service. + */ + private final RuleNameService ruleNameService; + + /** + * Home page. + * @param model Model + * @param user User + * @return View name + */ + @GetMapping("/list") + public String home(Model model, @AuthenticationPrincipal User user) { + // Find all RuleName, add to model + model.addAttribute("remoteUser", user.getUsername()); + model.addAttribute("ruleNames", ruleNameService.findAll()); return "ruleName/list"; } - @GetMapping("/ruleName/add") + /** + * Show add form. + * @param bid RuleName + * @return View name + */ + @GetMapping("/add") public String addRuleForm(RuleName bid) { return "ruleName/add"; } - @PostMapping("/ruleName/validate") + /** + * Validate ruleName and save to db. + * @param ruleName RuleName + * @param result BindingResult + * @param model Model + * @return View name + */ + @PostMapping("/validate") public String validate(@Valid RuleName ruleName, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return RuleName list + if(!result.hasErrors()) { + ruleNameService.save(ruleName); + } return "ruleName/add"; } - @GetMapping("/ruleName/update/{id}") + /** + * Show update form. + * @param id Integer + * @param model Model + * @return View name + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get RuleName by Id and to model then show to the form + try { + model.addAttribute("ruleName", ruleNameService.findById(id)); + } catch (RequestedObjectNotFoundException e) { + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } return "ruleName/update"; } - @PostMapping("/ruleName/update/{id}") + /** + * Update ruleName and return ruleName list. + * @param id Integer + * @param ruleName RuleName + * @param result BindingResult + * @param model Model + * @return View name + */ + @PostMapping("/update/{id}") public String updateRuleName(@PathVariable("id") Integer id, @Valid RuleName ruleName, BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update RuleName and return RuleName list + if(!result.hasErrors()) { + ruleName.setRulenameid(id); + ruleNameService.save(ruleName); + } return "redirect:/ruleName/list"; } - @GetMapping("/ruleName/delete/{id}") + /** + * Delete ruleName and return ruleName list. + * @param id Integer + * @param model Model + * @return View name + */ + @GetMapping("/delete/{id}") public String deleteRuleName(@PathVariable("id") Integer id, Model model) { - // TODO: Find RuleName by Id and delete the RuleName, return to Rule list + ruleNameService.delete(id); return "redirect:/ruleName/list"; } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java index 4e667eec22..83daaf8af2 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/TradeController.java @@ -1,6 +1,11 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.Trade; +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.TradeService; + +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -9,46 +14,120 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; + +/** + * TradeController + * + * The controller for the trade operations. + * Injects the Trade service. + */ @Controller +@RequestMapping("/trade") +@RequiredArgsConstructor public class TradeController { - // TODO: Inject Trade service - @RequestMapping("/trade/list") - public String home(Model model) - { - // TODO: find all Trade, add to model + /** + * The trade service. + */ + private final TradeService tradeService; + + /** + * The trade list page. + * + * @param model the model + * @param user the user + * @return the trade list page + */ + @GetMapping("/list") + public String home(Model model, @AuthenticationPrincipal User user) { + // find all Trade, add to model + model.addAttribute("remoteUser", user.getUsername()); + model.addAttribute("trades", tradeService.findAll()); return "trade/list"; } - @GetMapping("/trade/add") + /** + * The add trade page. + * + * @param bid the bid + * @return the add trade page + */ + @GetMapping("/add") public String addUser(Trade bid) { return "trade/add"; } - @PostMapping("/trade/validate") + /** + * Validate the trade. + * + * @param trade the trade + * @param result the result + * @param model the model + * @return the add trade page + */ + @PostMapping("/validate") public String validate(@Valid Trade trade, BindingResult result, Model model) { - // TODO: check data valid and save to db, after saving return Trade list + // check data valid and save to db, after saving return Trade list + if (!result.hasErrors()) { + tradeService.save(trade); + } return "trade/add"; } - @GetMapping("/trade/update/{id}") + /** + * The update trade page. + * + * @param id the trade id + * @param model the model + * @return the update trade page + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - // TODO: get Trade by Id and to model then show to the form + // get Trade by Id and to model then show to the form + try { + model.addAttribute("trade", tradeService.findById(id)); + } catch (RequestedObjectNotFoundException e) { + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } return "trade/update"; } - @PostMapping("/trade/update/{id}") + /** + * Update the trade. + * + * @param id the trade id + * @param trade the trade + * @param result the result + * @param model the model + * @return the trade list page + */ + @PostMapping("/update/{id}") public String updateTrade(@PathVariable("id") Integer id, @Valid Trade trade, - BindingResult result, Model model) { - // TODO: check required fields, if valid call service to update Trade and return Trade list + BindingResult result, Model model) { + // check required fields, if valid call service to update Trade and return Trade list + if (!result.hasErrors()) { + trade.setTradeid(id); + tradeService.save(trade); + } return "redirect:/trade/list"; } - @GetMapping("/trade/delete/{id}") + /** + * Delete the trade. + * + * @param id the trade id + * @param model the model + * @return the trade list page + */ + @GetMapping("/delete/{id}") public String deleteTrade(@PathVariable("id") Integer id, Model model) { - // TODO: Find Trade by Id and delete the Trade, return to Trade list + // Find Trade by Id and delete the Trade, return to Trade list + tradeService.delete(id); return "redirect:/trade/list"; } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java index 29e30be3d6..43d9ed37d7 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/controllers/UserController.java @@ -1,9 +1,10 @@ package com.nnk.springboot.controllers; import com.nnk.springboot.domain.User; -import com.nnk.springboot.repositories.UserRepository; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; + +import com.nnk.springboot.services.UserService; + import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; @@ -12,65 +13,127 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import javax.validation.Valid; +import jakarta.validation.Valid; +/** + * This class represents a controller for handling user related requests. + * It provides methods for listing all users, adding a new user, showing the update form, + * updating a user, deleting a user and displaying the login page. + */ @Controller +@RequestMapping("/user") public class UserController { - @Autowired - private UserRepository userRepository; - - @RequestMapping("/user/list") - public String home(Model model) - { - model.addAttribute("users", userRepository.findAll()); + private UserService userService; + public UserController(UserService userService) { + this.userService= userService; + } + /** + * This method handles the request to display a list of all users. + * It adds the list of users to the model and returns the string "user/list". + * + * @param model The model to add the list of users to. + * @return The string "user/list". + */ + @RequestMapping("/list") + public String home(Model model) { + model.addAttribute("users", userService.findAll()); return "user/list"; } - @GetMapping("/user/add") + /** + * This method handles the request to display the form for adding a new user. + * It returns the string "user/add". + * + * @return The string "user/add". + */ + @GetMapping("/add") public String addUser(User bid) { return "user/add"; } - @PostMapping("/user/validate") + /** + * This method handles the request to validate a user. + * If the user is valid, it saves the user and returns the string "user/add". + * + * @param user The user to validate. + * @param result The result of the validation. + * @param model The model to add error messages to. + * @return The string "user/add". + */ + @PostMapping("/validate") public String validate(@Valid User user, BindingResult result, Model model) { - if (!result.hasErrors()) { - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - user.setPassword(encoder.encode(user.getPassword())); - userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); - return "redirect:/user/list"; + if (!result.hasErrors()) { + userService.save(user); } return "user/add"; } - @GetMapping("/user/update/{id}") + /** + * This method handles the request to display the form for updating a user. + * It finds the user with the given ID and adds it to the model. If the user is not found, + * it adds an error message to the model and returns the string "404". + * + * @param id The ID of the user to update. + * @param model The model to add the user to or the error message to. + * @return The string "user/update" or "404". + */ + @GetMapping("/update/{id}") public String showUpdateForm(@PathVariable("id") Integer id, Model model) { - User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); - user.setPassword(""); - model.addAttribute("user", user); - return "user/update"; + try{ + model.addAttribute("user", userService.findById(id)); + return "user/update"; + } catch (RequestedObjectNotFoundException e) { + model.addAttribute("errorMsg", e.getMessage()); + return "404"; + } } - @PostMapping("/user/update/{id}") + /** + * This method handles the request to update a user. + * If the user is valid, it updates the user and returns the string "redirect:/user/list". + * + * @param id The ID of the user to update. + * @param user The user to update. + * @param result The result of the validation. + * @param model The model to add the list of users to. + * @return The string "redirect:/user/list". + */ + @PostMapping("/update/{id}") public String updateUser(@PathVariable("id") Integer id, @Valid User user, BindingResult result, Model model) { if (result.hasErrors()) { return "user/update"; } - - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - user.setPassword(encoder.encode(user.getPassword())); - user.setId(id); - userRepository.save(user); - model.addAttribute("users", userRepository.findAll()); + user.setUserid(id); + userService.save(user); + model.addAttribute("users", userService.findAll()); return "redirect:/user/list"; } - @GetMapping("/user/delete/{id}") + /** + * This method handles the request to delete a user. + * It deletes the user with the given ID and returns the string "redirect:/user/list". + * + * @param id The ID of the user to delete. + * @param model The model to add the list of users to. + * @return The string "redirect:/user/list". + */ + @GetMapping("/delete/{id}") public String deleteUser(@PathVariable("id") Integer id, Model model) { - User user = userRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Invalid user Id:" + id)); - userRepository.delete(user); - model.addAttribute("users", userRepository.findAll()); + userService.delete(id); + model.addAttribute("users", userService.findAll()); return "redirect:/user/list"; } + /** + * This method handles the request to display the login page. + * It returns the string "loginPage". + * + * @return The string "loginPage". + */ + @GetMapping("/loginPage") + public String getMethodName() { + return "loginPage"; + } + } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java index 3a0e27efc8..0d6f691ac6 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/BidList.java @@ -1,15 +1,161 @@ package com.nnk.springboot.domain; -import org.springframework.beans.factory.annotation.Required; +import java.util.Date; -import javax.persistence.*; -import javax.validation.constraints.Digits; -import javax.validation.constraints.NotBlank; -import java.sql.Date; -import java.sql.Timestamp; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.PositiveOrZero; +import lombok.Data; +/** + * The BidList class represents a bid list record in the database. + * It contains fields for all the attributes of a bid list record. + * Each instance of the class is a row in the bidlist table. + * + * @author Nguyen Ngoc Khanh + */ @Entity @Table(name = "bidlist") +@Data public class BidList { - // TODO: Map columns in data table BIDLIST with corresponding java fields + + /** + * The primary key of the bid list record. + */ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "bidlistid") + private int bidlistid; + + /** + * The account associated with the bid list. + */ + @NotBlank(message = "Account is mandatory") + private String account; + + /** + * The type of the bid list. + */ + @NotBlank(message = "type is mandatory") + private String type; + + /** + * The bid quantity associated with the bid list. + */ + @PositiveOrZero + private Double bidQuantity; + + /** + * The ask quantity associated with the bid list. + */ + private Double askQuantity; + + /** + * The bid price associated with the bid list. + */ + private Double bid; + + /** + * The ask price associated with the bid list. + */ + private Double ask; + + /** + * The benchmark associated with the bid list. + */ + private String benchmark; + + /** + * The date of the bid list. + */ + private Date bidListDate; + + /** + * The commentary associated with the bid list. + */ + private String commentary; + + /** + * The security associated with the bid list. + */ + private String security; + + /** + * The status of the bid list. + */ + private String status; + + /** + * The trader associated with the bid list. + */ + private String trader; + + /** + * The book associated with the bid list. + */ + private String book; + + /** + * The name of the user who created the bid list. + */ + private String creationName; + + /** + * The date and time the bid list was created. + */ + private Date creationDate; + + /** + * The name of the user who last modified the bid list. + */ + private String revisionName; + + /** + * The date and time the bid list was last modified. + */ + private Date revisionDate; + + /** + * The name of the deal associated with the bid list. + */ + private String dealName; + + /** + * The type of the deal associated with the bid list. + */ + private String dealType; + + /** + * The source list ID associated with the bid list. + */ + private String sourceListId; + + /** + * The side of the bid list. + */ + private String side; + + /** + * Default constructor. + */ + public BidList() { } + + /** + * Constructor with parameters. + * + * @param account the account associated with the bid list + * @param type the type of the bid list + * @param bidQuantity the bid quantity associated with the bid list + */ + public BidList(String account,String type,double bidQuantity) { + this.account = account; + this.type = type; + this.bidQuantity = bidQuantity; + } } + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java index 151f80d02f..1497a62e1e 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/CurvePoint.java @@ -1,15 +1,39 @@ package com.nnk.springboot.domain; -import org.hibernate.validator.constraints.Length; +import java.util.Date; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.sql.Timestamp; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; +import lombok.Data; @Entity @Table(name = "curvepoint") +@Data public class CurvePoint { + // TODO: Map columns in data table CURVEPOINT with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int curvepointid; + private int curveId; + private Date asOfDate; + @Min(0) + @NotNull + private double term; + @Min(0) + @NotNull + private double curvepointValue; + private Date creationDate; + public CurvePoint() {} + public CurvePoint(int curveId, double term, double value) { + this.curveId = curveId; + this.term = term; + this.curvepointValue = value; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java index 12d1be58c0..0f9c73f99d 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Rating.java @@ -1,12 +1,34 @@ package com.nnk.springboot.domain; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.sql.Timestamp; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; @Entity @Table(name = "rating") +@Data public class Rating { + // TODO: Map columns in data table RATING with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private int ratingid; + @NotBlank(message = "MoodysRating is mandatory") + private String moodysRating; + private String sandPRating; + private String fitchRating; + @Min(0) + private Integer orderNumber; + public Rating() {} + public Rating(String moodysRating, String sandPRating, String fitchRating, Integer orderNumber) { + this.moodysRating = moodysRating; + this.sandPRating = sandPRating; + this.fitchRating = fitchRating; + this.orderNumber = orderNumber; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java index b8ac970edf..b8c0f9fb90 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/RuleName.java @@ -1,11 +1,46 @@ package com.nnk.springboot.domain; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.sql.Timestamp; + + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + @Entity @Table(name = "rulename") +@Data public class RuleName { - // TODO: Map columns in data table RULENAME with corresponding java fields -} + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer rulenameid; + @NotBlank(message = "Name is mandatory") + private String name; + @NotNull + private String description; + @NotBlank(message = "Json is mandatory") + private String json; + @NotBlank(message = "Template is mandatory") + private String template; + @NotBlank(message = "Sql is mandatory") + private String sql; + @NotBlank(message = "SqlPart is mandatory") + private String sqlPart; + public RuleName() { + + } + public RuleName(String name, String description, String json, String template, String sqlStr, String sqlPart) { + this.name = name; + this.description = description; + this.json = json; + this.template = template; + this.sql = sqlStr; + this.sqlPart = sqlPart; + } + +} \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java index b6db7c13b7..4610195392 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/Trade.java @@ -1,12 +1,51 @@ package com.nnk.springboot.domain; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.sql.Timestamp; +import java.util.Date; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import lombok.Data; @Entity @Table(name = "trade") +@Data public class Trade { // TODO: Map columns in data table TRADE with corresponding java fields + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer tradeid; + @NotBlank(message = "Account is mandatory") + private String account; + @NotBlank(message = "type is mandatory") + private String type; + @Min(0) + private Double buyQuantity; + private Double sellQuantity; + private Double buyPrice; + private Double sellPrice; + private Date tradeDate; + private String security; + private String status; + private String trader; + private String benchmark; + private String book; + private String creationName; + private Date creationDate; + private String revisionName; + private Date revisionDate; + private String dealName; + private String dealType; + private String sourceListId; + private String side; + public Trade() { } + public Trade(String account, String type) { + this.type = type; + this.account = account; + } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java index 2be0b8c4ab..11109fe57f 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/domain/User.java @@ -1,60 +1,48 @@ package com.nnk.springboot.domain; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; + + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Size; +import lombok.Data; @Entity @Table(name = "users") -public class User { +@Data +public class User implements UserDetails{ @Id - @GeneratedValue(strategy= GenerationType.AUTO) - private Integer id; + @GeneratedValue(strategy= GenerationType.IDENTITY) + private Integer userid; @NotBlank(message = "Username is mandatory") private String username; @NotBlank(message = "Password is mandatory") + @Size(min = 8, message = "Password must be at least 8 characters") + @Pattern(regexp = "^(?=.*[A-Z])(?=.*\\d).*$", message = "Password must contain at least 1 uppercase and 1 digit") private String password; @NotBlank(message = "FullName is mandatory") private String fullname; @NotBlank(message = "Role is mandatory") private String role; - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = 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 String getFullname() { - return fullname; - } - - public void setFullname(String fullname) { - this.fullname = fullname; - } - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; + @Override + public Collection getAuthorities() { + Set authorities = new HashSet(); + authorities.add(() -> "USER"); + if(role.equals("ADMIN")) { + authorities.add(() -> "ADMIN"); + } + return authorities; } } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/exceptions/RequestedObjectNotFoundException.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/exceptions/RequestedObjectNotFoundException.java new file mode 100644 index 0000000000..e29308accc --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/exceptions/RequestedObjectNotFoundException.java @@ -0,0 +1,7 @@ +package com.nnk.springboot.exceptions; + +public class RequestedObjectNotFoundException extends Exception { + public RequestedObjectNotFoundException(String message) { + super(message); + } +} diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java index f74b94e51d..48410da67f 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/BidListRepository.java @@ -1,9 +1,16 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.BidList; -import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; -public interface BidListRepository extends JpaRepository { +import org.springframework.data.repository.RepositoryDefinition; +@RepositoryDefinition(domainClass = BidList.class, idClass = Integer.class) +public interface BidListRepository { + public BidList save(BidList bidList); + public List findAll(); + public void deleteByBidlistid(int Bidlistid); + public Optional findById(Integer id); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java index b01751b53e..88c2542e1b 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/CurvePointRepository.java @@ -1,9 +1,20 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.CurvePoint; -import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; -public interface CurvePointRepository extends JpaRepository { +import org.springframework.data.repository.RepositoryDefinition; + +@RepositoryDefinition(domainClass = CurvePoint.class, idClass = Integer.class) +public interface CurvePointRepository { +CurvePoint save(CurvePoint curvePoint); + +List findAll(); + +Optional findByCurvepointid(Integer id); + +void deleteById(int curvePoint); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java index 7ded405e6d..fc268d0fb9 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RatingRepository.java @@ -1,8 +1,14 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.Rating; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RatingRepository extends JpaRepository { +import java.util.List; +import java.util.Optional; +import org.springframework.data.repository.RepositoryDefinition; +@RepositoryDefinition(domainClass = Rating.class, idClass = Integer.class) +public interface RatingRepository { + Rating save(Rating rating); + List findAll(); + Optional findByRatingid(int id); + void deleteByRatingid(int rating); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java index 8053d1612e..33b2a0ba51 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/RuleNameRepository.java @@ -1,8 +1,16 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.RuleName; -import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; -public interface RuleNameRepository extends JpaRepository { +import org.springframework.data.repository.RepositoryDefinition; + +@RepositoryDefinition(domainClass = RuleName.class, idClass = Integer.class) +public interface RuleNameRepository { + RuleName save(RuleName ruleName); + List findAll(); + Optional findByRulenameid(Integer id); + void deleteByRulenameid(int ruleName); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java index e8da38af02..52f143209d 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/TradeRepository.java @@ -1,8 +1,20 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.Trade; -import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; -public interface TradeRepository extends JpaRepository { +import org.springframework.data.repository.RepositoryDefinition; + +@RepositoryDefinition(domainClass = Trade.class, idClass = Integer.class) +public interface TradeRepository { + + List findAll(); + + Optional findByTradeid(int id); + + Trade save(Trade trade); + + void deleteByTradeid(int trade); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java index b6a3363949..41a4923a5b 100644 --- a/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/repositories/UserRepository.java @@ -1,12 +1,17 @@ package com.nnk.springboot.repositories; import com.nnk.springboot.domain.User; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; +import java.util.List; +import java.util.Optional; -public interface UserRepository extends JpaRepository, JpaSpecificationExecutor { +import org.springframework.data.repository.RepositoryDefinition; +@RepositoryDefinition(domainClass = User.class, idClass = Integer.class) +public interface UserRepository{ + Optional findByUsername(String username); + List findAll(); + Optional findById(Integer id); + void deleteByuserid(int user); + User save(User user); } diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java new file mode 100644 index 0000000000..8a6bbfe30e --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/BidListService.java @@ -0,0 +1,64 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.BidList; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.BidListRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class BidListService { + private final BidListRepository bidListRepository; + + /** + * This method is used to get all BidList from database + * @return List all BidList in database + */ + public List findAll() { + return bidListRepository.findAll(); + } + + /** + * This method is used to add a new BidList to database + * @param bidList bidList to add + * @return BidList save in database + */ + public BidList addBidList(BidList bidList) { + return bidListRepository.save(bidList); + } + + /** + * This method is used to get a BidList by id + * @param id id of BidList + * @return BidList get from database + */ + public BidList getBidList(int id){ + return bidListRepository.findById(id).get(); + } + + /** + * This method is used to find a BidList by id + * @param id id of BidList + * @return BidList get from database + * @throws RequestedObjectNotFoundException if BidList not found + */ + public BidList findById(int id) throws RequestedObjectNotFoundException{ + return bidListRepository.findById(id).orElseThrow(()-> new RequestedObjectNotFoundException("BidList not found with id: " + id)); + } + + /** + * This method is used to delete a BidList by id + * @param id id of BidList + */ + @Transactional + public void deleteBidList(int id) { + bidListRepository.deleteByBidlistid(id); + } +} + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java new file mode 100644 index 0000000000..1d50b6a5f7 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/CurvePointService.java @@ -0,0 +1,63 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.nnk.springboot.domain.CurvePoint; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.CurvePointRepository; + +import lombok.RequiredArgsConstructor; + +/** + * Service layer for CurvePoint entity. + * + */ +@Service +@RequiredArgsConstructor +public class CurvePointService { + + /** + * The repository for CurvePoint entity. + */ + private final CurvePointRepository curvePointRepository; + + /** + * Save a CurvePoint into the repository. + * @param curvePoint The CurvePoint to save. + * @return The saved CurvePoint. + */ + public CurvePoint saveCurvePoint(CurvePoint curvePoint) { + return curvePointRepository.save(curvePoint); + } + + /** + * Find all CurvePoint in the repository. + * @return A list of CurvePoint. + */ + public List findAllCurvePoint() { + return curvePointRepository.findAll(); + } + + /** + * Find a CurvePoint by its id. + * @param id The id of the CurvePoint. + * @return The CurvePoint with the given id. + * @throws RequestedObjectNotFoundException If the CurvePoint is not found. + */ + public CurvePoint findCurvePointById(Integer id) throws RequestedObjectNotFoundException { + return curvePointRepository.findByCurvepointid(id).orElseThrow(()-> new RequestedObjectNotFoundException("CurvePoint not found with id: " + id)); + } + + /** + * Delete a CurvePoint from the repository. + * @param curvePoint The id of the CurvePoint to delete. + */ + @Transactional + public void deleteCurvePoint(int curvePoint) { + curvePointRepository.deleteById(curvePoint); + } +} + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java new file mode 100644 index 0000000000..c28322cd1a --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RatingService.java @@ -0,0 +1,59 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.Rating; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.RatingRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + + +@Service +@RequiredArgsConstructor +public class RatingService { + /** + * RatingRepository instance + */ + private final RatingRepository ratingRepository; + + /** + * Saves a rating + * @param rating The rating to be saved + * @return The saved rating + */ + public Rating saveRating(Rating rating) { + return ratingRepository.save(rating); + } + + /** + * Retrieves all ratings + * @return A list of ratings + */ + public List getRatings() { + return ratingRepository.findAll(); + } + + /** + * Retrieves a rating by its ID + * @param id The ID of the rating + * @return The rating with the specified ID + * @throws RequestedObjectNotFoundException If no rating with the specified ID is found + */ + public Rating getRatingById(int id) throws RequestedObjectNotFoundException{ + return ratingRepository.findByRatingid(id).orElseThrow(()-> new RequestedObjectNotFoundException("Rating not found with id: " + id)); + } + + /** + * Deletes a rating by its ID + * @param id The ID of the rating to be deleted + */ + @Transactional + public void deleteRating(int id) { + ratingRepository.deleteByRatingid(id); + } +} + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java new file mode 100644 index 0000000000..bbdefcfdd4 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/RuleNameService.java @@ -0,0 +1,68 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.RuleName; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.RuleNameRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +/** + * A service class for the RuleName domain. + * + */ +@Service +@RequiredArgsConstructor +public class RuleNameService { + /** + * The ruleName repository. + */ + @Autowired + private final RuleNameRepository ruleNameRepository; + + /** + * Save a ruleName to the repository. + * + * @param ruleName the ruleName to save + * @return the saved ruleName + */ + public RuleName save(RuleName ruleName) { + return ruleNameRepository.save(ruleName); + } + + /** + * Retrieve all ruleNames from the repository. + * + * @return a list of ruleNames + */ + public List findAll() { + return ruleNameRepository.findAll(); + } + + /** + * Retrieve a ruleName by its id from the repository. + * + * @param id the id of the ruleName + * @return the ruleName with the given id + * @throws RequestedObjectNotFoundException if no ruleName is found with the given id + */ + public RuleName findById(Integer id) throws RequestedObjectNotFoundException { + return ruleNameRepository.findByRulenameid(id).orElseThrow(()-> new RequestedObjectNotFoundException("RuleName not found with id: " + id)); + } + + /** + * Delete a ruleName from the repository. + * + * @param ruleName the id of the ruleName to delete + */ + @Transactional + public void delete(int ruleName) { + ruleNameRepository.deleteByRulenameid(ruleName); + } +} + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java new file mode 100644 index 0000000000..caed7051e8 --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/TradeService.java @@ -0,0 +1,68 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.nnk.springboot.domain.Trade; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.TradeRepository; + +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +/** + * TradeService + * + * The service for the trade operations. Injects the Trade repository. + * + */ +@Service +@RequiredArgsConstructor +public class TradeService { + + /** The trade repository. */ + private final TradeRepository tradeRepository; + + /** + * Save the trade. + * + * @param trade the trade + * @return the saved trade + */ + public Trade save(Trade trade) { + return tradeRepository.save(trade); + } + + /** + * Delete the trade. + * + * @param trade the trade id + */ + @Transactional + public void delete(int trade) { + tradeRepository.deleteByTradeid(trade); + } + + /** + * Find all trades. + * + * @return the list of trades + */ + public List findAll() { + return tradeRepository.findAll(); + } + + /** + * Find the trade by id. + * + * @param id the trade id + * @return the trade + * @throws RequestedObjectNotFoundException if the trade is not found + */ + public Trade findById(Integer id) throws RequestedObjectNotFoundException { + return tradeRepository.findByTradeid(id) + .orElseThrow(() -> new RequestedObjectNotFoundException("Trade not found with id: " + id)); + } +} + diff --git a/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java new file mode 100644 index 0000000000..3461d67d4f --- /dev/null +++ b/Poseiden-skeleton/src/main/java/com/nnk/springboot/services/UserService.java @@ -0,0 +1,79 @@ +package com.nnk.springboot.services; + +import java.util.List; + +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +import com.nnk.springboot.domain.User; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.repositories.UserRepository; + +import jakarta.transaction.Transactional; + + +/** + * Responsible for managing user related operations. + */ +public class UserService implements UserDetailsService { + + private final UserRepository userRepository; + + /** + * Constructor for UserService class. + * @param userRepository userRepository for performing CRUD operations + * @param user user object to be saved + */ + public UserService(UserRepository userRepository, User user) { + this.userRepository = userRepository; + save(user); + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return userRepository.findByUsername(username).orElseThrow(() -> new UsernameNotFoundException(username)); + } + + /** + * Encrypts the password and saves the user object. + * @param user user object to be saved + * @return saved user object + */ + public User save(User user) { + BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); + user.setPassword(encoder.encode(user.getPassword())); + return userRepository.save(user); + } + + /** + * Finds a user by their ID. + * @param id user ID + * @return user object + * @throws RequestedObjectNotFoundException if user not found + */ + public User findById(Integer id) throws RequestedObjectNotFoundException{ + return userRepository.findById(id).orElseThrow(()-> new RequestedObjectNotFoundException("User not found with id: " + id)); + } + + /** + * Deletes a user by their ID. + * @param user user ID + */ + @Transactional + public void delete(int user) { + userRepository.deleteByuserid(user); + } + + /** + * Finds all users. + * @return list of user objects + */ + public List findAll() { + return userRepository.findAll(); + } + +} + + diff --git a/Poseiden-skeleton/src/main/resources/application-prod.properties b/Poseiden-skeleton/src/main/resources/application-prod.properties index 83f1ee5b32..9fea131b2e 100644 --- a/Poseiden-skeleton/src/main/resources/application-prod.properties +++ b/Poseiden-skeleton/src/main/resources/application-prod.properties @@ -2,6 +2,7 @@ logging.level.org.springframework=INFO ################### DataSource Configuration ########################## +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=root diff --git a/Poseiden-skeleton/src/main/resources/application.properties b/Poseiden-skeleton/src/main/resources/application.properties index 8b194cc76e..623e81f56e 100644 --- a/Poseiden-skeleton/src/main/resources/application.properties +++ b/Poseiden-skeleton/src/main/resources/application.properties @@ -1,11 +1,13 @@ logging.level.org.springframework=INFO - +logging.level.web=DEBUG ################### DataSource Configuration ########################## -spring.datasource.driver-class-name=com.mysql.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/demo -spring.datasource.username=root -spring.datasource.password= +spring.datasource.driver-class-name=org.h2.Driver +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect +spring.datasource.url=jdbc:h2:mem:db +spring.datasource.username=admin +spring.datasource.password=admin + ################### Hibernate Configuration ########################## diff --git a/Poseiden-skeleton/src/main/resources/static/css/login.css b/Poseiden-skeleton/src/main/resources/static/css/login.css new file mode 100644 index 0000000000..f43a33de39 --- /dev/null +++ b/Poseiden-skeleton/src/main/resources/static/css/login.css @@ -0,0 +1,20 @@ +body { + display: flex; + align-items: center; + justify-content: center; + height: 100vh; + margin: 0; +} + +.form-section { + display: grid; + width: fit-content; + grid-template-rows: 1fr 3fr; + height: 300px; +} +#formId { + display: grid; + grid-template-columns: 1fr 3fr; + grid-gap: 10px; + grid-template-rows: min-content min-content min-content; +} \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/resources/templates/404.html b/Poseiden-skeleton/src/main/resources/templates/404.html new file mode 100644 index 0000000000..407e1a6890 --- /dev/null +++ b/Poseiden-skeleton/src/main/resources/templates/404.html @@ -0,0 +1,11 @@ + + + + Spring Boot + + +

Access Denied Exception

+ +

Error

+ + \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html index 62b67e22fc..ddf512e725 100644 --- a/Poseiden-skeleton/src/main/resources/templates/bidList/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/bidList/list.html @@ -17,7 +17,7 @@ Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]] + Logged in user: [[${remoteUser}]]
@@ -38,13 +38,13 @@ - + - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/bidList/update.html b/Poseiden-skeleton/src/main/resources/templates/bidList/update.html index b86c634d3a..f7c36550dd 100644 --- a/Poseiden-skeleton/src/main/resources/templates/bidList/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/bidList/update.html @@ -13,7 +13,7 @@

Update Bid

-
+
@@ -39,7 +39,7 @@

Update Bid

- + Cancel
diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html index a46e2afb74..a8d16ee3bf 100644 --- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html +++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/add.html @@ -23,10 +23,10 @@

Add New Curve Point

- +
- -

+ +

diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html index 3d31e22395..ee16b4ddc1 100644 --- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/list.html @@ -17,7 +17,7 @@ Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]] + Logged in user: [[${remoteUser}]] @@ -38,13 +38,13 @@ - - + + - + - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html b/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html index ee8c798f8b..ca8e32fcc2 100644 --- a/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/curvePoint/update.html @@ -13,7 +13,7 @@

Update CurvePoint

-
+
@@ -22,16 +22,16 @@

Update CurvePoint

- +
- -

+ +

- + Cancel
diff --git a/Poseiden-skeleton/src/main/resources/templates/loginPage.html b/Poseiden-skeleton/src/main/resources/templates/loginPage.html new file mode 100644 index 0000000000..2c99adca6a --- /dev/null +++ b/Poseiden-skeleton/src/main/resources/templates/loginPage.html @@ -0,0 +1,28 @@ + + + + + + Login + + + + + +
+
+
+

Login

+ + + + + + + +
+
+
+ + + \ No newline at end of file diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/add.html b/Poseiden-skeleton/src/main/resources/templates/rating/add.html index 0d8fa765bf..252390d775 100644 --- a/Poseiden-skeleton/src/main/resources/templates/rating/add.html +++ b/Poseiden-skeleton/src/main/resources/templates/rating/add.html @@ -37,10 +37,10 @@

Add New Rating

- +
- -

+ +

diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/list.html b/Poseiden-skeleton/src/main/resources/templates/rating/list.html index 020d6ea74d..cff96721f9 100644 --- a/Poseiden-skeleton/src/main/resources/templates/rating/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/rating/list.html @@ -17,7 +17,7 @@ Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]] + Logged in user: [[${remoteUser}]]
@@ -39,14 +39,14 @@ - + - + - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/rating/update.html b/Poseiden-skeleton/src/main/resources/templates/rating/update.html index 488ed5c7c7..108a2e9900 100644 --- a/Poseiden-skeleton/src/main/resources/templates/rating/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/rating/update.html @@ -14,7 +14,7 @@

Update Rating

-
+
@@ -37,17 +37,17 @@

Update Rating

- +
- -

+ +

- + Cancel
diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html index 210b6338f0..9dc0e6a480 100644 --- a/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html +++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/add.html @@ -61,7 +61,7 @@

Add New Rule

diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html index 739ec39d01..e566720fd3 100644 --- a/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/list.html @@ -17,7 +17,7 @@ Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]] + Logged in user: [[${remoteUser}]] @@ -41,7 +41,7 @@ - + @@ -49,8 +49,8 @@ - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html b/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html index f5c4437f84..bc134ccd43 100644 --- a/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/ruleName/update.html @@ -14,7 +14,7 @@

Update New Rule

-
+
@@ -61,7 +61,7 @@

Update New Rule

- + Cancel
diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/list.html b/Poseiden-skeleton/src/main/resources/templates/trade/list.html index debf1afa68..5661aa1cdb 100644 --- a/Poseiden-skeleton/src/main/resources/templates/trade/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/trade/list.html @@ -17,7 +17,7 @@ Rule
- Logged in user: [[${#httpServletRequest.remoteUser}]] + Logged in user: [[${remoteUser}]] @@ -38,13 +38,13 @@ - + - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/trade/update.html b/Poseiden-skeleton/src/main/resources/templates/trade/update.html index 7948653a14..a0ebae7ec0 100644 --- a/Poseiden-skeleton/src/main/resources/templates/trade/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/trade/update.html @@ -13,7 +13,7 @@

Update Trade

-
+
@@ -39,7 +39,7 @@

Update Trade

- + Cancel
diff --git a/Poseiden-skeleton/src/main/resources/templates/user/list.html b/Poseiden-skeleton/src/main/resources/templates/user/list.html index d239df6977..b2e942b2b4 100644 --- a/Poseiden-skeleton/src/main/resources/templates/user/list.html +++ b/Poseiden-skeleton/src/main/resources/templates/user/list.html @@ -31,13 +31,13 @@ - + - Edit |  - Delete + Edit |  + Delete diff --git a/Poseiden-skeleton/src/main/resources/templates/user/update.html b/Poseiden-skeleton/src/main/resources/templates/user/update.html index 0322cfdf39..5e40cff753 100644 --- a/Poseiden-skeleton/src/main/resources/templates/user/update.html +++ b/Poseiden-skeleton/src/main/resources/templates/user/update.html @@ -14,7 +14,7 @@

Update User

- +
@@ -47,7 +47,7 @@

Update User

- + Cancel
diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java index f1a4f40316..d08113b6e0 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/BidTests.java @@ -1,46 +1,57 @@ package com.nnk.springboot; import com.nnk.springboot.domain.BidList; -import com.nnk.springboot.repositories.BidListRepository; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.BidListService; + +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.List; -import java.util.Optional; -@RunWith(SpringRunner.class) + + @SpringBootTest public class BidTests { @Autowired - private BidListRepository bidListRepository; + private BidListService bidListService; @Test - public void bidListTest() { + @Transactional + public void bidListSaveTest() throws Exception { BidList bid = new BidList("Account Test", "Type Test", 10d); // Save - bid = bidListRepository.save(bid); - Assert.assertNotNull(bid.getBidListId()); - Assert.assertEquals(bid.getBidQuantity(), 10d, 10d); + bid = bidListService.addBidList(bid); + + assertNotNull(bid.getBidlistid()); + assertEquals(bid.getBidQuantity(), 10d); // Update bid.setBidQuantity(20d); - bid = bidListRepository.save(bid); - Assert.assertEquals(bid.getBidQuantity(), 20d, 20d); + bid = bidListService.addBidList(bid); + assertEquals(bid.getBidQuantity(), 20d, 20d); // Find - List listResult = bidListRepository.findAll(); - Assert.assertTrue(listResult.size() > 0); + List listResult = bidListService.findAll(); + assertEquals(true,listResult.size() > 0); // Delete - Integer id = bid.getBidListId(); - bidListRepository.delete(bid); - Optional bidList = bidListRepository.findById(id); - Assert.assertFalse(bidList.isPresent()); + Integer id = bid.getBidlistid(); + bidListService.deleteBidList(bid.getBidlistid()); + BidList bidList; + try { + bidList = bidListService.findById(id); + } catch (RequestedObjectNotFoundException e) { + bidList=null; + } + assertNull(bidList); } } diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java index 854615c0a0..fc0359b9f0 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/CurvePointTests.java @@ -1,47 +1,51 @@ package com.nnk.springboot; import com.nnk.springboot.domain.CurvePoint; -import com.nnk.springboot.repositories.CurvePointRepository; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.jupiter.api.Assertions.*; +import com.nnk.springboot.services.CurvePointService; import java.util.List; -import java.util.Optional; - -@RunWith(SpringRunner.class) @SpringBootTest public class CurvePointTests { @Autowired - private CurvePointRepository curvePointRepository; + private CurvePointService curvePointService; @Test + @Transactional public void curvePointTest() { CurvePoint curvePoint = new CurvePoint(10, 10d, 30d); // Save - curvePoint = curvePointRepository.save(curvePoint); - Assert.assertNotNull(curvePoint.getId()); - Assert.assertTrue(curvePoint.getCurveId() == 10); + curvePoint = curvePointService.saveCurvePoint(curvePoint); + assertNotNull(curvePoint.getCurveId()); + assertTrue(curvePoint.getCurveId() == 10); // Update curvePoint.setCurveId(20); - curvePoint = curvePointRepository.save(curvePoint); - Assert.assertTrue(curvePoint.getCurveId() == 20); + curvePoint = curvePointService.saveCurvePoint(curvePoint); + assertTrue(curvePoint.getCurveId() == 20); // Find - List listResult = curvePointRepository.findAll(); - Assert.assertTrue(listResult.size() > 0); + List listResult = curvePointService.findAllCurvePoint(); + assertTrue(listResult.size() > 0); // Delete - Integer id = curvePoint.getId(); - curvePointRepository.delete(curvePoint); - Optional curvePointList = curvePointRepository.findById(id); - Assert.assertFalse(curvePointList.isPresent()); + Integer id = curvePoint.getCurveId(); + curvePointService.deleteCurvePoint(id); + CurvePoint curvePointList; + try { + curvePointList = curvePointService.findCurvePointById(id); + } catch (RequestedObjectNotFoundException e) { + curvePointList=null; + } + assertNull(curvePointList); } } diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/PasswordEncodeTest.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/PasswordEncodeTest.java index 4f831d9024..27568eb169 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/PasswordEncodeTest.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/PasswordEncodeTest.java @@ -1,10 +1,9 @@ package com.nnk.springboot; -import org.junit.Test; -import org.junit.runner.RunWith; + +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.test.context.junit4.SpringRunner; /** * Created by Khang Nguyen. @@ -12,7 +11,7 @@ * Date: 09/03/2019 * Time: 11:26 AM */ -@RunWith(SpringRunner.class) + @SpringBootTest public class PasswordEncodeTest { @Test diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java index 6c3ebf0b08..163785029a 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RatingTests.java @@ -1,46 +1,53 @@ package com.nnk.springboot; import com.nnk.springboot.domain.Rating; -import com.nnk.springboot.repositories.RatingRepository; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.RatingService; + +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.*; import java.util.List; -import java.util.Optional; -@RunWith(SpringRunner.class) @SpringBootTest public class RatingTests { @Autowired - private RatingRepository ratingRepository; + private RatingService ratingRsService; @Test + @Transactional public void ratingTest() { Rating rating = new Rating("Moodys Rating", "Sand PRating", "Fitch Rating", 10); // Save - rating = ratingRepository.save(rating); - Assert.assertNotNull(rating.getId()); - Assert.assertTrue(rating.getOrderNumber() == 10); + rating = ratingRsService.saveRating(rating); + assertNotNull(rating.getRatingid()); + assertTrue(rating.getOrderNumber() == 10); // Update rating.setOrderNumber(20); - rating = ratingRepository.save(rating); - Assert.assertTrue(rating.getOrderNumber() == 20); + rating = ratingRsService.saveRating(rating); + assertTrue(rating.getOrderNumber() == 20); // Find - List listResult = ratingRepository.findAll(); - Assert.assertTrue(listResult.size() > 0); + List listResult = ratingRsService.getRatings(); + assertTrue(listResult.size() > 0); // Delete - Integer id = rating.getId(); - ratingRepository.delete(rating); - Optional ratingList = ratingRepository.findById(id); - Assert.assertFalse(ratingList.isPresent()); + int id = rating.getRatingid(); + ratingRsService.deleteRating(id); + Rating ratingList; + try { + ratingList = ratingRsService.getRatingById(id); + } catch (RequestedObjectNotFoundException e) { + ratingList = null; + } + assertNull(ratingList); } } diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java index 541dab5412..7cf24953c7 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/RuleTests.java @@ -1,46 +1,54 @@ package com.nnk.springboot; import com.nnk.springboot.domain.RuleName; -import com.nnk.springboot.repositories.RuleNameRepository; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.RuleNameService; + +import jakarta.transaction.Transactional; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; import java.util.List; -import java.util.Optional; -@RunWith(SpringRunner.class) + @SpringBootTest public class RuleTests { @Autowired - private RuleNameRepository ruleNameRepository; + private RuleNameService ruleNameService; @Test + @Transactional public void ruleTest() { RuleName rule = new RuleName("Rule Name", "Description", "Json", "Template", "SQL", "SQL Part"); // Save - rule = ruleNameRepository.save(rule); - Assert.assertNotNull(rule.getId()); - Assert.assertTrue(rule.getName().equals("Rule Name")); + rule = ruleNameService.save(rule); + assertNotNull(rule.getRulenameid()); + assertTrue(rule.getName().equals("Rule Name")); // Update rule.setName("Rule Name Update"); - rule = ruleNameRepository.save(rule); - Assert.assertTrue(rule.getName().equals("Rule Name Update")); + rule = ruleNameService.save(rule); + assertTrue(rule.getName().equals("Rule Name Update")); // Find - List listResult = ruleNameRepository.findAll(); - Assert.assertTrue(listResult.size() > 0); + List listResult = ruleNameService.findAll(); + assertTrue(listResult.size() > 0); // Delete - Integer id = rule.getId(); - ruleNameRepository.delete(rule); - Optional ruleList = ruleNameRepository.findById(id); - Assert.assertFalse(ruleList.isPresent()); + Integer id = rule.getRulenameid(); + ruleNameService.delete(id); + RuleName ruleList; + try { + ruleList = ruleNameService.findById(id); + } catch (RequestedObjectNotFoundException e) { + ruleList = null; + } + assertNull(ruleList); } } diff --git a/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java b/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java index ed50409266..54ad424545 100644 --- a/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java +++ b/Poseiden-skeleton/src/test/java/com/nnk/springboot/TradeTests.java @@ -1,46 +1,55 @@ package com.nnk.springboot; import com.nnk.springboot.domain.Trade; -import com.nnk.springboot.repositories.TradeRepository; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import com.nnk.springboot.exceptions.RequestedObjectNotFoundException; +import com.nnk.springboot.services.TradeService; + +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import java.util.Optional; -@RunWith(SpringRunner.class) @SpringBootTest public class TradeTests { @Autowired - private TradeRepository tradeRepository; + private TradeService tradeService; @Test + @Transactional public void tradeTest() { Trade trade = new Trade("Trade Account", "Type"); // Save - trade = tradeRepository.save(trade); - Assert.assertNotNull(trade.getTradeId()); - Assert.assertTrue(trade.getAccount().equals("Trade Account")); + trade = tradeService.save(trade); + assertNotNull(trade.getTradeid()); + assertTrue(trade.getAccount().equals("Trade Account")); // Update trade.setAccount("Trade Account Update"); - trade = tradeRepository.save(trade); - Assert.assertTrue(trade.getAccount().equals("Trade Account Update")); + trade = tradeService.save(trade); + assertTrue(trade.getAccount().equals("Trade Account Update")); // Find - List listResult = tradeRepository.findAll(); - Assert.assertTrue(listResult.size() > 0); + List listResult = tradeService.findAll(); + assertTrue(listResult.size() > 0); // Delete - Integer id = trade.getTradeId(); - tradeRepository.delete(trade); - Optional tradeList = tradeRepository.findById(id); - Assert.assertFalse(tradeList.isPresent()); + Integer id = trade.getTradeid(); + tradeService.delete(id); + Trade tradeList; + try { + tradeList =tradeService.findById(id); + } catch (RequestedObjectNotFoundException e) { + tradeList = null; + } + assertNull(tradeList); } }