use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class LectureServiceImpl method unsyncInternalCalendar.
/*
private void unsyncParticipantsCalendar(RepositoryEntry entry) {
List<Identity> participants = getParticipants(entry);
unsyncInternalCalendar(entry, participants);
}
*/
private void unsyncInternalCalendar(RepositoryEntry entry, List<Identity> identities) {
String prefix = generateExternalIdPrefix(entry);
for (Identity identity : identities) {
Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
if (event.getExternalId() != null && event.getExternalId().startsWith(prefix)) {
calendarMgr.removeEventFrom(cal, event);
}
}
lectureParticipantSummaryDao.updateCalendarSynchronization(entry, identity);
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class LectureServiceImpl method unsyncEvent.
private void unsyncEvent(LectureBlock lectureBlock, RepositoryEntry entry, Kalendar cal) {
String externalId = generateExternalId(lectureBlock, entry);
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
if (externalId.equals(event.getExternalId())) {
calendarMgr.removeEventFrom(cal, event);
}
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class EventsModel method getMatchingEvents.
private List<KalendarEvent> getMatchingEvents(UserRequest ureq, WindowControl wControl) {
Date startDate = new Date();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + 7);
Date endDate = cal.getTime();
List<KalendarEvent> events = new ArrayList<>();
List<KalendarRenderWrapper> calendars = personalCalendarManager.getListOfCalendarWrappers(ureq, wControl);
for (Iterator<KalendarRenderWrapper> iter = calendars.iterator(); iter.hasNext(); ) {
KalendarRenderWrapper calendarWrapper = iter.next();
boolean readOnly = (calendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY) && !calendarWrapper.isImported();
List<KalendarEvent> eventsWithinPeriod = calendarManager.getEvents(calendarWrapper.getKalendar(), startDate, endDate, true);
for (KalendarEvent event : eventsWithinPeriod) {
// skip non-public events
if (readOnly && event.getClassification() != KalendarEvent.CLASS_PUBLIC) {
continue;
}
events.add(event);
}
}
// sort events
Collections.sort(events, new Comparator<KalendarEvent>() {
public int compare(KalendarEvent arg0, KalendarEvent arg1) {
Date begin0 = arg0.getBegin();
Date begin1 = arg1.getBegin();
return begin0.compareTo(begin1);
}
});
if (events.size() > MAX_EVENTS)
events = events.subList(0, MAX_EVENTS);
return events;
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
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.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CourseCalendarTest method deleteCalendarEvent.
@Test
public void deleteCalendarEvent() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(auth1.getName(), "A6B7C8"));
// create an event if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course1);
Calendar cal = Calendar.getInstance();
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
String id = UUID.randomUUID().toString();
KalendarEvent kalEvent = new KalendarEvent(id, null, "Subject (" + id + ")", begin, cal.getTime());
calendarManager.addEventTo(calendarWrapper.getKalendar(), kalEvent);
// check if the event exists
URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").path("events").build();
HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
assertEquals(200, response.getStatusLine().getStatusCode());
List<EventVO> vos = parseEventArray(response.getEntity().getContent());
assertNotNull(vos);
boolean found = false;
for (EventVO vo : vos) {
if (id.equals(vo.getId())) {
found = true;
}
}
assertTrue(found);
// delete the event
URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").path("events").path(kalEvent.getID()).build();
HttpDelete delEventMethod = conn.createDelete(eventUri, MediaType.APPLICATION_JSON);
HttpResponse delEventResponse = conn.execute(delEventMethod);
assertEquals(200, delEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(delEventResponse.getEntity());
conn.shutdown();
// check if the event is really deleted
KalendarRenderWrapper reloadedCalendarWrapper = calendarManager.getCourseCalendar(course1);
Collection<KalendarEvent> savedEvents = reloadedCalendarWrapper.getKalendar().getEvents();
for (KalendarEvent savedEvent : savedEvents) {
Assert.assertFalse(savedEvent.getID().equals(kalEvent.getID()));
}
}
Aggregations