Package org.olat.commons.calendar.model

Examples of org.olat.commons.calendar.model.Kalendar


      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);
        }
      }
View Full Code Here


   */
  public DENStatus doEnroll(final Identity identity, final KalendarEvent event, final OLATResourceable ores, final DENCourseNode courseNode,
      final boolean allowOverfill) {
    final DENStatus status = new DENStatus();
    ICourse course = CourseFactory.loadCourse(ores);
    final Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    OLATResourceable calRes = calManager.getOresHelperFor(cal);
    CoordinatorManager.getCoordinator().getSyncer().doInSync(calRes, new SyncerExecutor() {
      public void execute() {
        boolean error = false;
        Collection<KalendarEvent> collEvents = cal.getEvents();
        // check if date is already full
        if (!allowOverfill && isDateFull(event)) {
          status.setEnrolled(false);
          status.setErrorMessage(DENStatus.ERROR_FULL);
          error = true;
View Full Code Here

   * @return status
   */
  public DENStatus cancelEnroll(Identity identity, KalendarEvent event, OLATResourceable ores, DENCourseNode courseNode) {
    DENStatus status = new DENStatus();
    ICourse course = CourseFactory.loadCourse(ores);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    Collection<KalendarEvent> collEvents = cal.getEvents();
    //check if identity is enrolled
    if( !isEnrolledInDate(identity, event) ) {
      status.setCancelled(false);
      status.setErrorMessage(DENStatus.ERROR_NOT_ENROLLED);
    }
    //cancel enroll in calendar entry
    if(event.getParticipants() != null) {
      int currLength = event.getParticipants().length;
      if (currLength > 1) {
        //more than one are enrolled
        String[] partsNew = new String[currLength - 1]; //one to delete
        String[] partsOld = event.getParticipants();
        String identityName = identity.getName();
        for (int i = 0, j = 0; i < partsOld.length; i++) {
          if ( !(partsOld[i].equals(identityName)) ) {
            partsNew[j] = partsOld[i];
            j++; //only increment if new entry was made
          }
        }
        event.setParticipants(partsNew);
      } else if (currLength == 1) {
        //only one is enrolled, only simple reset needed
        event.setParticipants(new String[0]);
      }
      //save calendar event
      boolean successfullyDone = calManager.updateEventFrom(cal, event);
      if (!successfullyDone) {
        status.setCancelled(false);
        status.setErrorMessage(DENStatus.ERROR_PERSISTING);
        return status;
      }
    } else {
      //no one to cancel
      status.setCancelled(false);
      status.setErrorMessage(DENStatus.ERROR_GENERAL);
      return status;
    }
    status.setCancelled(true);
    //delete date from the users calendar
    Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
    Collection<KalendarEvent> userEvents = userCal.getEvents();
    String sourceNodeId = event.getSourceNodeId();
    for( KalendarEvent userEvent : userEvents) {
      String eventSourceNodeId = userEvent.getSourceNodeId();
      if(eventSourceNodeId != null && eventSourceNodeId.equals(sourceNodeId)) {
        calManager.removeEventFrom(userCal, userEvent);
View Full Code Here

   * @param course
   * @param denNode
   */
  public void persistDENSettings(List<KalendarEvent> lstEvents, OLATResourceable ores, DENCourseNode denNode) {
    ICourse course = CourseFactory.loadCourse(ores);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    String sourceNode = denNode.getIdent();
    //remove deleted events
    Collection<KalendarEvent> allEvents = new ArrayList<KalendarEvent>(cal.getEvents());
    for( KalendarEvent event : allEvents) {
      if(event.getSourceNodeId() != null) {
        if ( event.getSourceNodeId().equals(sourceNode) && !lstEvents.contains(event) ) {
          removeDateInUserCalendar(event);
          calManager.removeEventFrom(cal, event);
        }
      }
    }

    for( KalendarEvent newEvent : lstEvents ) {
      createKalendarEventLinks(course, denNode, newEvent);
      KalendarEvent oldEvent = cal.getEvent(newEvent.getID());
      //new event?
      if (oldEvent != null) {
        //event is already in the calendar so first remove it
        calManager.removeEventFrom(cal, oldEvent);
      }
View Full Code Here

   * @return List of all KalendarEvent in this date enrollment
   */
  protected List<KalendarEvent> getDENEvents(Long courseId, String sourceNodeId) {
    List<KalendarEvent> denEvents = new ArrayList<KalendarEvent>();
    ICourse course = CourseFactory.loadCourse(courseId);
    Kalendar cal = calManager.getCourseCalendar(course).getKalendar();
    Collection<KalendarEvent> colEvents = cal.getEvents();
    for( KalendarEvent event : colEvents) {
      String eventSourceNodeId = event.getSourceNodeId();
      if(eventSourceNodeId != null) {
        if(eventSourceNodeId.equals(sourceNodeId))
          denEvents.add(event);
View Full Code Here

    String[] participants = newEvent.getParticipants();
    if(participants == null) return;//no users to update, cancel
    Manager manager = ManagerFactory.getManager();
    for( String participant : participants ) {
      Identity identity = manager.findIdentityByName(participant);
      Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
      Collection<KalendarEvent> userEvents = new ArrayList<KalendarEvent>();
      userEvents.addAll(userCal.getEvents());
      KalendarEvent userNewEvent = new KalendarEvent(CodeHelper.getGlobalForeverUniqueID(), newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
      userNewEvent.setLocation(newEvent.getLocation());
      userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
      userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
      List kalendarEventLinks = userNewEvent.getKalendarEventLinks();
View Full Code Here

    String[] participants = oldEvent.getParticipants();
    if(participants == null) return;//no users to update, cancel
    Manager manager = ManagerFactory.getManager();
    for( String participant : participants ) {
      Identity identity = manager.findIdentityByName(participant);
      Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
      Collection<KalendarEvent> userEvents = new ArrayList<KalendarEvent>();
      userEvents.addAll(userCal.getEvents());
      for( KalendarEvent userEvent : userEvents ) {
        String sourceNodeId = userEvent.getSourceNodeId();
        if(sourceNodeId != null && sourceNodeId.equals(oldEvent.getSourceNodeId())) {
          calManager.removeEventFrom(userCal, userEvent);
        }
View Full Code Here

  }
 
  public void testAddChangeRemoveEvent() {
    String TEST_EVENT_ID = "id-testAddEvent";
    CalendarManager manager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
    Kalendar cal = manager.getPersonalCalendar(test).getKalendar();
    // 1. Test Add Event
    KalendarEvent testEvent = new KalendarEvent(TEST_EVENT_ID,"testEvent", new Date(), 1);
    manager.addEventTo(cal, testEvent);
    // set manager null to force reload of calendar from file-system
    manager = null;
    manager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
    cal = manager.getPersonalCalendar(test).getKalendar();
    KalendarEvent reloadedEvent = cal.getEvent(TEST_EVENT_ID);
    assertNotNull("Could not found added event", reloadedEvent);
    assertEquals("Added event has wrong subject", testEvent.getSubject(),reloadedEvent.getSubject());
    // 2. Test Change event
    reloadedEvent.setSubject("testEvent changed");
    manager.updateEventFrom(cal, reloadedEvent);
    // set manager null to force reload of calendar from file-system
    manager = null;
    manager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
    cal = manager.getPersonalCalendar(test).getKalendar();
    KalendarEvent updatedEvent = cal.getEvent(TEST_EVENT_ID);
    assertNotNull("Could not found updated event", updatedEvent);
    assertEquals("Added event has wrong subject", reloadedEvent.getSubject(),updatedEvent.getSubject());
    // 3. Test Remove event
    manager.removeEventFrom(cal, updatedEvent);
    manager = null;
    manager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
    cal = manager.getPersonalCalendar(test).getKalendar();
    KalendarEvent removedEvent = cal.getEvent(TEST_EVENT_ID);
    assertNull("Found removed event", removedEvent);
  }
View Full Code Here

    new Thread(new Runnable() {
      public void run() {
        try {
          // 1. load calendar
          CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
          Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
         
          // 2. add Event1 => breakpoint hit         
          System.out.println("testConcurrentAddEvent thread1 addEvent1");
          calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_1,TEST_EVENT_SUBJECT_1, new Date(), 1));
          System.out.println("testConcurrentAddEvent thread1 addEvent1 DONE");
          // 3. check event1 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          // 4. sleep 2sec
         
          // 5. check event1 still exist (event2 added in meantime)
          cal = calManager.getPersonalCalendar(test).getKalendar();
          event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          statusList.add(Boolean.TRUE);
          System.out.println("testConcurrentAddEvent thread1 finished");
        } catch (Exception ex) {
          exceptionHolder.add(ex);// no exception should happen
        }
      }}).start();
   
    // thread 2
    new Thread(new Runnable() {
      public void run() {
        try {
          // 1. load calendar
          CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
          Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
          // 2. sleep 1sec
          sleep(1000);
          // 3. add Event2 (breakpoint of thread1 blocks)
          System.out.println("testConcurrentAddEvent thread2 addEvent2");
          calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2, new Date(), 1));
          System.out.println("testConcurrentAddEvent thread1 addEvent2 DONE");
          // 4. check event2 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent event2 = cal.getEvent(TEST_EVENT_ID_2);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_2, event2);
          assertEquals("Wrong calendar-event subject",event2.getSubject(), TEST_EVENT_SUBJECT_2);
          // 5. check event1 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          statusList.add(Boolean.TRUE);
          System.out.println("testConcurrentAddEvent thread2 finished");
        } catch (Exception ex) {
View Full Code Here

    final List<Exception> exceptionHolder = Collections.synchronizedList(new ArrayList<Exception>(1));
    final List<Boolean> statusList = Collections.synchronizedList(new ArrayList<Boolean>(1));

    // Generate event for update
    CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
    Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
    calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2, new Date(), 1));
    cal = calManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent event2 = cal.getEvent(TEST_EVENT_ID_2);
    assertNotNull("Did not found event with id=" + TEST_EVENT_ID_2, event2);
    assertEquals("Wrong calendar-event subject",event2.getSubject(), TEST_EVENT_SUBJECT_2);
    System.out.println("testConcurrentAddUpdateEvent thread2 addEvent2 DONE");

    // enable breakpoint
    CodepointClient codepointClient = null;
    CodepointRef codepointRef = null;
    try {
      codepointClient = CodepointClientFactory.createCodepointClient("vm://localhost?broker.persistent=false", CODEPOINT_SERVER_ID);
      codepointRef = codepointClient.getCodepoint("org.olat.commons.coordinate.cluster.ClusterSyncer.doInSync-in-sync.org.olat.commons.calendar.ICalFileCalendarManager.addEventTo");
      codepointRef.enableBreakpoint();
      System.out.println();
    } catch (Exception e) {
      e.printStackTrace();
      fail("Could not initialzed CodepointClient");
    }

    // thread 1
    new Thread(new Runnable() {
      public void run() {
        try {
          // 1. load calendar
          CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
          Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
         
          // 2. add Event1 => breakpoint hit         
          System.out.println("testConcurrentAddUpdateEvent thread1 addEvent1");
          calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_1,TEST_EVENT_SUBJECT_1, new Date(), 1));
          System.out.println("testConcurrentAddUpdateEvent thread1 addEvent1 DONE");
          // 3. check event1 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          // 4. sleep 2sec
         
          // 5. check event1 still exist (event2 added in meantime)
          cal = calManager.getPersonalCalendar(test).getKalendar();
          event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          statusList.add(Boolean.TRUE);
          System.out.println("testConcurrentAddUpdateEvent thread1 finished");
        } catch (Exception ex) {
          exceptionHolder.add(ex);// no exception should happen
        }
      }}).start();
   
    // thread 2
    new Thread(new Runnable() {
      public void run() {
        try {
          CalendarManager calManager = CalendarManagerFactory.getJUnitInstance().getCalendarManager();
          Kalendar cal = calManager.getPersonalCalendar(test).getKalendar();
          // 2. sleep 1sec
          sleep(1000);
          // 3. add Event2 (breakpoint of thread1 blocks)
          System.out.println("testConcurrentAddUpdateEvent thread2 updateEvent2");
          calManager.updateEventFrom(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2_UPDATED, new Date(), 1));
          System.out.println("testConcurrentAddUpdateEvent thread1 updateEvent2 DONE");
          // 4. check event2 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent updatedEvent = cal.getEvent(TEST_EVENT_ID_2);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_2, updatedEvent);
          assertEquals("Wrong calendar-event subject",updatedEvent.getSubject(), TEST_EVENT_SUBJECT_2_UPDATED);
          // 5. check event1 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent event1 = cal.getEvent(TEST_EVENT_ID_1);
          assertNotNull("Did not found event with id=" + TEST_EVENT_ID_1, event1);
          assertEquals("Wrong calendar-event subject",event1.getSubject(), TEST_EVENT_SUBJECT_1);
          // Delete Event
          boolean removed = calManager.removeEventFrom(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2_UPDATED, new Date(), 1));
          assertTrue(removed);
View Full Code Here

TOP

Related Classes of org.olat.commons.calendar.model.Kalendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.