Продолжаю работу над второй версией

This commit is contained in:
upagge 2020-07-08 16:57:09 +03:00
parent 7b9388f1a4
commit 3a90e04363
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
3 changed files with 92 additions and 25 deletions

View File

@ -3,7 +3,9 @@ package org.sadtech.bot.bitbucketbot.service.impl;
import lombok.NonNull; import lombok.NonNull;
import org.sadtech.basic.context.page.Pagination; import org.sadtech.basic.context.page.Pagination;
import org.sadtech.basic.context.page.Sheet; import org.sadtech.basic.context.page.Sheet;
import org.sadtech.basic.context.service.simple.FilterService;
import org.sadtech.basic.core.service.AbstractBusinessLogicService; import org.sadtech.basic.core.service.AbstractBusinessLogicService;
import org.sadtech.basic.filter.criteria.CriteriaFilter;
import org.sadtech.basic.filter.criteria.CriteriaQuery; import org.sadtech.basic.filter.criteria.CriteriaQuery;
import org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr; import org.sadtech.bot.bitbucketbot.domain.IdAndStatusPr;
import org.sadtech.bot.bitbucketbot.domain.PullRequestStatus; import org.sadtech.bot.bitbucketbot.domain.PullRequestStatus;
@ -17,6 +19,7 @@ import org.sadtech.bot.bitbucketbot.repository.PullRequestsRepository;
import org.sadtech.bot.bitbucketbot.service.ChangeService; import org.sadtech.bot.bitbucketbot.service.ChangeService;
import org.sadtech.bot.bitbucketbot.service.PullRequestsService; import org.sadtech.bot.bitbucketbot.service.PullRequestsService;
import org.sadtech.bot.bitbucketbot.utils.ChangeGenerator; import org.sadtech.bot.bitbucketbot.utils.ChangeGenerator;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -28,11 +31,17 @@ public class PullRequestsServiceImpl extends AbstractBusinessLogicService<PullRe
private final ChangeService changeService; private final ChangeService changeService;
private final PullRequestsRepository pullRequestsRepository; private final PullRequestsRepository pullRequestsRepository;
private final FilterService<PullRequest, PullRequestFilter> filterService;
protected PullRequestsServiceImpl(PullRequestsRepository pullRequestsRepository, ChangeService changeService) { protected PullRequestsServiceImpl(
PullRequestsRepository pullRequestsRepository,
ChangeService changeService,
@Qualifier("pullRequestFilterService") FilterService<PullRequest, PullRequestFilter> pullRequestsFilterService
) {
super(pullRequestsRepository); super(pullRequestsRepository);
this.changeService = changeService; this.changeService = changeService;
this.pullRequestsRepository = pullRequestsRepository; this.pullRequestsRepository = pullRequestsRepository;
this.filterService = pullRequestsFilterService;
} }
@Override @Override
@ -67,14 +76,6 @@ public class PullRequestsServiceImpl extends AbstractBusinessLogicService<PullRe
return oldPullRequest; return oldPullRequest;
} }
private PullRequest findAndFillId(@NonNull PullRequest pullRequest) {
return pullRequestsRepository.findByFilterQuery(
CriteriaQuery.create()
.matchPhrase(PullRequest_.BITBUCKET_ID, pullRequest.getBitbucketId())
.matchPhrase(PullRequest_.REPOSITORY_ID, pullRequest.getRepositoryId())
).orElseThrow(() -> new UpdateException("ПР с таким id не существует"));
}
@NonNull @NonNull
@Override @Override
public List<PullRequest> getAllByReviewerAndStatuses(String login, ReviewerStatus reviewerStatus, Set<PullRequestStatus> statuses) { public List<PullRequest> getAllByReviewerAndStatuses(String login, ReviewerStatus reviewerStatus, Set<PullRequestStatus> statuses) {
@ -92,27 +93,33 @@ public class PullRequestsServiceImpl extends AbstractBusinessLogicService<PullRe
} }
@Override @Override
public Sheet<PullRequest> getAllByFilter(@NonNull PullRequestFilter filter, Pagination pagination) { public Sheet<PullRequest> getAll(@NonNull PullRequestFilter filter, Pagination pagination) {
return null; return filterService.getAll(filter, pagination);
} }
@Override @Override
public Sheet<PullRequest> getALlByFilterQuery(@NonNull PullRequestFilter filter, Pagination pagination) { public List<PullRequest> getAll(@NonNull PullRequestFilter filter) {
return null; return filterService.getAll(filter);
} }
@Override @Override
public Optional<PullRequest> getByFilterQuery(@NonNull PullRequestFilter filterQuery) { public Optional<PullRequest> getFirst(@NonNull PullRequestFilter filter) {
return Optional.empty(); return filterService.getFirst(filter);
} }
@Override @Override
public boolean existsByFilterQuery(@NonNull PullRequestFilter filter) { public boolean exists(@NonNull PullRequestFilter filter) {
return pullRequestsRepository.existsByFilterQuery( return filterService.exists(filter);
CriteriaQuery.<PullRequest>create() }
.matchPhrase(PullRequest_.BITBUCKET_ID, filter.getBitbucketId())
.matchPhrase(PullRequest_.REPOSITORY_ID, filter.getBitbucketRepositoryId()) private PullRequest findAndFillId(@NonNull PullRequest pullRequest) {
); return pullRequestsRepository.findFirst(
CriteriaFilter.create().and(
CriteriaQuery.create()
.matchPhrase(PullRequest_.BITBUCKET_ID, pullRequest.getBitbucketId())
.matchPhrase(PullRequest_.REPOSITORY_ID, pullRequest.getRepositoryId())
)
).orElseThrow(() -> new UpdateException("ПР с таким id не существует"));
} }
} }

View File

@ -0,0 +1,60 @@
package org.sadtech.bot.bitbucketbot.service.impl.filter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.sadtech.basic.context.page.Pagination;
import org.sadtech.basic.context.page.Sheet;
import org.sadtech.basic.context.service.simple.FilterService;
import org.sadtech.basic.filter.Filter;
import org.sadtech.basic.filter.FilterQuery;
import org.sadtech.basic.filter.criteria.CriteriaFilter;
import org.sadtech.basic.filter.criteria.CriteriaQuery;
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest;
import org.sadtech.bot.bitbucketbot.domain.entity.PullRequest_;
import org.sadtech.bot.bitbucketbot.domain.filter.PullRequestFilter;
import org.sadtech.bot.bitbucketbot.repository.PullRequestsRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
@RequiredArgsConstructor
public class PullRequestFilterService implements FilterService<PullRequest, PullRequestFilter> {
private final PullRequestsRepository pullRequestsRepository;
@Override
public Sheet<PullRequest> getAll(@NonNull PullRequestFilter filter, Pagination pagination) {
return pullRequestsRepository.findAll(createFilter(filter), pagination);
}
@Override
public List<PullRequest> getAll(@NonNull PullRequestFilter filter) {
return pullRequestsRepository.findAll(createFilter(filter));
}
@Override
public Optional<PullRequest> getFirst(@NonNull PullRequestFilter filter) {
return pullRequestsRepository.findFirst(createFilter(filter));
}
@Override
public boolean exists(@NonNull PullRequestFilter filter) {
return pullRequestsRepository.exists(createFilter(filter));
}
private FilterQuery convertFilter(@NonNull PullRequestFilter filter) {
return CriteriaQuery.<PullRequest>create()
.matchPhrase(PullRequest_.BITBUCKET_ID, filter.getBitbucketId())
.matchPhrase(PullRequest_.REPOSITORY_ID, filter.getBitbucketRepositoryId());
}
private Filter createFilter(PullRequestFilter filter) {
return CriteriaFilter.<PullRequest>create()
.and(
convertFilter(filter)
);
}
}

View File

@ -55,7 +55,7 @@ public class PullRequestParser {
log.info("Закрыты: " + Arrays.toString(closeId.toArray())); log.info("Закрыты: " + Arrays.toString(closeId.toArray()));
log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray())); log.info("Не найдены: " + Arrays.toString(newNotExistsId.toArray()));
if (!newNotExistsId.isEmpty()) { if (!newNotExistsId.isEmpty()) {
pullRequestsService.deleteAll(newNotExistsId); pullRequestsService.deleteAllById(newNotExistsId);
} }
} }
@ -86,9 +86,9 @@ public class PullRequestParser {
private List<PullRequest> getExistsPr(@NonNull List<PullRequestJson> pullRequestJsons) { private List<PullRequest> getExistsPr(@NonNull List<PullRequestJson> pullRequestJsons) {
return pullRequestJsons.stream() return pullRequestJsons.stream()
.filter(json -> pullRequestsService.existsByFilterQuery(bitbucketIdAndPullRequestId(json))) .map(json -> pullRequestsService.getByFilterQuery(bitbucketIdAndPullRequestId(json)))
.map(pullRequestJson -> conversionService.convert(pullRequestJson, PullRequest.class)) .filter(Optional::isPresent)
.peek(pullRequest -> pullRequestsService.getIdByBitbucketIdAndReposId(pullRequest.getBitbucketId(), pullRequest.getRepositoryId()).ifPresent(pullRequest::setId)) .map(Optional::get)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }