use of net.fortuna.ical4j.model.parameter.FmtType in project opencast by opencast.
the class CalendarGenerator method addEvent.
/**
* Adds an SchedulerEvent as a new entry to this iCalendar
*
* @param mp
* {@link MediaPackage} of event
* @param agentId
* the agent identifier
* @param start
* the start date
* @param end
* the end date
* @param captureAgentMetadata
* properties for capture agent metadata
*
* @return true if the event could be added.
*/
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
String eventId = mp.getIdentifier().compact();
logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
DateTime startDate = new DateTime(start);
DateTime endDate = new DateTime(end);
Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
if (marginEndDate.before(new Date())) {
logger.debug("Event has already passed more than an hour, skipping!");
return false;
}
startDate.setUtc(true);
endDate.setUtc(true);
String seriesID = null;
VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
try {
ParameterList pl = new ParameterList();
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
}
event.getProperties().add(new Uid(eventId));
DateTime lastModifiedDate = new DateTime(lastModified);
lastModifiedDate.setUtc(true);
event.getProperties().add(new LastModified(lastModifiedDate));
// TODO Organizer should be URI (email-address?) created fake address
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
event.getProperties().add(new Organizer(pl, organizer));
}
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
}
event.getProperties().add(new Location(agentId));
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
event.getProperties().add(new RelatedTo(seriesID));
}
ParameterList dcParameters = new ParameterList();
dcParameters.add(new FmtType("application/xml"));
dcParameters.add(Value.BINARY);
dcParameters.add(Encoding.BASE64);
dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
event.getProperties().add(metadataAttachment);
String seriesDC = getSeriesDublinCoreAsString(seriesID);
if (seriesDC != null) {
logger.debug("Attaching series {} information to event {}", seriesID, eventId);
ParameterList sDcParameters = new ParameterList();
sDcParameters.add(new FmtType("application/xml"));
sDcParameters.add(Value.BINARY);
sDcParameters.add(Encoding.BASE64);
sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
event.getProperties().add(seriesAttachment);
} else {
logger.debug("No series provided for event {}.", eventId);
}
ParameterList caParameters = new ParameterList();
caParameters.add(new FmtType("application/text"));
caParameters.add(Value.BINARY);
caParameters.add(Encoding.BASE64);
caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
event.getProperties().add(agentsAttachment);
} catch (Exception e) {
logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
return false;
}
cal.getComponents().add(event);
logger.debug("new VEvent = {} ", event.toString());
return true;
}
use of net.fortuna.ical4j.model.parameter.FmtType in project zm-mailbox by Zimbra.
the class TestUserServlet method testIcsImportExport.
/**
* Test that can import into a new calendar from ICALENDAR containing an inline ATTACHment.
* Test that it is possible to export calendar entry with an attachment with the attachment
* inlined if icalAttach=inline or ignoring the attachment if icalAttach=none
* @throws Exception
*/
@Test
public void testIcsImportExport() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String calName = NAME_PREFIX + "2ndCalendar";
String calUri = String.format("/%s?fmt=ics", calName);
TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
calendar.getProperties().add(new ProdId("-//ZimbraTest 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
java.util.Calendar start = java.util.Calendar.getInstance();
start.set(java.util.Calendar.MONTH, java.util.Calendar.SEPTEMBER);
start.set(java.util.Calendar.DAY_OF_MONTH, 03);
VEvent wwII = new VEvent(new Date(start.getTime()), NAME_PREFIX + " Declarations of war");
wwII.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
wwII.getProperties().add(new Uid("3-14159"));
Attach attach = new Attach("Attachment.\nIsn't it short.".getBytes(MimeConstants.P_CHARSET_ASCII));
attach.getParameters().add(new XParameter("X-APPLE-FILENAME", "short.txt"));
attach.getParameters().add(new FmtType(MimeConstants.CT_TEXT_PLAIN));
wwII.getProperties().add(attach);
calendar.getComponents().add(wwII);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, buf);
URI uri = mbox.getRestURI(calUri);
HttpClient client = mbox.getHttpClient(uri);
HttpPost post = new HttpPost(uri.toString());
post.setEntity(new InputStreamEntity(new ByteArrayInputStream(buf.toByteArray()), ContentType.create(MimeConstants.CT_TEXT_CALENDAR)));
ZimbraLog.test.info("testIcsImportExport:ICS to be imported:%s", new String(buf.toByteArray()));
TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
uri = mbox.getRestURI(calUri + "&icalAttach=inline");
HttpGet get = new HttpGet(uri.toString());
TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.info("testIcsImportExport:ICS exported (with icalAttach=inline):%s", respIcal);
int attachNdx = respIcal.indexOf("ATTACH;");
Assert.assertTrue("ATTACH should be present", -1 != attachNdx);
String fromAttach = respIcal.substring(attachNdx);
Assert.assertTrue("BINARY should be present", -1 != fromAttach.indexOf("VALUE=BINARY"));
uri = mbox.getRestURI(calUri + "&icalAttach=none");
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (with icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
uri = mbox.getRestURI(calUri);
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (default - same as icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
}
use of net.fortuna.ical4j.model.parameter.FmtType in project bw-calendar-engine by Bedework.
the class IcalUtil method setAttachment.
/**
* make an attachment
*
* @param val
* @return Attendee
* @throws Throwable
*/
public static Attach setAttachment(final BwAttachment val) throws Throwable {
ParameterList pars = new ParameterList();
String temp = val.getFmtType();
if (temp != null) {
pars.add(new FmtType(temp));
}
temp = val.getEncoding();
if (temp == null) {
return new Attach(pars, val.getUri());
} else {
pars.add(new Encoding(temp));
temp = val.getValueType();
if (temp != null) {
pars.add(new Value(temp));
}
return new Attach(pars, val.getValue());
}
}
Aggregations