}
if (inv.hasParameter("year")) {
int year = inv.getInteger("year");
int month = inv.getInteger("month");
if (!inv.isValid()) {
throw new UserException(doc);
}
cal.set(Calendar.YEAR, year);
cal.set(Calendar.MONTH, month - 1);
} else {
cal.setTime(defaultDate.getDate());
}
cal.set(Calendar.DAY_OF_MONTH, 1);
cal.set(Calendar.HOUR, 0);
cal.set(Calendar.MINUTE, 30);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
Date startDate;
try {
startDate = cal.getTime();
} catch (IllegalArgumentException e) {
throw new UserException(doc, "Invalid date. " + e.getMessage());
}
source.appendChild(defaultDate.toXml(doc));
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.MINUTE, -30);
Date finishDate = cal.getTime();
if ((generationFinishDate != null && generationFinishDate.getDate()
.before(startDate))
|| generationStartDate.getDate().after(finishDate)) {
throw new UserException(doc,
"This month doesn't overlap with the generation.");
}
for (HhDatum datum : (List<HhDatum>) Hiber
.session()
.createQuery(