calendar.add(Calendar.DATE, 35);
Date lastDay = calendar.getTime();
User loginUser = UserUtil.getLoginUser();
List<CalendarVO> calendarVOs = new ArrayList<CalendarVO>();
CalendarVO calendarVO = null;
String subject = null;
Date startDate = null;
Date endDate = null;
// Gets call records
int callScope = loginUser.getScope_call();
StringBuilder hqlBuilder = new StringBuilder(
"select subject,start_date from Call call where start_date>=? and start_date<?");
if (callScope == Role.OWNER_OR_DISABLED) {
hqlBuilder.append(" and owner = ").append(loginUser.getId());
}
List calls = callService.findVOByParams(hqlBuilder.toString(),
new Date[] { firstDay, lastDay });
Iterator calllIter = calls.iterator();
while (calllIter.hasNext()) {
Object[] row = (Object[]) calllIter.next();
calendarVO = new CalendarVO();
subject = (String) row[0];
startDate = (Date) row[1];
calendarVO.setSubject(subject);
calendarVO.setStartDate(startDate.getTime());
calendarVO.setEndDate(startDate.getTime());
calendarVO.setType(getText("entity.call.label"));
calendarVO.setDescription("");
calendarVOs.add(calendarVO);
}
// Gets meeting records
int meetingScope = loginUser.getScope_meeting();
hqlBuilder = new StringBuilder(
"select subject,start_date,end_date,location from Meeting meeting where start_date>=? and start_date<?");
if (meetingScope == Role.OWNER_OR_DISABLED) {
hqlBuilder.append(" and owner = ").append(loginUser.getId());
}
List meetings = meetingService.findVOByParams(hqlBuilder.toString(),
new Date[] { firstDay, lastDay });
Iterator meetingIter = meetings.iterator();
String location = null;
StringBuilder descriptionBuilder = null;
while (meetingIter.hasNext()) {
Object[] row = (Object[]) meetingIter.next();
calendarVO = new CalendarVO();
subject = (String) row[0];
startDate = (Date) row[1];
endDate = (Date) row[2];
location = (String) row[3];
descriptionBuilder = new StringBuilder("");
descriptionBuilder.append(CommonUtil.fromNullToEmpty(location));
calendarVO.setSubject(subject);
calendarVO.setStartDate(startDate.getTime());
calendarVO.setEndDate(endDate.getTime());
calendarVO.setType(getText("entity.meeting.label"));
calendarVO.setDescription(descriptionBuilder.toString());
calendarVOs.add(calendarVO);
}
// Gets task records
int taskScope = loginUser.getScope_task();
hqlBuilder = new StringBuilder(
"select subject,start_date,due_date from Task task where start_date>=? and start_date<?");
if (taskScope == Role.OWNER_OR_DISABLED) {
hqlBuilder.append(" and owner = ").append(loginUser.getId());
}
List tasks = taskService.findVOByParams(hqlBuilder.toString(),
new Date[] { firstDay, lastDay });
Iterator taskIter = tasks.iterator();
while (taskIter.hasNext()) {
Object[] row = (Object[]) taskIter.next();
calendarVO = new CalendarVO();
subject = (String) row[0];
startDate = (Date) row[1];
endDate = (Date) row[2];
calendarVO.setSubject(subject);
calendarVO.setStartDate(startDate.getTime());
calendarVO.setEndDate(endDate.getTime());
calendarVO.setType(getText("entity.task.label"));
calendarVO.setDescription("");
calendarVOs.add(calendarVO);
}
JSONArray result = new JSONArray();
if (calendarVOs.size() > 0) {