use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CalendarTest method putCalendarEvent.
@Test
public void putCalendarEvent() 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 = 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();
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.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.model.KalendarEvent 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.model.KalendarEvent 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.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class EventsModel method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableController) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
if (actionid.equals(CMD_LAUNCH)) {
int rowid = te.getRowId();
KalendarEvent kalendarEvent = ((EventsModel) tableController.getTableDataModel()).getObject(rowid);
String resourceUrl = "[HomeSite:" + ureq.getIdentity().getKey() + "][calendar:0]" + BusinessControlFactory.getInstance().getContextEntryStringForDate(kalendarEvent.getBegin());
BusinessControl bc = BusinessControlFactory.getInstance().createFromString(resourceUrl);
WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, getWindowControl());
NewControllerFactory.getInstance().launch(ureq, bwControl);
}
}
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method synchronizeCalendarFrom.
@Test
public void synchronizeCalendarFrom() throws ValidationException, IOException {
Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("s1-");
Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
String eventId1 = "id-not-managed-event";
// 1. Add a standard event, not managed
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MILLISECOND, 0);
Date start = calendar.getTime();
calendar.add(Calendar.HOUR_OF_DAY, 1);
Date end = calendar.getTime();
KalendarEvent notManagedEvent = new KalendarEvent(eventId1, null, "testEvent", start, end);
calendarManager.addEventTo(cal, notManagedEvent);
// 2. Synchronize with a first calendar
Kalendar baseCalendar = calendarManager.createCalendar("user", "first-sync");
String eventIdManaged1 = "managed-event-1";
KalendarEvent managedEvent1 = new KalendarEvent(eventIdManaged1, null, "managedEvent", start, end);
baseCalendar.addEvent(managedEvent1);
String eventIdManaged2 = "managed-event-2";
KalendarEvent managedEvent2 = new KalendarEvent(eventIdManaged2, null, "managedEvent", start, end);
baseCalendar.addEvent(managedEvent2);
ByteArrayOutputStream os1 = new ByteArrayOutputStream();
new CalendarOutputter(false).output(calendarManager.buildCalendar(baseCalendar), os1);
InputStream in1 = new ByteArrayInputStream(os1.toByteArray());
calendarManager.synchronizeCalendarFrom(in1, "http://localhost:8080/unittest", cal);
in1.close();
// 3. Synchronize with a second calendar
Kalendar resyncCalendar = calendarManager.createCalendar("user", "first-sync");
KalendarEvent managedEvent1Alt = new KalendarEvent(eventIdManaged1, null, "managedEvent resync", start, end);
resyncCalendar.addEvent(managedEvent1Alt);
String eventIdManaged3 = "managed-event-3";
KalendarEvent managedEvent3 = new KalendarEvent(eventIdManaged3, null, "managedEvent 3", start, end);
resyncCalendar.addEvent(managedEvent3);
ByteArrayOutputStream os2 = new ByteArrayOutputStream();
new CalendarOutputter(false).output(calendarManager.buildCalendar(resyncCalendar), os2);
InputStream in2 = new ByteArrayInputStream(os2.toByteArray());
calendarManager.synchronizeCalendarFrom(in2, "http://localhost:8080/unittest", cal);
in2.close();
emptyCalendarCache();
// check
Kalendar synchedCal = calendarManager.getPersonalCalendar(test).getKalendar();
KalendarEvent notManagedEvent1 = synchedCal.getEvent(eventId1, null);
Assert.assertNotNull(notManagedEvent1);
Assert.assertEquals("testEvent", notManagedEvent1.getSubject());
KalendarEvent event1 = synchedCal.getEvent(eventIdManaged1, null);
Assert.assertNotNull(event1);
Assert.assertEquals("managedEvent resync", event1.getSubject());
KalendarEvent event2 = synchedCal.getEvent(eventIdManaged2, null);
Assert.assertNull(event2);
KalendarEvent event3 = synchedCal.getEvent(eventIdManaged3, null);
Assert.assertNotNull(event3);
Assert.assertEquals("managedEvent 3", event3.getSubject());
}
Aggregations