Java Code Examples for net.fortuna.ical4j.model.component.VEvent#getEndDate()

The following examples show how to use net.fortuna.ical4j.model.component.VEvent#getEndDate() . 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: 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 2
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 3
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 4
Source File: MainActivity.java    From ICSImport with GNU General Public License v3.0 4 votes vote down vote up
@Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);

       Intent intent = getIntent();

Uri data = intent.getData();

try {
	//use ical4j to parse the event
	CalendarBuilder cb = new CalendarBuilder();
	Calendar calendar = null;
	calendar = cb.build(getStreamFromOtherSource(data));

	if (calendar != null) {

		Iterator i = calendar.getComponents(Component.VEVENT).iterator();

		while (i.hasNext()) {
			VEvent event = (VEvent) i.next();

			Intent insertIntent = new Intent(Intent.ACTION_INSERT)
				.setType("vnd.android.cursor.item/event");

			if (event.getStartDate() != null)
				insertIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.getStartDate().getDate().getTime());

			if (event.getEndDate() != null)
				insertIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.getEndDate().getDate().getTime());

			if (event.getSummary() != null)
				insertIntent.putExtra(CalendarContract.Events.TITLE, event.getSummary().getValue());

			if (event.getDescription() != null)
				insertIntent.putExtra(CalendarContract.Events.DESCRIPTION, event.getDescription().getValue());

			if (event.getLocation() != null) 
				insertIntent.putExtra(CalendarContract.Events.EVENT_LOCATION, event.getLocation().getValue());

			insertIntent.putExtra(CalendarContract.Events.ACCESS_LEVEL, CalendarContract.Events.ACCESS_PRIVATE);
			startActivity(insertIntent);

		}
	}

} catch (Exception e) {
	e.printStackTrace();
	Toast.makeText(getBaseContext(), "Invalid ICS file", Toast.LENGTH_LONG).show();
}
finish();

   }