Package org.olat.commons.calendar.model

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


    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("testConcurrentAddRemoveEvent 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 CoepointClient");
    }

    // 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("testConcurrentAddRemoveEvent thread1 addEvent1");
          calManager.addEventTo(cal, new KalendarEvent(TEST_EVENT_ID_1,TEST_EVENT_SUBJECT_1, new Date(), 1));
          System.out.println("testConcurrentAddRemoveEvent 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("testConcurrentAddRemoveEvent 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("testConcurrentAddRemoveEvent thread2 removeEvent2");
          boolean removed = calManager.removeEventFrom(cal, new KalendarEvent(TEST_EVENT_ID_2,TEST_EVENT_SUBJECT_2, new Date(), 1));
          assertTrue(removed);
          System.out.println("testConcurrentAddRemoveEvent thread1 removeEvent2 DONE");
          // 4. check event2 exist
          cal = calManager.getPersonalCalendar(test).getKalendar();
          KalendarEvent updatedEvent = cal.getEvent(TEST_EVENT_ID_2);
          assertNull("Still found deleted event with id=" + TEST_EVENT_ID_2, updatedEvent);
          // 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("testConcurrentAddRemoveEvent thread2 finished");
        } catch (Exception ex) {
View Full Code Here


    super.setUp();
    if (CalendarUtilsTest.isInitialized  == false) {
      DBFactory.getJunitInstance().clearDatabase();
      test = ManagerFactory.getManager().createAndPersistIdentity("test", null, OLATAuthenticationController.PROVIDER_OLAT, "test",
          Encoder.encrypt("test"));
      kalendar = new Kalendar("test", CalendarManager.TYPE_USER);
      CalendarUtilsTest.isInitialized  = true;
    }
  }
View Full Code Here

      }
    }
  }

  public void event(UserRequest ureq, Controller source, Event event) {
    Kalendar affectedCal = null;
    if (dirty) {
      dirty = false;
      fireEvent(ureq, new KalendarModifiedEvent());
    }
    if (source == editController) {
      affectedCal = editController.getKalendarEvent().getCalendar();
      cmc.deactivate();
      weeklyCalendar.setDirty(true);
    } else if(source == cmc && event == CloseableModalController.CLOSE_MODAL_EVENT){
      //DO NOT DEACTIVATE AS ALREADY CLOSED BY CloseableModalController INTERNALLY
      weeklyCalendar.setDirty(true);
    } else if (source == calendarConfig || source == importedCalendarConfig) {
      if (event instanceof KalendarGUIAddEvent) {
        pushAddEventController((KalendarGUIAddEvent)event, ureq);
      } else if (event == Event.CHANGED_EVENT) {
        importedCalendarWrappers = ImportCalendarManager.getImportedCalendarsForIdentity(ureq);
        importedCalendarConfig.setCalendars(importedCalendarWrappers);
        this.setCalendars(calendarWrappers, importedCalendarWrappers);
        weeklyCalendar.setDirty(true);
        vcMain.setDirty(true);
      }
    } else if (source == searchController) {
      if (event instanceof GotoDateEvent) {
        Date gotoDate = ((GotoDateEvent)event).getGotoDate();
        weeklyCalendar.setDate(gotoDate);
      }
      cmc.deactivate();
    } else if (source == subscriptionController) {
      // nothing to do here
      mainPanel.setContent(vcMain);
      vcMain.contextPut("isSubscribed", new Boolean(calendarSubscription.isSubscribed()));
    } else if (source == gotoDateForm) {
      weeklyCalendar.setDate(gotoDateForm.getGotoDate());
    } else if (source == dbcSequence) {
      if(event != Event.CANCELLED_EVENT) {
        int pos = DialogBoxUIFactory.getButtonPos(event);
        KalendarGUIEditEvent guiEvent = (KalendarGUIEditEvent)dbcSequence.getUserObject();
        KalendarRenderWrapper kalendarWrapper = guiEvent.getKalendarRenderWrapper();
        KalendarEvent kalendarEvent = guiEvent.getKalendarEvent();
        if(pos == 0) { // edit the sequence
          // load the parent event of this sequence
          KalendarEvent parentEvent = kalendarWrapper.getKalendar().getEvent(kalendarEvent.getID());
          pushEditEventController(ureq, parentEvent, kalendarWrapper);
        } else if(pos == 1) { // delete a single event of the sequence
          deleteSingleYesNoController = activateYesNoDialog(ureq, null, translator.translate("cal.delete.dialogtext"), deleteSingleYesNoController);
          deleteSingleYesNoController.setUserObject(kalendarEvent);
        } else if(pos == 2) { // delete the whole sequence
          deleteSequenceYesNoController = activateYesNoDialog(ureq, null, translator.translate("cal.delete.dialogtext.sequence"), deleteSequenceYesNoController);
          deleteSequenceYesNoController.setUserObject(kalendarEvent);
        }
      }
      dbcSequence.dispose();
    } else if (source == deleteSingleYesNoController) {
      if (DialogBoxUIFactory.isYesEvent(event)) {
        KalendarEvent kalendarEvent = (KalendarEvent)deleteSingleYesNoController.getUserObject();
        affectedCal = kalendarEvent.getCalendar();
        KalendarEvent kEvent = affectedCal.getEvent(kalendarEvent.getID());
        kEvent.addRecurrenceExc(kalendarEvent.getBegin());
        CalendarManagerFactory.getInstance().getCalendarManager().updateEventFrom(affectedCal, kEvent);
        deleteSingleYesNoController.dispose();
        weeklyCalendar.setDirty(true);
        vcMain.setDirty(true);
View Full Code Here

          // this is a new event, add event to calendar
          String calendarID = eventForm.getChoosenKalendarID();
          for (Iterator iter = availableCalendars.iterator(); iter.hasNext();) {
            KalendarRenderWrapper calendarWrapper = (KalendarRenderWrapper) iter.next();
            if (!calendarWrapper.getKalendar().getCalendarID().equals(calendarID)) continue;
            Kalendar cal = calendarWrapper.getKalendar();
            boolean result = CalendarManagerFactory.getInstance().getCalendarManager().addEventTo(cal, kalendarEvent);
            if (result==false) {
              // if one failed => done not successfully
              doneSuccessfully = false;
            }
          }
        } else {
          // this is an existing event, so we get the previousely assigned calendar from the event
          Kalendar cal = kalendarEvent.getCalendar();
          doneSuccessfully =CalendarManagerFactory.getInstance().getCalendarManager().updateEventFrom(cal, kalendarEvent);
        }
        // check if event is still available
        if (!doneSuccessfully) {
          showError("cal.error.save");
View Full Code Here

  }

  public void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteYesNoController) {
      if (DialogBoxUIFactory.isYesEvent(event)) {
        Kalendar cal = kalendarEvent.getCalendar();
        CalendarManagerFactory.getInstance().getCalendarManager().removeEventFrom(cal,kalendarEvent);
        fireEvent(ureq, Event.DONE_EVENT);
      }
    } else if (source == copyEventToCalendarController) {
      if (event.equals(Event.DONE_EVENT))
View Full Code Here

        CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
        for (Iterator iter = selectedNodesIDS.iterator(); iter.hasNext();) {
          String nodeId = (String)iter.next();
          GenericTreeNode node = (GenericTreeNode)model.getNodeById(nodeId);
          KalendarRenderWrapper calendarWrapper = (KalendarRenderWrapper)node.getUserObject();
          Kalendar cal = calendarWrapper.getKalendar();
          KalendarEvent clonedKalendarEvent = (KalendarEvent)XStreamHelper.xstreamClone(kalendarEvent);
          if (clonedKalendarEvent.getKalendarEventLinks().size() != 0)
            clonedKalendarEvent.setKalendarEventLinks(new ArrayList());
          calendarManager.addEventTo(cal, clonedKalendarEvent);
//          calendarManager.persistCalendar(cal);     
View Full Code Here

  /**
   *
   * @see org.olat.calendar.CalendarManager#createClaendar(java.lang.String)
   */
  public Kalendar createCalendar(String type, String calendarID) {
    return new Kalendar(calendarID, type);
  }
View Full Code Here

  public Kalendar getCalendar(String type, String calendarID) {
    //o_clusterOK by:cg
    OLATResourceable calOres = OresHelper.createOLATResourceableType(getKeyFor(type,calendarID));
    final String callType = type;
    final String callCalendarID = calendarID;
    Kalendar cal = CoordinatorManager.getCoordinator().getSyncer().doInSync( calOres, new SyncerCallback<Kalendar>() {
      public Kalendar execute() {
        return getCalendarFromCache(callType, callCalendarID);
      }
    });
    return cal;
View Full Code Here

  protected Kalendar getCalendarFromCache(final String callType, final String callCalendarID) {
    OLATResourceable calOres = OresHelper.createOLATResourceableType(getKeyFor(callType,callCalendarID));   
    CoordinatorManager.getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
   
    String key = getKeyFor(callType,callCalendarID);
    Kalendar cal = (Kalendar)calendarCache.get(key);
    if (cal == null) {
      cal = loadOrCreateCalendar(callType, callCalendarID);
      calendarCache.put(key, cal);
    }
    return cal;
View Full Code Here

   * Internal load calendar file from filesystem.
   */
  // o_clusterOK by:cg This must not be synchronized because the caller already synchronized
  private Kalendar loadCalendarFromFile(String type, String calendarID) {
    Calendar calendar = readCalendar(type, calendarID);
    Kalendar kalendar = createKalendar(type, calendarID, calendar);
    return kalendar;
  }
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.