use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CalendarTest method startup.
@Before
public void startup() {
if (id1 == null) {
id1 = JunitTestHelper.createAndPersistIdentityAsUser("cal-1-" + UUID.randomUUID().toString());
}
if (id2 == null) {
id2 = JunitTestHelper.createAndPersistIdentityAsUser("cal-2-" + UUID.randomUUID().toString());
}
if (course1 == null) {
// create a course with a calendar
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
dbInstance.commit();
ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
Assert.assertTrue(courseConfig.isCalendarEnabled());
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 10; i++) {
Date begin = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end = cal.getTime();
KalendarEvent event = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test " + i, begin, end);
calendarManager.addEventTo(calendarWrapper.getKalendar(), event);
cal.add(Calendar.DATE, 1);
}
cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
Date begin2 = cal.getTime();
cal.add(Calendar.HOUR_OF_DAY, 1);
Date end2 = cal.getTime();
KalendarEvent event2 = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test 2", begin2, end2);
calendarManager.addEventTo(calendarWrapper.getKalendar(), event2);
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course1, false);
entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
repositoryService.addRole(id1, entry, GroupRoles.participant.name());
dbInstance.commit();
}
if (course2 == null) {
// create a course with a calendar
CourseConfigVO config = new CourseConfigVO();
config.setCalendar(Boolean.TRUE);
course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
dbInstance.commit();
KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
Assert.assertNotNull(calendarWrapper);
RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
dbInstance.commit();
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CourseCalendarPeekViewController method init.
private void init(UserRequest ureq, CalCourseNode courseNode, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
CourseCalendars myCal = CourseCalendars.createCourseCalendarsWrapper(ureq, getWindowControl(), courseEnv, ne);
Date refDate;
ModuleConfiguration config = courseNode.getModuleConfiguration();
if (CalEditController.getAutoDate(config)) {
refDate = new Date();
} else {
refDate = CalEditController.getStartDate(config);
if (refDate == null)
refDate = new Date();
}
List<KalendarEvent> nextEvents = new ArrayList<KalendarEvent>();
for (KalendarRenderWrapper calendar : myCal.getCalendars()) {
Kalendar cal = calendar.getKalendar();
Collection<KalendarEvent> events = cal.getEvents();
for (KalendarEvent event : events) {
if (refDate.compareTo(event.getBegin()) <= 0) {
nextEvents.add(event);
}
}
}
Collections.sort(nextEvents, new KalendarEventComparator());
List<KalendarEvent> nextThreeEvents = nextEvents.subList(0, Math.min(3, nextEvents.size()));
TableGuiConfiguration tableConfig = new TableGuiConfiguration();
tableConfig.setTableEmptyMessage(translate("calendar.noEvents"));
tableConfig.setDisplayTableHeader(false);
tableConfig.setCustomCssClass("o_portlet_table");
tableConfig.setDisplayRowCount(false);
tableConfig.setPageingEnabled(false);
tableConfig.setDownloadOffered(false);
tableConfig.setSortingEnabled(false);
removeAsListenerAndDispose(tableController);
tableController = new TableController(tableConfig, ureq, getWindowControl(), getTranslator());
listenTo(tableController);
// dummy header key, won't be used since setDisplayTableHeader is set to
// false
tableController.addColumnDescriptor(new DefaultColumnDescriptor("calendar.date", 0, null, ureq.getLocale()));
tableController.addColumnDescriptor(new DefaultColumnDescriptor("calendar.subject", 1, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT));
tableController.setTableDataModel(new CourseCalendarPeekViewModel(nextThreeEvents, getTranslator()));
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class PortletDateColumnDescriptor method renderValue.
/**
* Render different for all-day events and none all-day events like e.g. :
* Today all day - 31.03.10
* Today 18:00 - 19:00
* 30.03.10 all day
* 30.03.10 - 31.03.10 all day
* 30.03.10 07:00 - 08:00
* @see org.olat.core.gui.components.table.DefaultColumnDescriptor#renderValue(org.olat.core.gui.render.StringOutput, int, org.olat.core.gui.render.Renderer)
*/
@Override
public void renderValue(StringOutput sb, int row, Renderer renderer) {
Object val = getModelData(row);
if (val instanceof KalendarEvent) {
KalendarEvent event = (KalendarEvent) val;
if (event.isToday() && event.isAllDayEvent()) {
sb.append(translator.translate("calendar.today.all.day"));
} else if (event.isToday()) {
sb.append(translator.translate("calendar.title") + " " + timeFormat.format(event.getBegin()) + " - " + timeFormat.format(event.getEnd()));
} else if (event.isAllDayEvent()) {
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DATE, 1);
if (event.getBegin().before(new Date())) {
sb.append(translator.translate("calendar.today.all.day"));
if (event.getEnd().after(tomorrow.getTime())) {
sb.append(" - ");
sb.append(dateOnlyFormat.format(event.getEnd()));
}
} else {
sb.append(dateOnlyFormat.format(event.getBegin()));
if (event.getEnd().after(tomorrow.getTime())) {
sb.append(" - ");
sb.append(dateOnlyFormat.format(event.getEnd()));
}
sb.append(" ");
sb.append(translator.translate("calendar.tomorrow.all.day"));
}
} else if (event.isWithinOneDay()) {
sb.append(dateOnlyFormat.format(event.getBegin()) + " " + timeFormat.format(event.getBegin()) + " - " + timeFormat.format(event.getEnd()));
} else {
sb.append(dateFormat.format(event.getBegin()) + " - " + dateFormat.format(event.getEnd()));
}
} else {
sb.append(val.toString());
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class PortletDateColumnDescriptor method compareTo.
@Override
public int compareTo(int rowa, int rowb) {
Object a = table.getTableDataModel().getValueAt(rowa, dataColumn);
Object b = table.getTableDataModel().getValueAt(rowb, dataColumn);
if ((a instanceof KalendarEvent) && (b instanceof KalendarEvent)) {
Date begin0 = ((KalendarEvent) a).getBegin();
Date begin1 = ((KalendarEvent) b).getBegin();
return begin0.compareTo(begin1);
}
return 0;
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManagerTest method testListEventsForPeriod.
@Test
public void testListEventsForPeriod() {
final int numEvents = 10000;
// maximum of 14 days duration
final int maxEventDuratio = 1000 * 60 * 60 * 24 * 14;
final int oneYearSec = 60 * 60 * 24 * 365;
final int goBackNumYears = 1;
final long kalendarStart = new Date().getTime() - (((long) goBackNumYears * oneYearSec) * 1000);
Identity test = JunitTestHelper.createAndPersistIdentityAsUser("test");
Kalendar kalendar = new Kalendar("test", CalendarManager.TYPE_USER);
log.info("*** Starting test with the following configuration:");
log.info("*** Number of events: " + numEvents);
log.info("*** Maximum event duration (ms): " + maxEventDuratio);
log.info("*** Generate events in between " + new Date(kalendarStart) + " and " + new Date(kalendarStart + (1000 * ((long) goBackNumYears * oneYearSec))));
Random rand = new Random();
long startUsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
for (int i = 0; i < numEvents; i++) {
long begin = kalendarStart + (1000 * ((long) rand.nextInt(goBackNumYears * oneYearSec)));
String eventId = "id" + i;
KalendarEvent event = new KalendarEvent(eventId, "test" + i, new Date(begin), rand.nextInt(maxEventDuratio));
kalendar.addEvent(event);
}
long stopUsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
log.info("*** SETUP: Kalendar structure uses approx. " + (stopUsed - startUsed) / 1024 + " kb memory.");
calendarManager.persistCalendar(kalendar);
log.info("*** Load calendar...");
long start = System.currentTimeMillis();
calendarManager.getPersonalCalendar(test).getKalendar();
long stop = System.currentTimeMillis();
log.info("Duration load: " + (stop - start) + " ms.");
log.info("*** Find events within period...");
start = System.currentTimeMillis();
List<KalendarEvent> events = calendarManager.getEvents(kalendar, new Date(kalendarStart), new Date(kalendarStart + (1000 * ((long) (goBackNumYears * oneYearSec)))), true);
stop = System.currentTimeMillis();
log.info("Duration find: " + (stop - start) + " ms.");
log.info("Found " + events.size() + " events out of " + kalendar.getEvents().size() + " total events.");
assertEquals(kalendar.getEvents().size(), events.size());
log.info("*** Save calendar...");
start = System.currentTimeMillis();
calendarManager.persistCalendar(kalendar);
stop = System.currentTimeMillis();
log.info("Duration save: " + (stop - start) + " ms.");
}
Aggregations