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