Search in sources :

Example 6 with Appointment

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());
    }
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) OmCalendarConverter(org.apache.openmeetings.backup.converter.OmCalendarConverter) UserConverter(org.apache.openmeetings.backup.converter.UserConverter) RoomConverter(org.apache.openmeetings.backup.converter.RoomConverter) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Example 7 with Appointment

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;
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) NumberUtils.toLong(org.apache.commons.lang3.math.NumberUtils.toLong)

Example 8 with Appointment

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;
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) CalDAVReportMethod(org.osaf.caldav4j.methods.CalDAVReportMethod) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(net.fortuna.ical4j.model.Calendar) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse) ArrayList(java.util.ArrayList) CompFilter(org.osaf.caldav4j.model.request.CompFilter) CalendarData(org.osaf.caldav4j.model.request.CalendarData) CalendarQuery(org.osaf.caldav4j.model.request.CalendarQuery) DavPropertyNameSet(org.apache.jackrabbit.webdav.property.DavPropertyNameSet) Map(java.util.Map)

Example 9 with Appointment

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;
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) CalDAVReportMethod(org.osaf.caldav4j.methods.CalDAVReportMethod) OmCalendar(org.apache.openmeetings.db.entity.calendar.OmCalendar) Calendar(net.fortuna.ical4j.model.Calendar) MultiStatusResponse(org.apache.jackrabbit.webdav.MultiStatusResponse)

Example 10 with Appointment

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);
    }
}
Also used : Appointment(org.apache.openmeetings.db.entity.calendar.Appointment) MailMessage(org.apache.openmeetings.db.entity.basic.MailMessage) IApplication(org.apache.openmeetings.IApplication) User(org.apache.openmeetings.db.entity.user.User) ArrayList(java.util.ArrayList) IcalHandler(org.apache.openmeetings.util.mail.IcalHandler) Map(java.util.Map)

Aggregations

Appointment (org.apache.openmeetings.db.entity.calendar.Appointment)34 User (org.apache.openmeetings.db.entity.user.User)10 ArrayList (java.util.ArrayList)9 MeetingMember (org.apache.openmeetings.db.entity.calendar.MeetingMember)9 Test (org.junit.Test)9 Date (java.util.Date)7 Calendar (java.util.Calendar)6 Room (org.apache.openmeetings.db.entity.room.Room)5 OmCalendar (org.apache.openmeetings.db.entity.calendar.OmCalendar)4 Calendar (net.fortuna.ical4j.model.Calendar)3 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)3 JSONObject (com.github.openjson.JSONObject)2 Map (java.util.Map)2 TimeZone (java.util.TimeZone)2 DavPropertyNameSet (org.apache.jackrabbit.webdav.property.DavPropertyNameSet)2 AppointmentDTO (org.apache.openmeetings.db.dto.calendar.AppointmentDTO)2 Invitation (org.apache.openmeetings.db.entity.room.Invitation)2 GroupUser (org.apache.openmeetings.db.entity.user.GroupUser)2 PrivateMessage (org.apache.openmeetings.db.entity.user.PrivateMessage)2 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)2