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 */
020package org.sonar.api.issue.internal;
021
022import org.sonar.api.issue.IssueComment;
023import org.sonar.api.utils.internal.Uuids;
024
025import javax.annotation.CheckForNull;
026import javax.annotation.Nullable;
027
028import java.io.Serializable;
029import java.util.Date;
030
031/**
032 * PLUGINS MUST NOT BE USED THIS CLASS, EXCEPT FOR UNIT TESTING.
033 *
034 * @since 3.6
035 */
036public class DefaultIssueComment implements Serializable, IssueComment {
037
038  private String issueKey;
039  private String userLogin;
040  private Date createdAt, updatedAt;
041  private String key;
042  private String markdownText;
043  private boolean isNew;
044
045  public static DefaultIssueComment create(String issueKey, @Nullable String login, String markdownText) {
046    DefaultIssueComment comment = new DefaultIssueComment();
047    comment.setIssueKey(issueKey);
048    comment.setKey(Uuids.create());
049    Date now = new Date();
050    comment.setUserLogin(login);
051    comment.setMarkdownText(markdownText);
052    comment.setCreatedAt(now).setUpdatedAt(now);
053    comment.setNew(true);
054    return comment;
055  }
056
057  @Override
058  public String markdownText() {
059    return markdownText;
060  }
061
062  public DefaultIssueComment setMarkdownText(String s) {
063    this.markdownText = s;
064    return this;
065  }
066
067  @Override
068  public String issueKey() {
069    return issueKey;
070  }
071
072  public DefaultIssueComment setIssueKey(String s) {
073    this.issueKey = s;
074    return this;
075  }
076
077  @Override
078  public String key() {
079    return key;
080  }
081
082  public DefaultIssueComment setKey(String key) {
083    this.key = key;
084    return this;
085  }
086
087  /**
088   * The user who created the comment. Null if it was automatically generated during project scan.
089   */
090  @Override
091  @CheckForNull
092  public String userLogin() {
093    return userLogin;
094  }
095
096  public DefaultIssueComment setUserLogin(@Nullable String userLogin) {
097    this.userLogin = userLogin;
098    return this;
099  }
100
101  @Override
102  public Date createdAt() {
103    return createdAt;
104  }
105
106  public DefaultIssueComment setCreatedAt(Date createdAt) {
107    this.createdAt = createdAt;
108    return this;
109  }
110
111  @Override
112  public Date updatedAt() {
113    return updatedAt;
114  }
115
116  public DefaultIssueComment setUpdatedAt(@Nullable Date updatedAt) {
117    this.updatedAt = updatedAt;
118    return this;
119  }
120
121  public boolean isNew() {
122    return isNew;
123  }
124
125  public DefaultIssueComment setNew(boolean b) {
126    isNew = b;
127    return this;
128  }
129}