From 336a16ff73938acb32188a0f55caca3577961c16 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 27 May 2019 09:14:24 +0400 Subject: [PATCH] some refactor --- .../grant/controller/GrantController.java | 2 +- src/main/java/ru/ulstu/grant/model/Grant.java | 7 ++-- .../grant/repository/GrantRepository.java | 3 ++ .../ulstu/grant/service/GrantScheduler.java | 2 +- .../ru/ulstu/grant/service/GrantService.java | 19 +++++---- .../java/ru/ulstu/timeline/model/Event.java | 4 +- src/main/resources/application.properties | 2 +- .../grants/fragments/grantLineFragment.html | 3 +- .../resources/templates/grants/grant.html | 42 +------------------ .../papers/fragments/paperLineFragment.html | 3 +- 10 files changed, 27 insertions(+), 60 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index 91b0f91..a9c01ed 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -43,7 +43,7 @@ public class GrantController { @GetMapping("/dashboard") public void getDashboard(ModelMap modelMap) { - modelMap.put("grants", grantService.findAllDto()); + modelMap.put("grants", grantService.findAllActiveDto()); } @GetMapping("/grant") diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index e0cd9be..369568f 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -43,7 +43,8 @@ public class Grant extends BaseEntity implements UserContainer { IN_WORK("В работе"), COMPLETED("Завершен"), FAILED("Провалены сроки"), - LOADED_FROM_KIAS("Загружен автоматически"); + LOADED_FROM_KIAS("Загружен автоматически"), + SKIPPED("Не интересует"); private String statusName; @@ -62,14 +63,14 @@ public class Grant extends BaseEntity implements UserContainer { @Enumerated(value = EnumType.STRING) private GrantStatus status = GrantStatus.APPLICATION; - @OneToMany(cascade = CascadeType.ALL) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "grant_id") @OrderBy("date") private List deadlines = new ArrayList<>(); private String comment; - @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "grant_id", unique = true) @Fetch(FetchMode.SUBSELECT) private List files = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java index ae9fcc8..876a8c1 100644 --- a/src/main/java/ru/ulstu/grant/repository/GrantRepository.java +++ b/src/main/java/ru/ulstu/grant/repository/GrantRepository.java @@ -17,4 +17,7 @@ public interface GrantRepository extends JpaRepository, BaseRepo @Override @Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ") String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); + + @Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')") + List findAllActive(); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java index fb236af..a2950a6 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantScheduler.java +++ b/src/main/java/ru/ulstu/grant/service/GrantScheduler.java @@ -31,7 +31,7 @@ public class GrantScheduler { log.debug("GrantScheduler.checkDeadlineBeforeWeek finished"); } - @Scheduled(cron = "0 0 8 1 * ?", zone = "Europe/Samara") + @Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara") public void loadGrantsFromKias() { log.debug("GrantScheduler.loadGrantsFromKias started"); try { diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 8d65da7..86f8f1b 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -41,7 +41,6 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @Service public class GrantService extends BaseService { - private final static int MAX_DISPLAY_SIZE = 50; private final Logger log = LoggerFactory.getLogger(GrantService.class); private final GrantRepository grantRepository; @@ -80,9 +79,7 @@ public class GrantService extends BaseService { } public List findAllDto() { - List grants = convert(findAll(), GrantDto::new); - grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE))); - return grants; + return convert(findAll(), GrantDto::new); } public GrantDto findOneDto(Integer id) { @@ -273,11 +270,7 @@ public class GrantService extends BaseService { } public List getAllUncompletedPapers() { - List papers = paperService.findAllNotCompleted(); - papers.stream() - .forEach(paper -> - paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE))); - return papers; + return paperService.findAllNotCompleted(); } public void attachPaper(GrantDto grantDto) { @@ -335,4 +328,12 @@ public class GrantService extends BaseService { } } } + + public List findAllActiveDto() { + return convert(findAllActive(), GrantDto::new); + } + + private List findAllActive() { + return grantRepository.findAllActive(); + } } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index e56c91c..8038f0b 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -65,8 +65,8 @@ public class Event extends BaseEntity { private String description; - @ManyToMany(fetch = FetchType.EAGER) - private List recipients = new ArrayList(); + @ManyToMany(fetch = FetchType.LAZY) + private List recipients = new ArrayList<>(); @ManyToOne @JoinColumn(name = "child_id") diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cdd7569..f4be778 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -35,6 +35,6 @@ liquibase.change-log=classpath:db/changelog-master.xml ng-tracker.base-url=http://127.0.0.1:8080 ng-tracker.undead-user-login=admin ng-tracker.dev-mode=true -ng-tracker.debug_email=romanov73@gmail.com +ng-tracker.debug_email= ng-tracker.use-https=false ng-tracker.check-run=false \ No newline at end of file diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index dda0e8d..877f1d7 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -8,7 +8,8 @@
- + + diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index 38047bf..acb7f7b 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -186,47 +186,7 @@
- - -
- - - Статус статьи - -
- +
diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html index b703859..40d9c34 100644 --- a/src/main/resources/templates/papers/fragments/paperLineFragment.html +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -8,7 +8,8 @@