Long users_id = sessiondataDao.checkSession(SID);
Long user_level = userManager.getUserLevelByID(users_id);
// users only
if (AuthLevelUtil.checkUserLevel(user_level)) {
User from = userManager.getUserById(users_id);
TimeZone timezone = timezoneUtil.getTimeZone(from);
Date start = createCalendarDate(timezone, validFromDate, validFromTime);
Date end = createCalendarDate(timezone, validToDate, validToTime);
log.info("validFromDate: " + CalendarPatterns.getDateWithTimeByMiliSeconds(start));
log.info("validToDate: " + CalendarPatterns.getDateWithTimeByMiliSeconds(end));
Appointment a = new Appointment();
a.setTitle(subject);
a.setDescription(message);
a.setStart(start);
a.setEnd(end);
a.setCategory(appointmentCategoryDao.get(1L));
a.setOwner(from);
if (bookedRoom) {
a.setRoom(new Room());
a.getRoom().setAppointment(true);
a.getRoom().setName(subject);
a.getRoom().setRoomtype(roomTypeDao.get(roomtype_id));
a.getRoom().setNumberOfPartizipants(100L);
a.getRoom().setAllowUserQuestions(true);
a.getRoom().setAllowFontStyles(true);
}
for (String email : recipients) {
MeetingMember mm = new MeetingMember();
mm.setAppointment(a);
mm.setUser(userDao.getContact(email, users_id));
a.getMeetingMembers().add(mm);
}
a = appointmentDao.update(a, users_id);
for (MeetingMember mm : a.getMeetingMembers()) {
User to = mm.getUser();
Room room = a.getRoom();
//TODO should be reviewed
if (!to.getUser_id().equals(from.getUser_id())) {
// One message to the Send
privateMessagesDao.addPrivateMessage(subject,
message, parentMessageId, from, to, from,
bookedRoom, room, false, 0L);
// One message to the Inbox
privateMessagesDao.addPrivateMessage(subject,
message, parentMessageId, from, to, to,
bookedRoom, room, false, 0L);
}
// We do not send an email to the one that has created the
// private message
if (to != null && to.getUser_id().equals(from.getUser_id())) {
continue;
}
if (to.getAdresses() != null) {
String aLinkHTML = "<br/><br/>" + "<a href='" + ContactsHelper.getLink() + "'>"
+ fieldLanguagesValuesDao.get(1302, from.getLanguage_id()) + "</a><br/>";
mailHandler.send(to.getAdresses().getEmail(),
fieldLanguagesValuesDao.get(1301, from.getLanguage_id()) + subject,
message.replaceAll("\\<.*?>", "") + aLinkHTML);
}
}
}