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

The following examples show how to use net.fortuna.ical4j.model.property.DtStart. 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: HibEventExceptionStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Toggle the event exception anytime parameter.
 * @param isAnyTime True if the event occurs anytime<br/>
 *                  False if the event does not occur anytime</br>
 *                  null if the event should inherit the anyTime
 *                  attribute of the master event.
 */
@Override
public void setAnyTime(Boolean isAnyTime) {
    // Interpret null as "missing" anyTime, meaning inherited from master
    if(isAnyTime==null) {
        DtStart dtStart = getEvent().getStartDate();
        if (dtStart == null) {
            throw new IllegalStateException("event has no start date");
        }
        Parameter parameter = dtStart.getParameters().getParameter(
                PARAM_X_OSAF_ANYTIME);
        if(parameter!=null) {
            dtStart.getParameters().remove(parameter);
        }
        
        // "missing" anyTime is represented as X-OSAF-ANYTIME=MISSING
        dtStart.getParameters().add(getInheritedAnyTimeXParam());
    } else {
        super.setAnyTime(isAnyTime);
    }
}
 
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: StandardContentServiceTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testUpdateCollectionFailsForEventsWithInvalidDates() throws Exception {
    User user = testHelper.makeDummyUser();
    CollectionItem rootCollection = contentDao.createRootItem(user);

    NoteItem noteItem = new MockNoteItem();
    noteItem.getAttributeValue("");
    noteItem.setName("foo");
    noteItem.setOwner(user);
    
    Calendar c = new Calendar();
    VEvent e = new VEvent();
    e.getProperties().add(new DtStart("20131010T101010Z"));
    e.getProperties().add(new DtEnd("20131010T091010Z"));
    
    c.getComponents().add(e);
    MockEventStamp mockEventStamp = new MockEventStamp();
    mockEventStamp.setEventCalendar(c);
    noteItem.addStamp(mockEventStamp);
    
    service.updateCollection(rootCollection, Collections.singleton((Item)noteItem));
}
 
Example #4
Source File: StandardContentServiceTest.java    From cosmo with Apache License 2.0 6 votes vote down vote up
@Test(expected=IllegalArgumentException.class)
public void testCreateContentThrowsExceptionForInvalidDates() throws Exception {
    User user = testHelper.makeDummyUser();
    CollectionItem rootCollection = contentDao.createRootItem(user);

    NoteItem noteItem = new MockNoteItem();
    noteItem.getAttributeValue("");
    noteItem.setName("foo");
    noteItem.setOwner(user);
    
    Calendar c = new Calendar();
    VEvent e = new VEvent();
    e.getProperties().add(new DtStart("20131010T101010Z"));
    e.getProperties().add(new DtEnd("20131010T091010Z"));
    
    c.getComponents().add(e);
    MockEventStamp mockEventStamp = new MockEventStamp();
    mockEventStamp.setEventCalendar(c);
    noteItem.addStamp(mockEventStamp);
    
    service.createContent(rootCollection, noteItem);
}
 
Example #5
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets any time.
 * @param isAnyTime isAnyTime.
 */
public void setAnyTime(Boolean isAnyTime) {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        throw new IllegalStateException("event has no start date");
    }
    Parameter parameter = dtStart.getParameters().getParameter(
            PARAM_X_OSAF_ANYTIME);

    // add X-OSAF-ANYTIME if it doesn't exist
    if (parameter == null && Boolean.TRUE.equals(isAnyTime)) {
        dtStart.getParameters().add(getAnyTimeXParam());
        return;
    }

    // if it exists, update based on isAnyTime
    if (parameter != null) {
        dtStart.getParameters().remove(parameter);
        if (Boolean.TRUE.equals(isAnyTime)) {   
            dtStart.getParameters().add(getAnyTimeXParam());
        }
    }
}
 
Example #6
Source File: MockEventExceptionStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Is any time.
 * @return boolean.
 */
@Override
public Boolean isAnyTime() {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        return Boolean.FALSE;
    }
    Parameter parameter = dtStart.getParameters()
        .getParameter(PARAM_X_OSAF_ANYTIME);
    if (parameter == null) {
        return Boolean.FALSE;
    }
 
    // return null for "missing" anyTime
    if (VALUE_MISSING.equals(parameter.getValue())) {
        return null;
    }

    return Boolean.valueOf(VALUE_TRUE.equals(parameter.getValue()));
}
 
Example #7
Source File: MockEventExceptionStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Sets any time.
 * @param isAnyTime Boolean.
 */
@Override
public void setAnyTime(Boolean isAnyTime) {
    // Interpret null as "missing" anyTime, meaning inherited from master
    if(isAnyTime==null) {
        DtStart dtStart = getEvent().getStartDate();
        if (dtStart == null) {
            throw new IllegalStateException("event has no start date");
        }
        Parameter parameter = dtStart.getParameters().getParameter(
                PARAM_X_OSAF_ANYTIME);
        if (parameter != null) {
            dtStart.getParameters().remove(parameter);
        }
        
        // "missing" anyTime is represented as X-OSAF-ANYTIME=MISSING
        dtStart.getParameters().add(getInheritedAnyTimeXParam());
    } else {
        super.setAnyTime(isAnyTime);
    }
}
 
Example #8
Source File: EventValidator.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private static boolean isEventValid(VEvent event, ValidationConfig config) {
    if (config == null) {
        LOG.error("ValidationConfig cannot be null");
        return false;
    }
    DtStart startDate = event.getStartDate();
    DtEnd endDate = event.getEndDate(true);
    if (startDate == null || startDate.getDate() == null
            || endDate != null && startDate.getDate().after(endDate.getDate())) {

        return false;
    }

    for (PropertyValidator validator : values()) {
        if (!validator.isValid(event, config)) {
            return false;
        }
    }

    return areTimeZoneIdsValid(event);
}
 
Example #9
Source File: HibEventExceptionStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Is the event exception marked as anytime.
 * @return True if the event is an anytime event<br/>
 *         False if it is not an anytime event<br/>
 *         null if the anyTime attribute is "missing", ie inherited
 *         from the master event.
 */
@Override
public Boolean isAnyTime() {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        return Boolean.FALSE;
    }
    Parameter parameter = dtStart.getParameters()
        .getParameter(PARAM_X_OSAF_ANYTIME);
    if (parameter == null) {
        return Boolean.FALSE;
    }
 
    // return null for "missing" anyTime
    if(!VALUE_MISSING.equals(parameter.getValue())) {
        return Boolean.valueOf(VALUE_TRUE.equals(parameter.getValue()));
    }
    
    return Boolean.FALSE;
}
 
Example #10
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 6 votes vote down vote up
public void setAnyTime(Boolean isAnyTime) {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        throw new IllegalStateException("event has no start date");
    }
    Parameter parameter = dtStart.getParameters().getParameter(
            PARAM_X_OSAF_ANYTIME);

    // add X-OSAF-ANYTIME if it doesn't exist
    if (parameter == null && Boolean.TRUE.equals(isAnyTime)) {
        dtStart.getParameters().add(getAnyTimeXParam());
        return;
    }

    // if it exists, update based on isAnyTime
    if (parameter != null) {
        dtStart.getParameters().remove(parameter);
        if (Boolean.TRUE.equals(isAnyTime)) {
            dtStart.getParameters().add(getAnyTimeXParam());
        }
    }
}
 
Example #11
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Evaluates VJournal time range.
 * @param journal The VJournal.
 * @param filter The time range filter.
 * @return The result.
 */
private boolean evaluateVJournalTimeRange(VJournal journal, TimeRangeFilter filter) {
    DtStart start = journal.getStartDate();
  
    if(start==null) {
        return false;
    }
    
    InstanceList instances = new InstanceList();
    if (filter.getTimezone() != null) {
        instances.setTimezone(new TimeZone(filter.getTimezone()));
    }
    instances.addComponent(journal, filter.getPeriod().getStart(),
            filter.getPeriod().getEnd());
    return instances.size() > 0;
}
 
Example #12
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public static void convert(TemporalExpression expr, PropertyList<Property> eventProps) {
    ICalRecurConverter converter = new ICalRecurConverter();
    expr.accept(converter);
    DtStart dateStart = (DtStart) eventProps.getProperty(Property.DTSTART);
    if (converter.dateStart != null) {
        if (dateStart != null) {
            eventProps.remove(dateStart);
        }
        dateStart = converter.dateStart;
        eventProps.add(dateStart);
    }
    if (dateStart != null && converter.exRuleList.size() > 0) {
        // iCalendar quirk - if exclusions exist, then the start date must be excluded also
        ExDate exdate = new ExDate();
        exdate.getDates().add(dateStart.getDate());
        converter.exDateList.add(exdate);
    }
    eventProps.addAll(converter.incDateList);
    eventProps.addAll(converter.incRuleList);
    eventProps.addAll(converter.exDateList);
    eventProps.addAll(converter.exRuleList);
}
 
Example #13
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * Get the duration for an event.  If the DURATION property
 * exist, use that.  Else, calculate duration from DTSTART and
 * DTEND.
 * @param event The event.
 * @return duration for event
 */
public static Dur getDuration(VEvent event) {
    Duration duration = (Duration)
        event.getProperties().getProperty(Property.DURATION);
    if (duration != null) {
        return duration.getDuration();
    }
    DtStart dtstart = event.getStartDate();
    if (dtstart == null) {
        return null;
    }
    DtEnd dtend = (DtEnd) event.getProperties().getProperty(Property.DTEND);
    if (dtend == null) {
        return null;
    }
    return new Duration(dtstart.getDate(), dtend.getDate()).getDuration();
}
 
Example #14
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
protected static Timestamp fromDtStart(PropertyList<Property> propertyList) {
    DtStart iCalObj = (DtStart) propertyList.getProperty(DtStart.DTSTART);
    if (iCalObj == null) {
        return null;
    }
    Date date = iCalObj.getDate();
    return new Timestamp(date.getTime());
}
 
Example #15
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 #16
Source File: StandardContentServiceTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
private Calendar createEventCalendarWithDates(String start, String end) throws ParseException{
    Calendar c = new Calendar();
    VEvent e = new VEvent();
    e.getProperties().add(new DtStart(start));
    e.getProperties().add(new DtEnd(end));
    
    c.getComponents().add(e);
    
    return c;
}
 
Example #17
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(TemporalExpressions.Frequency expr) {
    if (this.dateStart == null) {
        this.dateStart = new DtStart(new net.fortuna.ical4j.model.Date(expr.getStartDate()));
    }
    int freqCount = expr.getFreqCount();
    int freqType = expr.getFreqType();
    switch (freqType) {
    case Calendar.SECOND:
        this.state.addRecur((new Recur(Recur.SECONDLY, freqCount)));
        break;
    case Calendar.MINUTE:
        this.state.addRecur((new Recur(Recur.MINUTELY, freqCount)));
        break;
    case Calendar.HOUR:
        this.state.addRecur((new Recur(Recur.HOURLY, freqCount)));
        break;
    case Calendar.DAY_OF_MONTH:
        this.state.addRecur((new Recur(Recur.DAILY, freqCount)));
        break;
    case Calendar.MONTH:
        this.state.addRecur((new Recur(Recur.MONTHLY, freqCount)));
        break;
    case Calendar.YEAR:
        this.state.addRecur((new Recur(Recur.YEARLY, freqCount)));
        break;
    default:
        break;
    }
}
 
Example #18
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Is any time
 * @return boolean.
 */
public Boolean isAnyTime() {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        return Boolean.FALSE;
    }
    Parameter parameter = dtStart.getParameters()
        .getParameter(PARAM_X_OSAF_ANYTIME);
    if (parameter == null) {
        return Boolean.FALSE;
    }

    return Boolean.valueOf(VALUE_TRUE.equals(parameter.getValue()));
}
 
Example #19
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets start date.
 * @return date.
 */
public Date getStartDate() {
    VEvent event = getEvent();
    if (event==null) {
        return null;
    }
    
    DtStart dtStart = event.getStartDate();
    if (dtStart == null) {
        return null;
    }
    return dtStart.getDate();
}
 
Example #20
Source File: StandardContentService.java    From cosmo with Apache License 2.0 5 votes vote down vote up
private NoteOccurrence getNoteOccurrence(NoteItem parent, net.fortuna.ical4j.model.Date recurrenceId) {
     EventStamp eventStamp = StampUtils.getEventStamp(parent);
     
     // Parent must be a recurring event
     if(eventStamp==null || !eventStamp.isRecurring()) {
         return null;
     }
     RecurrenceId rid = null; 
     if(eventStamp.getEvent() != null && eventStamp.getEvent().getStartDate() != null){
     	DtStart startDate = eventStamp.getEvent().getStartDate();
     	rid = new RecurrenceId();
     	try {
	if(startDate.isUtc()){
		rid.setUtc(true);
	}else if(startDate.getTimeZone() != null){
		rid.setTimeZone(startDate.getTimeZone());
	}
	rid.setValue(recurrenceId.toString());
} catch (ParseException e) {
	rid = null;
}
     }
     net.fortuna.ical4j.model.Date recurrenceIdToUse = rid == null ? recurrenceId : rid.getDate();
     // Verify that occurrence date is valid
     RecurrenceExpander expander = new RecurrenceExpander();
     if(expander.isOccurrence(eventStamp.getEventCalendar(), recurrenceIdToUse)) {
         return NoteOccurrenceUtil.createNoteOccurrence(recurrenceIdToUse, parent);
     }
     
     return null;
 }
 
Example #21
Source File: StandardContentService.java    From cosmo with Apache License 2.0 5 votes vote down vote up
private void checkDatesForComponent(Component component){
    if(component == null){
        return;
    }
    
    Property dtStart = component.getProperty(Property.DTSTART);
    Property dtEnd = component.getProperty(Property.DTEND);
    
    if( dtStart instanceof DtStart && dtStart.getValue()!= null 
        && dtEnd instanceof DtEnd && dtEnd.getValue() != null 
       && ((DtStart)dtStart).getDate().compareTo(((DtEnd)dtEnd).getDate()) > 0 ){
        throw new IllegalArgumentException("End date [" + dtEnd + " is lower than start date [" + dtStart + "]");
    }
    
}
 
Example #22
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 #23
Source File: CalendarFilterEvaluater.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates VFreeBusy time range.
 * @param freeBusy freebusy.
 * @param filter The filter.
 * @return The result.
 */
private boolean evaulateVFreeBusyTimeRange(VFreeBusy freeBusy, TimeRangeFilter filter) {
    DtStart start = freeBusy.getStartDate();
    DtEnd end = freeBusy.getEndDate();
     
    if (start != null && end != null) {
        InstanceList instances = new InstanceList();
        if (filter.getTimezone() != null) {
            instances.setTimezone(new TimeZone(filter.getTimezone()));
        }
        instances.addComponent(freeBusy, filter.getPeriod().getStart(),
                filter.getPeriod().getEnd());
        return instances.size() > 0;
    }
    
    PropertyList<FreeBusy> props = freeBusy.getProperties(Property.FREEBUSY);
    if(props.size()==0) {
        return false;
    }
    
    for (FreeBusy fb : props) {            
        PeriodList periods = fb.getPeriods();
        Iterator<Period> periodIt = periods.iterator();
        while(periodIt.hasNext()) {
            Period period = periodIt.next();
            if(filter.getPeriod().getStart().before(period.getEnd()) &&
               filter.getPeriod().getEnd().after(period.getStart())) {
                return true;
            }
        }
    }
    
    return false;
}
 
Example #24
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public Boolean isAnyTime() {
    DtStart dtStart = getEvent().getStartDate();
    if (dtStart == null) {
        return Boolean.FALSE;
    }
    Parameter parameter = dtStart.getParameters()
        .getParameter(PARAM_X_OSAF_ANYTIME);
    if (parameter == null) {
        return Boolean.FALSE;
    }

    return Boolean.valueOf(VALUE_TRUE.equals(parameter.getValue()));
}
 
Example #25
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public Date getStartDate() {
    VEvent event = getEvent();
    if(event==null) {
        return null;
    }
    
    DtStart dtStart = event.getStartDate();
    if (dtStart == null) {
        return null;
    }
    return dtStart.getDate();
}
 
Example #26
Source File: ICalendarUtils.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Return the date that a trigger refers to, which can be an absolute
 * date or a date relative to the start or end time of a parent 
 * component (VEVENT/VTODO).
 * @param trigger The trigger.
 * @param parent The component.
 * @return date of trigger.
 */
public static Date getTriggerDate(Trigger trigger, Component parent) {
    
    if(trigger==null) {
        return null;
    }
    
    // if its absolute then we are done
    if(trigger.getDateTime()!=null) {
        return trigger.getDateTime();
    }
    
    // otherwise we need a start date if VEVENT
    DtStart start = (DtStart) parent.getProperty(Property.DTSTART);
    if(start==null && parent instanceof VEvent) {
        return null;
    }
    
    // is trigger relative to start or end
    Related related = (Related) trigger.getParameter(Parameter.RELATED);
    if(related==null || related.equals(Related.START)) {    
        // must have start date
        if(start==null) {
            return null;
        }
        
        // relative to start
        return Dates.getInstance(trigger.getDuration().getTime(start.getDate()), start.getDate());
    } else {
        // relative to end
        Date endDate = null;
        
        // need an end date or duration or due 
        DtEnd end = (DtEnd) parent.getProperty(Property.DTEND);
        if(end!=null) {
            endDate = end.getDate();
        }
       
        if(endDate==null) {
            Duration dur = (Duration) parent.getProperty(Property.DURATION);
            if(dur!=null && start!=null) {
                endDate= Dates.getInstance(dur.getDuration().getTime(start.getDate()), start.getDate());
            }
        }
        
        if(endDate==null) {
            Due due = (Due) parent.getProperty(Property.DUE);
            if(due!=null) {
                endDate = due.getDate();
            }
        }
        
        // require end date
        if(endDate==null) {
            return null;
        }
        
        return Dates.getInstance(trigger.getDuration().getTime(endDate), endDate);
    }
}
 
Example #27
Source File: RecurrenceExpander.java    From cosmo with Apache License 2.0 4 votes vote down vote up
/**
 * Gets start date.
 * @param comp The component.
 * @return The date.
 */
private Date getStartDate(Component comp) {
    DtStart prop = (DtStart) comp.getProperties().getProperty(
            Property.DTSTART);
    return (prop != null) ? prop.getDate() : null;
}
 
Example #28
Source File: ICalConverter.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
protected static DtStart toDtStart(Timestamp javaObj) {
    if (javaObj == null) {
        return null;
    }
    return new DtStart(new DateTime(javaObj));
}
 
Example #29
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 4 votes vote down vote up
@Transactional
protected ICalendarEvent findOrCreateEvent(VEvent vEvent, ICalendar calendar) {

  String uid = vEvent.getUid().getValue();
  DtStart dtStart = vEvent.getStartDate();
  DtEnd dtEnd = vEvent.getEndDate();

  ICalendarEvent event = iEventRepo.findByUid(uid);
  if (event == null) {
    event = ICalendarEventFactory.getNewIcalEvent(calendar);
    event.setUid(uid);
    event.setCalendar(calendar);
  }

  ZoneId zoneId = OffsetDateTime.now().getOffset();
  if (dtStart.getDate() != null) {
    if (dtStart.getTimeZone() != null) {
      zoneId = dtStart.getTimeZone().toZoneId();
    }
    event.setStartDateTime(LocalDateTime.ofInstant(dtStart.getDate().toInstant(), zoneId));
  }

  if (dtEnd.getDate() != null) {
    if (dtEnd.getTimeZone() != null) {
      zoneId = dtEnd.getTimeZone().toZoneId();
    }
    event.setEndDateTime(LocalDateTime.ofInstant(dtEnd.getDate().toInstant(), zoneId));
  }

  event.setAllDay(!(dtStart.getDate() instanceof DateTime));

  event.setSubject(getValue(vEvent, Property.SUMMARY));
  event.setDescription(getValue(vEvent, Property.DESCRIPTION));
  event.setLocation(getValue(vEvent, Property.LOCATION));
  event.setGeo(getValue(vEvent, Property.GEO));
  event.setUrl(getValue(vEvent, Property.URL));
  event.setSubjectTeam(event.getSubject());
  if (Clazz.PRIVATE.getValue().equals(getValue(vEvent, Property.CLASS))) {
    event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PRIVATE);
  } else {
    event.setVisibilitySelect(ICalendarEventRepository.VISIBILITY_PUBLIC);
  }
  if (Transp.TRANSPARENT.getValue().equals(getValue(vEvent, Property.TRANSP))) {
    event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_AVAILABLE);
  } else {
    event.setDisponibilitySelect(ICalendarEventRepository.DISPONIBILITY_BUSY);
  }
  if (event.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
    event.setSubjectTeam(I18n.get("Available"));
    if (event.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
      event.setSubjectTeam(I18n.get("Busy"));
    }
  }
  ICalendarUser organizer = findOrCreateUser(vEvent.getOrganizer(), event);
  if (organizer != null) {
    event.setOrganizer(organizer);
    iCalendarUserRepository.save(organizer);
  }

  for (Object item : vEvent.getProperties(Property.ATTENDEE)) {
    ICalendarUser attendee = findOrCreateUser((Property) item, event);
    if (attendee != null) {
      event.addAttendee(attendee);
      iCalendarUserRepository.save(attendee);
    }
  }
  iEventRepo.save(event);
  return event;
}
 
Example #30
Source File: FreeBusyUtils.java    From cosmo with Apache License 2.0 3 votes vote down vote up
/**
    A VFREEBUSY component overlaps a given time range if the condition
    for the corresponding component state specified in the table below
    is satisfied.  The conditions depend on the presence in the
    VFREEBUSY component of the DTSTART and DTEND properties, and any
    FREEBUSY properties in the absence of DTSTART and DTEND.  Any
    DURATION property is ignored, as it has a special meaning when
    used in a VFREEBUSY component.

    When only FREEBUSY properties are used, each period in each
    FREEBUSY property is compared against the time range, irrespective
    of the type of free busy information (free, busy, busy-tentative,
    busy-unavailable) represented by the property.


    +------------------------------------------------------+
    | VFREEBUSY has both the DTSTART and DTEND properties? |
    |   +--------------------------------------------------+
    |   | VFREEBUSY has the FREEBUSY property?             |
    |   |   +----------------------------------------------+
    |   |   | Condition to evaluate                        |
    +---+---+----------------------------------------------+
    | Y | * | (start <= DTEND) AND (end > DTSTART)         |
    +---+---+----------------------------------------------+
    | N | Y | (start <  freebusy-period-end) AND           |
    |   |   | (end   >  freebusy-period-start)             |
    +---+---+----------------------------------------------+
    | N | N | FALSE                                        |
    +---+---+----------------------------------------------+
 *
 * @param freeBusy comoponent to test
 * @param period period to test against
 * @param tz timezone to use for floating times
 * @return true if component overlaps specified range, false otherwise
 */
public static boolean overlapsPeriod(VFreeBusy freeBusy, Period period, TimeZone tz){
    
    DtStart start = freeBusy.getStartDate();
    DtEnd end = freeBusy.getEndDate();
     
    if (start != null && end != null) {
        InstanceList instances = new InstanceList();
        instances.setTimezone(tz);
        instances.addComponent(freeBusy, period.getStart(),period.getEnd());
        return instances.size() > 0;
    }
    
    PropertyList<FreeBusy> props = freeBusy.getProperties(Property.FREEBUSY);
    if (props.size()==0) {
        return false;
    }
    
    for (FreeBusy fb: props) {            
        PeriodList periods = fb.getPeriods();
        Iterator<Period> periodIt = periods.iterator();
        while(periodIt.hasNext()) {
            Period fbPeriod = periodIt.next();
            if(fbPeriod.intersects(period)) {
                return true;
            }
        }
    }
    
    return false;
}