net.fortuna.ical4j.model.component.VEvent Java Examples
The following examples show how to use
net.fortuna.ical4j.model.component.VEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IcsCalendarBuilder.java From fredbet with Creative Commons Attribution Share Alike 4.0 International | 7 votes |
public byte[] build() { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone(timeZone); VTimeZone tz = timezone.getVTimeZone(); VEvent vEvent = new VEvent(toDate(this.start), toDate(this.end), this.title); vEvent.getProperties().add(tz.getTimeZoneId()); vEvent.getProperties().add(uidGenerator.generateUid()); vEvent.getProperties().add(new Description(this.content)); vEvent.getProperties().add(new Location(this.location)); net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar(); icsCalendar.getProperties().add(new ProdId("-//FredBet//iCal4j 1.0//EN")); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getComponents().add(vEvent); try (ByteArrayOutputStream out = new ByteArrayOutputStream();) { CalendarOutputter outputter = new CalendarOutputter(); outputter.output(icsCalendar, out); return out.toByteArray(); } catch (IOException e) { LOG.error(e.getMessage()); return null; } }
Example #2
Source File: OrganizerEmailBase.java From sakai with Educational Community License v2.0 | 6 votes |
/** * {@inheritDoc} */ public List<VEvent> generateEvents(User user, SignupCalendarHelper calendarHelper) { List<VEvent> events = new ArrayList<VEvent>(); VEvent meetingEvent = meeting.getVevent(); if (meetingEvent == null) { return events; } Set<SignupAttendee> attendees = new HashSet<SignupAttendee>(); for(SignupTimeslot timeslot: meeting.getSignupTimeSlots()) { attendees.addAll(timeslot.getAttendees()); } calendarHelper.addAttendeesToVEvent(meetingEvent, attendees); events.add(meetingEvent); return events; }
Example #3
Source File: EntityConverter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Sync exceptions. * @param exceptions The exceptions. * @param masterNote The master note. */ private void syncExceptions(Map<Date, VEvent> exceptions, NoteItem masterNote) { for (Entry<Date, VEvent> entry : exceptions.entrySet()) { syncException(entry.getValue(), masterNote); } // remove old exceptions for (NoteItem noteItem : masterNote.getModifications()) { EventExceptionStamp eventException = StampUtils.getEventExceptionStamp(noteItem); if (eventException==null || !exceptions.containsKey(eventException.getRecurrenceId())) { noteItem.setIsActive(false); } } }
Example #4
Source File: StandardContentServiceTest.java From cosmo with Apache License 2.0 | 6 votes |
@Test(expected=IllegalArgumentException.class) public void testCreateContentThrowsExceptionForInvalidDates() throws Exception { User user = testHelper.makeDummyUser(); CollectionItem rootCollection = contentDao.createRootItem(user); NoteItem noteItem = new MockNoteItem(); noteItem.getAttributeValue(""); noteItem.setName("foo"); noteItem.setOwner(user); Calendar c = new Calendar(); VEvent e = new VEvent(); e.getProperties().add(new DtStart("20131010T101010Z")); e.getProperties().add(new DtEnd("20131010T091010Z")); c.getComponents().add(e); MockEventStamp mockEventStamp = new MockEventStamp(); mockEventStamp.setEventCalendar(c); noteItem.addStamp(mockEventStamp); service.createContent(rootCollection, noteItem); }
Example #5
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Export the calendar to the given output writer. * * @param calendar the source {@link ICalendar} * @param writer the output writer * @throws IOException * @throws ParseException * @throws ValidationException */ public void export(ICalendar calendar, Writer writer) throws IOException, ParseException, ValidationException { Preconditions.checkNotNull(calendar, "calendar can't be null"); Preconditions.checkNotNull(writer, "writer can't be null"); Preconditions.checkNotNull(getICalendarEvents(calendar), "can't export empty calendar"); Calendar cal = newCalendar(); cal.getProperties().add(new XProperty(X_WR_CALNAME, calendar.getName())); for (ICalendarEvent item : getICalendarEvents(calendar)) { VEvent event = createVEvent(item); cal.getComponents().add(event); } CalendarOutputter outputter = new CalendarOutputter(); outputter.output(cal, writer); }
Example #6
Source File: SignupEmailFacadeImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Generate an ICS file for the user and the email message type and return as an attachment. * * @param email email obj * @param user User * @return */ private List<Attachment> generateICS(SignupEmailNotification email, User user) { List<Attachment> attachments = new ArrayList<Attachment>(); String method = email.isCancellation() ? "CANCEL" : "REQUEST"; final List<VEvent> events = email.generateEvents(user, calendarHelper); if (events.size() > 0) { Attachment a = formatICSAttachment(events, method); if (a != null) { attachments.add(a); } } /* * Note that there is no notification if a meeting is removed altogether. */ return attachments; }
Example #7
Source File: OrganizerEmailBase.java From sakai with Educational Community License v2.0 | 6 votes |
/** * {@inheritDoc} */ public List<VEvent> generateEvents(User user, SignupCalendarHelper calendarHelper) { List<VEvent> events = new ArrayList<VEvent>(); VEvent meetingEvent = meeting.getVevent(); if (meetingEvent == null) { return events; } Set<SignupAttendee> attendees = new HashSet<SignupAttendee>(); for(SignupTimeslot timeslot: meeting.getSignupTimeSlots()) { attendees.addAll(timeslot.getAttendees()); } calendarHelper.addAttendeesToVEvent(meetingEvent, attendees); events.add(meetingEvent); return events; }
Example #8
Source File: EventCollectionResource.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
private String extractUid(String icalendar) throws IOException, ParserException { String uid = null; StringReader reader = new StringReader(icalendar); CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(new UnfoldingReader(reader, true)); if ( calendar != null && calendar.getComponents() != null ) { Iterator<Component> iterator = calendar.getComponents().iterator(); while (iterator.hasNext()) { Component component = iterator.next(); if ( component instanceof VEvent ) { uid = ((VEvent)component).getUid().getValue(); break; } } } return uid; }
Example #9
Source File: SignupEmailFacadeImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Generate an ICS file for the user and the email message type and return as an attachment. * * @param email email obj * @param user User * @return */ private List<Attachment> generateICS(SignupEmailNotification email, User user) { List<Attachment> attachments = new ArrayList<Attachment>(); String method = email.isCancellation() ? "CANCEL" : "REQUEST"; final List<VEvent> events = email.generateEvents(user, calendarHelper); if (events.size() > 0) { Attachment a = formatICSAttachment(events, method); if (a != null) { attachments.add(a); } } /* * Note that there is no notification if a meeting is removed altogether. */ return attachments; }
Example #10
Source File: AllUsersEmailBase.java From sakai with Educational Community License v2.0 | 6 votes |
/** * {@inheritDoc} */ public List<VEvent> generateEvents(User user, SignupCalendarHelper calendarHelper) { List<VEvent> events = new ArrayList<VEvent>(); if (this.userIsAnOrganiser(user)) { final VEvent meetingEvent = this.meeting.getVevent(); if (meetingEvent != null) { events.add(meetingEvent); } } else { events.addAll(eventsWhichUserIsAttending(user)); } if (this.cancellation) { for (VEvent event : events) { calendarHelper.cancelVEvent(event); } } return events; }
Example #11
Source File: ExternalCalendaringServiceImpl.java From sakai with Educational Community License v2.0 | 6 votes |
/** * {@inheritDoc} */ public VEvent cancelEvent(VEvent vevent) { if(!isIcsEnabled()) { log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties"); return null; } // You can only have one status so make sure we remove any previous ones. vevent.getProperties().removeAll(vevent.getProperties(Property.STATUS)); vevent.getProperties().add(Status.VEVENT_CANCELLED); // Must define a sequence for cancellations. If one was not defined when the event was created use 1 if (vevent.getProperties().getProperty(Property.SEQUENCE) == null) { vevent.getProperties().add(new Sequence("1")); } if(log.isDebugEnabled()){ log.debug("VEvent cancelled:" + vevent); } return vevent; }
Example #12
Source File: CancellationEmailTest.java From sakai with Educational Community License v2.0 | 6 votes |
@Test public void canGenerateEventsFromAttendeeCancellationOwnEmail() { when(_mockedUser.getId()).thenReturn("userId"); when(_mockedCancelledTimeslot.getAttendee("userId")).thenReturn(_mockedAttendee); when(_mockedItem.isInitiator()).thenReturn(true); final List<SignupTrackingItem> items = Collections.singletonList(_mockedItem); _email = new AttendeeCancellationOwnEmail(_mockedUser, items, _mockedMeeting, _mockedFacade); final List<VEvent> events = _email.generateEvents(_mockedUser, _mockedCalendarHelper); verify(_mockedCalendarHelper, times(1)).cancelVEvent(any(VEvent.class)); assertEquals(1, events.size()); assertTrue(_email.isCancellation()); }
Example #13
Source File: TeamEventUtils.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
public static List<TeamEventDO> convert(final List<VEvent> list) { final List<TeamEventDO> events = new ArrayList<TeamEventDO>(); if (list == null || list.size() == 0) { return events; } for (final VEvent vEvent : list) { events.add(createTeamEventDO(vEvent)); } Collections.sort(events, new Comparator<TeamEventDO>() { public int compare(final TeamEventDO o1, final TeamEventDO 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 events; }
Example #14
Source File: StandardContentService.java From cosmo with Apache License 2.0 | 6 votes |
private void checkDatesForEvent(ContentItem item){ if(!(item instanceof NoteItem)){ return; } NoteItem noteItem = (NoteItem)item; Stamp stamp = noteItem.getStamp("event"); if(!(stamp instanceof EventStamp)){ return; } EventStamp eventStamp = (EventStamp) stamp; VEvent masterEvent = eventStamp.getMasterEvent(); checkDatesForComponent(masterEvent); for(Component component : eventStamp.getExceptions()){ checkDatesForComponent(component); } }
Example #15
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 6 votes |
/** * Ensure we can get a ical4j Calendar from the generated event. */ @Test public void testGeneratingCalendar() { //generate new event CalendarEvent event = generateEvent(); //create vevent net.fortuna.ical4j.model.component.VEvent vevent = service.createEvent(event); //create calendar from vevent net.fortuna.ical4j.model.Calendar calendar = service.createCalendar(Collections.singletonList(vevent)); log.debug("testGeneratingCalendar"); log.debug("######################"); log.debug("{}", calendar); Assert.assertNotNull(calendar); //check attributes of the ical4j calendar are what we expect and match those in the event Assert.assertEquals(Version.VERSION_2_0, calendar.getVersion()); Assert.assertEquals(CalScale.GREGORIAN, calendar.getCalendarScale()); }
Example #16
Source File: ExternalCalendaringServiceTest.java From sakai with Educational Community License v2.0 | 6 votes |
@Test public void testCancellingVEvent() { //generate new event CalendarEvent event = generateEvent(); //create vevent net.fortuna.ical4j.model.component.VEvent vevent = service.createEvent(event); //set it to cancelled VEvent cancelled = service.cancelEvent(vevent); log.debug("testCancellingVEvent"); log.debug("####################"); log.debug("{}", cancelled); Assert.assertNotNull(cancelled); //TODO check the attributes of the vevent //Assert.assertEquals(EVENT_NAME, vevent.getProperty("SUMMARY")); //Assert.assertEquals(LOCATION, vevent.getProperty("LOCATION")); }
Example #17
Source File: HibBaseEventStamp.java From cosmo with Apache License 2.0 | 6 votes |
public void createCalendar() { NoteItem note = (NoteItem) getItem(); String icalUid = note.getIcalUid(); if(icalUid==null) { // A modifications UID will be the parent's icaluid // or uid if(note.getModifies()!=null) { if(note.getModifies().getIcalUid()!=null) { icalUid = note.getModifies().getIcalUid(); } else { icalUid = note.getModifies().getUid(); } } else { icalUid = note.getUid(); } } Calendar cal = ICalendarUtils.createBaseCalendar(new VEvent(), icalUid); setEventCalendar(cal); }
Example #18
Source File: EventValidator.java From cosmo with Apache License 2.0 | 6 votes |
private static boolean areTimeZoneIdsValid(VEvent event) { for (String propertyName : PROPERTIES_WITH_TIMEZONES) { List<Property> props = event.getProperties(propertyName); for (Property p : props) { if (p != null && p.getParameter(Parameter.TZID) != null) { String tzId = p.getParameter(Parameter.TZID).getValue(); if (tzId != null && timeZoneRegistry.getTimeZone(tzId) == null) { LOG.warn("Unknown TZID [" + tzId + "] for event " + event); return false; } } } } return true; }
Example #19
Source File: CalendarFilterEvaluater.java From cosmo with Apache License 2.0 | 6 votes |
/** * Evaluates. * @param comps The component list. * @param filter The time range filter. * @return the result. */ private boolean evaluate(ComponentList<? extends Component> comps, TimeRangeFilter filter) { Component comp = (Component) comps.get(0); if(comp instanceof VEvent) { return evaluateVEventTimeRange(comps, filter); } else if(comp instanceof VFreeBusy) { return evaulateVFreeBusyTimeRange((VFreeBusy) comp, filter); } else if(comp instanceof VToDo) { return evaulateVToDoTimeRange(comps, filter); } else if(comp instanceof VJournal) { return evaluateVJournalTimeRange((VJournal) comp, filter); } else if(comp instanceof VAlarm) { return evaluateVAlarmTimeRange(comps, filter); } else { return false; } }
Example #20
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 6 votes |
/** * Parses a List of Appointments into a VCALENDAR component. * * @param appointments List of Appointments for the Calendar * @param ownerId Owner of the Appointments * @return VCALENDAR representation of the Appointments */ public Calendar parseAppointmentstoCalendar(List<Appointment> appointments, Long ownerId) { String tzid = parseTimeZone(null, userDao.get(ownerId)).getID(); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid); if (timeZone == null) { throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid); } Calendar icsCalendar = new Calendar(); icsCalendar.getProperties().add(new ProdId(PROD_ID)); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getComponents().add(timeZone.getVTimeZone()); for (Appointment appointment : appointments) { DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd()); VEvent meeting = new VEvent(start, end, appointment.getTitle()); meeting = addVEventpropsfromAppointment(appointment, meeting); icsCalendar.getComponents().add(meeting); } return icsCalendar; }
Example #21
Source File: AttendeeCancellationOwnEmail.java From sakai with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ public List<VEvent> generateEvents(User user, SignupCalendarHelper calendarHelper) { List<VEvent> events = new ArrayList<VEvent>(); for (SignupTimeslot timeslot : removed) { VEvent event = timeslot.getVevent(); calendarHelper.cancelVEvent(event); events.add(event); } return events; }
Example #22
Source File: CalendarFilterEvaluater.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets subcomponents. * @param component The component. * @return The component list. */ private ComponentList<? extends Component> getSubComponents(Component component) { if(component instanceof VEvent) { return ((VEvent) component).getAlarms(); } else if(component instanceof VTimeZone) { return ((VTimeZone) component).getObservances(); } else if(component instanceof VToDo) { return ((VToDo) component).getAlarms(); } return new ComponentList<>(); }
Example #23
Source File: HibEventExceptionStamp.java From cosmo with Apache License 2.0 | 5 votes |
public void setExceptionEvent(VEvent event) { if(getEventCalendar()==null) { createCalendar(); } // remove all events getEventCalendar().getComponents().removeAll( getEventCalendar().getComponents().getComponents(Component.VEVENT)); // add event exception getEventCalendar().getComponents().add(event); }
Example #24
Source File: LimitRecurrenceSetTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests the set of limit recurrence. * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testLimitRecurrenceSetThisAndFuture() throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + "limit_recurr_taf_test.ics"); Calendar calendar = cb.build(fis); Assert.assertEquals(4, calendar.getComponents().getComponents("VEVENT").size()); VTimeZone vtz = (VTimeZone) calendar.getComponents().getComponent("VTIMEZONE"); TimeZone tz = new TimeZone(vtz); OutputFilter filter = new OutputFilter("test"); DateTime start = new DateTime("20060108T170000", tz); DateTime end = new DateTime("20060109T170000", tz); start.setUtc(true); end.setUtc(true); Period period = new Period(start, end); filter.setLimit(period); filter.setAllSubComponents(); filter.setAllProperties(); StringBuilder buffer = new StringBuilder(); filter.filter(calendar, buffer); StringReader sr = new StringReader(buffer.toString()); Calendar filterCal = cb.build(sr); Assert.assertEquals(2, filterCal.getComponents().getComponents("VEVENT").size()); // Make sure 2nd and 3rd override are dropped ComponentList<VEvent> vevents = filterCal.getComponents().getComponents(VEvent.VEVENT); for(VEvent c : vevents) { Assert.assertNotSame("event 6 changed",c.getProperties().getProperty("SUMMARY").getValue()); Assert.assertNotSame("event 6 changed 2",c.getProperties().getProperty("SUMMARY").getValue()); } }
Example #25
Source File: StandardContentServiceTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets event. * @param recurrenceId The recurrence id. * @param calendar The calendar. * @return The event. */ private VEvent getEvent(String recurrenceId, Calendar calendar) { ComponentList<VEvent> events = calendar.getComponents().getComponents(Component.VEVENT); for(VEvent event : events) { if(event.getRecurrenceId()!=null && event.getRecurrenceId().getDate().toString().equals(recurrenceId)) return event; } return null; }
Example #26
Source File: HibEventStamp.java From cosmo with Apache License 2.0 | 5 votes |
public VEvent getMasterEvent() { if(getEventCalendar()==null) { return null; } ComponentList<VEvent> events = getEventCalendar().getComponents().getComponents( Component.VEVENT); if(events.size()==0) { return null; } return (VEvent) events.get(0); }
Example #27
Source File: CancellationEmail.java From sakai with Educational Community License v2.0 | 5 votes |
/** * {@inheritDoc} */ public List<VEvent> generateEvents(User user, SignupCalendarHelper calendarHelper) { List<VEvent> events = new ArrayList<VEvent>(); for (SignupTimeslot timeslot : this.getRemoved()) { final VEvent event = timeslot.getVevent(); if (event != null) { calendarHelper.cancelVEvent(event); events.add(event); } } return events; }
Example #28
Source File: MockBaseEventStamp.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets recurrence rules. * @return The list. */ public List<Recur> getRecurrenceRules() { ArrayList<Recur> l = new ArrayList<Recur>(); VEvent event = getEvent(); if(event!=null) { for (Object rrule : getEvent().getProperties().getProperties(Property.RRULE)) { l.add(((RRule)rrule).getRecur()); } } return l; }
Example #29
Source File: HibBaseEventStamp.java From cosmo with Apache License 2.0 | 5 votes |
public void setIcalUid(String uid) { VEvent event = getEvent(); if(event==null) { throw new IllegalStateException("no event"); } ICalendarUtils.setUid(uid, getEvent()); }
Example #30
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 5 votes |
/** * Methods to parse Appointment to iCalendar according RFC 2445 * * @param appointment to be converted to iCalendar * @return iCalendar representation of the Appointment */ public Calendar parseAppointmenttoCalendar(Appointment appointment) { String tzid = parseTimeZone(null, appointment.getOwner()).getID(); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone timeZone = registry.getTimeZone(tzid); if (timeZone == null) { throw new NoSuchElementException("Unable to get time zone by id provided: " + tzid); } Calendar icsCalendar = new Calendar(); icsCalendar.getProperties().add(new ProdId("-//Events Calendar//Apache Openmeetings//EN")); icsCalendar.getProperties().add(Version.VERSION_2_0); icsCalendar.getProperties().add(CalScale.GREGORIAN); icsCalendar.getComponents().add(timeZone.getVTimeZone()); DateTime start = new DateTime(appointment.getStart()), end = new DateTime(appointment.getEnd()); VEvent meeting = new VEvent(start, end, appointment.getTitle()); meeting = addVEventpropsfromAppointment(appointment, meeting); icsCalendar.getComponents().add(meeting); return icsCalendar; }