001 package com.technoetic.xplanner.domain; 002 003 import java.util.Collection; 004 import java.util.HashSet; 005 import java.util.Iterator; 006 007 public class UserStory extends DomainObject { 008 private String name; 009 private String description; 010 private int trackerId; 011 private int iterationId; 012 private Collection tasks = new HashSet(); 013 private Person customer; 014 private double estimatedHours; 015 private double estimatedHoursCache; 016 private double actualHours; 017 private int priority; 018 019 public void setName(String name) { 020 this.name = name; 021 } 022 023 public String getName() { 024 return name; 025 } 026 027 public void setDescription(String description) { 028 this.description = description; 029 } 030 031 public String getDescription() { 032 return description; 033 } 034 035 public void setTrackerId(int trackerId) { 036 this.trackerId = trackerId; 037 } 038 039 public int getTrackerId() { 040 return trackerId; 041 } 042 043 public void setIterationId(int iterationId) { 044 this.iterationId = iterationId; 045 } 046 047 public int getIterationId() { 048 return iterationId; 049 } 050 051 // Hibernate 052 private void setEstimatedHoursField(double estimatedHours) { 053 this.estimatedHours = estimatedHours; 054 } 055 056 // For Hibernate 057 protected double getEstimatedHoursField() { 058 return estimatedHours; 059 } 060 061 public double getEstimatedHours() { 062 if (estimatedHoursCache == 0 && tasks.size() > 0) { 063 estimatedHoursCache = getTaskBasedEstimatedHours(); 064 } 065 if (estimatedHoursCache == 0) { 066 estimatedHoursCache = estimatedHours; 067 } 068 return estimatedHoursCache; 069 } 070 071 public double getTaskBasedEstimatedHours() { 072 double taskBasedEstimatedHours = 0; 073 Iterator itr = tasks.iterator(); 074 while (itr.hasNext()) { 075 Task task = (Task)itr.next(); 076 taskBasedEstimatedHours += task.getEstimatedHours(); 077 } 078 return taskBasedEstimatedHours; 079 } 080 081 public void setEstimatedHours(double estimatedHours) { 082 setEstimatedHoursField(estimatedHours); 083 } 084 085 public double getRemainingHours() { 086 087 if (tasks.size() == 0) 088 return estimatedHours; 089 090 double remainingHours = 0; 091 boolean isTaskEstimatePresent = false; 092 Iterator itr = tasks.iterator(); 093 while (itr.hasNext()) { 094 Task task = (Task)itr.next(); 095 remainingHours += task.getRemainingHours(); 096 isTaskEstimatePresent = isTaskEstimatePresent || (task.getEstimatedHours() > 0); 097 } 098 return isTaskEstimatePresent ? remainingHours : estimatedHours; 099 } 100 101 public double getActualHours() { 102 if (actualHours == 0) { 103 Iterator itr = tasks.iterator(); 104 while (itr.hasNext()) { 105 Task task = (Task)itr.next(); 106 actualHours += task.getActualHours(); 107 } 108 } 109 return actualHours; 110 } 111 112 public double getOriginalEstimatedHours() { 113 double originalEstimatedHours = 0; 114 if (tasks.size() > 0) { 115 Iterator itr = tasks.iterator(); 116 while (itr.hasNext()) { 117 Task task = (Task)itr.next(); 118 originalEstimatedHours += task.getOriginalEstimatedHours(); 119 } 120 } 121 if (originalEstimatedHours == 0) { 122 originalEstimatedHours = estimatedHours; 123 } 124 return originalEstimatedHours; 125 } 126 127 public double getAdjustedEstimatedHours() { 128 double adjustedEstimatedHours = 0; Rate129 if (!tasks.isEmpty()) { 130 Iterator itr = tasks.iterator(); 131 while (itr.hasNext()) { 132 Task task = (Task)itr.next(); 133 adjustedEstimatedHours += task.getAdjustedEstimatedHours(); 134 } 135 if (adjustedEstimatedHours == 0) { 136 adjustedEstimatedHours = estimatedHours; 137 } 138 } else { 139 adjustedEstimatedHours = getEstimatedHours(); 140 } 141 return adjustedEstimatedHours; 142 } 143 144 public boolean isCompleted() { 145 if (tasks.size() > 0) { 146 Iterator itr = tasks.iterator(); 147 while (itr.hasNext()) { 148 Task task = (Task)itr.next(); 149 if (task.isCompleted() == false) { 150 return false; 151 } 152 } 153 return true; 154 } else { 155 return false; 156 } 157 } 158 159 public Collection getTasks() { 160 return tasks; 161 } 162 163 public void setTasks(Collection tasks) { 164 this.tasks = tasks; 165 } 166 167 public int getCustomerId() { 168 if (getCustomer() == null) return 0; 169 return getCustomer().getId(); 170 } 171 172 // public void setCustomerId(int id) { 173 // 174 // } 175 176 public Person getCustomer() { 177 return customer; 178 } 179 180 public void setCustomer(Person customer) { 181 this.customer = customer; 182 } 183 184 public void setPriority(int priority) { 185 this.priority = priority; 186 } 187 188 public int getPriority() { 189 return priority; 190 } 191 192 public String toString() { 193 return "UserStory{" + 194 "name='" + name + "'" + 195 ", iterationId=" + iterationId + 196 "}"; 197 } 198 }