Search in sources :

Example 1 with TeamEventDO

use of org.projectforge.business.teamcal.event.model.TeamEventDO in project projectforge by micromata.

the class ICalParser method parse.

private TeamEventDO parse(final VEvent vEvent) {
    final ICalConverterStore store = ICalConverterStore.getInstance();
    // create vEvent
    final TeamEventDO event = new TeamEventDO();
    event.setCreator(user);
    for (String extract : this.parseVEvent) {
        VEventComponentConverter converter = store.getVEventConverter(extract);
        if (converter == null) {
            log.warn(String.format("No converter found for '%s', converter is skipped", extract));
            continue;
        }
        converter.fromVEvent(event, vEvent);
    }
    return event;
}
Also used : TeamEventDO(org.projectforge.business.teamcal.event.model.TeamEventDO)

Example 2 with TeamEventDO

use of org.projectforge.business.teamcal.event.model.TeamEventDO in project projectforge by micromata.

the class ICalHandler method saveOrUpdate.

private void saveOrUpdate(final EventHandle eventHandle) {
    final TeamEventDO event = eventHandle.getEvent();
    final TeamEventDO eventInDB = eventHandle.getEventInDB();
    // set calendar
    event.setCalendar(eventHandle.getCalendar());
    // fix attendees
    this.fixAttendees(eventHandle);
    if (eventInDB != null) {
        // event exists, update metadata
        event.setId(eventInDB.getPk());
        event.setCreated(eventInDB.getCreated());
        event.setLastUpdate();
        event.setCreator(eventInDB.getCreator());
        final boolean isDeleted = eventInDB.isDeleted();
        if (isDeleted) {
            // event is deleted, restore
            eventService.undelete(eventInDB);
        }
        // update attendees & event
        eventService.updateAttendees(event, eventInDB.getAttendees());
        eventService.update(event);
        // send notification mail
        if (isDeleted) {
            eventService.checkAndSendMail(event, TeamEventDiffType.NEW);
        } else {
            eventService.checkAndSendMail(event, eventInDB);
        }
    } else {
        // save attendee list, assign after saving the event
        Set<TeamEventAttendeeDO> attendees = new HashSet<>();
        event.getAttendees().forEach(att -> attendees.add(att.clone()));
        event.setAttendees(null);
        // save event & set attendees
        eventService.save(event);
        eventService.assignAttendees(event, attendees, null);
        // send notification mail
        eventService.checkAndSendMail(event, TeamEventDiffType.NEW);
    }
}
Also used : TeamEventAttendeeDO(org.projectforge.business.teamcal.event.model.TeamEventAttendeeDO) TeamEventDO(org.projectforge.business.teamcal.event.model.TeamEventDO)

Example 3 with TeamEventDO

use of org.projectforge.business.teamcal.event.model.TeamEventDO in project projectforge by micromata.

the class ICalHandler method delete.

private void delete(final EventHandle eventHandle) {
    final TeamEventDO event = eventHandle.getEventInDB();
    if (event == null)
        return;
    eventService.markAsDeleted(event);
    eventService.checkAndSendMail(event, TeamEventDiffType.DELETED);
}
Also used : TeamEventDO(org.projectforge.business.teamcal.event.model.TeamEventDO)

Example 4 with TeamEventDO

use of org.projectforge.business.teamcal.event.model.TeamEventDO in project projectforge by micromata.

the class ICalHandler method validate.

private void validate(final EventHandle eventHandle) {
    final TeamEventDO event = eventHandle.getEvent();
    final TeamCalDO calendar = eventHandle.getCalendar();
    // clear errors & warnings
    eventHandle.getErrors().clear();
    eventHandle.getWarnings().clear();
    // check calender
    if (calendar == null) {
        eventHandle.setEventInDB(null);
        eventHandle.addError(EventHandleError.CALANDER_NOT_SPECIFIED);
        return;
    }
    // check method
    if (eventHandle.getMethod() == null) {
        eventHandle.addError(EventHandleError.NO_METHOD_SELECTED);
        return;
    }
    // check event
    if (event == null) {
        eventHandle.addWarning(EventHandleError.WARN_MAIN_RECURRING_EVENT_MISSING);
        return;
    }
    // check db
    TeamEventDO eventInDB;
    switch(eventHandle.getMethod()) {
        case ADD_UPDATE:
            eventInDB = eventService.findByUid(calendar.getId(), event.getUid(), false);
            eventHandle.setEventInDB(eventInDB);
            if (eventInDB != null && eventInDB.getDtStamp() != null && eventInDB.getDtStamp().after(event.getDtStamp())) {
                eventHandle.addWarning(EventHandleError.WARN_OUTDATED);
            }
            break;
        case CANCEL:
            eventInDB = eventService.findByUid(calendar.getId(), event.getUid(), true);
            eventHandle.setEventInDB(eventInDB);
            if (eventInDB == null) {
                eventHandle.addWarning(EventHandleError.WARN_EVENT_TO_DELETE_NOT_FOUND);
            }
            break;
    }
}
Also used : TeamEventDO(org.projectforge.business.teamcal.event.model.TeamEventDO) TeamCalDO(org.projectforge.business.teamcal.admin.model.TeamCalDO)

Example 5 with TeamEventDO

use of org.projectforge.business.teamcal.event.model.TeamEventDO in project projectforge by micromata.

the class ICalParser method parse.

@Deprecated
public boolean parse(final Calendar calendar) {
    this.method = calendar.getMethod();
    final List<CalendarComponent> list = calendar.getComponents(Component.VEVENT);
    if (list == null || list.size() == 0) {
        // no events found
        return true;
    }
    for (final Component c : list) {
        final VEvent vEvent = (VEvent) c;
        // skip setup event!
        if (vEvent.getSummary() != null && StringUtils.equals(vEvent.getSummary().getValue(), TeamCalConfig.SETUP_EVENT)) {
            continue;
        }
        final TeamEventDO event = this.parse(vEvent);
        if (event != null) {
            this.events.add(vEvent);
            this.extractedEvents.add(event);
        }
    }
    // sorting events
    this.extractedEvents.sort((o1, o2) -> {
        final Date startDate1 = o1.getStartDate();
        final Date startDate2 = o2.getStartDate();
        if (startDate1 == null) {
            if (startDate2 == null) {
                return 0;
            }
            return -1;
        }
        return startDate1.compareTo(startDate2);
    });
    return true;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) TeamEventDO(org.projectforge.business.teamcal.event.model.TeamEventDO) CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) Component(net.fortuna.ical4j.model.Component)

Aggregations

TeamEventDO (org.projectforge.business.teamcal.event.model.TeamEventDO)64 TeamCalDO (org.projectforge.business.teamcal.admin.model.TeamCalDO)17 Test (org.junit.jupiter.api.Test)15 TeamEventAttendeeDO (org.projectforge.business.teamcal.event.model.TeamEventAttendeeDO)12 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ICalHandler (org.projectforge.business.teamcal.event.ical.ICalHandler)8 ICalendarEvent (org.projectforge.business.calendar.event.model.ICalendarEvent)7 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)6 PFUserDO (org.projectforge.framework.persistence.user.entities.PFUserDO)6 Date (java.util.Date)5 HashSet (java.util.HashSet)5 TeamEventEditPage (org.projectforge.web.teamcal.event.TeamEventEditPage)5 ICalParser (org.projectforge.business.teamcal.event.ical.ICalParser)4 ArrayList (java.util.ArrayList)3 InputStream (java.io.InputStream)2 Timestamp (java.sql.Timestamp)2 Calendar (net.fortuna.ical4j.model.Calendar)2 RRule (net.fortuna.ical4j.model.property.RRule)2 ToStringBuilder (org.apache.commons.lang3.builder.ToStringBuilder)2