Исправил дублирующийся ответ на комментарии

This commit is contained in:
upagge 2020-10-01 16:30:15 +03:00
parent 9f687469ee
commit b8f4a5fb2a
No known key found for this signature in database
GPG Key ID: 15CD012E46F6BA34
7 changed files with 66 additions and 49 deletions

View File

@ -4,6 +4,7 @@ package org.sadtech.bot.vcs.bitbucket.app.service.converter;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson; import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentJson;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.core.domain.entity.Comment; import org.sadtech.bot.vcs.core.domain.entity.Comment;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,7 +20,7 @@ public class CommentJsonToComment implements Converter<CommentJson, Comment> {
comment.setCreateDate(source.getCreatedDate()); comment.setCreateDate(source.getCreatedDate());
comment.setAuthor(source.getAuthor().getName()); comment.setAuthor(source.getAuthor().getName());
comment.setPullRequestId(source.getCustomPullRequestId()); comment.setPullRequestId(source.getCustomPullRequestId());
comment.setMessage(source.getText()); comment.setMessage(StringUtils.cutOff(source.getText(), 490));
comment.setUrlApi(source.getCustomCommentApiUrl()); comment.setUrlApi(source.getCustomCommentApiUrl());
comment.setBitbucketVersion(source.getVersion()); comment.setBitbucketVersion(source.getVersion());
comment.setAnswers( comment.setAnswers(

View File

@ -6,6 +6,7 @@ import org.sadtech.bot.vcs.bitbucket.sdk.domain.CommentState;
import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity; import org.sadtech.bot.vcs.bitbucket.sdk.domain.Severity;
import org.sadtech.bot.vcs.core.domain.TaskStatus; import org.sadtech.bot.vcs.core.domain.TaskStatus;
import org.sadtech.bot.vcs.core.domain.entity.Task; import org.sadtech.bot.vcs.core.domain.entity.Task;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -19,7 +20,7 @@ public class CommentJsonToTaskConvert implements Converter<CommentJson, Task> {
final Task task = new Task(); final Task task = new Task();
task.setId(source.getId()); task.setId(source.getId());
task.setAuthor(source.getAuthor().getName()); task.setAuthor(source.getAuthor().getName());
task.setDescription(source.getText()); task.setDescription(StringUtils.cutOff(source.getText(), 490));
task.setCreateDate(source.getCreatedDate()); task.setCreateDate(source.getCreatedDate());
task.setBitbucketVersion(source.getVersion()); task.setBitbucketVersion(source.getVersion());
task.setPullRequestId(source.getCustomPullRequestId()); task.setPullRequestId(source.getCustomPullRequestId());

View File

@ -12,6 +12,7 @@ import org.sadtech.bot.vcs.core.domain.PullRequestStatus;
import org.sadtech.bot.vcs.core.domain.ReviewerStatus; import org.sadtech.bot.vcs.core.domain.ReviewerStatus;
import org.sadtech.bot.vcs.core.domain.entity.PullRequest; import org.sadtech.bot.vcs.core.domain.entity.PullRequest;
import org.sadtech.bot.vcs.core.domain.entity.Reviewer; import org.sadtech.bot.vcs.core.domain.entity.Reviewer;
import org.sadtech.bot.vcs.core.utils.StringUtils;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -30,9 +31,9 @@ public class PullRequestJsonConverter implements Converter<PullRequestJson, Pull
pullRequest.setCreateDate(json.getCreatedDate()); pullRequest.setCreateDate(json.getCreatedDate());
pullRequest.setUpdateDate(json.getUpdatedDate()); pullRequest.setUpdateDate(json.getUpdatedDate());
pullRequest.setConflict(convertConflict(json.getProperties())); pullRequest.setConflict(convertConflict(json.getProperties()));
pullRequest.setDescription(convertString(json.getDescription(), 180)); pullRequest.setDescription(StringUtils.cutOff(json.getDescription(), 180));
pullRequest.setAuthorLogin(json.getAuthor().getUser().getName()); pullRequest.setAuthorLogin(json.getAuthor().getUser().getName());
pullRequest.setTitle(convertString(json.getTitle(), 90)); pullRequest.setTitle(StringUtils.cutOff(json.getTitle(), 90));
pullRequest.setUrl(json.getLinks().getSelf().get(0).getHref()); pullRequest.setUrl(json.getLinks().getSelf().get(0).getHref());
pullRequest.setStatus(convertPullRequestStatus(json.getState())); pullRequest.setStatus(convertPullRequestStatus(json.getState()));
pullRequest.setProjectKey(json.getFromRef().getRepository().getProject().getKey()); pullRequest.setProjectKey(json.getFromRef().getRepository().getProject().getKey());
@ -50,13 +51,6 @@ public class PullRequestJsonConverter implements Converter<PullRequestJson, Pull
&& Outcome.CONFLICTED.equals(properties.getMergeResult().getOutcome()); && Outcome.CONFLICTED.equals(properties.getMergeResult().getOutcome());
} }
private String convertString(String string, int length) {
if (string != null) {
return string.length() > length ? string.substring(0, length) + "..." : string;
}
return null;
}
public static PullRequestStatus convertPullRequestStatus(PullRequestState state) { public static PullRequestStatus convertPullRequestStatus(PullRequestState state) {
switch (state) { switch (state) {
case OPEN: case OPEN:

View File

@ -122,23 +122,25 @@ public class CommentServiceImpl extends AbstractSimpleManagerService<Comment, Lo
final Set<Long> newAnswerIds = newComment.getAnswers(); final Set<Long> newAnswerIds = newComment.getAnswers();
if (!oldAnswerIds.equals(newAnswerIds)) { if (!oldAnswerIds.equals(newAnswerIds)) {
final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds); final Set<Long> existsNewAnswersIds = commentRepository.existsById(newAnswerIds);
final List<Comment> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream() if (!existsNewAnswersIds.isEmpty()) {
.filter(comment -> !oldAnswerIds.contains(comment.getId())) final List<Comment> newAnswers = commentRepository.findAllById(existsNewAnswersIds).stream()
.collect(Collectors.toList()); .filter(comment -> !oldAnswerIds.contains(comment.getId()))
oldComment.getAnswers().clear(); .collect(Collectors.toList());
oldComment.setAnswers(existsNewAnswersIds); oldComment.getAnswers().clear();
notifyService.send( oldComment.setAnswers(existsNewAnswersIds);
AnswerCommentNotify.builder() notifyService.send(
.logins(Collections.singleton(newComment.getAuthor())) AnswerCommentNotify.builder()
.url(oldComment.getUrl()) .logins(Collections.singleton(newComment.getAuthor()))
.youMessage(newComment.getMessage()) .url(oldComment.getUrl())
.answers( .youMessage(newComment.getMessage())
newAnswers.stream() .answers(
.map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage())) newAnswers.stream()
.collect(Collectors.toList()) .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
) .collect(Collectors.toList())
.build() )
); .build()
);
}
} }
} }

View File

@ -120,23 +120,25 @@ public class TaskServiceImpl extends AbstractSimpleManagerService<Task, Long> im
final Set<Long> newAnswerIds = task.getAnswers(); final Set<Long> newAnswerIds = task.getAnswers();
if (!oldAnswerIds.equals(newAnswerIds)) { if (!oldAnswerIds.equals(newAnswerIds)) {
final Set<Long> existsNewAnswersIds = commentService.existsById(newAnswerIds); final Set<Long> existsNewAnswersIds = commentService.existsById(newAnswerIds);
final List<Comment> newAnswers = commentService.getAllById(existsNewAnswersIds).stream() if (!existsNewAnswersIds.isEmpty()) {
.filter(comment -> !oldAnswerIds.contains(comment.getId())) final List<Comment> newAnswers = commentService.getAllById(existsNewAnswersIds).stream()
.collect(Collectors.toList()); .filter(comment -> !oldAnswerIds.contains(comment.getId()))
oldTask.getAnswers().clear(); .collect(Collectors.toList());
oldTask.setAnswers(existsNewAnswersIds); oldTask.getAnswers().clear();
notifyService.send( oldTask.setAnswers(existsNewAnswersIds);
AnswerCommentNotify.builder() notifyService.send(
.logins(Collections.singleton(oldTask.getAuthor())) AnswerCommentNotify.builder()
.url(oldTask.getUrl()) .logins(Collections.singleton(oldTask.getAuthor()))
.youMessage(oldTask.getDescription()) .url(oldTask.getUrl())
.answers( .youMessage(oldTask.getDescription())
newAnswers.stream() .answers(
.map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage())) newAnswers.stream()
.collect(Collectors.toList()) .map(answerComment -> Answer.of(answerComment.getAuthor(), answerComment.getMessage()))
) .collect(Collectors.toList())
.build() )
); .build()
);
}
} }
} }

View File

@ -52,8 +52,4 @@ public enum Smile {
return value; return value;
} }
public static class Constants {
public static final String EMPTY = "";
}
} }

View File

@ -0,0 +1,21 @@
package org.sadtech.bot.vcs.core.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
/**
* // TODO: 29.09.2020 Добавить описание.
*
* @author upagge 29.09.2020
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class StringUtils {
public static String cutOff(String string, int length) {
if (string != null) {
return string.length() > length ? string.substring(0, length) + "..." : string;
}
return null;
}
}