Search in sources :

Example 6 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project OpenOLAT by OpenOLAT.

the class CalendarImportTest method testImportOktoberFromOutlook.

@Test
public void testImportOktoberFromOutlook() throws IOException, ParserException {
    InputStream in = CalendarImportTest.class.getResourceAsStream("BB_Okt.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Calendar(net.fortuna.ical4j.model.Calendar) Test(org.junit.Test)

Example 7 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project OpenOLAT by OpenOLAT.

the class CalendarImportTest method testImportFromFGiCal.

/*
	 * Why is this test not reliable???
	@Test(expected = ParserException.class)
	public void testImportRefresh() throws IOException, ParserException {
		InputStream in = CalendarImportTest.class.getResourceAsStream("Refresh.ics");
		CalendarBuilder builder = new CalendarBuilder();
		Calendar calendar = builder.build(in);
        assertNotNull(calendar);
	}
	*/
@Test
@Ignore
public void testImportFromFGiCal() throws IOException, ParserException {
    // default settings in olat
    System.setProperty(CompatibilityHints.KEY_RELAXED_UNFOLDING, "true");
    System.setProperty(CompatibilityHints.KEY_RELAXED_PARSING, "true");
    InputStream in = CalendarImportTest.class.getResourceAsStream("EMAIL.ics");
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(in);
    assertNotNull(calendar);
}
Also used : CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) InputStream(java.io.InputStream) Calendar(net.fortuna.ical4j.model.Calendar) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project ofbiz-framework by apache.

the class ICalConverter method makeCalendar.

protected static Calendar makeCalendar(GenericValue workEffort, Map<String, Object> context) throws GenericEntityException {
    String iCalData = null;
    GenericValue iCalValue = workEffort.getRelatedOne("WorkEffortIcalData", false);
    if (iCalValue != null) {
        iCalData = iCalValue.getString("icalData");
    }
    boolean newCalendar = true;
    Calendar calendar = null;
    if (iCalData == null) {
        if (Debug.verboseOn())
            Debug.logVerbose("iCalendar Data not found, creating new Calendar", module);
        calendar = new Calendar();
    } else {
        if (Debug.verboseOn())
            Debug.logVerbose("iCalendar Data found, using saved Calendar", module);
        StringReader reader = new StringReader(iCalData);
        CalendarBuilder builder = new CalendarBuilder();
        try {
            calendar = builder.build(reader);
            newCalendar = false;
        } catch (Exception e) {
            Debug.logError(e, "Error while parsing saved iCalendar, creating new iCalendar: ", module);
            calendar = new Calendar();
        }
    }
    PropertyList propList = calendar.getProperties();
    replaceProperty(propList, prodId);
    replaceProperty(propList, new XProperty(workEffortIdXPropName, workEffort.getString("workEffortId")));
    if (newCalendar) {
        propList.add(Version.VERSION_2_0);
        propList.add(CalScale.GREGORIAN);
        // TODO: Get time zone from publish properties value
        java.util.TimeZone tz = java.util.TimeZone.getDefault();
        TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
        net.fortuna.ical4j.model.TimeZone timezone = registry.getTimeZone(tz.getID());
        calendar.getComponents().add(timezone.getVTimeZone());
    }
    return calendar;
}
Also used : GenericValue(org.apache.ofbiz.entity.GenericValue) XProperty(net.fortuna.ical4j.model.property.XProperty) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) URISyntaxException(java.net.URISyntaxException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) ParserException(net.fortuna.ical4j.data.ParserException) GenericEntityException(org.apache.ofbiz.entity.GenericEntityException) GeneralException(org.apache.ofbiz.base.util.GeneralException) ValidationException(net.fortuna.ical4j.model.ValidationException) IOException(java.io.IOException) PropertyList(net.fortuna.ical4j.model.PropertyList) StringReader(java.io.StringReader)

Example 9 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project opencast by opencast.

the class SchedulerServiceImplTest method checkIcalFeed.

private void checkIcalFeed(Map<String, String> caProps, String title) throws Exception {
    final String cs = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
    final Calendar cal = new CalendarBuilder().build(new StringReader(cs));
    assertEquals("number of entries", 1, cal.getComponents().size());
    for (Object co : cal.getComponents()) {
        final Component c = (Component) co;
        assertEquals("SUMMARY property should contain the DC title", title, c.getProperty(Property.SUMMARY).getValue());
        final Monadics.ListMonadic<Property> attachments = mlist(c.getProperties(Property.ATTACH)).map(Misc.<Object, Property>cast());
        // episode dublin core
        final List<DublinCoreCatalog> dcsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "episode.xml")).map(parseDc.o(decodeBase64).o(getValue)).value();
        assertEquals("number of episode DCs", 1, dcsIcal.size());
        assertEquals("dcterms:title", title, dcsIcal.get(0).getFirst(PROPERTY_TITLE));
        // capture agent properties
        final List<Properties> caPropsIcal = attachments.filter(byParamNameAndValue("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties")).map(parseProperties.o(decodeBase64).o(getValue)).value();
        assertEquals("number of CA property sets", 1, caPropsIcal.size());
        assertTrue("CA properties", eqObj(caProps, caPropsIcal.get(0)));
    }
}
Also used : Monadics(org.opencastproject.util.data.Monadics) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) Properties(java.util.Properties) StringReader(java.io.StringReader) Component(net.fortuna.ical4j.model.Component) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Property(net.fortuna.ical4j.model.Property)

Example 10 with CalendarBuilder

use of net.fortuna.ical4j.data.CalendarBuilder in project opencast by opencast.

the class SchedulerServiceImplTest method testEventManagement.

@Test
public void testEventManagement() throws Exception {
    MediaPackage mediaPackage = generateEvent(Opt.<String>none());
    DublinCoreCatalog event = generateEvent("testdevice", new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000));
    event.set(PROPERTY_TITLE, "Demotitle");
    event.add(PROPERTY_CREATOR, "creator2");
    String catalogId = addDublinCore(Opt.<String>none(), mediaPackage, event);
    Map<String, String> caProperties = generateCaptureAgentMetadata("testdevice");
    schedSvc.addEvent(new Date(System.currentTimeMillis() - 2000), new Date(System.currentTimeMillis() + 60000), "testdevice", Collections.<String>emptySet(), mediaPackage, wfProperties, caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
    // test iCalender export
    CalendarBuilder calBuilder = new CalendarBuilder();
    Calendar cal;
    try {
        String icalString = schedSvc.getCalendar(Opt.<String>none(), Opt.<String>none(), Opt.<Date>none());
        cal = calBuilder.build(IOUtils.toInputStream(icalString, "UTF-8"));
        ComponentList vevents = cal.getComponents(VEVENT);
        for (int i = 0; i < vevents.size(); i++) {
            PropertyList attachments = ((VEvent) vevents.get(i)).getProperties(Property.ATTACH);
            for (int j = 0; j < attachments.size(); j++) {
                String attached = ((Property) attachments.get(j)).getValue();
                String filename = ((Property) attachments.get(j)).getParameter("X-APPLE-FILENAME").getValue();
                attached = new String(Base64.decodeBase64(attached));
                if ("org.opencastproject.capture.agent.properties".equals(filename)) {
                    Assert.assertTrue(attached.contains("capture.device.id=testdevice"));
                }
                if ("episode.xml".equals(filename)) {
                    Assert.assertTrue(attached.contains("Demotitle"));
                }
            }
        }
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    } catch (ParserException e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
    // test for upcoming events (it should not be in there).
    List<MediaPackage> upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(upcoming.isEmpty());
    List<MediaPackage> all = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, all.size());
    all = schedSvc.search(Opt.some("somedevice"), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    Assert.assertTrue(all.isEmpty());
    // update event
    event.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(new Date(System.currentTimeMillis() + 180000), new Date(System.currentTimeMillis() + 600000)), Precision.Second));
    addDublinCore(Opt.some(catalogId), mediaPackage, event);
    schedSvc.updateEvent(mediaPackage.getIdentifier().compact(), Opt.some(new Date(System.currentTimeMillis() + 180000)), Opt.some(new Date(System.currentTimeMillis() + 600000)), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.some(wfPropertiesUpdated), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
    // test for upcoming events (now it should be there)
    upcoming = schedSvc.search(Opt.<String>none(), Opt.some(new Date(System.currentTimeMillis())), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(1, upcoming.size());
    // delete event
    schedSvc.removeEvent(mediaPackage.getIdentifier().compact());
    try {
        schedSvc.getMediaPackage(mediaPackage.getIdentifier().compact());
        Assert.fail();
    } catch (NotFoundException e) {
        Assert.assertNotNull(e);
    }
    upcoming = schedSvc.search(Opt.<String>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none(), Opt.<Date>none());
    assertEquals(0, upcoming.size());
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) ParserException(net.fortuna.ical4j.data.ParserException) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) Calendar(net.fortuna.ical4j.model.Calendar) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) NotFoundException(org.opencastproject.util.NotFoundException) ComponentList(net.fortuna.ical4j.model.ComponentList) IOException(java.io.IOException) Date(java.util.Date) PropertyList(net.fortuna.ical4j.model.PropertyList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Property(net.fortuna.ical4j.model.Property) Test(org.junit.Test)

Aggregations

CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)28 Calendar (net.fortuna.ical4j.model.Calendar)25 Test (org.junit.Test)15 InputStream (java.io.InputStream)14 URISyntaxException (java.net.URISyntaxException)7 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 BufferedReader (java.io.BufferedReader)5 IOException (java.io.IOException)5 InputStreamReader (java.io.InputStreamReader)5 ParserException (net.fortuna.ical4j.data.ParserException)5 FileNotFoundException (java.io.FileNotFoundException)4 ParseException (java.text.ParseException)4 Property (net.fortuna.ical4j.model.Property)4 VEvent (net.fortuna.ical4j.model.component.VEvent)4 Kalendar (org.olat.commons.calendar.model.Kalendar)4 Date (java.util.Date)3 Component (net.fortuna.ical4j.model.Component)3 DateTime (net.fortuna.ical4j.model.DateTime)3 Period (net.fortuna.ical4j.model.Period)3 PeriodList (net.fortuna.ical4j.model.PeriodList)3