use of net.fortuna.ical4j.model.property.Organizer in project android by nextcloud.
the class SaveCalendar method convertFromDb.
private VEvent convertFromDb(Cursor cur, Calendar cal, DtStamp timestamp) {
Log_OC.d(TAG, "cursor: " + DatabaseUtils.dumpCurrentRowToString(cur));
if (hasStringValue(cur, Events.ORIGINAL_ID)) {
// FIXME: Support these edited instances
Log_OC.w(TAG, "Ignoring edited instance of a recurring event");
return null;
}
PropertyList l = new PropertyList();
l.add(timestamp);
copyProperty(l, Property.UID, cur, Events.UID_2445);
String summary = copyProperty(l, Property.SUMMARY, cur, Events.TITLE);
String description = copyProperty(l, Property.DESCRIPTION, cur, Events.DESCRIPTION);
String organizer = getString(cur, Events.ORGANIZER);
if (!TextUtils.isEmpty(organizer)) {
// incorrectly left it in the organizer column.
if (!organizer.startsWith("mailto:")) {
organizer = "mailto:" + organizer;
}
try {
l.add(new Organizer(organizer));
} catch (URISyntaxException ignored) {
if (!mFailedOrganisers.contains(organizer)) {
Log_OC.e(TAG, "Failed to create mailTo for organizer " + organizer);
mFailedOrganisers.add(organizer);
}
}
}
copyProperty(l, Property.LOCATION, cur, Events.EVENT_LOCATION);
copyEnumProperty(l, Property.STATUS, cur, Events.STATUS, STATUS_ENUM);
boolean allDay = TextUtils.equals(getString(cur, Events.ALL_DAY), "1");
boolean isTransparent;
DtEnd dtEnd = null;
if (allDay) {
// All day event
isTransparent = true;
Date start = getDateTime(cur, Events.DTSTART, null, null);
Date end = getDateTime(cur, Events.DTEND, null, null);
l.add(new DtStart(new Date(start)));
if (end != null) {
dtEnd = new DtEnd(new Date(end));
} else {
dtEnd = new DtEnd(utcDateFromMs(start.getTime() + DateUtils.DAY_IN_MILLIS));
}
l.add(dtEnd);
} else {
// Regular or zero-time event. Start date must be a date-time
Date startDate = getDateTime(cur, Events.DTSTART, Events.EVENT_TIMEZONE, cal);
l.add(new DtStart(startDate));
// Use duration if we have one, otherwise end date
if (hasStringValue(cur, Events.DURATION)) {
isTransparent = getString(cur, Events.DURATION).equals("PT0S");
if (!isTransparent) {
copyProperty(l, Property.DURATION, cur, Events.DURATION);
}
} else {
String endTz = Events.EVENT_END_TIMEZONE;
if (endTz == null) {
endTz = Events.EVENT_TIMEZONE;
}
Date end = getDateTime(cur, Events.DTEND, endTz, cal);
dtEnd = new DtEnd(end);
isTransparent = startDate.getTime() == end.getTime();
if (!isTransparent) {
l.add(dtEnd);
}
}
}
copyEnumProperty(l, Property.CLASS, cur, Events.ACCESS_LEVEL, CLASS_ENUM);
int availability = getInt(cur, Events.AVAILABILITY);
if (availability > Events.AVAILABILITY_TENTATIVE) {
// Unknown/Invalid
availability = -1;
}
if (isTransparent) {
// not free, then mark it opaque.
if (availability >= 0 && availability != Events.AVAILABILITY_FREE) {
l.add(Transp.OPAQUE);
}
} else if (availability > Events.AVAILABILITY_BUSY) {
// This event is ordinarily busy but differs, so output a FREEBUSY
// period covering the time of the event
FreeBusy fb = new FreeBusy();
fb.getParameters().add(new FbType(AVAIL_ENUM.get(availability)));
DateTime start = new DateTime(((DtStart) l.getProperty(Property.DTSTART)).getDate());
if (dtEnd != null) {
fb.getPeriods().add(new Period(start, new DateTime(dtEnd.getDate())));
} else {
Duration d = (Duration) l.getProperty(Property.DURATION);
fb.getPeriods().add(new Period(start, d.getDuration()));
}
l.add(fb);
}
copyProperty(l, Property.RRULE, cur, Events.RRULE);
copyProperty(l, Property.RDATE, cur, Events.RDATE);
copyProperty(l, Property.EXRULE, cur, Events.EXRULE);
copyProperty(l, Property.EXDATE, cur, Events.EXDATE);
if (TextUtils.isEmpty(getString(cur, Events.CUSTOM_APP_PACKAGE))) {
// Only copy URL if there is no app i.e. we probably imported it.
copyProperty(l, Property.URL, cur, Events.CUSTOM_APP_URI);
}
VEvent e = new VEvent(l);
if (getInt(cur, Events.HAS_ALARM) == 1) {
// Add alarms
String s = summary == null ? (description == null ? "" : description) : summary;
Description desc = new Description(s);
ContentResolver resolver = activity.getContentResolver();
long eventId = getLong(cur, Events._ID);
Cursor alarmCur;
alarmCur = Reminders.query(resolver, eventId, mAllCols ? null : REMINDER_COLS);
while (alarmCur.moveToNext()) {
int mins = getInt(alarmCur, Reminders.MINUTES);
if (mins == -1) {
// FIXME: Get the real default
mins = 60;
}
// FIXME: We should support other types if possible
int method = getInt(alarmCur, Reminders.METHOD);
if (method == Reminders.METHOD_DEFAULT || method == Reminders.METHOD_ALERT) {
VAlarm alarm = new VAlarm(new Dur(0, 0, -mins, 0));
alarm.getProperties().add(Action.DISPLAY);
alarm.getProperties().add(desc);
e.getAlarms().add(alarm);
}
}
alarmCur.close();
}
return e;
}
use of net.fortuna.ical4j.model.property.Organizer 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.property.Organizer in project openmeetings by apache.
the class TestSendIcalMessage method simpleInvitionIcalLink.
public void simpleInvitionIcalLink() {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/Mexico_City");
VTimeZone tz = timezone.getVTimeZone();
// Start Date is on: April 1, 2008, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2008);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 9);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);
// End Date is on: April 1, 2008, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2008);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 13);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);
// Create the event
String eventName = "Progress Meeting";
DateTime start = new DateTime(startDate.getTime());
DateTime end = new DateTime(endDate.getTime());
VEvent meeting = new VEvent(start, end, eventName);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
Uid uid = new Uid(UUID.randomUUID().toString());
meeting.getProperties().add(uid);
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
icsCalendar.getProperties().add(Version.VERSION_2_0);
// Add the event and print
icsCalendar.getComponents().add(meeting);
Organizer orger = new Organizer(URI.create("seba.wagner@gmail.com"));
orger.getParameters().add(new Cn("Sebastian Wagner"));
meeting.getProperties().add(orger);
icsCalendar.getProperties().add(Method.REQUEST);
log.debug(icsCalendar.toString());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
try {
outputter.output(icsCalendar, bout);
iCalMimeBody = bout.toByteArray();
sendIcalMessage();
} catch (Exception e) {
log.error("Error", e);
}
}
Aggregations