Java Code Examples for net.fortuna.ical4j.model.ComponentList#get()

The following examples show how to use net.fortuna.ical4j.model.ComponentList#get() . 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: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluates.
 * @param comps The component list.
 * @param filter The time range filter.
 * @return the result.
 */
private boolean evaluate(ComponentList<? extends Component> comps, TimeRangeFilter filter) {
    
    Component comp = (Component) comps.get(0);
    
    if(comp instanceof VEvent) {
        return evaluateVEventTimeRange(comps, filter);
    }
    else if(comp instanceof VFreeBusy) {
        return evaulateVFreeBusyTimeRange((VFreeBusy) comp, filter);
    }
    else if(comp instanceof VToDo) {
        return evaulateVToDoTimeRange(comps, filter);
    }
    else if(comp instanceof VJournal) {
        return evaluateVJournalTimeRange((VJournal) comp, filter);
    }
    else if(comp instanceof VAlarm) {
        return evaluateVAlarmTimeRange(comps, filter);
    }
    else {
        return false;
    }
}
 
Example 2
Source File: HibEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public VEvent getMasterEvent() {
    if(getEventCalendar()==null) {
        return null;
    }
    
    ComponentList<VEvent> events = getEventCalendar().getComponents().getComponents(
            Component.VEVENT);
    
    if(events.size()==0) {
        return null;
    }
    
    return (VEvent) events.get(0);
}
 
Example 3
Source File: MockEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets master event.
 * @return The event.
 */
public VEvent getMasterEvent() {
    if (getEventCalendar() == null) {
        return null;
    }
    
    ComponentList<VEvent> events = getEventCalendar().getComponents().getComponents(
            Component.VEVENT);
    
    if (events.size() == 0) {
        return null;
    }
    
    return (VEvent) events.get(0);
}
 
Example 4
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 5
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());
}