public CandidateEvent recordCandidateItemEvent(
      final CandidateSession candidateSession,
      final CandidateItemEventType itemEventType,
      final ItemSessionState itemSessionState,
      final NotificationRecorder notificationRecorder) {
    /* Create event */
    final CandidateEvent event = new CandidateEvent();
    event.setCandidateSession(candidateSession);
    event.setItemEventType(itemEventType);
    event.setTimestamp(requestTimestampContext.getCurrentRequestTimestamp());

    /* Store event */
    candidateEventDao.persist(event);

    /* Save current ItemSessionState */
    storeItemSessionState(event, itemSessionState);

    /* Now store processing notifications */
    if (notificationRecorder != null) {
      for (final Notification notification : notificationRecorder.getNotifications()) {
        recordNotification(event, notification);
      }
    }

    return event;
  }
 public CandidateEvent getMostRecentEvent(final CandidateSession candidateSession) {
   final CandidateEvent mostRecentEvent =
       candidateEventDao.getNewestEventInSession(candidateSession);
   if (mostRecentEvent == null) {
     throw new QtiWorksLogicException(
         "Session has no events registered. Current logic should not have allowed this!");
   }
   return mostRecentEvent;
 }
  public CandidateEvent recordCandidateTestEvent(
      final CandidateSession candidateSession,
      final CandidateTestEventType testEventType,
      final CandidateItemEventType itemEventType,
      final TestPlanNodeKey itemKey,
      final TestSessionState testSessionState,
      final NotificationRecorder notificationRecorder) {
    Assert.notNull(candidateSession, "candidateSession");
    Assert.notNull(testEventType, "testEventType");
    Assert.notNull(testSessionState, "testSessionState");

    /* Create event */
    final CandidateEvent event = new CandidateEvent();
    event.setCandidateSession(candidateSession);
    event.setTestEventType(testEventType);
    event.setItemEventType(itemEventType);
    if (itemKey != null) {
      event.setTestItemKey(itemKey.toString());
    }
    event.setTimestamp(requestTimestampContext.getCurrentRequestTimestamp());

    /* Store event */
    candidateEventDao.persist(event);

    /* Store test session state */
    storeTestSessionState(event, testSessionState);

    /* Now store processing notifications */
    if (notificationRecorder != null) {
      for (final Notification notification : notificationRecorder.getNotifications()) {
        recordNotification(event, notification);
      }
    }

    return event;
  }