use of org.apache.openmeetings.db.entity.calendar.Appointment in project openmeetings by apache.
the class BackupImport method importAppointments.
/*
* ##################### Import Appointements
*/
private void importAppointments(File f) throws Exception {
log.info("Calendar import complete, starting appointement import");
Registry registry = new Registry();
Strategy strategy = new RegistryStrategy(registry);
Serializer serializer = new Persister(strategy);
registry.bind(User.class, new UserConverter(userDao, userMap));
registry.bind(Appointment.Reminder.class, AppointmentReminderTypeConverter.class);
registry.bind(Room.class, new RoomConverter(roomDao, roomMap));
registry.bind(Date.class, DateConverter.class);
registry.bind(OmCalendar.class, new OmCalendarConverter(calendarDao, calendarMap));
List<Appointment> list = readList(serializer, f, "appointements.xml", "appointments", Appointment.class);
for (Appointment a : list) {
Long appId = a.getId();
// We need to reset this as openJPA reject to store them otherwise
a.setId(null);
if (a.getOwner() != null && a.getOwner().getId() == null) {
a.setOwner(null);
}
if (a.getRoom() == null || a.getRoom().getId() == null) {
log.warn("Appointment without room was found, skipping: {}", a);
continue;
}
if (a.getStart() == null || a.getEnd() == null) {
log.warn("Appointment without start/end time was found, skipping: {}", a);
continue;
}
a = appointmentDao.update(a, null, false);
appointmentMap.put(appId, a.getId());
}
}
use of org.apache.openmeetings.db.entity.calendar.Appointment in project openmeetings by apache.
the class AppointmentConverter method read.
@Override
public Appointment read(InputNode node) throws Exception {
long oldId = toLong(node.getValue());
Long newId = idMap.containsKey(oldId) ? idMap.get(oldId) : oldId;
Appointment a = appointmentDao.getAny(newId);
return a == null ? new Appointment() : a;
}
use of org.apache.openmeetings.db.entity.calendar.Appointment in project openmeetings by apache.
the class EtagsHandler method internalSyncItems.
@Override
DavMethodBase internalSyncItems() throws IOException, DavException {
Long ownerId = this.calendar.getOwner().getId();
Map<String, Appointment> map = listToMap(appointmentDao.getHrefsbyCalendar(calendar.getId()), appointmentDao.getbyCalendar(calendar.getId()));
DavPropertyNameSet properties = new DavPropertyNameSet();
properties.add(DavPropertyName.GETETAG);
CompFilter vcalendar = new CompFilter(Calendar.VCALENDAR);
vcalendar.addCompFilter(new CompFilter(Component.VEVENT));
CalendarQuery query = new CalendarQuery(properties, vcalendar, map.isEmpty() ? new CalendarData() : null, false, false);
CalDAVReportMethod method = new CalDAVReportMethod(path, query, CalDAVConstants.DEPTH_1);
client.executeMethod(method);
if (method.succeeded()) {
MultiStatusResponse[] multiStatusResponses = method.getResponseBodyAsMultiStatus().getResponses();
if (map.isEmpty()) {
// Parse the responses into Appointments
for (MultiStatusResponse response : multiStatusResponses) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
String etag = CalendarDataProperty.getEtagfromResponse(response);
Calendar ical = CalendarDataProperty.getCalendarfromResponse(response);
Appointment appointments = utils.parseCalendartoAppointment(ical, response.getHref(), etag, calendar);
appointmentDao.update(appointments, ownerId);
}
}
} else {
// Calendar has been inited before
List<String> currenthrefs = new ArrayList<>();
for (MultiStatusResponse response : multiStatusResponses) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
Appointment appointment = map.get(response.getHref());
// Event updated
if (appointment != null) {
String origetag = appointment.getEtag(), currentetag = CalendarDataProperty.getEtagfromResponse(response);
// If etag is modified
if (!currentetag.equals(origetag)) {
currenthrefs.add(appointment.getHref());
}
map.remove(response.getHref());
} else {
// The orig list of events doesn't contain this event.
currenthrefs.add(response.getHref());
}
}
}
// Remaining Events have been deleted on the server, thus delete them
for (Map.Entry<String, Appointment> entry : map.entrySet()) {
appointmentDao.delete(entry.getValue(), ownerId);
}
// Get the rest of the events through a Multiget Handler.
MultigetHandler multigetHandler = new MultigetHandler(currenthrefs, path, calendar, client, appointmentDao, utils);
releaseConnection(method);
return multigetHandler.internalSyncItems();
}
} else {
log.error("Report Method return Status: {} for calId {} ", method.getStatusCode(), calendar.getId());
}
return method;
}
use of org.apache.openmeetings.db.entity.calendar.Appointment in project openmeetings by apache.
the class MultigetHandler method internalSyncItems.
@Override
DavMethodBase internalSyncItems() throws IOException, DavException {
Long ownerId = this.calendar.getOwner().getId();
if (!isMultigetDisabled) {
CalDAVReportMethod method = new CalDAVReportMethod(path, query, CalDAVConstants.DEPTH_1);
client.executeMethod(method);
if (method.succeeded()) {
// Map for each Href as key and Appointment as Value.
Map<String, Appointment> map = listToMap(appointmentDao.getHrefsbyCalendar(calendar.getId()), appointmentDao.getbyCalendar(calendar.getId()));
for (MultiStatusResponse response : method.getResponseBodyAsMultiStatus().getResponses()) {
if (response.getStatus()[0].getStatusCode() == SC_OK) {
Appointment a = map.get(response.getHref());
// Check if it's an updated Appointment
if (a != null) {
String origetag = a.getEtag(), currentetag = CalendarDataProperty.getEtagfromResponse(response);
// If etag is modified
if (!currentetag.equals(origetag)) {
if (onlyEtag) {
a.setEtag(currentetag);
} else {
Calendar calendar = CalendarDataProperty.getCalendarfromResponse(response);
a = utils.parseCalendartoAppointment(a, calendar, currentetag);
}
appointmentDao.update(a, ownerId);
}
} else if (!onlyEtag) {
// Else it's a new Appointment
// i.e. parse into a new Appointment
// Only applicable when we get calendar data along with etag.
String etag = CalendarDataProperty.getEtagfromResponse(response);
Calendar ical = CalendarDataProperty.getCalendarfromResponse(response);
Appointment appointments = utils.parseCalendartoAppointment(ical, response.getHref(), etag, calendar);
appointmentDao.update(appointments, ownerId);
}
}
}
} else {
log.error("Report Method return Status: {} for calId {}", method.getStatusCode(), calendar.getId());
}
return method;
}
return null;
}
use of org.apache.openmeetings.db.entity.calendar.Appointment in project openmeetings by apache.
the class InvitationManager method sendInvitationLink.
@Override
public void sendInvitationLink(Invitation i, MessageType type, String subject, String message, boolean ical) throws Exception {
String invitationLink = null;
if (type != MessageType.Cancel) {
IApplication app = ensureApplication(1L);
invitationLink = app.getOmInvitationLink(i);
}
User owner = i.getInvitedBy();
String invitorName = owner.getFirstname() + " " + owner.getLastname();
String template = InvitationTemplate.getEmail(i.getInvitee(), invitorName, message, invitationLink);
String email = i.getInvitee().getAddress().getEmail();
String replyToEmail = owner.getAddress().getEmail();
if (ical) {
String username = i.getInvitee().getLogin();
boolean isOwner = owner.getId().equals(i.getInvitee().getId());
IcalHandler handler = new IcalHandler(MessageType.Cancel == type ? IcalHandler.ICAL_METHOD_CANCEL : IcalHandler.ICAL_METHOD_REQUEST);
Map<String, String> attendeeList = handler.getAttendeeData(email, username, isOwner);
List<Map<String, String>> atts = new ArrayList<>();
atts.add(attendeeList);
// Defining Organizer
Map<String, String> organizerAttendee = handler.getAttendeeData(replyToEmail, owner.getLogin(), isOwner);
Appointment a = i.getAppointment();
// Create ICal Message
String meetingId = handler.addNewMeeting(a.getStart(), a.getEnd(), a.getTitle(), atts, invitationLink, organizerAttendee, a.getIcalId(), getTimeZone(owner).getID());
// Writing back meetingUid
if (Strings.isEmpty(a.getIcalId())) {
a.setIcalId(meetingId);
}
log.debug(handler.getICalDataAsString());
mailHandler.send(new MailMessage(email, replyToEmail, subject, template, handler.getIcalAsByteArray()));
} else {
mailHandler.send(email, replyToEmail, subject, template);
}
}
Aggregations