use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class DENManager method getDENEvents.
/**
* Returns all generated Events for this course and node
* @param courseId
* @param sourseNodeId
* @return List of all KalendarEvent in this date enrollment
*/
protected List<KalendarEvent> getDENEvents(Long courseId, String sourceNodeId) {
List<KalendarEvent> denEvents = new ArrayList<KalendarEvent>();
ICourse course = CourseFactory.loadCourse(courseId);
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
Collection<KalendarEvent> colEvents = cal.getEvents();
for (KalendarEvent event : colEvents) {
String eventSourceNodeId = event.getSourceNodeId();
if (eventSourceNodeId != null) {
if (eventSourceNodeId.equals(sourceNodeId))
denEvents.add(event);
}
}
return denEvents;
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class DENManager method doEnroll.
/**
* Enrolls an user into a specific calendar event
* @param identity
* @param event
* @param course
* @param courseNode
* @param allowOverfill
* @return status
*/
public DENStatus doEnroll(final Identity identity, final KalendarEvent event, final OLATResourceable ores, final DENCourseNode courseNode, final boolean allowOverfill) {
final DENStatus status = new DENStatus();
ICourse course = CourseFactory.loadCourse(ores);
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
final Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
OLATResourceable calRes = calManager.getOresHelperFor(cal);
// reload calendar events
final List<KalendarEvent> denEvents = getDENEvents(ores.getResourceableId(), courseNode.getIdent());
CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calRes, new SyncerExecutor() {
public void execute() {
boolean error = false;
// try to find choosen calendar event in the reloaded event list
KalendarEvent reloadEvent = event;
for (Iterator<KalendarEvent> iterator = denEvents.iterator(); iterator.hasNext(); ) {
KalendarEvent kalendarEvent = iterator.next();
if (event.getID().equals(kalendarEvent.getID())) {
reloadEvent = kalendarEvent;
break;
} else if (!iterator.hasNext()) {
// cannot find reloaded calendar event
status.setEnrolled(false);
status.setErrorMessage(DENStatus.ERROR_GENERAL);
error = true;
}
}
Collection<KalendarEvent> collEvents = cal.getEvents();
// check if date is already full
if (!error && !allowOverfill && isDateFull(reloadEvent)) {
status.setEnrolled(false);
status.setErrorMessage(DENStatus.ERROR_FULL);
error = true;
}
// check if identity is already enrolled
if (!error && isAlreadyEnrolled(identity, collEvents, courseNode)) {
status.setEnrolled(false);
status.setErrorMessage(DENStatus.ERROR_ALREADY_ENROLLED);
error = true;
}
// enroll in event
if (!error) {
if (reloadEvent.getParticipants() != null && reloadEvent.getParticipants().length > 0) {
int currLength = reloadEvent.getParticipants().length;
// one to add
String[] partsNew = new String[currLength + 1];
String[] partsOld = reloadEvent.getParticipants();
for (int i = 0; i < partsOld.length; i++) {
partsNew[i] = partsOld[i];
}
partsNew[partsNew.length - 1] = identity.getName();
reloadEvent.setParticipants(partsNew);
} else {
String[] partsNew = new String[] { identity.getName() };
reloadEvent.setParticipants(partsNew);
}
// save calendar event
boolean successfullyDone = calManager.updateEventAlreadyInSync(cal, reloadEvent);
if (!successfullyDone) {
status.setEnrolled(false);
status.setErrorMessage(DENStatus.ERROR_PERSISTING);
}
status.setEnrolled(true);
}
}
});
// success
return status;
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
the class DENManager method persistDENSettings.
/**
* Persists settings of the date enrollment
* @param lstEvents
* @param course
* @param denNode
*/
public void persistDENSettings(List<KalendarEvent> lstEvents, OLATResourceable ores, DENCourseNode denNode) {
ICourse course = CourseFactory.loadCourse(ores);
CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
String sourceNode = denNode.getIdent();
// remove deleted events
Collection<KalendarEvent> allEvents = new ArrayList<KalendarEvent>(cal.getEvents());
for (KalendarEvent event : allEvents) {
if (event.getSourceNodeId() != null) {
if (event.getSourceNodeId().equals(sourceNode) && !lstEvents.contains(event)) {
removeDateInUserCalendar(event);
calManager.removeEventFrom(cal, event);
}
}
}
for (KalendarEvent newEvent : lstEvents) {
createKalendarEventLinks(course, denNode, newEvent);
KalendarEvent oldEvent = cal.getEvent(newEvent.getID(), newEvent.getRecurrenceID());
// new event?
if (oldEvent != null) {
// event is already in the calendar so first remove it
calManager.removeEventFrom(cal, oldEvent);
}
// now add the event to the course calendar
calManager.addEventTo(cal, newEvent);
// update event in user calendars
addDateInUserCalendar(newEvent);
}
}
use of org.olat.commons.calendar.model.Kalendar in project openolat by klemens.
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 CalendarUserConfigurationDAOTest method getCalendarUserConfigurations_byTypes.
@Test
public void getCalendarUserConfigurations_byTypes() {
Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Cal-3");
String calendarId = UUID.randomUUID().toString();
Kalendar courseCalendar = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
CalendarUserConfiguration courseCalConfig = calendarDao.createCalendarUserConfiguration(courseCalendar, user);
Kalendar groupCalendar = new Kalendar(calendarId, CalendarManager.TYPE_GROUP);
CalendarUserConfiguration groupCalConfig = calendarDao.createCalendarUserConfiguration(groupCalendar, user);
Kalendar personalCalendar = new Kalendar(user.getName(), CalendarManager.TYPE_USER);
CalendarUserConfiguration personalCalConfig = calendarDao.createCalendarUserConfiguration(personalCalendar, user);
dbInstance.commit();
Assert.assertNotNull(courseCalConfig);
// get all
List<CalendarUserConfiguration> configList = calendarDao.getCalendarUserConfigurations(user);
Assert.assertNotNull(configList);
Assert.assertEquals(3, configList.size());
Assert.assertTrue(configList.contains(courseCalConfig));
Assert.assertTrue(configList.contains(groupCalConfig));
Assert.assertTrue(configList.contains(personalCalConfig));
// get course
List<CalendarUserConfiguration> courseConfigList = calendarDao.getCalendarUserConfigurations(user, CalendarManager.TYPE_COURSE);
Assert.assertNotNull(courseConfigList);
Assert.assertEquals(1, courseConfigList.size());
Assert.assertTrue(courseConfigList.contains(courseCalConfig));
// null check
List<CalendarUserConfiguration> nullConfigList = calendarDao.getCalendarUserConfigurations(user, (String) null);
Assert.assertNotNull(nullConfigList);
Assert.assertEquals(3, nullConfigList.size());
}
Aggregations