001 /*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019 */
020 package org.sonar.api.issue.internal;
021
022 import org.sonar.api.issue.IssueComment;
023 import org.sonar.api.utils.internal.Uuids;
024
025 import javax.annotation.CheckForNull;
026 import javax.annotation.Nullable;
027 import java.io.Serializable;
028 import java.util.Date;
029
030 /**
031 * PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
032 *
033 * @since 3.6
034 */
035 public class DefaultIssueComment implements Serializable, IssueComment {
036
037 private String issueKey;
038 private String userLogin;
039 private Date createdAt, updatedAt;
040 private String key;
041 private String markdownText;
042 private boolean isNew;
043
044 @Override
045 public String markdownText() {
046 return markdownText;
047 }
048
049 public DefaultIssueComment setMarkdownText(String s) {
050 this.markdownText = s;
051 return this;
052 }
053
054 @Override
055 public String issueKey() {
056 return issueKey;
057 }
058
059 public DefaultIssueComment setIssueKey(String s) {
060 this.issueKey = s;
061 return this;
062 }
063
064 @Override
065 public String key() {
066 return key;
067 }
068
069 public DefaultIssueComment setKey(String key) {
070 this.key = key;
071 return this;
072 }
073
074 /**
075 * The user who created the comment. Null if it was automatically generated during project scan.
076 */
077 @Override
078 @CheckForNull
079 public String userLogin() {
080 return userLogin;
081 }
082
083 public DefaultIssueComment setUserLogin(@Nullable String userLogin) {
084 this.userLogin = userLogin;
085 return this;
086 }
087
088 @Override
089 public Date createdAt() {
090 return createdAt;
091 }
092
093 public DefaultIssueComment setCreatedAt(Date createdAt) {
094 this.createdAt = createdAt;
095 return this;
096 }
097
098 @Override
099 public Date updatedAt() {
100 return updatedAt;
101 }
102
103 public DefaultIssueComment setUpdatedAt(Date updatedAt) {
104 this.updatedAt = updatedAt;
105 return this;
106 }
107
108 public boolean isNew() {
109 return isNew;
110 }
111
112 public DefaultIssueComment setNew(boolean b) {
113 isNew = b;
114 return this;
115 }
116
117 public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
118 DefaultIssueComment comment = new DefaultIssueComment();
119 comment.setIssueKey(issueKey);
120 comment.setKey(Uuids.create());
121 Date now = new Date();
122 comment.setUserLogin(login);
123 comment.setMarkdownText(markdownText);
124 comment.setCreatedAt(now).setUpdatedAt(now);
125 comment.setNew(true);
126 return comment;
127 }
128 }