net.fortuna.ical4j.model.Calendar Java Examples
The following examples show how to use
net.fortuna.ical4j.model.Calendar.
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: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public net.fortuna.ical4j.model.Calendar getCalendar(String uid, ICalendar calendar) throws ICalendarException, MalformedURLException { net.fortuna.ical4j.model.Calendar cal = null; PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect()); Protocol protocol = getProtocol(calendar.getIsSslConnection()); URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), ""); ICalendarStore store = new ICalendarStore(url, RESOLVER); try { if (store.connect(calendar.getLogin(), calendar.getPassword())) { List<CalDavCalendarCollection> colList = store.getCollections(); if (!colList.isEmpty()) { CalDavCalendarCollection collection = colList.get(0); cal = collection.getCalendar(uid); } } else { throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } return cal; }
Example #2
Source File: CalendarFilterEvaluaterTest.java From cosmo with Apache License 2.0 | 6 votes |
/** * Tests evaluate filter. * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testEvaluateVToDoFilterPropFilter() throws Exception { CalendarFilterEvaluater evaluater = new CalendarFilterEvaluater(); Calendar calendar = getCalendar("vtodo.ics"); CalendarFilter filter = new CalendarFilter(); ComponentFilter compFilter = new ComponentFilter("VCALENDAR"); ComponentFilter eventFilter = new ComponentFilter("VTODO"); filter.setFilter(compFilter); compFilter.getComponentFilters().add(eventFilter); Assert.assertTrue(evaluater.evaluate(calendar, filter)); PropertyFilter propFilter = new PropertyFilter("SUMMARY"); TextMatchFilter textFilter = new TextMatchFilter("Income"); propFilter.setTextMatchFilter(textFilter); eventFilter.getPropFilters().add(propFilter); Assert.assertTrue(evaluater.evaluate(calendar, filter)); textFilter.setValue("bogus"); Assert.assertFalse(evaluater.evaluate(calendar, filter)); }
Example #3
Source File: ICALAttributeDTOTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void buildShouldWork() throws Exception { byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES; MailAddress sender = MailAddressFixture.OTHER_AT_JAMES; ICALAttributeDTO ical = ICALAttributeDTO.builder() .from(calendar, ics) .sender(sender) .recipient(recipient) .replyTo(sender); assertThat(ical.getRecipient()).isEqualTo(recipient.asString()); assertThat(ical.getSender()).isEqualTo(sender.asString()); assertThat(ical.getUid()) .contains("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7" + "c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(ical.getMethod()).contains("REQUEST"); assertThat(ical.getRecurrenceId()).isEmpty(); assertThat(ical.getDtstamp()).contains("20170106T115036Z"); assertThat(ical.getSequence()).isEqualTo("0"); assertThat(ical.getIcal()).isEqualTo(new String(ics, "UTF-8")); }
Example #4
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public net.fortuna.ical4j.model.Calendar removeCalendar( CalDavCalendarCollection collection, String uid) throws FailedOperationException, ObjectStoreException { net.fortuna.ical4j.model.Calendar calendar = collection.getCalendar(uid); DeleteMethod deleteMethod = new DeleteMethod(collection.getPath() + uid + ".ics"); try { collection.getStore().getClient().execute(deleteMethod); } catch (IOException e) { throw new ObjectStoreException(e); } if (!deleteMethod.succeeded()) { throw new FailedOperationException(deleteMethod.getStatusLine().toString()); } return calendar; }
Example #5
Source File: CalendarCollectionProvider.java From cosmo with Apache License 2.0 | 6 votes |
/** * @param collectionItem * @return */ private Calendar getCalendarFromCollection(DavRequest req, CollectionItem collectionItem) { Calendar result = new Calendar(); if (productId == null) { synchronized (this) { if (productId == null) { Environment environment = WebApplicationContextUtils .findWebApplicationContext(req.getServletContext()).getEnvironment(); productId = environment.getProperty(PRODUCT_ID_KEY); } } } result.getProperties().add(new ProdId(productId)); result.getProperties().add(Version.VERSION_2_0); result.getProperties().add(CalScale.GREGORIAN); for (Item item : collectionItem.getChildren()) { if (!NoteItem.class.isInstance(item)) { continue; } for (Stamp s : item.getStamps()) { if (BaseEventStamp.class.isInstance(s)) { BaseEventStamp baseEventStamp = BaseEventStamp.class.cast(s); result.getComponents().add(baseEventStamp.getEvent()); } } } return result; }
Example #6
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 #7
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 #8
Source File: ICALToHeadersTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void serviceShouldWriteSingleICalendarToHeaders() throws Exception { Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting.ics")); ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder() .put("key", calendar) .build(); testee.init(FakeMailetConfig.builder().build()); Mail mail = FakeMail.builder() .name("mail") .mimeMessage(MimeMessageUtil.defaultMimeMessage()) .attribute(makeAttribute(icals)) .build(); testee.service(mail); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER)) .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).containsOnly("20170106T115036Z"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0"); }
Example #9
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Load the calendar events from the given reader. * * @param calendar the target {@link ICalendar} * @param reader the input source reader * @throws IOException * @throws ParserException */ @Transactional(rollbackOn = {Exception.class}) public void load(ICalendar calendar, Reader reader) throws IOException, ParserException { Preconditions.checkNotNull(calendar, "calendar can't be null"); Preconditions.checkNotNull(reader, "reader can't be null"); final CalendarBuilder builder = new CalendarBuilder(); final Calendar cal = builder.build(reader); if (calendar.getName() == null && cal.getProperty(X_WR_CALNAME) != null) { calendar.setName(cal.getProperty(X_WR_CALNAME).getValue()); } for (Object item : cal.getComponents(Component.VEVENT)) { findOrCreateEvent((VEvent) item, calendar); } }
Example #10
Source File: ICALToHeadersTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void serviceShouldNotWriteHeaderWhenPropertyIsAbsent() throws Exception { Calendar calendar = new CalendarBuilder().build(ClassLoader.getSystemResourceAsStream("ics/meeting_without_dtstamp.ics")); ImmutableMap<String, Calendar> icals = ImmutableMap.<String, Calendar>builder() .put("key", calendar) .build(); testee.init(FakeMailetConfig.builder().build()); Mail mail = FakeMail.builder() .name("mail") .mimeMessage(MimeMessageUtil.defaultMimeMessage()) .attribute(makeAttribute(icals)) .build(); testee.service(mail); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_METHOD_HEADER)).containsOnly("REQUEST"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_UID_HEADER)) .containsOnly("f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc"); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_DTSTAMP_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_RECURRENCE_ID_HEADER)).isNull(); assertThat(mail.getMessage().getHeader(ICALToHeader.X_MEETING_SEQUENCE_HEADER)).containsOnly("0"); }
Example #11
Source File: CalendarDaoICalFileImpl.java From olat with Apache License 2.0 | 6 votes |
/** * [spring] */ private CalendarDaoICalFileImpl() { this.fStorageBase = new File(WebappHelper.getUserDataRoot() + "/calendars"); if (!fStorageBase.exists()) { if (!fStorageBase.mkdirs()) { throw new OLATRuntimeException("Error creating calendar base directory at: " + fStorageBase.getAbsolutePath(), null); } } createCalendarFileDirectories(); // set parser to relax (needed for allday events // see http://sourceforge.net/forum/forum.php?thread_id=1253735&forum_id=368291 System.setProperty("ical4j.unfolding.relaxed", "true"); // initialize timezone tz = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID()); // INSTANCE = this; }
Example #12
Source File: CalendarFactory.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
public static Calendar createCalendar(List<EventBean> events) { final String prodIdCompany = Unit.getInstitutionName().getContent(); Calendar calendar = new Calendar(); calendar.getProperties().add(new ProdId("-//" + prodIdCompany + "//" + PROD_ID_APPLICATION + "//PT")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); VTimeZone tz = TIMEZONE.getVTimeZone(); calendar.getComponents().add(tz); for (EventBean eventBean : events) { calendar.getComponents().add(convertEventBean(eventBean)); } return calendar; }
Example #13
Source File: ICalendarParserTest.java From james-project with Apache License 2.0 | 6 votes |
@Test public void parsingShouldBeLenient() throws Exception { FakeMailetConfig mailetConfiguration = FakeMailetConfig.builder() .mailetName("ICalendarParser") .setProperty(SOURCE_ATTRIBUTE, SOURCE_CUSTOM_ATTRIBUTE) .setProperty(DESTINATION_ATTRIBUTE, DESTINATION_CUSTOM_ATTRIBUTE) .build(); mailet.init(mailetConfiguration); Map<String, byte[]> attachments = ImmutableMap.<String, byte[]>builder() .put("key", ClassLoaderUtils.getSystemResourceAsByteArray("ics/ics_with_error.ics")) .build(); Mail mail = FakeMail.builder() .name("mail") .attribute(makeCustomSourceAttribute((Serializable) attachments)) .build(); mailet.service(mail); Optional<Map<String, Calendar>> expectedCalendars = AttributeUtils.getValueAndCastFromMail(mail, DESTINATION_CUSTOM_ATTRIBUTE_NAME, MAP_STRING_CALENDAR_CLASS); assertThat(expectedCalendars).hasValueSatisfying(calendars -> assertThat(calendars) .hasSize(1)); }
Example #14
Source File: ICalendarStore.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public static List<VEvent> getModifiedEvents( CalDavCalendarCollection calendar, Instant instant, Set<String> remoteUids) { final List<VEvent> events = new ArrayList<>(); for (Calendar cal : calendar.getEvents()) { cal.toString(); for (Object item : ((List<CalendarComponent>) cal.getComponents(Component.VEVENT))) { VEvent event = (VEvent) item; if (instant == null || event.getLastModified().getDate().toInstant().isAfter(instant)) { events.add(event); } remoteUids.add(event.getUid().getValue()); } } return events; }
Example #15
Source File: FreeBusyObfuscaterDefault.java From cosmo with Apache License 2.0 | 6 votes |
@Override public void apply(User owner, ContentItem contentItem) { contentItem.setDisplayName(FREE_BUSY_TEXT); contentItem.setName(FREE_BUSY_TEXT); EventStamp stamp = (EventStamp) contentItem.getStamp(EventStamp.class); if (stamp != null) { Calendar calendar = stamp.getEventCalendar(); stamp.setEventCalendar(copy(calendar)); } EventExceptionStamp exceptionStamp = (EventExceptionStamp) contentItem.getStamp(EventExceptionStamp.class); if (exceptionStamp != null) { Calendar original = exceptionStamp.getEventCalendar(); exceptionStamp.setEventCalendar(copy(original)); } }
Example #16
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 #17
Source File: ICalFormatTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:marshal").marshal("ical").to("mock:result"); } }); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); Calendar calendar = createTestCalendar(); MockEndpoint mock = camelctx.getEndpoint("mock:result", MockEndpoint.class); mock.expectedBodiesReceived(calendar.toString()); producer.sendBody("direct:marshal", calendar); mock.assertIsSatisfied(); } finally { camelctx.close(); } }
Example #18
Source File: ICALToJsonAttribute.java From james-project with Apache License 2.0 | 6 votes |
private void setAttribute(Mail mail, Map<String, Calendar> calendars, Map<String, byte[]> rawCalendars) throws MessagingException { Optional<MailAddress> sender = retrieveSender(mail); if (!sender.isPresent()) { LOGGER.info("Skipping {} because no sender and no from", mail.getName()); return; } MailAddress transportSender = sender.get(); MailAddress replyTo = fetchReplyTo(mail).orElse(transportSender); Map<String, byte[]> jsonsInByteForm = calendars.entrySet() .stream() .flatMap(calendar -> toJson(calendar, rawCalendars, mail, transportSender, replyTo)) .collect(Guavate.toImmutableMap(Pair::getKey, Pair::getValue)); mail.setAttribute(new Attribute(destinationAttributeName, AttributeValue.ofAny(jsonsInByteForm))); }
Example #19
Source File: ICALToJsonAttribute.java From james-project with Apache License 2.0 | 6 votes |
private Stream<ICALAttributeDTO> toICAL(Map.Entry<String, Calendar> entry, Map<String, byte[]> rawCalendars, MailAddress recipient, MailAddress sender, MailAddress replyTo) { Calendar calendar = entry.getValue(); byte[] rawICal = rawCalendars.get(entry.getKey()); if (rawICal == null) { LOGGER.debug("Cannot find matching raw ICAL from key: {}", entry.getKey()); return Stream.of(); } try { return Stream.of(ICALAttributeDTO.builder() .from(calendar, rawICal) .sender(sender) .recipient(recipient) .replyTo(replyTo)); } catch (Exception e) { LOGGER.error("Exception while converting calendar to ICAL", e); return Stream.of(); } }
Example #20
Source File: ComponentFilter.java From cosmo with Apache License 2.0 | 6 votes |
private void validateName(Element element) throws ParseException { name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException( "CALDAV:comp-filter a calendar component name (e.g., \"VEVENT\") is required", -1); } if (!(name.equals(Calendar.VCALENDAR) || CalendarUtils.isSupportedComponent(name) || name.equals(Component.VALARM) || name.equals(Component.VTIMEZONE))) { throw new ParseException(name + " is not a supported iCalendar component", -1); } }
Example #21
Source File: CalendarDaoICalFileImpl.java From olat with Apache License 2.0 | 6 votes |
private Calendar buildCalendar(final OlatCalendar olatCalendar) { final Calendar calendar = new Calendar(); // add standard propeties calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(CalScale.GREGORIAN); for (final Iterator<CalendarEntry> iter = olatCalendar.getAllCalendarEntries().iterator(); iter.hasNext();) { final CalendarEntry kEvent = iter.next(); final VEvent vEvent = getVEvent(kEvent); calendar.getComponents().add(vEvent); } return calendar; }
Example #22
Source File: FreeBusyReport.java From cosmo with Apache License 2.0 | 5 votes |
/** * <p> * Runs the report query and generates a resulting <code>VFREEBUSY</code>. * </p> * <p> * The set of <code>VFREEBUSY</code> components that are returned by the * query are merged into a single component. It is wrapped in a calendar * object and converted using UTF-8 to bytes which are set as the report * stream. The report's content type and encoding are also set. * </p> * * @throws CosmoDavException - If something is wrong this excepton is thrown. */ protected void runQuery() throws CosmoDavException { if (!(getResource().isCollection() || getResource() instanceof DavCalendarResource)) { throw new UnprocessableEntityException(getType() + " report not supported for non-calendar resources"); } // if the resource or any of its ancestors is excluded from // free busy rollups, deny the query DavItemCollection dc = getResource().isCollection() ? (DavItemCollection) getResource() : (DavItemCollection) getResource().getParent(); while (dc != null) { if (dc.isExcludedFromFreeBusyRollups()) { throw new ForbiddenException("Targeted resource or ancestor collection does not participate in freebusy rollups"); } dc = (DavItemCollection) dc.getParent(); if (!dc.exists()) { dc = null; } } freeBusyResults = new ArrayList<VFreeBusy>(); super.runQuery(); VFreeBusy vfb = FreeBusyUtils.mergeComponents(freeBusyResults, freeBusyRange); Calendar calendar = ICalendarUtils.createBaseCalendar(vfb); String output = writeCalendar(calendar); setContentType("text/calendar"); setEncoding("UTF-8"); try { setStream(new ByteArrayInputStream(output.getBytes("UTF-8"))); } catch (Exception e) { throw new CosmoDavException(e); } }
Example #23
Source File: InstanceListTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Tests instance start before range. * * @throws Exception - if something is wrong this exception is thrown. */ @Test public void testInstanceStartBeforeRange() throws Exception { Calendar calendar = getCalendar("recurring_with_exdates.ics"); InstanceList instances = new InstanceList(); // make sure startRange is after the startDate of an occurrence, // in this case the occurrence is at 20070529T101500Z DateTime start = new DateTime("20070529T110000Z"); DateTime end = new DateTime("20070530T051500Z"); addToInstanceList(calendar, instances, start, end); Assert.assertEquals(1, instances.size()); Iterator<String> keys = instances.keySet().iterator(); String key = null; Instance instance = null; key = keys.next(); instance = (Instance) instances.get(key); Assert.assertEquals("20070529T101500Z", key); Assert.assertEquals("20070529T051500", instance.getStart().toString()); Assert.assertEquals("20070529T061500", instance.getEnd().toString()); }
Example #24
Source File: EntityConverterTest.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets calendar. * @param name The name. * @return The calendar. * @throws Exception - if something is wrong this exception is thrown. */ protected Calendar getCalendar(String name) throws Exception { CalendarBuilder cb = new CalendarBuilder(); FileInputStream fis = new FileInputStream(baseDir + name); Calendar calendar = cb.build(fis); return calendar; }
Example #25
Source File: ICALAttributeDTOTest.java From james-project with Apache License 2.0 | 5 votes |
@Test public void buildShouldSetDefaultValueWhenCalendarWithoutSequence() throws Exception { byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting_without_sequence.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES; MailAddress sender = MailAddressFixture.OTHER_AT_JAMES; ICALAttributeDTO ical = ICALAttributeDTO.builder() .from(calendar, ics) .sender(sender) .recipient(recipient) .replyTo(sender); assertThat(ical.getSequence()).isEqualTo(ICALAttributeDTO.DEFAULT_SEQUENCE_VALUE); }
Example #26
Source File: ICALToJsonAttributeTest.java From james-project with Apache License 2.0 | 5 votes |
@Test void serviceShouldAttachJson() throws Exception { testee.init(FakeMailetConfig.builder().build()); byte[] ics = ClassLoaderUtils.getSystemResourceAsByteArray("ics/meeting.ics"); Calendar calendar = new CalendarBuilder().build(new ByteArrayInputStream(ics)); ImmutableMap<String, Calendar> icals = ImmutableMap.of("key", calendar); ImmutableMap<String, byte[]> rawIcals = ImmutableMap.of("key", ics); MailAddress recipient = MailAddressFixture.ANY_AT_JAMES2; Mail mail = FakeMail.builder() .name("mail") .sender(SENDER) .recipient(recipient) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_SOURCE, AttributeValue.ofAny(icals))) .attribute(new Attribute(ICALToJsonAttribute.DEFAULT_RAW_SOURCE, AttributeValue.ofAny(rawIcals))) .build(); testee.service(mail); assertThat(AttributeUtils.getValueAndCastFromMail(mail, ICALToJsonAttribute.DEFAULT_DESTINATION, MAP_STRING_BYTES_CLASS)) .isPresent() .hasValueSatisfying(jsons -> { assertThat(jsons).hasSize(1); assertThatJson(new String(jsons.values().iterator().next(), StandardCharsets.UTF_8)) .isEqualTo("{" + "\"ical\": \"" + toJsonValue(ics) + "\"," + "\"sender\": \"" + SENDER.asString() + "\"," + "\"replyTo\": \"" + SENDER.asString() + "\"," + "\"recipient\": \"" + recipient.asString() + "\"," + "\"uid\": \"f1514f44bf39311568d640727cff54e819573448d09d2e5677987ff29caa01a9e047feb2aab16e43439a608f28671ab7c10e754ce92be513f8e04ae9ff15e65a9819cf285a6962bc\"," + "\"sequence\": \"0\"," + "\"dtstamp\": \"20170106T115036Z\"," + "\"method\": \"REQUEST\"," + "\"recurrence-id\": null" + "}"); }); }
Example #27
Source File: ICalendarSyncPoint.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
private void encodeAndTransmitResponse(HttpServletResponse httpServletResponse, Calendar calendar) throws Exception { httpServletResponse.setHeader("Content-Type", "text/calendar; charset=" + CharEncoding.UTF_8); final OutputStream outputStream = httpServletResponse.getOutputStream(); outputStream.write(calendar.toString().getBytes(CharEncoding.UTF_8)); outputStream.close(); }
Example #28
Source File: ICALToHeader.java From james-project with Apache License 2.0 | 5 votes |
private void writeToHeaders(Calendar calendar, Mail mail) throws MessagingException { MimeMessage mimeMessage = mail.getMessage(); VEvent vevent = (VEvent) calendar.getComponent("VEVENT"); addIfPresent(mimeMessage, X_MEETING_METHOD_HEADER, calendar.getMethod()); addIfPresent(mimeMessage, X_MEETING_UID_HEADER, vevent.getUid()); addIfPresent(mimeMessage, X_MEETING_RECURRENCE_ID_HEADER, vevent.getRecurrenceId()); addIfPresent(mimeMessage, X_MEETING_SEQUENCE_HEADER, vevent.getSequence()); addIfPresent(mimeMessage, X_MEETING_DTSTAMP_HEADER, vevent.getDateStamp()); }
Example #29
Source File: CalendarUtils.java From cosmo with Apache License 2.0 | 5 votes |
public static boolean hasSupportedComponent(Calendar calendar) { for (Object component : calendar.getComponents()) { if (isSupportedComponent(((CalendarComponent) component).getName())) { return true; } } return false; }
Example #30
Source File: MockCalendarDao.java From cosmo with Apache License 2.0 | 5 votes |
/** * Find calendar events by filter. * NOTE: This impl always returns an empty set, but has the side effect * of setting the last * @param collection * calendar collection to search * @param filter * filter to use in search * @return set CalendarEventItem objects matching specified * filter. */ public Set<ICalendarItem> findCalendarItems(CollectionItem collection, CalendarFilter filter) { lastCalendarFilter = filter; HashSet<ICalendarItem> results = new HashSet<ICalendarItem>(); CalendarFilterEvaluater evaluater = new CalendarFilterEvaluater(); // Evaluate filter against all calendar items for (Item child : collection.getChildren()) { // only care about calendar items if (child instanceof ICalendarItem) { ICalendarItem content = (ICalendarItem) child; Calendar calendar = new EntityConverter(null).convertContent(content); if(calendar!=null) { if (evaluater.evaluate(calendar, filter) == true) { results.add(content); } } } } return results; }