IssueActivity.java

  1. /*
  2.  * This software was designed and created by Jason Carroll.
  3.  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
  4.  * The author can be reached at jcarroll@cowsultants.com
  5.  * ITracker website: http://www.cowsultants.com
  6.  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it only under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  */

  18. package org.itracker.model;

  19. import org.apache.commons.lang.builder.ToStringBuilder;

  20. /**
  21.  * An issue activity.
  22.  * <p/>
  23.  * <p>
  24.  * An IssueActivity can only belong to 1 Issue (composition).
  25.  * </p>
  26.  * <p/>
  27.  * <p>
  28.  * The natural key of an IssueActivity is issue + user + type + createDate.
  29.  * </p>
  30.  *
  31.  * @author ready
  32.  */
  33. public class IssueActivity extends AbstractEntity {

  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;

  38.     /**
  39.      * Issue to which this activity is related.
  40.      */
  41.     private Issue issue;

  42.     /**
  43.      * The User who generated this activity.
  44.      */
  45.     private User user;

  46.     /**
  47.      * Optional activity description.
  48.      */
  49.     private String description = "";

  50.     /**
  51.      * Whether a notification has been sent for this activity.
  52.      */
  53.     private boolean notificationSent = false;

  54.     private IssueActivityType activityType = IssueActivityType.ISSUE_CREATED;

  55.     /**
  56.      * Default constructor (required by Hibernate).
  57.      * <p/>
  58.      * <p>
  59.      * PENDING: should be <code>private</code> so that it can only be used by
  60.      * Hibernate, to ensure that <code>issue</code>, <code>user</code> and
  61.      * <code>type</code>, which form an instance's identity, are always
  62.      * initialized.
  63.      * </p>
  64.      */
  65.     public IssueActivity() {

  66.     }

  67.     /**
  68.      * Creates a new instance with a <code>notificationSent</code> flag set to
  69.      * <tt>false</tt> and a creation and last modified time stamp set to the
  70.      * current time.
  71.      */
  72.     public IssueActivity(Issue issue, User user, IssueActivityType type) {
  73.         setIssue(issue);
  74.         setUser(user);
  75.         setActivityType(type);
  76.     }

  77.     public Issue getIssue() {
  78.         return issue;
  79.     }

  80.     public void setIssue(Issue issue) {
  81.         if (issue == null) {
  82.             throw new IllegalArgumentException("null issue");
  83.         }
  84.         this.issue = issue;
  85.     }

  86.     public User getUser() {
  87.         return user;
  88.     }

  89.     public void setUser(User user) {
  90.         if (user == null) {
  91.             throw new IllegalArgumentException("null user");
  92.         }
  93.         this.user = user;
  94.     }

  95.     public void setActivityType(IssueActivityType type) {

  96.         // this.type = type.code;
  97.         this.activityType = type;
  98.     }

  99.     public IssueActivityType getActivityType() {
  100.         return this.activityType;
  101.     }

  102.     public String getDescription() {
  103.         return description;
  104.     }

  105.     public void setDescription(String description) {
  106.         this.description = description;
  107.     }

  108.     public boolean getNotificationSent() {
  109.         return notificationSent;
  110.     }

  111.     public void setNotificationSent(boolean sent) {
  112.         this.notificationSent = sent;
  113.     }

  114.     public String toString() {
  115.         return new ToStringBuilder(this).append("id", getId())
  116.                 .append("issue", getIssue()).append("user", getUser()).append("type",
  117.                         getActivityType()).append("createDate", getCreateDate())
  118.                 .toString();

  119.     }

  120. }