OWL ITS + 탐지시스템(인터넷 진흥원)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package kr.wisestone.owl.service.impl;
 
import kr.wisestone.owl.constant.MsgConstants;
import kr.wisestone.owl.domain.Issue;
import kr.wisestone.owl.domain.IssueComment;
import kr.wisestone.owl.domain.User;
import kr.wisestone.owl.exception.OwlRuntimeException;
import kr.wisestone.owl.repository.IssueCommentRepository;
import kr.wisestone.owl.service.IssueCommentService;
import kr.wisestone.owl.service.IssueService;
import kr.wisestone.owl.service.WorkspaceService;
import kr.wisestone.owl.util.ConvertUtil;
import kr.wisestone.owl.vo.IssueCommentVo;
import kr.wisestone.owl.vo.UserVo;
import kr.wisestone.owl.web.form.IssueCommentForm;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
 
@Service
public class IssueCommentServiceImpl extends AbstractServiceImpl<IssueComment, Long, JpaRepository<IssueComment, Long>>
        implements IssueCommentService {
 
    static final Logger log = LoggerFactory.getLogger(IssueCommentServiceImpl.class);
 
    @Autowired
    private IssueCommentRepository issueCommentRepository;
 
    @Autowired
    private IssueService issueService;
 
    @Autowired
    private WorkspaceService workspaceService;
 
    @Override
    protected JpaRepository<IssueComment, Long> getRepository() {
        return this.issueCommentRepository;
    }
 
    //  댓글을 등록한다.
    @Override
    @Transactional
    public IssueComment addIssueComment(IssueCommentForm issueCommentForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
 
        IssueComment issueComment = ConvertUtil.copyProperties(issueCommentForm, IssueComment.class);
 
        this.verifyComment(issueCommentForm.getDescription());
 
        Issue issue = this.issueService.getIssue(issueCommentForm.getIssueId());
        issueComment.setIssue(issue);
        issueComment.setWorkspace(issue.getProject().getWorkspace());
 
        this.issueCommentRepository.saveAndFlush(issueComment);
 
        return issueComment;
    }
 
    //  댓글을 등록한다. (api용)
    @Override
    @Transactional
    public IssueComment addIssueComment(IssueCommentForm issueCommentForm, User user) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace(user);
 
        IssueComment issueComment = ConvertUtil.copyProperties(issueCommentForm, IssueComment.class);
 
        this.verifyComment(issueCommentForm.getDescription());
 
        Issue issue = this.issueService.getIssue(issueCommentForm.getIssueId());
        issueComment.setIssue(issue);
        issueComment.setWorkspace(issue.getProject().getWorkspace());
 
        this.issueCommentRepository.saveAndFlush(issueComment);
 
        return issueComment;
    }
 
    private void verifyComment(String comment) {
        if (StringUtils.isEmpty(comment)) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_COMMENT_NOT_COMMENT));
        }
 
        if (comment.length() > 300) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_COMMENT_MAX_LENGTH_OUT));
        }
    }
 
    //  댓글을 삭제한다.
    @Override
    @Transactional
    public void removeIssueComments(IssueCommentForm issueCommentForm) {
        //  사용하고 있는 업무 공간이 활성 상태인지 확인한다. 사용 공간에서 로그인한 사용자가 비활성인지 확인한다.
        this.workspaceService.checkUseWorkspace();
 
        if (issueCommentForm.getRemoveIds().size() < 1) {
            throw new OwlRuntimeException(MsgConstants.ISSUE_COMMENT_REMOVE_NOT_SELECT);
        }
 
        for (Long issueCommentId : issueCommentForm.getRemoveIds()) {
            this.removeIssueComments(issueCommentId);
        }
 
        this.issueCommentRepository.flush();
    }
 
    //  댓글을 삭제한다.
    private void removeIssueComments(Long issueCommentId) {
        IssueComment issueComment = this.getIssueComment(issueCommentId);
        //  댓글 삭제 권한 체크
        this.checkRemovePermission(issueComment);
 
        this.issueCommentRepository.delete(issueComment);
    }
 
    //  댓글 삭제 권한이 있는지 체크한다.
    private void checkRemovePermission(IssueComment issueComment) {
        UserVo userVo = this.webAppUtil.getLoginUser();
 
        if (!issueComment.getRegisterId().equals(userVo.getId())) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_COMMENT_NOT_REMOVE_PERMISSION));
        }
    }
 
    //  댓글 아이디로 댓글을 조회한다.
    @Override
    @Transactional(readOnly = true)
    public IssueComment getIssueComment(Long id ) {
        if (id == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_COMMENT_NOT_EXIST));
        }
 
        IssueComment issueComment = this.findOne(id);
 
        if (issueComment == null) {
            throw new OwlRuntimeException(
                    this.messageAccessor.getMessage(MsgConstants.ISSUE_COMMENT_NOT_EXIST));
        }
 
        return issueComment;
    }
 
    //  이슈에 등록된 댓글 목록을 조회한다.
    @Override
    @Transactional(readOnly = true)
    public List<IssueCommentVo> findIssueComment(Long issueId) {
        List<IssueCommentVo> issueCommentVos = this.issueCommentRepository.findByIssueId(issueId);
        Issue issue = this.issueService.getIssue(issueId);
        if (issueCommentVos != null && issueCommentVos.size() > 0) {
            for (IssueCommentVo issueCommentVo : issueCommentVos) {
                issueCommentVo.setTitle(issue.getTitle());
            }
        }
        return issueCommentVos;
    }
 
}