RoomKey roomKey = null;
if (roomName != null) {
roomKey = new RoomKey(roomName);
InfoSiteRoomTimeTable bodyComponent = new InfoSiteRoomTimeTable();
DynaActionForm indexForm = (DynaActionForm) form;
Integer indexWeek = (Integer) indexForm.get("indexWeek");
// Integer executionPeriodID = (Integer)
// indexForm.get("selectedExecutionPeriodID");
String executionPeriodIDString = request.getParameter("selectedExecutionPeriodID");
if (executionPeriodIDString == null) {
executionPeriodIDString = (String) request.getAttribute("selectedExecutionPeriodID");
}
String executionPeriodID = (executionPeriodIDString != null) ? executionPeriodIDString : null;
if (executionPeriodID == null) {
try {
// executionPeriodID = (Integer)
// indexForm.get("selectedExecutionPeriodID");
executionPeriodID =
indexForm.get("selectedExecutionPeriodID").equals("") ? null : (String) indexForm
.get("selectedExecutionPeriodID");
} catch (IllegalArgumentException ex) {
}
}
Calendar today = new DateMidnight().toCalendar(null);
ArrayList weeks = new ArrayList();
InfoExecutionPeriod executionPeriod;
if (executionPeriodID == null) {
executionPeriod = ReadCurrentExecutionPeriod.run();
executionPeriodID = executionPeriod.getExternalId();
try {
indexForm.set("selectedExecutionPeriodID", executionPeriod.getExternalId().toString());
} catch (IllegalArgumentException ex) {
}
} else {
executionPeriod = ReadExecutionPeriodByOID.run(executionPeriodID);
}
// weeks
Calendar begin = Calendar.getInstance();
begin.setTime(executionPeriod.getBeginDate());
Calendar end = Calendar.getInstance();
end.setTime(executionPeriod.getEndDate());
ArrayList weeksLabelValueList = new ArrayList();
begin.add(Calendar.DATE, Calendar.MONDAY - begin.get(Calendar.DAY_OF_WEEK));
int i = 0;
boolean selectedWeek = false;
while (begin.before(end) || begin.before(Calendar.getInstance())) {
Calendar day = Calendar.getInstance();
day.setTimeInMillis(begin.getTimeInMillis());
weeks.add(day);
String beginWeekString = DateFormatUtils.format(begin.getTime(), "dd/MM/yyyy");
begin.add(Calendar.DATE, 5);
String endWeekString = DateFormatUtils.format(begin.getTime(), "dd/MM/yyyy");
weeksLabelValueList.add(new LabelValueBean(beginWeekString + " - " + endWeekString, new Integer(i).toString()));
begin.add(Calendar.DATE, 2);
if (!selectedWeek && indexWeek == null && Calendar.getInstance().before(begin)) {
indexForm.set("indexWeek", new Integer(i));
selectedWeek = true;
}
i++;
}
final Collection<ExecutionSemester> executionSemesters = rootDomainObject.getExecutionPeriodsSet();
final List<LabelValueBean> executionPeriodLabelValueBeans = new ArrayList<LabelValueBean>();
for (final ExecutionSemester ep : executionSemesters) {
if (ep.getState().equals(PeriodState.OPEN) || ep.getState().equals(PeriodState.CURRENT)) {
executionPeriodLabelValueBeans.add(new LabelValueBean(ep.getName() + " " + ep.getExecutionYear().getYear(),
ep.getExternalId().toString()));
}
}
request.setAttribute(PresentationConstants.LABELLIST_EXECUTIONPERIOD, executionPeriodLabelValueBeans);
request.setAttribute(PresentationConstants.LABELLIST_WEEKS, weeksLabelValueList);
if (indexWeek != null) {
final int xpto = indexWeek.intValue();
if (xpto < weeks.size()) {
today = (Calendar) weeks.get(xpto);
} else {
today = (Calendar) weeks.iterator().next();
indexForm.set("indexWeek", new Integer(0));
}
}
try {
InfoSiteRoomTimeTable component = run(roomKey, today, executionPeriodID);
request.setAttribute("component", component);
} catch (NonExistingServiceException e) {
throw new NonExistingActionException(e);
} catch (FenixServiceException e) {
throw new FenixActionException(e);