Java Code Examples for net.fortuna.ical4j.model.Calendar#getComponents()

The following examples show how to use net.fortuna.ical4j.model.Calendar#getComponents() . 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: IcalUtils.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
/**
 * Parses a Calendar with multiple VEvents into Appointments
 *
 * @param calendar Calendar to Parse
 * @param ownerId  Owner of the Appointments
 * @return <code>List</code> of Appointments
 */
public List<Appointment> parseCalendartoAppointments(Calendar calendar, Long ownerId) {
	List<Appointment> appointments = new ArrayList<>();
	ComponentList<CalendarComponent> events = calendar.getComponents(Component.VEVENT);
	User owner = userDao.get(ownerId);

	for (CalendarComponent event : events) {
		Appointment a = new Appointment();
		a.setOwner(owner);
		a.setDeleted(false);
		a.setRoom(createDefaultRoom());
		a.setReminder(Appointment.Reminder.NONE);
		a = addVEventPropertiestoAppointment(a, event);
		appointments.add(a);
	}
	return appointments;
}
 
Example 2
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Load the calendar events from the given reader.
 *
 * @param calendar the target {@link ICalendar}
 * @param reader the input source reader
 * @throws IOException
 * @throws ParserException
 */
@Transactional(rollbackOn = {Exception.class})
public void load(ICalendar calendar, Reader reader) throws IOException, ParserException {
  Preconditions.checkNotNull(calendar, "calendar can't be null");
  Preconditions.checkNotNull(reader, "reader can't be null");

  final CalendarBuilder builder = new CalendarBuilder();
  final Calendar cal = builder.build(reader);

  if (calendar.getName() == null && cal.getProperty(X_WR_CALNAME) != null) {
    calendar.setName(cal.getProperty(X_WR_CALNAME).getValue());
  }

  for (Object item : cal.getComponents(Component.VEVENT)) {
    findOrCreateEvent((VEvent) item, calendar);
  }
}
 
Example 3
Source File: ICalendarStore.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
public static List<VEvent> getModifiedEvents(
    CalDavCalendarCollection calendar, Instant instant, Set<String> remoteUids) {
  final List<VEvent> events = new ArrayList<>();

  for (Calendar cal : calendar.getEvents()) {
    cal.toString();
    for (Object item : ((List<CalendarComponent>) cal.getComponents(Component.VEVENT))) {
      VEvent event = (VEvent) item;
      if (instant == null || event.getLastModified().getDate().toInstant().isAfter(instant)) {
        events.add(event);
      }
      remoteUids.add(event.getUid().getValue());
    }
  }
  return events;
}
 
Example 4
Source File: ICal3ClientFilter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void filterCalendar(Calendar calendar) {
   
    try {
        ComponentList<VEvent> events = calendar.getComponents(Component.VEVENT);
        for(VEvent event : events) {                 
            // fix VALUE=DATE-TIME instances
            fixDateTimeProperties(event);
            // fix EXDATEs
            if(event.getRecurrenceId()==null) {
                fixExDates(event);
            }
        }
    } catch (Exception e) {
        throw new CosmoException(e);
    } 
}
 
Example 5
Source File: FreeBusyUtil.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Obfuscates the specified calendar by removing unnecessary properties and replacing text fields with specified
 * text.
 * 
 * @param original
 *            calendar to be obfuscated
 * @param productId
 *            productId to be set for the copy calendar.
 * @param freeBusyText
 * @return obfuscated calendar.
 */
public static Calendar getFreeBusyCalendar(Calendar original, String productId, String freeBusyText) {
    // Make a copy of the original calendar
    Calendar copy = new Calendar();
    copy.getProperties().add(new ProdId(productId));
    copy.getProperties().add(Version.VERSION_2_0);
    copy.getProperties().add(CalScale.GREGORIAN);
    copy.getProperties().add(new XProperty(FREE_BUSY_X_PROPERTY, Boolean.TRUE.toString()));

    ComponentList<CalendarComponent> events = original.getComponents(Component.VEVENT);
    for (Component event : events) {
        copy.getComponents().add(getFreeBusyEvent((VEvent) event, freeBusyText));
    }
    return copy;
}
 
Example 6
Source File: EntityConverter.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Compact timezones.
 * @param calendar The calendar.
 */
private void compactTimezones(Calendar calendar) {
    
    if (calendar==null) {
        return;
    }

    // Get list of timezones in master calendar and remove all timezone
    // definitions that are in the registry.  The idea is to not store
    // extra data.  Instead, the timezones will be added to the calendar
    // by the getCalendar() api.
    ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE);
    List<VTimeZone> toRemove = new ArrayList<>();
    for(VTimeZone vtz : timezones) {
        String tzid = vtz.getTimeZoneId().getValue();
        TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid);
        //  Remove timezone iff it matches the one in the registry
        if(tz!=null && vtz.equals(tz.getVTimeZone())) {
            toRemove.add(vtz);
        }
    }

    // remove known timezones from master calendar
    calendar.getComponents().removeAll(toRemove);
}
 
Example 7
Source File: CalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public static boolean hasMultipleComponentTypes(Calendar calendar) {
String found = null;
for (Object component : calendar.getComponents()) {
    if (component instanceof VTimeZone) {
	continue;
    }
    if (found == null) {
	found = ((CalendarComponent) component).getName();
	continue;
    }
    if (!found.equals(((CalendarComponent) component).getName())) {
	return true;
    }
}
return false;
   }
 
Example 8
Source File: EventCollectionResource.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
private String extractUid(String icalendar) throws IOException, ParserException {
    
    String uid = null;
    StringReader reader = new StringReader(icalendar);
    CalendarBuilder builder = new CalendarBuilder();
    Calendar calendar = builder.build(new UnfoldingReader(reader, true));
    if ( calendar != null && calendar.getComponents() != null ) {
        Iterator<Component> iterator = calendar.getComponents().iterator();
        while (iterator.hasNext()) {
            Component component = iterator.next();
            if ( component instanceof VEvent ) {
                uid = ((VEvent)component).getUid().getValue();
                break;
            }
        }
    }
    
    return uid;
}
 
Example 9
Source File: CalendarUtils.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public static boolean hasSupportedComponent(Calendar calendar) {
for (Object component : calendar.getComponents()) {
    if (isSupportedComponent(((CalendarComponent) component).getName())) {
	return true;
    }
}
return false;
   }
 
Example 10
Source File: RecurrenceExpander.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if date is a valid occurence in recurring calendar component
 * @param calendar recurring calendar component
 * @param occurrence occurrence date
 * @return true if the occurrence date is a valid occurrence, otherwise false
 */
public boolean isOccurrence(Calendar calendar, Date occurrence) {
    java.util.Calendar cal = Dates.getCalendarInstance(occurrence);
    cal.setTime(occurrence);
   
    // Add a second or day (one unit forward) so we can set a range for
    // finding instances.  This is required because ical4j's Recur apis
    // only calculate recurring dates up until but not including the 
    // end date of the range.
    if(occurrence instanceof DateTime) {
        cal.add(java.util.Calendar.SECOND, 1);
    }
    else {
        cal.add(java.util.Calendar.DAY_OF_WEEK, 1);
    }
    
    Date rangeEnd = 
        org.unitedinternet.cosmo.calendar.util.Dates.getInstance(cal.getTime(), occurrence);
    
    TimeZone tz = null;
    
    for(Object obj : calendar.getComponents(Component.VEVENT)){
    	VEvent evt = (VEvent)obj;
    	if(evt.getRecurrenceId() == null && evt.getStartDate() != null){
    		tz = evt.getStartDate().getTimeZone();
    	}
    }
    InstanceList instances = getOcurrences(calendar, occurrence, rangeEnd, tz);
    
    for(Iterator<Instance> it = instances.values().iterator(); it.hasNext();) {
        Instance instance = it.next();
        if(instance.getRid().getTime()==occurrence.getTime()) {
            return true;
        }
    }
    
    return false;
}
 
Example 11
Source File: DavEvent.java    From cosmo with Apache License 2.0 5 votes vote down vote up
protected void setCalendar(Calendar calendar) throws CosmoDavException {

        ComponentList<VEvent> vevents = calendar.getComponents(Component.VEVENT);
        if (vevents.isEmpty()) {
            throw new UnprocessableEntityException("VCALENDAR does not contain any VEVENTs");
        }

        getEventStamp().setEventCalendar(calendar);
    }
 
Example 12
Source File: DavJournal.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * @param cal Imports a calendar object containing a VJOURNAL. Sets the
 * following properties:
 * </p>
 * <ul>
 * <li>display name: the VJOURNAL's SUMMARY (or the item's name, if the
 * SUMMARY is blank)</li>
 * <li>icalUid: the VJOURNAL's UID</li>
 * <li>body: the VJOURNAL's DESCRIPTION</li>
 * </ul>
 */
public void setCalendar(Calendar cal)
    throws CosmoDavException {
    NoteItem note = (NoteItem) getItem();
  
    ComponentList<VJournal> vjournals = cal.getComponents(Component.VJOURNAL);
    if (vjournals.isEmpty()) {
        throw new UnprocessableEntityException("VCALENDAR does not contain any VJOURNALS");
    }

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertJournalCalendar(note, cal);
}
 
Example 13
Source File: EntityConverterTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
   * Tests convert task.
   * @throws Exception - if something is wrong this exception is thrown.
   */
  @Test
  public void testConvertTask() throws Exception {
      @SuppressWarnings("unused")
TimeZoneRegistry registry =
          TimeZoneRegistryFactory.getInstance().createRegistry();
      NoteItem master = new MockNoteItem();
      master.setDisplayName("displayName");
      master.setBody("body");
      master.setIcalUid("icaluid");
      master.setClientModifiedDate(new DateTime("20070101T100000Z"));
      master.setTriageStatus(TriageStatusUtil.initialize(new MockTriageStatus()));
      
      Calendar cal = converter.convertNote(master);
      cal.validate();
      
      Assert.assertEquals(1, cal.getComponents().size());
      
      ComponentList<VToDo> comps = cal.getComponents(Component.VTODO);
      Assert.assertEquals(1, comps.size());
      VToDo task = comps.get(0);
      
      Assert.assertNull(task.getDateCompleted());
      Assert.assertNull(ICalendarUtils.getXProperty("X-OSAF-STARRED", task));
      
      DateTime completeDate = new DateTime("20080122T100000Z");
      
      master.getTriageStatus().setCode(TriageStatus.CODE_DONE);
      master.getTriageStatus().setRank(TriageStatusUtil.getRank(completeDate.getTime()));
      master.addStamp(new MockTaskStamp());
      
      cal = converter.convertNote(master);
      task = (VToDo) cal.getComponents().get(0);
      
      Completed completed = task.getDateCompleted();
      Assert.assertNotNull(completed);
      Assert.assertEquals(completeDate.getTime(), completed.getDate().getTime());
      Assert.assertEquals("TRUE", ICalendarUtils.getXProperty("X-OSAF-STARRED", task));
      
  }
 
Example 14
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/** Returns a calendar derived from a Work Effort calendar publish point.
 * @param workEffortId ID of a work effort with <code>workEffortTypeId</code> equal to
 * <code>PUBLISH_PROPS</code>.
 * @param context The conversion context
 * @return An iCalendar as a <code>String</code>, or <code>null</code>
 * if <code>workEffortId</code> is invalid.
 * @throws GenericEntityException
 */
public static ResponseProperties getICalendar(String workEffortId, Map<String, Object> context) throws GenericEntityException {
    Delegator delegator = (Delegator) context.get("delegator");
    GenericValue publishProperties = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne();
    if (!isCalendarPublished(publishProperties)) {
        Debug.logInfo("WorkEffort calendar is not published: " + workEffortId, module);
        return ICalWorker.createNotFoundResponse(null);
    }
    if (!"WES_PUBLIC".equals(publishProperties.get("scopeEnumId"))) {
        if (context.get("userLogin") == null) {
            return ICalWorker.createNotAuthorizedResponse(null);
        }
        if (!hasPermission(workEffortId, "VIEW", context)) {
            return ICalWorker.createForbiddenResponse(null);
        }
    }
    Calendar calendar = makeCalendar(publishProperties, context);
    ComponentList<CalendarComponent> components = calendar.getComponents();
    List<GenericValue> workEfforts = getRelatedWorkEfforts(publishProperties, context);
    if (workEfforts != null) {
        for (GenericValue workEffort : workEfforts) {
            ResponseProperties responseProps = toCalendarComponent(components, workEffort, context);
            if (responseProps != null) {
                return responseProps;
            }
        }
    }
    if (Debug.verboseOn()) {
        try {
            calendar.validate(true);
            Debug.logVerbose("iCalendar passes validation", module);
        } catch (ValidationException e) {
            if (Debug.verboseOn()) Debug.logVerbose("iCalendar fails validation: " + e, module);
        }
    }
    return ICalWorker.createOkResponse(calendar.toString());
}
 
Example 15
Source File: ICalendarStore.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<VEvent> getEvents(CalDavCalendarCollection calendar) {
  final List<VEvent> events = new ArrayList<>();
  for (Calendar cal : calendar.getEvents()) {
    for (Object item : cal.getComponents(Component.VEVENT)) {
      VEvent event = (VEvent) item;
      events.add(event);
    }
  }
  return events;
}
 
Example 16
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 17
Source File: IcsFileImporter.java    From ganttproject with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Reads calendar events from file
 * @return a list of events if file was parsed successfully or null otherwise
 */
private static List<CalendarEvent> readEvents(File f) {
  try {
    CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true);
    CalendarBuilder builder = new CalendarBuilder();
    List<CalendarEvent> gpEvents = Lists.newArrayList();
    Calendar c = builder.build(new UnfoldingReader(new FileReader(f)));
    for (Component comp : (List<Component>)c.getComponents()) {
      if (comp instanceof VEvent) {
        VEvent event = (VEvent) comp;
        if (event.getStartDate() == null) {
          GPLogger.log("No start date found, ignoring. Event="+event);
          continue;
        }
        Date eventStartDate = event.getStartDate().getDate();
        if (event.getEndDate() == null) {
          GPLogger.log("No end date found, using start date instead. Event="+event);
        }
        Date eventEndDate = event.getEndDate() == null ? eventStartDate : event.getEndDate().getDate();
        TimeDuration oneDay = GPTimeUnitStack.createLength(GPTimeUnitStack.DAY, 1);
        if (eventEndDate != null) {
          java.util.Date startDate = GPTimeUnitStack.DAY.adjustLeft(eventStartDate);
          java.util.Date endDate = GPTimeUnitStack.DAY.adjustLeft(eventEndDate);
          RRule recurrenceRule = (RRule) event.getProperty(Property.RRULE);
          boolean recursYearly = false;
          if (recurrenceRule != null) {
            recursYearly = Recur.YEARLY.equals(recurrenceRule.getRecur().getFrequency()) && 1 == recurrenceRule.getRecur().getInterval();
          }
          while (startDate.compareTo(endDate) <= 0) {
            Summary summary = event.getSummary();
            gpEvents.add(CalendarEvent.newEvent(
                startDate, recursYearly, CalendarEvent.Type.HOLIDAY,
                summary == null ? "" : summary.getValue(),
                null));
            startDate = GPCalendarCalc.PLAIN.shiftDate(startDate, oneDay);
          }
        }
      }
    }
    return gpEvents;
  } catch (IOException | ParserException e) {
    GPLogger.log(e);
    return null;
  }
}
 
Example 18
Source File: EntityConverterTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
     * Tests entity converter event.
     * @throws Exception - if something is wrong this exception is thrown.
     */
    @Test
    public void testEntityConverterEvent() throws Exception {
        
        Calendar calendar = getCalendar("event_with_exception.ics");
        NoteItem master = entityFactory.createNote();
        Set<NoteItem> items = converter.convertEventCalendar(master, calendar);
        
        // should be master and mod
        Assert.assertEquals(2, items.size());
        
        // get master
        Iterator<NoteItem> it = items.iterator();
        master = it.next();
        
        // check ical props
        // DTSTART
//      This fails, which is pretty strange
//        EventStamp masterEvent = StampUtils.getEventStamp(master); 
//        Assert.assertNotNull(masterEvent);
//        DateTime testStart = new DateTime("20060102T140000", TimeZoneUtils.getTimeZone("US/Eastern_mod"));
//        Assert.assertTrue(masterEvent.getStartDate().equals(testStart));
        // Triage status
        TriageStatus ts = master.getTriageStatus();
        // the event is in the past, it should be DONE
        Assert.assertTrue(TriageStatus.CODE_DONE==ts.getCode());
        // DTSTAMP
        Assert.assertEquals(master.getClientModifiedDate().getTime(), new DateTime("20051222T210507Z").getTime());
        // UID
        Assert.assertEquals(master.getIcalUid(), "[email protected]");
        // SUMMARY
        Assert.assertEquals(master.getDisplayName(), "event 6");
        
        // get mod
        NoteItem mod = it.next();
        
        ModificationUidImpl uid = new ModificationUidImpl(mod.getUid());
        
        Assert.assertEquals(master.getUid(), uid.getParentUid());
        Assert.assertEquals("20060104T190000Z", uid.getRecurrenceId().toString());
        
        Assert.assertTrue(mod.getModifies()==master);
        EventExceptionStamp ees = StampUtils.getEventExceptionStamp(mod);
        Assert.assertNotNull(ees);
        
        // mod should include VTIMEZONES
        Calendar eventCal = ees.getEventCalendar();
        ComponentList<VTimeZone> vtimezones = eventCal.getComponents(Component.VTIMEZONE);
        Assert.assertEquals(1, vtimezones.size());
        
        
        // update event (change mod and add mod)
        calendar = getCalendar("event_with_exception2.ics");
        items = converter.convertEventCalendar(master, calendar);
        
        // should be master and 2 mods
        Assert.assertEquals(3, items.size());
        
        mod = findModByRecurrenceIdForNoteItems(items, "20060104T190000Z");
        Assert.assertNotNull(mod);
        Assert.assertEquals("event 6 mod 1 changed", mod.getDisplayName());
        
        mod = findModByRecurrenceIdForNoteItems(items, "20060105T190000Z");
        Assert.assertNotNull(mod);
        Assert.assertEquals("event 6 mod 2", mod.getDisplayName());
        
        // update event again (remove mod)
        calendar = getCalendar("event_with_exception3.ics");
        items = converter.convertEventCalendar(master, calendar);
        
        // should be master and 1 active mod/ 1 deleted mod
        Assert.assertEquals(3, items.size());
        
        mod = findModByRecurrenceIdForNoteItems(items, "20060104T190000Z");
        Assert.assertNotNull(mod);
        Assert.assertFalse(mod.getIsActive().booleanValue());
        
        mod = findModByRecurrenceIdForNoteItems(items, "20060105T190000Z");
        Assert.assertNotNull(mod);
        Assert.assertEquals("event 6 mod 2 changed", mod.getDisplayName());
        
    }
 
Example 19
Source File: EntityConverterTest.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Tests convert event.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testConvertEvent() throws Exception {
    TimeZoneRegistry registry =
        TimeZoneRegistryFactory.getInstance().createRegistry();
    NoteItem master = new MockNoteItem();
    master.setDisplayName("displayName");
    master.setBody("body");
    master.setIcalUid("icaluid");
    master.setClientModifiedDate(new DateTime("20070101T100000Z"));
    EventStamp eventStamp = new MockEventStamp(master);
    eventStamp.createCalendar();
    eventStamp.setStartDate(new DateTime("20070212T074500"));
    master.addStamp(eventStamp);
    
    Calendar cal = converter.convertNote(master);
    cal.validate();
    
    // date has no timezone, so there should be no timezones
    Assert.assertEquals(0, cal.getComponents(Component.VTIMEZONE).size());
  
    eventStamp.setStartDate(new DateTime("20070212T074500",TIMEZONE_REGISTRY.getTimeZone("America/Chicago")));
    
    cal = converter.convertNote(master);
    cal.validate();
    
    // should be a single VEVENT
    ComponentList<VEvent> comps = cal.getComponents(Component.VEVENT);
    Assert.assertEquals(1, comps.size());
    VEvent event = (VEvent) comps.get(0);
    
    // test VALUE=DATE-TIME is not present
    Assert.assertNull(event.getStartDate().getParameter(Parameter.VALUE));
    
    // test item properties got merged into calendar
    Assert.assertEquals("displayName", event.getSummary().getValue());
    Assert.assertEquals("body", event.getDescription().getValue());
    Assert.assertEquals("icaluid", event.getUid().getValue());
    Assert.assertEquals(master.getClientModifiedDate().getTime(), event.getDateStamp().getDate().getTime());
     
    // date has timezone, so there should be a timezone
    Assert.assertEquals(1, cal.getComponents(Component.VTIMEZONE).size());
    
    eventStamp.setEndDate(new DateTime("20070212T074500",TIMEZONE_REGISTRY.getTimeZone("America/Los_Angeles")));
    
    cal = converter.convertNote(master);
    cal.validate();
    
    // dates have 2 different timezones, so there should be 2 timezones
    Assert.assertEquals(2, cal.getComponents(Component.VTIMEZONE).size());
    
    // add timezones to master event calendar
    eventStamp.getEventCalendar().getComponents().add(registry.getTimeZone("America/Chicago").getVTimeZone());
    eventStamp.getEventCalendar().getComponents().add(registry.getTimeZone("America/Los_Angeles").getVTimeZone());
    
    cal = converter.convertNote(master);
    cal.validate();
    Assert.assertEquals(2, cal.getComponents(Component.VTIMEZONE).size());
}
 
Example 20
Source File: DavTask.java    From cosmo with Apache License 2.0 3 votes vote down vote up
/**
 * <p>
 * Imports a calendar object containing a VTODO. Sets the
 * following properties:
 * </p>
 * <ul>
 * <li>display name: the VTODO's SUMMARY (or the item's name, if the
 * SUMMARY is blank)</li>
 * <li>icalUid: the VTODO's UID</li>
 * <li>body: the VTODO's DESCRIPTION</li>
 * <li>reminderTime: if the VTODO has a DISPLAY VALARM
 *     the reminderTime will be set to the trigger time</li>
 * </ul>
 * @param cal The calendar imported.
 * @throws CosmoDavException - if something is wrong this exception is thrown.
 */
public void setCalendar(Calendar cal)
    throws CosmoDavException {
    NoteItem note = (NoteItem) getItem();
    
    ComponentList<VToDo> vtodos = cal.getComponents(Component.VTODO);
    if (vtodos.isEmpty()) {
        throw new UnprocessableEntityException("VCALENDAR does not contain any VTODOS");
    }

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertTaskCalendar(note, cal);
}