use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class CalendarTest method testPostCalendarEvents.
@Test
public void testPostCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id2.getName(), "A6B7C8"));
URI calUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").build();
HttpGet calMethod = conn.createGet(calUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(calMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
List<CalendarVO> vos = parseArray(response);
assertTrue(vos != null && !vos.isEmpty());
CalendarVO calendar = getCourseCalendar(vos, course2);
Assert.assertNotNull(calendar);
// create an event
EventVO event = new EventVO();
Calendar cal = Calendar.getInstance();
event.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event.setEnd(cal.getTime());
String subject = UUID.randomUUID().toString();
event.setSubject(subject);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").path(calendar.getId()).path("event").build();
HttpPost postEventMethod = conn.createPost(eventUri, MediaType.APPLICATION_JSON);
conn.addJsonEntity(postEventMethod, event);
HttpResponse postEventResponse = conn.execute(postEventMethod);
assertEquals(200, postEventResponse.getStatusLine().getStatusCode());
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
boolean found = false;
for (KalendarEvent savedEvent : savedEvents) {
if (subject.equals(savedEvent.getSubject())) {
found = true;
}
}
Assert.assertTrue(found);
conn.shutdown();
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class CalendarTest method testPutPersonalCalendarEvents.
@Test
public void testPutPersonalCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id2.getName(), "A6B7C8"));
URI calUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").build();
HttpGet calMethod = conn.createGet(calUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(calMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
List<CalendarVO> vos = parseArray(response);
assertNotNull(vos);
assertTrue(2 <= vos.size());
CalendarVO calendar = getUserCalendar(vos);
// create an event
EventVO event = new EventVO();
Calendar cal = Calendar.getInstance();
event.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event.setEnd(cal.getTime());
String subject = UUID.randomUUID().toString();
event.setSubject(subject);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").path(calendar.getId()).path("event").build();
HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(putEventMethod, event);
HttpResponse putEventResponse = conn.execute(putEventMethod);
assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(putEventResponse.getEntity());
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(id2);
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
boolean found = false;
for (KalendarEvent savedEvent : savedEvents) {
if (subject.equals(savedEvent.getSubject())) {
found = true;
}
}
Assert.assertTrue(found);
conn.shutdown();
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testCalendarRecurringEventInversed.
/**
* A recurring event with the start and end date reversed. This error
* in the calendar cause the whole calendar to crash.
*
* @throws URISyntaxException
* @throws IOException
*/
@Test
public void testCalendarRecurringEventInversed() throws URISyntaxException, IOException {
Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ur1-");
URL calendarUrl = CalendarImportTest.class.getResource("ReversedRecurringEvent.ics");
File calendarFile = new File(calendarUrl.toURI());
String calendarName = UUID.randomUUID().toString().replace("-", "");
KalendarRenderWrapper importedCalendar = importCalendarManager.importCalendar(test, calendarName, CalendarManager.TYPE_USER, calendarFile);
List<KalendarEvent> events = importedCalendar.getKalendar().getEvents();
Assert.assertEquals(1, events.size());
Calendar cal = Calendar.getInstance();
cal.set(2018, 03, 10, 10, 00);
Date startDate = cal.getTime();
cal.set(2018, 03, 17);
Date endDate = cal.getTime();
List<KalendarEvent> recurringEvents = calendarManager.getEvents(importedCalendar.getKalendar(), startDate, endDate, true);
Assert.assertEquals(0, recurringEvents.size());
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testListEventsForPeriodWithoutDTEndEvent.
/**
* Check a NPE
* @throws IOException
*/
@Test
public void testListEventsForPeriodWithoutDTEndEvent() throws IOException {
// replace the standard calendar with a forged one
Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cal-test-1-");
File calendarFile = calendarManager.getCalendarFile("user", identity.getName());
if (calendarFile.exists()) {
calendarFile.delete();
}
File newCalendarFile = new File(calendarFile.getParentFile(), calendarFile.getName());
InputStream in = CalendarImportTest.class.getResourceAsStream("cal_without_dtend.ics");
FileUtils.copyInputStreamToFile(in, newCalendarFile);
// to be sure
emptyCalendarCache();
// load the calendar
KalendarRenderWrapper reloadCalWrapper = calendarManager.getPersonalCalendar(identity);
// check if its the right calendar
Collection<KalendarEvent> events = reloadCalWrapper.getKalendar().getEvents();
Assert.assertNotNull(events);
Assert.assertEquals(1, events.size());
KalendarEvent event = events.iterator().next();
Assert.assertEquals("Arbeitszeit: 1-3h", event.getSubject());
Assert.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", event.getID());
Assert.assertNull(event.getEnd());
// test persist
boolean allOk = calendarManager.persistCalendar(reloadCalWrapper.getKalendar());
Assert.assertTrue(allOk);
// an other possible RS
// within period
Date periodStart = CalendarUtils.getDate(2010, Calendar.MARCH, 15);
Date periodEnd = CalendarUtils.getDate(2010, Calendar.MARCH, 20);
List<KalendarEvent> eventsForPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart, periodEnd, true);
Assert.assertNotNull(eventsForPeriod);
Assert.assertEquals(0, eventsForPeriod.size());
KalendarEvent eventForPeriod = events.iterator().next();
Assert.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", eventForPeriod.getID());
// out of scope
Date periodStart2 = CalendarUtils.getDate(2008, Calendar.APRIL, 15);
Date periodEnd2 = CalendarUtils.getDate(2008, Calendar.APRIL, 17);
List<KalendarEvent> eventsOutOfPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart2, periodEnd2, true);
Assert.assertNotNull(eventsOutOfPeriod);
Assert.assertTrue(eventsOutOfPeriod.isEmpty());
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class CourseCalendarController method getListOfCalendarWrappers.
private List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq) {
List<KalendarRenderWrapper> calendars = new ArrayList<>();
// add course calendar
ICourse course = CourseFactory.loadCourse(userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
courseKalendarWrapper = calendarManager.getCourseCalendar(course);
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
Roles roles = ureq.getUserSession().getRoles();
boolean isPrivileged = !userCourseEnv.isCourseReadOnly() && (roles.isOLATAdmin() || userCourseEnv.isAdmin() || repositoryManager.isInstitutionalRessourceManagerFor(getIdentity(), roles, cgm.getCourseEntry()));
if (isPrivileged) {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
courseKalendarWrapper.setPrivateEventsVisible(true);
} else {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
courseKalendarWrapper.setPrivateEventsVisible(userCourseEnv.isAdmin() || userCourseEnv.isCoach() || userCourseEnv.isParticipant());
}
CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), getIdentity());
if (config != null) {
courseKalendarWrapper.setConfiguration(config);
}
// add link provider
CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.<ICourse>singletonList(course), ureq, getWindowControl());
courseKalendarWrapper.setLinkProvider(clpc);
calendars.add(courseKalendarWrapper);
// add course group calendars
// learning groups
List<BusinessGroup> ownerGroups = cgm.getOwnedBusinessGroups(getIdentity());
addCalendars(ownerGroups, !userCourseEnv.isCourseReadOnly(), clpc, calendars);
List<BusinessGroup> attendedGroups = cgm.getParticipatingBusinessGroups(getIdentity());
for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext(); ) {
BusinessGroup ownerGroup = ownerGroupsIterator.next();
if (attendedGroups.contains(ownerGroup))
attendedGroups.remove(ownerGroup);
}
addCalendars(attendedGroups, false, clpc, calendars);
return calendars;
}
Aggregations