SimpleDateFormat dateTimeFormat = getDateTimeFormat(request);
SimpleDateFormat dateFormat = getDateFormat(request);
List entries = session.find("from timeEntry in class org.nxplanner.domain.TimeEntry " +
"where timeEntry.taskId = ? order by timeEntry.reportDate",
form.getOid(), Hibernate.STRING);
Task task = null;
if (entries.size() == 0) {
int taskId = Integer.parseInt(form.getOid());
task = (Task)session.load(Task.class, new Integer(taskId));
}
session.connection().rollback();
int i = 0;
TimeEntry entry = null;
Iterator itr = entries.iterator();
while (itr.hasNext()) {
entry = (TimeEntry)itr.next();
form.setEntryId(i, Integer.toString(entry.getId()));
if (entry.getStartTime() != null) {
form.setStartTime(i, dateTimeFormat.format(entry.getStartTime()));
} else {
form.setStartTime(i, "");
}
if (entry.getEndTime() != null) {
form.setEndTime(i, dateTimeFormat.format(entry.getEndTime()));
} else {
form.setEndTime(i, "");
}
form.setDuration(i, DecimalFormat.format(request, entry.getDuration()));
form.setPerson1Id(i, Integer.toString(entry.getPerson1Id()));
form.setPerson2Id(i, Integer.toString(entry.getPerson2Id()));
if (entry.getReportDate() != null) {
form.setReportDate(i, dateFormat.format(entry.getReportDate()));
} else {
form.setReportDate(i, "");
}
i++;
}
if (entry == null || entry.getEndTime() != null || entry.getDuration() > 0) {
// start new row
form.setEntryId(i, "0");
form.setDeleted(i, null);
form.setStartTime(i, "");
form.setEndTime(i, "");
form.setReportDate(i, dateFormat.format(new Date()));
if (i == 0) {
int personId = task.getAcceptorId();
form.setPerson1Id(i, personId == 0 ? null : Integer.toString(personId));
form.setPerson2Id(i, null);
} else {
form.setPerson1Id(i, form.getPerson1Id(i - 1));
form.setPerson2Id(i, form.getPerson2Id(i - 1));