return task;
}
private static TimecardVO createTimecard(PersonVO submitter, PersonVO approver) {
// Instantiate a timecard
TimecardVO timecard = new TimecardVO();
timecard.setStatus(TimecardStatus.DRAFT);
timecard.setBegDate(new Date());
timecard.setSubmitterName(submitter.getUsername());
timecard.setApproverName(approver.getUsername());
timecard.setComments("On track!");
// Get all tasks to choose from
TaskVO[] tasks = timeTrackingService.getAllTasks();
// Instantiate allocations
int count = (int) (Math.random() * 3 + 1);
TimeAllocationVO[] allocations = new TimeAllocationVO[count];
timecard.setAllocations(allocations);
for (int i = 0; i < count; i++) {
Date startTime = new Date(timecard.getBegDate().getTime() + i * MILLIS_IN_DAY);
Date endTime = new Date(timecard.getBegDate().getTime() + (i + 1) * MILLIS_IN_DAY);
TaskVO task = tasks[(int)Math.round((Math.random()*(tasks.length - 1)))];
allocations[i] = new TimeAllocationVO(
null,
new TimePeriodVO(startTime, endTime),
task.getId());
}
// Create timecard
timecard.setId(timeTrackingService.createTimecard(timecard));
System.out.println(
"Timecard " + timecard.getId() + " created with " +
timecard.getAllocations().length + " allocations");
return timecard;
}