use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class HomeCalendarManager method addCalendars.
/**
* Append the calendars of a list of groups. The groups must have their calendar tool
* enabled, this routine doesn't check it.
* @param ureq
* @param groups
* @param isOwner
* @param calendars
*/
private void addCalendars(List<BusinessGroup> groups, boolean isOwner, boolean isParticipant, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
Map<Long, Long> groupKeyToAccess = CoreSpringFactory.getImpl(CollaborationManager.class).lookupCalendarAccess(groups);
for (BusinessGroup bGroup : groups) {
try {
KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
groupCalendarWrapper.setPrivateEventsVisible(true);
// set calendar access
int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
Long lCalAccess = groupKeyToAccess.get(bGroup.getKey());
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);
}
if (isOwner || isParticipant) {
groupCalendarWrapper.setPrivateEventsVisible(true);
}
calendars.add(groupCalendarWrapper);
} catch (Exception e) {
log.error("Cannot read calendar of group: " + bGroup, e);
}
}
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.
the class HomeCalendarManager method appendPersonalCalendar.
private void appendPersonalCalendar(Identity identity, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
// get the personal calendar
if (calendarModule.isEnablePersonalCalendar()) {
try {
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(identity);
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
calendarWrapper.setPrivateEventsVisible(true);
CalendarUserConfiguration config = configMap.get(calendarWrapper.getCalendarKey());
if (config != null) {
calendarWrapper.setConfiguration(config);
}
calendars.add(calendarWrapper);
} catch (Exception e) {
log.error("Cannot read personal calendar of: " + identity, e);
}
}
}
use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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.ui.components.KalendarRenderWrapper 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.ui.components.KalendarRenderWrapper 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