From edfff7f35750488a8845b890e9eb4a181c78c6f0 Mon Sep 17 00:00:00 2001 From: Meissshu Date: Fri, 2 Feb 2018 12:53:57 +0300 Subject: [PATCH] Clean up --- application.log | 12 +++++++++++ .../MobilePaymentSystemApplication.java | 10 --------- .../service/BillService.java | 8 +++++-- .../service/ServiceUnitService.java | 21 +++++++++++++++---- src/main/resources/data-h2.sql | 2 +- 5 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 application.log diff --git a/application.log b/application.log new file mode 100644 index 0000000..344e49c --- /dev/null +++ b/application.log @@ -0,0 +1,12 @@ +[2018-02-02 10:47:05] ERROR There is an error: java.lang.NullPointerException Default message: null +[2018-02-02 10:55:32] ERROR [THYMELEAF][http-nio-80-exec-6] Exception processing template "service/service_user_list": An error happened during template parsing (template: "class path resource [templates/service/service_user_list.html]" - line 122, col 37) +[2018-02-02 10:55:32] ERROR Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/service/service_user_list.html]" - line 122, col 37)] with root cause +[2018-02-02 10:55:32] ERROR [THYMELEAF][http-nio-80-exec-6] Exception processing template "error": Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers +[2018-02-02 10:55:32] ERROR Servlet.service() for servlet [dispatcherServlet] threw exception +[2018-02-02 10:55:32] ERROR Exception Processing ErrorPage[errorCode=0, location=/error] +[2018-02-02 10:59:24] ERROR An internal error occurred while trying to authenticate the user. +[2018-02-02 12:21:57] ERROR An internal error occurred while trying to authenticate the user. +[2018-02-02 12:37:13] ERROR There is an error: java.lang.NullPointerException Default message: null +[2018-02-02 12:37:30] ERROR [THYMELEAF][http-nio-80-exec-2] Exception processing template "error": Error resolving template "error", template might not exist or might not be accessible by any of the configured Template Resolvers +[2018-02-02 12:37:30] ERROR Servlet.service() for servlet [dispatcherServlet] threw exception +[2018-02-02 12:37:30] ERROR Exception Processing ErrorPage[errorCode=0, location=/error] diff --git a/src/main/java/com/epam/lab/mobilepaymentsystem/MobilePaymentSystemApplication.java b/src/main/java/com/epam/lab/mobilepaymentsystem/MobilePaymentSystemApplication.java index 82ae028..f675d91 100644 --- a/src/main/java/com/epam/lab/mobilepaymentsystem/MobilePaymentSystemApplication.java +++ b/src/main/java/com/epam/lab/mobilepaymentsystem/MobilePaymentSystemApplication.java @@ -2,17 +2,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.LocaleResolver; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; -import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; -import org.springframework.web.servlet.i18n.SessionLocaleResolver; - -import java.util.Locale; @SpringBootApplication public class MobilePaymentSystemApplication extends WebMvcConfigurerAdapter{ diff --git a/src/main/java/com/epam/lab/mobilepaymentsystem/service/BillService.java b/src/main/java/com/epam/lab/mobilepaymentsystem/service/BillService.java index 90877ec..789318d 100644 --- a/src/main/java/com/epam/lab/mobilepaymentsystem/service/BillService.java +++ b/src/main/java/com/epam/lab/mobilepaymentsystem/service/BillService.java @@ -96,7 +96,11 @@ public long numberOfUnpaidBillsOfUserByUserId(long userId) { return billsRepository.countAllByPaidForAndUser_Id(UNPAID, userId); } - // payment for EXPIRED PAID BILL + /** + * Withdraw cash to pay for all services of User with ID userId + * Find expired active services and try to renew subscription + * @param userId id of User + */ public void withdrawCashToPayForServicesByUserId(long userId) { List serviceUnits = userService.getActiveServicesByUserId(userId); User user = userService.getUserById(userId); @@ -108,7 +112,7 @@ public void withdrawCashToPayForServicesByUserId(long userId) { } } - userService.updateUser(user); // todo: maybe it's not needed + userService.updateUser(user); } public void withdrawCashToPayForOneBill(Bill bill, User user) { diff --git a/src/main/java/com/epam/lab/mobilepaymentsystem/service/ServiceUnitService.java b/src/main/java/com/epam/lab/mobilepaymentsystem/service/ServiceUnitService.java index 1842d38..5f16ee7 100644 --- a/src/main/java/com/epam/lab/mobilepaymentsystem/service/ServiceUnitService.java +++ b/src/main/java/com/epam/lab/mobilepaymentsystem/service/ServiceUnitService.java @@ -60,13 +60,20 @@ public long numberOfAllPaidActiveUserServicesByUserId(long userId) { + billService.getAllExpiredActiveServicesOfUserByUserId(userId).size(); } + /** + * Subscribe User with ID userId to Service with ID serviceID + * Withdraw cash at the moment of subscribing + * Create paid bill if payment is successful + * Create unpaid bill if payment is unsuccessful + * Already existing Service cannot be subscribed to User + * @param userId ID of User + * @param serviceId ID of Service + */ public void subscribeUserToServiceByUserAndServiceId(long userId, long serviceId) { - // if we chose actual existing service if (serviceId != -1) { User user = userService.getUserById(userId); ServiceUnit service = getServiceById(serviceId); - // we create bill only if the service is new if (user.addService(service)) { Bill bill = billService.createAndSaveBill(user, service); billService.withdrawCashToPayForOneBill(bill, user); @@ -75,11 +82,17 @@ public void subscribeUserToServiceByUserAndServiceId(long userId, long serviceId } } + /** + * Unsubscribe User from Service + * Delete unpaid Bill of this Service from User in process + * Service cannot be unsubscribed if User doesn't have it + * @param bill Bill that contains information about User subscribed to Service + * @param userId ID of User + */ public void unsubscribeUserFromServiceByBillAndUserId(Bill bill, long userId) { User user = userService.getUserById(userId); - ServiceUnit service = getServiceById(bill.getId()); + ServiceUnit service = getServiceById(bill.getServiceUnit().getId()); - // if service exists and it is unpaid - remove also unpaid bill if (user.removeService(service)) { userService.updateUser(user); billService.deleteUnpaidBillByUserIdAndServiceId(userId, service.getId()); diff --git a/src/main/resources/data-h2.sql b/src/main/resources/data-h2.sql index 8a76434..a69162d 100644 --- a/src/main/resources/data-h2.sql +++ b/src/main/resources/data-h2.sql @@ -8,7 +8,7 @@ VALUES ('admin', 'Vladimir Kostin', 99999, '$2a$10$hW7TdoUPWhEdprtj0XjCJ.iDopWV2UUaHWp2l7FoK3mRbLTX7W81q', 'ROLE_ADMIN'), ('mikey', 'Marsel Allaiarov', 435, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_SUBSCRIBER'), ('stranger', 'Bill Gates', 107, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_LOCKED'), - ('exceptional', 'Gryu Felonius', 0, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_DELETED'); + ('exceptional', 'Gryu Felonius', 0, '$2a$10$fPK7rqD0QjOBVGp9YdxnfOxBBX2ZSdiNp3wCp1nlLIxQf6EAaOlsK', 'ROLE_LOCKED'); -- INSERT INTO SERVICES (cost, duration, name, description)