use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class DENManager method cancelEnroll.
/**
* Deletes the already enrolled user from the date
* @param identity
* @param event
* @param course
* @param userCourseEnv
* @return status
*/
public DENStatus cancelEnroll(Identity identity, KalendarEvent event, OLATResourceable ores) {
DENStatus status = new DENStatus();
ICourse course = CourseFactory.loadCourse(ores);
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
// check if identity is enrolled
if (!isEnrolledInDate(identity, event)) {
status.setCancelled(false);
status.setErrorMessage(DENStatus.ERROR_NOT_ENROLLED);
}
// cancel enroll in calendar entry
if (event.getParticipants() != null) {
int currLength = event.getParticipants().length;
if (currLength > 0) {
// more than one are enrolled
// one to delete
List<String> partsNew = new ArrayList<>(currLength);
String[] partsOld = event.getParticipants();
String identityName = identity.getName();
for (String partOld : partsOld) {
if (!partOld.equals(identityName)) {
partsNew.add(partOld);
}
}
event.setParticipants(partsNew.toArray(new String[partsNew.size()]));
}
// save calendar event
boolean successfullyDone = calManager.updateEventFrom(cal, event);
if (!successfullyDone) {
status.setCancelled(false);
status.setErrorMessage(DENStatus.ERROR_PERSISTING);
return status;
}
} else {
// no one to cancel
status.setCancelled(false);
status.setErrorMessage(DENStatus.ERROR_GENERAL);
return status;
}
status.setCancelled(true);
// delete date from the users calendar
Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
Collection<KalendarEvent> userEvents = userCal.getEvents();
String sourceNodeId = event.getSourceNodeId();
for (KalendarEvent userEvent : userEvents) {
String eventSourceNodeId = userEvent.getSourceNodeId();
if (eventSourceNodeId != null && eventSourceNodeId.equals(sourceNodeId)) {
calManager.removeEventFrom(userCal, userEvent);
break;
}
}
// success
return status;
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class DENManager method addDateInUserCalendar.
/**
* Add this event in the calendar of an enrolled user
* @param newEvent
*/
private void addDateInUserCalendar(KalendarEvent newEvent) {
String[] participants = newEvent.getParticipants();
// no users to update, cancel
if (participants == null)
return;
BaseSecurity manager = BaseSecurityManager.getInstance();
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
for (String participant : participants) {
Identity identity = manager.findIdentityByName(participant);
if (identity != null) {
Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
List<KalendarEvent> userEvents = new ArrayList<>();
userEvents.addAll(userCal.getEvents());
String eventId = CodeHelper.getGlobalForeverUniqueID();
KalendarEvent userNewEvent = new KalendarEvent(eventId, null, newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
userNewEvent.setLocation(newEvent.getLocation());
userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
List<KalendarEventLink> kalendarEventLinks = userNewEvent.getKalendarEventLinks();
kalendarEventLinks.clear();
kalendarEventLinks.addAll(newEvent.getKalendarEventLinks());
calManager.addEventTo(userCal, userNewEvent);
}
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class CourseCalendarController method needToDifferentiateManagedEvents.
private boolean needToDifferentiateManagedEvents(List<KalendarRenderWrapper> calednarWrappers) {
boolean hasManaged = false;
for (KalendarRenderWrapper wrapper : calednarWrappers) {
Kalendar cal = wrapper.getKalendar();
hasManaged |= cal.hasManagedEvents();
}
return hasManaged;
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class LectureServiceImpl method fullSyncCourseCalendar.
private void fullSyncCourseCalendar(RepositoryEntry entry) {
List<LectureBlock> blocks = getLectureBlocks(entry);
Map<String, LectureBlock> externalIds = blocks.stream().collect(Collectors.toMap(b -> generateExternalId(b, entry), b -> b));
Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_COURSE, entry.getOlatResource().getResourceableId().toString());
String prefix = generateExternalIdPrefix(entry);
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
String externalId = event.getExternalId();
if (StringHelper.containsNonWhitespace(externalId) && externalId.startsWith(prefix)) {
if (externalIds.containsKey(externalId)) {
if (updateEvent(externalIds.get(externalId), event)) {
calendarMgr.updateEventFrom(cal, event);
}
externalIds.remove(externalId);
} else {
calendarMgr.removeEventFrom(cal, event);
}
}
}
// add new calendar events
List<KalendarEvent> eventsToAdd = new ArrayList<>();
for (Map.Entry<String, LectureBlock> entryToAdd : externalIds.entrySet()) {
eventsToAdd.add(createEvent(entryToAdd.getValue(), entry));
}
if (eventsToAdd.size() > 0) {
calendarMgr.addEventTo(cal, eventsToAdd);
}
}
use of org.olat.commons.calendar.model.Kalendar in project OpenOLAT by OpenOLAT.
the class LectureServiceImpl method unsyncInternalCalendar.
private void unsyncInternalCalendar(LectureBlock lectureBlock, List<Identity> identities) {
RepositoryEntry entry = lectureBlock.getEntry();
for (Identity identity : identities) {
Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
unsyncEvent(lectureBlock, entry, cal);
lectureParticipantSummaryDao.updateCalendarSynchronization(entry, identity);
}
}
Aggregations