use of biweekly.ICalendar in project alf.io by alfio-event.
the class EventUtil method getIcalForEvent.
public static Optional<byte[]> getIcalForEvent(Event event, TicketCategory ticketCategory, String description) {
ICalendar ical = new ICalendar();
VEvent vEvent = new VEvent();
vEvent.setSummary(event.getDisplayName());
vEvent.setDescription(description);
vEvent.setLocation(StringUtils.replacePattern(event.getLocation(), "[\n\r\t]+", " "));
ZonedDateTime begin = Optional.ofNullable(ticketCategory).map(tc -> tc.getTicketValidityStart(event.getZoneId())).orElse(event.getBegin());
ZonedDateTime end = Optional.ofNullable(ticketCategory).map(tc -> tc.getTicketValidityEnd(event.getZoneId())).orElse(event.getEnd());
vEvent.setDateStart(Date.from(begin.toInstant()));
vEvent.setDateEnd(Date.from(end.toInstant()));
vEvent.setUrl(event.getWebsiteUrl());
ical.addEvent(vEvent);
StringWriter strWriter = new StringWriter();
try (ICalWriter writer = new ICalWriter(strWriter, ICalVersion.V2_0)) {
writer.write(ical);
return Optional.of(strWriter.toString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
log.warn("was not able to generate iCal for event " + event.getShortName(), e);
return Optional.empty();
}
}
use of biweekly.ICalendar in project substitution-schedule-parser by vertretungsplanme.
the class BaseIcalParser method getAdditionalInfo.
@Override
public AdditionalInfo getAdditionalInfo() throws IOException {
AdditionalInfo info = new AdditionalInfo();
info.setTitle(getTitle());
String rawdata = httpGet(getIcalUrl(), "UTF-8");
if (shouldStripTimezoneInfo()) {
Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL);
rawdata = pattern.matcher(rawdata).replaceAll("");
}
DateTime now = DateTime.now().withTimeAtStartOfDay();
List<ICalendar> icals = Biweekly.parse(rawdata).all();
List<Event> events = new ArrayList<>();
for (ICalendar ical : icals) {
for (VEvent event : ical.getEvents()) {
Event item = new Event();
TimeZone timezoneStart = getTimeZoneStart(ical, event);
if (event.getDescription() != null) {
item.description = event.getDescription().getValue();
}
if (event.getSummary() != null) {
item.summary = event.getSummary().getValue();
}
if (event.getDateStart() != null) {
item.startDate = new DateTime(event.getDateStart().getValue());
item.startHasTime = event.getDateStart().getValue().hasTime();
} else {
continue;
}
if (event.getDateEnd() != null) {
item.endDate = new DateTime(event.getDateEnd().getValue());
item.endHasTime = event.getDateEnd().getValue().hasTime();
}
if (event.getLocation() != null) {
item.location = event.getLocation().getValue();
}
if (event.getUrl() != null) {
item.url = event.getUrl().getValue();
}
if (event.getRecurrenceRule() == null && item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) {
continue;
}
if (event.getRecurrenceRule() != null) {
Duration duration = null;
if (event.getDateEnd() != null) {
duration = new Duration(new DateTime(event.getDateStart().getValue()), new DateTime(event.getDateEnd().getValue()));
}
DateIterator iterator = event.getDateIterator(timezoneStart);
while (iterator.hasNext()) {
Date date = iterator.next();
Event reccitem = item.clone();
reccitem.startDate = new DateTime(date);
reccitem.endDate = reccitem.startDate.plus(duration);
if (item.startDate.equals(reccitem.startDate))
continue;
if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
events.add(reccitem);
}
}
if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
continue;
} else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
continue;
}
events.add(item);
}
}
Collections.sort(events, new Comparator<Event>() {
@Override
public int compare(Event o1, Event o2) {
return o1.startDate.compareTo(o2.startDate);
}
});
StringBuilder content = new StringBuilder();
int count = 0;
DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY);
DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY);
for (Event item : events) {
if (count >= getMaxItemsCount()) {
break;
} else if (count != 0) {
content.append("<br><br>\n\n");
}
DateTime start = item.startDate;
if (item.endDate != null) {
DateTime end = item.endDate;
if (!item.endHasTime) {
end = end.minusDays(1);
}
content.append((item.startHasTime ? fmtDt : fmtD).print(start));
if (!end.equals(start)) {
content.append(" - ");
content.append((item.endHasTime ? fmtDt : fmtD).print(end));
}
} else {
content.append(fmtDt.print(start));
}
content.append("<br>\n");
content.append("<b>");
content.append(item.summary);
content.append("</b>");
count++;
}
info.setText(content.toString());
return info;
}
use of biweekly.ICalendar in project drbookings by DrBookings.
the class ICalBookingFactory method build.
@Override
public Collection<BookingBeanSer> build() throws IOException {
final Collection<BookingBeanSer> result = new ArrayList<>();
final List<ICalendar> icals = Biweekly.parse(file).all();
for (final ICalendar ical : icals) {
for (final VEvent e : ical.getEvents()) {
try {
result.add(processEvent(e));
} catch (final Exception ex) {
if (logger.isInfoEnabled()) {
logger.info("Failed to process event ", e);
}
// ex.printStackTrace();
}
}
}
return result;
}
use of biweekly.ICalendar in project common by zenlunatics.
the class EventProvider method writeICS.
// --------------------------------------------------------------------------
@AdminTask
public synchronized void writeICS(Request request) throws IOException {
ICalendar ical = new ICalendar();
String string = request.site.getSettings().getString("time zone");
TimeZone time_zone = TimeZone.getTimeZone(string);
TimezoneAssignment tza = TimezoneAssignment.download(time_zone, false);
ical.getTimezoneInfo().setDefaultTimezone(tza);
ArrayList<Event> events = new ArrayList<Event>();
addAllEvents(events, request);
for (Event event : events) {
VEvent vevent = event.newVEvent(request);
if (vevent != null)
ical.addEvent(vevent);
}
FilePathStringBuilder fpsb = request.site.getBaseFilePath().append("calendars");
new File(fpsb.toString()).mkdirs();
String file_path = fpsb.append(m_name).toString();
Biweekly.write(ical).go(new File(file_path));
new File(file_path).renameTo(new File(file_path + ".ics"));
}
Aggregations