net.fortuna.ical4j.model.property.Uid Java Examples

The following examples show how to use net.fortuna.ical4j.model.property.Uid. 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: ICalConverter.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
protected static void loadWorkEffort(PropertyList<Property> componentProps, GenericValue workEffort) {
    replaceProperty(componentProps, new DtStamp()); // iCalendar object created date/time
    replaceProperty(componentProps, toClazz(workEffort.getString("scopeEnumId")));
    replaceProperty(componentProps, toCreated(workEffort.getTimestamp("createdDate")));
    replaceProperty(componentProps, toDescription(workEffort.getString("description")));
    replaceProperty(componentProps, toDtStart(workEffort.getTimestamp("estimatedStartDate")));
    replaceProperty(componentProps, toLastModified(workEffort.getTimestamp("lastModifiedDate")));
    replaceProperty(componentProps, toPriority(workEffort.getLong("priority")));
    replaceProperty(componentProps, toLocation(workEffort.getString("locationDesc")));
    replaceProperty(componentProps, toStatus(workEffort.getString("currentStatusId")));
    replaceProperty(componentProps, toSummary(workEffort.getString("workEffortName")));
    Property uid = componentProps.getProperty(Uid.UID);
    if (uid == null) {
        // Don't overwrite UIDs created by calendar clients
        replaceProperty(componentProps, toUid(workEffort.getString("workEffortId")));
    }
    replaceProperty(componentProps, toXProperty(workEffortIdXPropName, workEffort.getString("workEffortId")));
}
 
Example #2
Source File: Util.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone(timeZone.getID());

    Calendar calendar = new Calendar();
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(new ProdId("openHAB"));
    VEvent vEvent = new VEvent();
    vEvent.getProperties().add(new Summary(calDavEvent.getName()));
    vEvent.getProperties().add(new Description(calDavEvent.getContent()));
    final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
    dtStart.setTimeZone(timezone);
    vEvent.getProperties().add(dtStart);
    final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
    dtEnd.setTimeZone(timezone);
    vEvent.getProperties().add(dtEnd);
    vEvent.getProperties().add(new Uid(calDavEvent.getId()));
    vEvent.getProperties().add(Clazz.PUBLIC);
    vEvent.getProperties()
            .add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
    calendar.getComponents().add(vEvent);

    return calendar;
}
 
Example #3
Source File: ICalUtils.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime end, String summary, String attendee) {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    String tzId = start.getZone().getId();
    TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId);
    VTimeZone tz = timezone.getVTimeZone();

    // Create the event
    PropertyList propertyList = new PropertyList();
    DateTime ts = new DateTime(true);
    ts.setTime(0);
    propertyList.add(new DtStamp(ts));
    propertyList.add(new DtStart(toDateTime(start, registry)));
    propertyList.add(new DtEnd(toDateTime(end, registry)));
    propertyList.add(new Summary(summary));
    VEvent meeting = new VEvent(propertyList);

    // add timezone info..
    meeting.getProperties().add(tz.getTimeZoneId());

    // generate unique identifier..
    meeting.getProperties().add(new Uid("00000000"));

    // add attendees..
    Attendee dev1 = new Attendee(URI.create("mailto:" + attendee));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn(attendee));
    meeting.getProperties().add(dev1);

    // Create a calendar
    net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
    icsCalendar.getProperties().add(Version.VERSION_2_0);
    icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
    icsCalendar.getProperties().add(CalScale.GREGORIAN);

    // Add the event and print
    icsCalendar.getComponents().add(meeting);
    return icsCalendar;
}
 
Example #4
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected static String fromUid(PropertyList<Property> propertyList) {
    Uid iCalObj = (Uid) propertyList.getProperty(Uid.UID);
    if (iCalObj == null) {
        return null;
    }
    return iCalObj.getValue();
}
 
Example #5
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Generate next {@link Uid} to be used with calendar event.
 *
 * @return an {@link Uid} instance
 * @throws SocketException if unable to determine host name
 */
public static Uid nextUid() throws SocketException {
  if (generator == null) {
    HostInfo info = new SimpleHostInfo("localhost");
    try {
      info = new InetAddressHostInfo(InetAddress.getLocalHost());
    } catch (Exception e) {
    }
    generator = new FixedUidGenerator(info, "" + new SecureRandom().nextInt(Integer.MAX_VALUE));
  }
  return generator.generateUid();
}
 
Example #6
Source File: ICalFormatTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private Calendar createTestCalendar() throws ParseException {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone("America/New_York");
    VTimeZone tz = timezone.getVTimeZone();

    // Start Date is on: April 1, 2013, 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, 2013);
    startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
    startDate.set(java.util.Calendar.MINUTE, 0);
    startDate.set(java.util.Calendar.SECOND, 0);

    // End Date is on: April 1, 2013, 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, 2013);
    endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
    endDate.set(java.util.Calendar.MINUTE, 0);
    endDate.set(java.util.Calendar.SECOND, 0);

    // Create the event
    PropertyList propertyList = new PropertyList();
    propertyList.add(new DtStamp("20130324T180000Z"));
    propertyList.add(new DtStart(new DateTime(startDate.getTime())));
    propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
    propertyList.add(new Summary("Progress Meeting"));
    VEvent meeting = new VEvent(propertyList);

    // add timezone info..
    meeting.getProperties().add(tz.getTimeZoneId());

    // generate unique identifier..
    meeting.getProperties().add(new Uid("00000000"));

    // add attendees..
    Attendee dev1 = new Attendee(URI.create("mailto:[email protected]"));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn("Developer 1"));
    meeting.getProperties().add(dev1);

    Attendee dev2 = new Attendee(URI.create("mailto:[email protected]"));
    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(Version.VERSION_2_0);
    icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
    icsCalendar.getProperties().add(CalScale.GREGORIAN);

    // Add the event and print
    icsCalendar.getComponents().add(meeting);
    return icsCalendar;
}
 
Example #7
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
protected static Uid toUid(String javaObj) {
    if (javaObj == null) {
        return null;
    }
    return new Uid(uidPrefix.concat(javaObj));
}
 
Example #8
Source File: TestSendIcalMessage.java    From openmeetings with Apache License 2.0 4 votes vote down vote up
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(randomUUID().toString());
	meeting.getProperties().add(uid);

	// add attendees..
	Attendee dev1 = new Attendee(URI.create("mailto:[email protected]"));
	dev1.getParameters().add(Role.REQ_PARTICIPANT);
	dev1.getParameters().add(new Cn("Developer 1"));
	meeting.getProperties().add(dev1);

	Attendee dev2 = new Attendee(URI.create("mailto:[email protected]"));
	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("[email protected]"));
	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);
	}
}
 
Example #9
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public VEvent createEvent(CalendarEvent event, Set<User> attendees, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	VTimeZone tz = getTimeZone(timeIsLocal);

	//start and end date
	DateTime start = new DateTime(getStartDate(event.getRange()).getTime());
	DateTime end = new DateTime(getEndDate(event.getRange()).getTime());
	
	//create event incl title/summary
	VEvent vevent = new VEvent(start, end, event.getDisplayName());
		
	//add timezone
	vevent.getProperties().add(tz.getTimeZoneId());
	
	//add uid to event
	//could come from the vevent_uuid field in the calendar event, otherwise from event ID.
	String uuid = null;
	if(StringUtils.isNotBlank(event.getField("vevent_uuid"))) {
		uuid = event.getField("vevent_uuid");
	} else {
		uuid = event.getId();
	}		
	vevent.getProperties().add(new Uid(uuid));
	
	//add sequence to event
	//will come from the vevent_sequnece field in the calendar event, otherwise skip it
	String sequence = null;
	if(StringUtils.isNotBlank(event.getField("vevent_sequence"))) {
		sequence = event.getField("vevent_sequence");
		vevent.getProperties().add(new Sequence(sequence));
	}
		
	//add description to event
	vevent.getProperties().add(new Description(event.getDescription()));
	
	//add location to event
	vevent.getProperties().add(new Location(event.getLocation()));
	
	//add organiser to event
	if(StringUtils.isNotBlank(event.getCreator())) {

		String creatorEmail = sakaiProxy.getUserEmail(event.getCreator());

		URI mailURI = createMailURI(creatorEmail);
		Cn commonName = new Cn(sakaiProxy.getUserDisplayName(event.getCreator()));

		Organizer organizer = new Organizer(mailURI);
		organizer.getParameters().add(commonName);
		vevent.getProperties().add(organizer);
	}
	
	//add attendees to event with 'required participant' role
	vevent = addAttendeesToEvent(vevent, attendees);
	
	//add URL to event, if present
	String url = null;
	if(StringUtils.isNotBlank(event.getField("vevent_url"))) {
		url = event.getField("vevent_url");
		Url u = new Url();
		try {
			u.setValue(url);
			vevent.getProperties().add(u);
		} catch (URISyntaxException e) {
			//it doesnt matter, ignore it
		}
	}
	
	if(log.isDebugEnabled()){
		log.debug("VEvent:" + vevent);
	}
	
	return vevent;
}
 
Example #10
Source File: EntityConverter.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Given a calendar with many different components, split into
 * separate calendars that contain only a single component type
 * and a single UID.
 * @param calendar The calendar.
 * @return The split calendar.
 */
private CalendarContext[] splitCalendar(Calendar calendar) {
    Vector<CalendarContext> contexts = new Vector<CalendarContext>();
    Set<String> allComponents = new HashSet<String>();
    Map<String, ComponentList<CalendarComponent>> componentMap = new HashMap<>();
    
    ComponentList<CalendarComponent> comps = calendar.getComponents();
    for(CalendarComponent comp : comps) {            
        // ignore vtimezones for now
        if(comp instanceof VTimeZone) {
            continue;
        }
        
        Uid uid = (Uid) comp.getProperty(Property.UID);
        RecurrenceId rid = (RecurrenceId) comp.getProperty(Property.RECURRENCE_ID);
        
        String key = uid.getValue();
        if(rid!=null) {
            key+=rid.toString();
        }
        
        // ignore duplicates
        if(allComponents.contains(key)) {
            continue;
        }
        
        allComponents.add(key);
        
        ComponentList<CalendarComponent> cl = componentMap.get(uid.getValue());
        
        if(cl==null) {
            cl = new ComponentList<>();
            componentMap.put(uid.getValue(), cl);
        }
        
        cl.add(comp);
    }
    
    for(Entry<String, ComponentList<CalendarComponent>> entry : componentMap.entrySet()) {
       
        Component firstComp = (Component) entry.getValue().get(0);
        
        Calendar cal = ICalendarUtils.createBaseCalendar();
        cal.getComponents().addAll(entry.getValue());
        addTimezones(cal);
        
        CalendarContext cc = new CalendarContext();
        cc.calendar = cal;
        cc.type = firstComp.getName();
        
        contexts.add(cc);
    }
    
    return contexts.toArray(new CalendarContext[contexts.size()]);
}
 
Example #11
Source File: TestHelper.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Makes dummy event.
 * @return The event.
 */
public VEvent makeDummyEvent() {
    String serial = Integer.toString(++eseq);
    String summary = "dummy" + serial;

    // tomorrow
    java.util.Calendar start = java.util.Calendar.getInstance();
    start.add(java.util.Calendar.DAY_OF_MONTH, 1);
    start.set(java.util.Calendar.HOUR_OF_DAY, 9);
    start.set(java.util.Calendar.MINUTE, 30);

    // 1 hour duration
    Dur duration = new Dur(0, 1, 0, 0);
 
    VEvent event = new VEvent(new Date(start.getTime()), duration, summary);
    event.getProperties().add(new Uid(serial));
 
    // add timezone information
    VTimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry().
        getTimeZone("America/Los_Angeles").getVTimeZone();
    String tzValue =
        tz.getProperties().getProperty(Property.TZID).getValue();
    net.fortuna.ical4j.model.parameter.TzId tzParam =
        new net.fortuna.ical4j.model.parameter.TzId(tzValue);
    event.getProperties().getProperty(Property.DTSTART).
        getParameters().add(tzParam);

    // add an alarm for 5 minutes before the event with an xparam
    // on the description
    Dur trigger = new Dur(0, 0, -5, 0);
    VAlarm alarm = new VAlarm(trigger);
    alarm.getProperties().add(Action.DISPLAY);
    Description description = new Description("Meeting at 9:30am");
    XParameter xparam = new XParameter("X-COSMO-TEST-PARAM", "deadbeef");
    description.getParameters().add(xparam);
    alarm.getProperties().add(description);
    alarm.getProperties().add(new Description("Meeting at 9:30am"));
    event.getAlarms().add(alarm);

    // add an x-property with an x-param
    XProperty xprop = new XProperty("X-COSMO-TEST-PROP", "abc123");
    xprop.getParameters().add(xparam);
    event.getProperties().add(xprop);

    return event;
}
 
Example #12
Source File: ExternalCalendaringServiceImpl.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public VEvent createEvent(CalendarEvent event, Set<User> attendees, boolean timeIsLocal) {
	
	if(!isIcsEnabled()) {
		log.debug("ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
		return null;
	}
	
	VTimeZone tz = getTimeZone(timeIsLocal);

	//start and end date
	DateTime start = new DateTime(getStartDate(event.getRange()).getTime());
	DateTime end = new DateTime(getEndDate(event.getRange()).getTime());
	
	//create event incl title/summary
	VEvent vevent = new VEvent(start, end, event.getDisplayName());
		
	//add timezone
	vevent.getProperties().add(tz.getTimeZoneId());
	
	//add uid to event
	//could come from the vevent_uuid field in the calendar event, otherwise from event ID.
	String uuid = null;
	if(StringUtils.isNotBlank(event.getField("vevent_uuid"))) {
		uuid = event.getField("vevent_uuid");
	} else {
		uuid = event.getId();
	}		
	vevent.getProperties().add(new Uid(uuid));
	
	//add sequence to event
	//will come from the vevent_sequnece field in the calendar event, otherwise skip it
	String sequence = null;
	if(StringUtils.isNotBlank(event.getField("vevent_sequence"))) {
		sequence = event.getField("vevent_sequence");
		vevent.getProperties().add(new Sequence(sequence));
	}
		
	//add description to event
	vevent.getProperties().add(new Description(event.getDescription()));
	
	//add location to event
	vevent.getProperties().add(new Location(event.getLocation()));
	
	//add organiser to event
	if(StringUtils.isNotBlank(event.getCreator())) {

		String creatorEmail = sakaiProxy.getUserEmail(event.getCreator());

		URI mailURI = createMailURI(creatorEmail);
		Cn commonName = new Cn(sakaiProxy.getUserDisplayName(event.getCreator()));

		Organizer organizer = new Organizer(mailURI);
		organizer.getParameters().add(commonName);
		vevent.getProperties().add(organizer);
	}
	
	//add attendees to event with 'required participant' role
	vevent = addAttendeesToEvent(vevent, attendees);
	
	//add URL to event, if present
	String url = null;
	if(StringUtils.isNotBlank(event.getField("vevent_url"))) {
		url = event.getField("vevent_url");
		Url u = new Url();
		try {
			u.setValue(url);
			vevent.getProperties().add(u);
		} catch (URISyntaxException e) {
			//it doesnt matter, ignore it
		}
	}
	
	if(log.isDebugEnabled()){
		log.debug("VEvent:" + vevent);
	}
	
	return vevent;
}
 
Example #13
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 2 votes vote down vote up
/**
 * Create a base Calendar containing a single component.
 * @param comp Component to add to the base Calendar
 * @param icalUid uid of component, if null no UID 
 *                property will be added to the component
 * @return base Calendar
 */
public static Calendar createBaseCalendar(CalendarComponent comp, String icalUid) {
    Uid uid = new Uid(icalUid);
    comp.getProperties().add(uid);
    return createBaseCalendar(comp);
}