use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ImportCalendarManager method reloadCalendarFromUrl.
/**
* Reload calendar from url and store calendar file locally.
* @param importUrl
* @param calType
* @param calId
*/
private void reloadCalendarFromUrl(String importUrl, String calType, String calId, KalendarEventFilter filter) {
try (InputStream in = new URL(importUrl).openStream()) {
String targetId = "-" + CalendarManager.TYPE_USER + "-" + calId;
Kalendar kalendar = calendarManager.buildKalendarFrom(in, calType, calId);
Collection<KalendarEvent> events = kalendar.getEvents();
for (KalendarEvent event : events) {
if (!filter.test(event) || event.getID().contains(targetId)) {
kalendar.removeEvent(event);
}
}
calendarManager.persistCalendar(kalendar);
} catch (Exception e) {
log.error("Could not reload calendar from url=" + importUrl, e);
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ImportToCalendarManager method importCalendarIn.
/**
* Append the stream of events to the specified calendar.
*
* @param calenderWrapper The target calendar.
* @param in An iCal stream.
* @return true if successfully imported
*/
public boolean importCalendarIn(KalendarRenderWrapper calenderWrapper, InputStream in) {
try {
Kalendar cal = calenderWrapper.getKalendar();
Kalendar importedCal = calendarManager.buildKalendarFrom(in, cal.getType(), cal.getCalendarID());
return calendarManager.updateCalendar(cal, importedCal);
} catch (Exception e) {
log.error("", e);
return false;
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ImportToCalendarManager method importCalendarIn.
/**
* Import an external calendar.
*
* @param cal
* @param importUrl
* @return
*/
public boolean importCalendarIn(Kalendar cal, String importUrl) {
try (InputStream in = new URL(importUrl).openStream()) {
Kalendar importedCal = calendarManager.buildKalendarFrom(in, cal.getType(), cal.getCalendarID());
boolean imported = calendarManager.updateCalendar(cal, importedCal);
if (imported) {
List<ImportedToCalendar> importedToCalendars = importedToCalendarDao.getImportedToCalendars(cal.getCalendarID(), cal.getType(), importUrl);
if (importedToCalendars.isEmpty()) {
importedToCalendarDao.createImportedToCalendar(cal.getCalendarID(), cal.getType(), importUrl, new Date());
} else {
ImportedToCalendar importedToCalendar = importedToCalendars.get(0);
importedToCalendar.setLastUpdate(new Date());
importedToCalendar = importedToCalendarDao.update(importedToCalendar);
}
}
return imported;
} catch (Exception e) {
log.error("", e);
return false;
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class ImportToCalendarManager method updateCalendarIn.
/**
* Method used by the cron job
* @return
*/
public boolean updateCalendarIn() {
List<ImportedToCalendar> importedToCalendars = importedToCalendarDao.getImportedToCalendars();
log.audit("Begin to update " + importedToCalendars.size() + " calendars.");
// make a full check only every 10 runs
boolean check = counter.incrementAndGet() % 10 == 0;
int count = 0;
for (ImportedToCalendar importedToCalendar : importedToCalendars) {
String type = importedToCalendar.getToType();
String id = importedToCalendar.getToCalendarId();
String importUrl = importedToCalendar.getUrl();
if (check || check(importedToCalendar)) {
try (InputStream in = new URL(importUrl).openStream()) {
Kalendar cal = calendarManager.getCalendar(type, id);
if (calendarManager.synchronizeCalendarFrom(in, importUrl, cal)) {
log.audit("Updated successfully calendar: " + type + " / " + id);
} else {
log.audit("Failed to update calendar: " + type + " / " + id);
}
} catch (Exception ex) {
log.error("Cannot synchronize calendar (" + importedToCalendar.getKey() + ") from url: " + importUrl, ex);
}
} else {
log.audit("Delete imported calendar because of missing resource: " + type + " " + id + " with URL: " + importUrl);
deleteImportedCalendars(type, id);
}
if (count++ % 20 == 0) {
DBFactory.getInstance().commit();
try {
// sleep to don't overload the system
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("", e);
}
}
}
return false;
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class CalendarEntryDetailsController method doSave.
private void doSave(UserRequest ureq) {
// ok, save edited entry
kalendarEvent = eventForm.getUpdatedKalendarEvent();
if (isNew) {
boolean doneSuccessfully = true;
// this is a new event, add event to calendar
String calendarID = eventForm.getChoosenKalendarID();
for (Iterator<KalendarRenderWrapper> iter = availableCalendars.iterator(); iter.hasNext(); ) {
KalendarRenderWrapper calendarWrapper = iter.next();
if (!calendarWrapper.getKalendar().getCalendarID().equals(calendarID)) {
continue;
}
Kalendar cal = calendarWrapper.getKalendar();
boolean result = calendarManager.addEventTo(cal, kalendarEvent);
if (result == false) {
// if one failed => done not successfully
doneSuccessfully = false;
}
}
reportSaveStatus(ureq, doneSuccessfully);
} else if (kalendarEvent instanceof KalendarRecurEvent && !StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceID())) {
updateCtr = new ConfirmUpdateController(ureq, getWindowControl(), (KalendarRecurEvent) kalendarEvent);
listenTo(updateCtr);
String title = translate("cal.edit.update");
cmc = new CloseableModalController(getWindowControl(), translate("close"), updateCtr.getInitialComponent(), true, title);
listenTo(cmc);
cmc.activate();
} else {
// this is an existing event, so we get the previousely assigned calendar from the event
Kalendar cal = kalendarEvent.getCalendar();
boolean doneSuccessfully = calendarManager.updateEventFrom(cal, kalendarEvent);
reportSaveStatus(ureq, doneSuccessfully);
}
}
Aggregations