diff --git a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java index f978d82..1dd0ae6 100644 --- a/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java +++ b/src/main/java/com/tsc/bitbucketbot/config/AppConfig.java @@ -13,7 +13,7 @@ public class AppConfig { @Bean public TaskScheduler taskScheduler() { ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); - taskScheduler.setPoolSize(5); + taskScheduler.setPoolSize(6); return taskScheduler; } diff --git a/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java b/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java index fcaf24a..80ec58a 100644 --- a/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java +++ b/src/main/java/com/tsc/bitbucketbot/repository/jpa/UserRepository.java @@ -4,6 +4,8 @@ import com.tsc.bitbucketbot.domain.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + /** * TODO: Добавить описание класса. * @@ -16,4 +18,6 @@ public interface UserRepository extends JpaRepository { boolean existsByLogin(String login); + List findAllByTelegramIdNotNullAndTokenNotNull(); + } diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java new file mode 100644 index 0000000..7e93fb2 --- /dev/null +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerNotification.java @@ -0,0 +1,22 @@ +//package com.tsc.bitbucketbot.scheduler; +// +//import com.tsc.bitbucketbot.domain.entity.User; +//import com.tsc.bitbucketbot.service.UserService; +//import lombok.RequiredArgsConstructor; +//import org.springframework.scheduling.annotation.Scheduled; +//import org.springframework.stereotype.Service; +// +//import java.util.List; +// +//@Service +//@RequiredArgsConstructor +//public class SchedulerNotification { +// +// private final UserService userService; +// +// @Scheduled(cron = "0 9 * * MON-FRI") +// public void goodMorning() { +// List users = userService.getAllRegister(); +// } +// +//} diff --git a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java index e7cc89d..e7d9ec0 100644 --- a/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java +++ b/src/main/java/com/tsc/bitbucketbot/scheduler/SchedulerPullRequest.java @@ -48,7 +48,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkClosePullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestClose(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { @@ -98,7 +98,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkOldPullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { @@ -237,7 +237,7 @@ public class SchedulerPullRequest { @Scheduled(fixedRate = 30000) public void checkNewPullRequest() { - final List users = userService.getAll(); + final List users = userService.getAllRegister(); for (User user : users) { Optional sheetJson = Utils.urlToJson(bitbucketConfig.getUrlPullRequestOpen(), user.getToken(), PullRequestSheetJson.class); while (sheetJson.isPresent() && sheetJson.get().getValues() != null && !sheetJson.get().getValues().isEmpty()) { diff --git a/src/main/java/com/tsc/bitbucketbot/service/UserService.java b/src/main/java/com/tsc/bitbucketbot/service/UserService.java index 20dedc3..f3e2724 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/UserService.java +++ b/src/main/java/com/tsc/bitbucketbot/service/UserService.java @@ -18,12 +18,11 @@ public interface UserService { Optional getByLogin(String login); - Optional update(User user); - Set existsByLogin(@NonNull Set logins); Optional reg(@NonNull User user); List addAll(Set newUsers); + List getAllRegister(); } diff --git a/src/main/java/com/tsc/bitbucketbot/service/Utils.java b/src/main/java/com/tsc/bitbucketbot/service/Utils.java index ffcca57..5a89540 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/Utils.java +++ b/src/main/java/com/tsc/bitbucketbot/service/Utils.java @@ -2,7 +2,6 @@ package com.tsc.bitbucketbot.service; import com.google.gson.Gson; import lombok.NonNull; -import org.springframework.stereotype.Service; import java.io.BufferedReader; import java.io.IOException; @@ -17,12 +16,16 @@ import java.util.zip.GZIPInputStream; * * @author upagge [30.01.2020] */ -@Service public class Utils { private static Gson gson = new Gson(); - public static Optional urlToJson(@NonNull String urlValue, String token, Class classOfT) { + private Utils() { + throw new IllegalStateException("Утилитарный класс"); + } + + @NonNull + public static Optional urlToJson(String urlValue, String token, Class classOfT) { StringBuilder sb = null; URL url; URLConnection urlCon; diff --git a/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java b/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java index 4c8ea18..3f5cd74 100644 --- a/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java +++ b/src/main/java/com/tsc/bitbucketbot/service/impl/UserServiceImpl.java @@ -38,14 +38,6 @@ public class UserServiceImpl implements UserService { return userRepository.findById(login); } - @Override - public Optional update(User user) { - if (userRepository.existsById(user.getLogin())) { - return Optional.of(userRepository.save(user)); - } - return Optional.empty(); - } - @Override public Set existsByLogin(@NonNull Set logins) { return logins.stream().filter(userRepository::existsById).collect(Collectors.toSet()); @@ -70,4 +62,9 @@ public class UserServiceImpl implements UserService { return userRepository.saveAll(newUsers); } + @Override + public List getAllRegister() { + return userRepository.findAllByTelegramIdNotNullAndTokenNotNull(); + } + }