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;
}
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);
}
}
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);
}
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;
}
}
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;
}
Aggregations