IssueRelation.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.core.resources.ITrackerResources;

  21. /**
  22.  * A relation between issues.
  23.  *
  24.  * @author ready
  25.  */
  26. public class IssueRelation extends AbstractEntity {

  27.     /**
  28.      *
  29.      */
  30.     private static final long serialVersionUID = 1L;

  31.     private Issue issue;

  32.     private Issue relatedIssue;

  33.     /**
  34.      * Indicates the kind of relation that exists between the 2 issues.
  35.      */
  36.     private Type type;

  37.     private Integer matchingRelationId;

  38.     /**
  39.      * Default constructor (required by Hibernate).
  40.      * <p/>
  41.      * <p>
  42.      * PENDING: should be <code>private</code> so that it can only be used by
  43.      * Hibernate, to ensure that the fields which form an instance's identity
  44.      * are always initialized/never <tt>null</tt>.
  45.      * </p>
  46.      */
  47.     public IssueRelation() {
  48.     }

  49.     public IssueRelation(Issue issue, Issue relatedIssue, Type relationType) {
  50.         setIssue(issue);
  51.         setRelatedIssue(relatedIssue);
  52.         setRelationType(relationType);
  53.     }

  54.     public Issue getIssue() {
  55.         return issue;
  56.     }

  57.     public void setIssue(Issue issue) {
  58.         if (issue == null) {
  59.             throw new IllegalArgumentException("null issue");
  60.         }
  61.         this.issue = issue;
  62.     }

  63.     public Issue getRelatedIssue() {
  64.         return relatedIssue;
  65.     }

  66.     public void setRelatedIssue(Issue relatedIssue) {
  67.         if (relatedIssue == null) {
  68.             throw new IllegalArgumentException("null relatedIssue");
  69.         }
  70.         this.relatedIssue = relatedIssue;
  71.     }

  72.     public Type getRelationType() {
  73.         return type;
  74.     }

  75.     public void setRelationType(Type type) {
  76.         this.type = type;
  77.     }

  78.     public Integer getMatchingRelationId() {
  79.         return matchingRelationId;
  80.     }

  81.     public void setMatchingRelationId(Integer matchingRelationId) {
  82.         this.matchingRelationId = matchingRelationId;
  83.     }


  84.     @Override
  85.     public String toString() {
  86.         return new ToStringBuilder(this).append("id", getId())
  87.                 .append("issue", getIssue()).append("relatedIssue", getRelatedIssue())
  88.                 .append("type", getRelationType()).toString();
  89.     }

  90.     public static enum Type implements IntCodeEnum<Type> {

  91.         /**
  92.          * Defines a related issue. Sample text: related to
  93.          */
  94.         RELATED_P(1),

  95.         /**
  96.          * Defines a related issue. Sample text: related to
  97.          */
  98.         RELATED_C(2),

  99.         /**
  100.          * Defines a duplicate issue. Sample text: duplicates
  101.          */
  102.         DUPLICATE_P(3),

  103.         /**
  104.          * Defines a duplicate issue. Sample text: duplicate of
  105.          */
  106.         DUPLICATE_C(4),

  107.         /**
  108.          * Defines a cloned issue. Sample text: cloned to
  109.          */
  110.         CLONED_P(5),

  111.         /**
  112.          * Defines a cloned issue. Sample text: cloned from
  113.          */
  114.         CLONED_C(6),

  115.         /**
  116.          * Defines a split issue. Sample text: split to
  117.          */
  118.         SPLIT_P(7),

  119.         /**
  120.          * Defines a split issue. Sample text: split from
  121.          */
  122.         SPLIT_C(8),

  123.         /**
  124.          * Defines a dependent issue. Sample text: dependents
  125.          */
  126.         DEPENDENT_P(9),

  127.         /**
  128.          * Defines a dependent issue. Sample text: depends on
  129.          */
  130.         DEPENDENT_C(10);



  131.         private final Integer code;

  132.         private Type(Integer code) {
  133.             this.code = code;
  134.         }

  135.         public Integer getCode() {
  136.             return code;
  137.         }

  138.         public Type fromCode(Integer code) {
  139.             return Type.valueOf(code);
  140.         }

  141.         public static Type valueOf(Integer code) {
  142.             for (Type val: values()) {
  143.                 if (val.code.compareTo(code) == 0) {
  144.                     return val;
  145.                 }
  146.             }
  147.             throw new IllegalArgumentException("Unknown code : " + code);
  148.         }
  149.         /**
  150.          * Returns the key for a particular issue relation type.
  151.          *
  152.          * @return the key for the item
  153.          */
  154.         public String getLanguageKeyCode() {
  155.             String key = ITrackerResources.KEY_BASE_ISSUE_RELATION + getCode();
  156.             return key;
  157.         }


  158.     }

  159. }