001: /*
002: * @(#)IterationDataSource.java
003: *
004: * Copyright (c) 2003 Sabre Inc. All rights reserved.
005: */
006:
007: package com.technoetic.xplanner.export;
008:
009: import com.technoetic.xplanner.domain.Iteration;
010: import com.technoetic.xplanner.domain.Person;
011: import com.technoetic.xplanner.domain.Task;
012: import com.technoetic.xplanner.domain.UserStory;
013: import dori.jasper.engine.JRDataSource;
014: import dori.jasper.engine.JRException;
015: import dori.jasper.engine.JRField;
016: import net.sf.hibernate.Hibernate;
017: import net.sf.hibernate.HibernateException;
018: import net.sf.hibernate.Session;
019:
020: import java.util.Iterator;
021: import java.util.List;
022:
023: public class IterationDataSource implements JRDataSource {
024: private Iterator iterator = null;
025: private Task task = null;
026: private UserStory story = null;
027: private String acceptor = null;
028: private Session session = null;
029:
030: public IterationDataSource(Iteration iteration, Session session)
031: throws HibernateException {
032:
033: List data = session
034: .find(
035: "select story, task"
036: + " from "
037: + UserStory.class.getName()
038: + " story"
039: + " left join story.tasks as task"
040: + " where story.iterationId = ? order by story.priority, story.name, task.name",
041: new Integer(iteration.getId()),
042: Hibernate.INTEGER);
043: this .session = session;
044: if (data != null) {
045: iterator = data.iterator();
046: }
047: }
048:
049: public boolean next() throws JRException {
050: if (iterator == null || !iterator.hasNext()) {
051: return false;
052: }
053:
054: Object[] result = (Object[]) iterator.next();
055:
056: story = (UserStory) result[0];
057: task = (Task) result[1];
058: if (task != null)
059: acceptor = PdfReportExporter.getPersonName(session,
060: new Integer(task.getAcceptorId()));
061: return true;
062: }
063:
064: public Object getFieldValue(JRField field) throws JRException {
065: return getFieldValue(field.getName());
066: }
067:
068: public Object getFieldValue(String fieldName) throws JRException {
069: if ("StoryName".equals(fieldName)) {
070: return story.getName();
071: }
072:
073: if ("StoryCustomerName".equals(fieldName)) {
074: Person cust = story.getCustomer();
075: return (cust != null) ? cust.getName() : "<no customer>";
076: }
077:
078: if ("StoryEstimatedHours".equals(fieldName)) {
079: return new Double(story.getEstimatedHours());
080: }
081:
082: if ("TaskName".equals(fieldName)) {
083: if (task == null)
084: return "No Tasks Defined";
085: return task.getName();
086: }
087:
088: if ("TaskPercentage".equals(fieldName)) {
089: if (task == null)
090: return new Integer(0);
091: double actual = task.getActualHours();
092: return new Integer((int) ((actual * 100) / (actual + task
093: .getRemainingHours())));
094: }
095:
096: if ("TaskDisposition".equals(fieldName)) {
097: if (task == null)
098: return "";
099: return task.getDisposition().getName();
100: }
101:
102: if ("TaskType".equals(fieldName)) {
103: if (task == null)
104: return "";
105: return task.getType();
106: }
107:
108: if ("TaskEstimate".equals(fieldName)) {
109: if (task == null)
110: return new Double(0.0);
111: return new Double(task.getEstimatedHours());
112: }
113:
114: if ("TaskCompleted".equals(fieldName)) {
115: if (task == null)
116: return new Boolean(false);
117: return new Boolean(task.isCompleted());
118: }
119:
120: if ("TaskAcceptor".equals(fieldName)) {
121: if (task == null)
122: return null;
123: return acceptor;
124: }
125:
126: throw new JRException("Unexpected field name '" + fieldName
127: + "'");
128: }
129: }
|