IssueHistory.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. import org.itracker.model.util.IssueUtilities;

  21. /**
  22.  * An issue history entry.
  23.  * <p/>
  24.  * <p>
  25.  * An IssueHistory can only belong to 1 Issue (composition).
  26.  * </p>
  27.  * <p/>
  28.  * <p>
  29.  * PENDING : what's the difference with an IssueActivity ?
  30.  * </p>
  31.  *
  32.  * @author ready
  33.  */
  34. public class IssueHistory extends AbstractEntity {

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

  39.     private Issue issue;

  40.     private String description;

  41.     private int status;

  42.     /**
  43.      * The User who generated this history entry.
  44.      */
  45.     private User creator;

  46.     /**
  47.      * Default constructor (required by Hibernate).
  48.      * <p/>
  49.      * <p>
  50.      * PENDING: should be <code>private</code> so that it can only be used by
  51.      * Hibernate, to ensure that the fields which form an instance's identity
  52.      * are always initialized/never <tt>null</tt>.
  53.      * </p>
  54.      */
  55.     public IssueHistory() {
  56.     }

  57.     public IssueHistory(Issue issue, User creator) {
  58.         setIssue(issue);
  59.         setUser(creator);
  60.         setStatus(IssueUtilities.HISTORY_STATUS_AVAILABLE);
  61.     }

  62.     public IssueHistory(Issue issue, User creator, String description,
  63.                         int status) {
  64.         setIssue(issue);
  65.         setUser(creator);
  66.         setDescription(description);
  67.         setStatus(status);
  68.     }

  69.     public Issue getIssue() {
  70.         return issue;
  71.     }

  72.     public void setIssue(Issue issue) {
  73.         if (issue == null) {
  74.             throw new IllegalArgumentException("null issue");
  75.         }
  76.         this.issue = issue;
  77.     }

  78.     public User getUser() {
  79.         return creator;
  80.     }

  81.     public void setUser(User creator) {
  82.         if (creator == null) {
  83.             throw new IllegalArgumentException("null creator");
  84.         }
  85.         this.creator = creator;
  86.     }

  87.     public int getStatus() {
  88.         return status;
  89.     }

  90.     public void setStatus(int status) {
  91.         this.status = status;
  92.     }

  93.     public String getDescription() {
  94.         return description;
  95.     }

  96.     public void setDescription(String description) {
  97.         this.description = description;
  98.     }


  99.     @Override
  100.     public String toString() {
  101.         return new ToStringBuilder(this).append("id", getId())
  102.                 .append("issue", issue).append("creator", getUser()).append(
  103.                         "createDate", getCreateDate()).toString();
  104.     }

  105.     public static enum Status {

  106.         STATUS_REMOVED(-1),

  107.         STATUS_AVAILABLE(1);

  108.         @SuppressWarnings("unused")
  109.         private final int code;

  110.         private Status(int code) {
  111.             this.code = code;
  112.         }

  113.     }

  114. }