use of org.olat.commons.calendar.CalendarManager 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.CalendarManager in project OpenOLAT by OpenOLAT.
the class CourseCalendars method addCalendars.
private static void addCalendars(UserRequest ureq, UserCourseEnvironment courseEnv, List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, List<KalendarRenderWrapper> calendars) {
if (groups == null || groups.isEmpty())
return;
CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(ureq.getIdentity(), CalendarManager.TYPE_GROUP);
for (BusinessGroup bGroup : groups) {
CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup);
if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR)) {
continue;
}
boolean member = courseEnv.isIdentityInCourseGroup(bGroup.getKey());
KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
groupCalendarWrapper.setPrivateEventsVisible(member || isOwner);
// set calendar access
int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
Long lCalAccess = collabTools.lookupCalendarAccess();
if (lCalAccess != null)
iCalAccess = lCalAccess.intValue();
if (iCalAccess == CollaborationTools.CALENDAR_ACCESS_OWNERS && !isOwner) {
groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
} else {
groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
}
CalendarUserConfiguration config = configMap.get(groupCalendarWrapper.getCalendarKey());
if (config != null) {
groupCalendarWrapper.setConfiguration(config);
}
groupCalendarWrapper.setLinkProvider(linkProvider);
calendars.add(groupCalendarWrapper);
}
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class CourseCalendarTest method setUp.
/**
* SetUp is called before each test.
*/
@Before
public void setUp() throws Exception {
super.setUp();
try {
// create course and persist as OLATResourceImpl
auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
dbInstance.commit();
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
KalendarRenderWrapper calendarWrapper = calManager.getCourseCalendar(course);
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 2; i++) {
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end = cal.getTime();
String eventId = UUID.randomUUID().toString();
KalendarEvent event = new KalendarEvent(eventId, null, "Unit test " + i, begin, end);
calManager.addEventTo(calendarWrapper.getKalendar(), event);
cal.add(Calendar.DATE, 1);
}
} catch (Exception e) {
log.error("Exception in setUp(): " + e);
}
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
the class DENManager method removeDateInUserCalendar.
/**
* Removes this event in all calendars of enrolled users
* @param oldEvent
*/
private void removeDateInUserCalendar(KalendarEvent oldEvent) {
String[] participants = oldEvent.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());
for (KalendarEvent userEvent : userEvents) {
String sourceNodeId = userEvent.getSourceNodeId();
if (sourceNodeId != null && sourceNodeId.equals(oldEvent.getSourceNodeId())) {
calManager.removeEventFrom(userCal, userEvent);
}
}
}
}
}
use of org.olat.commons.calendar.CalendarManager in project openolat by klemens.
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;
}
Aggregations