/**
   * Index a forum in a group.
   *
   * @param parentResourceContext
   * @param businessGroup
   * @param indexWriter
   * @throws IOException
   */
  @Override
  public void doIndex(
      final SearchResourceContext parentResourceContext,
      final Object businessObj,
      final OlatFullIndexer indexWriter)
      throws IOException, InterruptedException {
    if (!(businessObj instanceof BusinessGroup)) {
      throw new AssertException("businessObj must be BusinessGroup");
    }
    final BusinessGroup businessGroup = (BusinessGroup) businessObj;

    final NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    final ForumManager fom = ForumManager.getInstance();

    final Property forumKeyProperty =
        npm.findProperty(
            null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
      final Long forumKey = forumKeyProperty.getLongValue();
      final Forum forum = fom.loadForum(forumKey);
      final SearchResourceContext forumSearchResourceContext =
          new SearchResourceContext(parentResourceContext);
      forumSearchResourceContext.setBusinessControlFor(
          BusinessGroupMainRunController.ORES_TOOLFORUM);
      forumSearchResourceContext.setDocumentType(TYPE);
      forumSearchResourceContext.setDocumentContext(businessGroup.getKey() + " " + forumKey);
      forumSearchResourceContext.setParentContextType(GroupDocument.TYPE);
      forumSearchResourceContext.setParentContextName(businessGroup.getName());
      doIndexAllMessages(forumSearchResourceContext, forum, indexWriter);
    }
  }
  /**
   * Index a forum in a group.
   *
   * @param parentResourceContext
   * @param businessGroup
   * @param indexWriter
   * @throws IOException
   */
  public void doIndex(
      SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter)
      throws IOException, InterruptedException {
    if (!(businessObj instanceof BusinessGroup))
      throw new AssertException("businessObj must be BusinessGroup");
    BusinessGroup businessGroup = (BusinessGroup) businessObj;

    NarrowedPropertyManager npm = NarrowedPropertyManager.getInstance(businessGroup);
    ForumManager fom = ForumManager.getInstance();

    Property forumKeyProperty =
        npm.findProperty(
            null, null, CollaborationTools.PROP_CAT_BG_COLLABTOOLS, CollaborationTools.KEY_FORUM);
    // Check if forum-property exist
    if (forumKeyProperty != null) {
      Long forumKey = forumKeyProperty.getLongValue();
      Forum forum = fom.loadForum(forumKey);
      SearchResourceContext forumSearchResourceContext =
          new SearchResourceContext(parentResourceContext);
      forumSearchResourceContext.setBusinessControlFor(
          BusinessGroupMainRunController.ORES_TOOLFORUM);
      forumSearchResourceContext.setDocumentType(TYPE);
      forumSearchResourceContext.setParentContextType(GroupDocument.TYPE);
      forumSearchResourceContext.setParentContextName(businessGroup.getName());
      if (forum == null) { // fxdiff: FXOLAT-104 warn about missing forums
        logError(
            "found a forum-key "
                + forumKey
                + " for businessgroup "
                + businessGroup.getName()
                + " ["
                + businessGroup.getKey()
                + "] to index a forum that could not be "
                + "found by key! skip indexing, check if forum should still be enabled. context: "
                + forumSearchResourceContext.getResourceUrl(),
            null);
        return;
      }
      doIndexAllMessages(forumSearchResourceContext, forum, indexWriter);
    }
  }
  /**
   * @see
   *     org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
   *     java.util.Locale, java.util.Date)
   */
  public SubscriptionInfo createSubscriptionInfo(
      final Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
      // course don't exist anymore
      NotificationsManager.getInstance().deactivate(p);
      return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }

    try {
      Date latestNews = p.getLatestNewsDate();
      Identity identity = subscriber.getIdentity();

      // do not try to create a subscription info if state is deleted - results in
      // exceptions, course
      // can't be loaded when already deleted
      if (NotificationsManager.getInstance().isPublisherValid(p)
          && compareDate.before(latestNews)) {
        Long courseId = new Long(p.getData());
        final ICourse course = loadCourseFromId(courseId);
        if (course != null) {
          // course admins or users with the course right to have full access to
          // the assessment tool will have full access to user tests
          CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
          final boolean hasFullAccess =
              (cgm.isIdentityCourseAdministrator(identity)
                  ? true
                  : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
          final List<Identity> coachedUsers = new ArrayList<Identity>();
          if (!hasFullAccess) {
            // initialize list of users, only when user has not full access
            List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
            BusinessGroupService businessGroupService =
                CoreSpringFactory.getImpl(BusinessGroupService.class);
            List<Identity> coachedIdentites =
                businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
            coachedUsers.addAll(coachedIdentites);
          }

          List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
          Translator translator =
              Util.createPackageTranslator(AssessmentNotificationsHandler.class, locale);

          for (AssessableCourseNode test : testNodes) {
            final CoursePropertyManager cpm =
                course.getCourseEnvironment().getCoursePropertyManager();

            List<Property> scoreProperties =
                cpm.listCourseNodeProperties(test, null, null, AssessmentManager.SCORE);
            List<Property> attemptProperties =
                cpm.listCourseNodeProperties(test, null, null, AssessmentManager.ATTEMPTS);

            for (Property attemptProperty : attemptProperties) {
              Date modDate = attemptProperty.getLastModified();
              Identity assessedIdentity = attemptProperty.getIdentity();
              if (modDate.after(compareDate)
                  && (hasFullAccess
                      || PersistenceHelper.listContainsObjectByKey(
                          coachedUsers, assessedIdentity))) {
                String score = null;
                for (Property scoreProperty : scoreProperties) {
                  if (scoreProperty.getIdentity().equalsByPersistableKey(assessedIdentity)) {
                    score = scoreProperty.getFloatValue().toString();
                    break;
                  }
                }

                if (test instanceof ScormCourseNode) {
                  ScormCourseNode scormTest = (ScormCourseNode) test;
                  // check if completed or passed
                  String status =
                      ScormAssessmentManager.getInstance()
                          .getLastLessonStatus(
                              assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
                  if (!"passed".equals(status) && !"completed".equals(status)) {
                    continue;
                  }
                }

                String desc;
                String type = translator.translate("notifications.entry." + test.getType());
                if (score == null) {
                  desc =
                      translator.translate(
                          "notifications.entry.attempt",
                          new String[] {
                            test.getShortTitle(),
                            NotificationHelper.getFormatedName(assessedIdentity),
                            type
                          });
                } else {
                  desc =
                      translator.translate(
                          "notifications.entry",
                          new String[] {
                            test.getShortTitle(),
                            NotificationHelper.getFormatedName(assessedIdentity),
                            score,
                            type
                          });
                }

                String urlToSend = null;
                String businessPath = null;
                if (p.getBusinessPath() != null) {
                  businessPath =
                      p.getBusinessPath()
                          + "[assessmentTool:0][Identity:"
                          + assessedIdentity.getKey()
                          + "][CourseNode:"
                          + test.getIdent()
                          + "]";
                  urlToSend =
                      BusinessControlFactory.getInstance()
                          .getURLFromBusinessPathString(businessPath);
                }

                SubscriptionListItem subListItem =
                    new SubscriptionListItem(
                        desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
                if (si == null) {
                  String title =
                      translator.translate(
                          "notifications.header", new String[] {course.getCourseTitle()});
                  String css =
                      CourseNodeFactory.getInstance()
                          .getCourseNodeConfigurationEvenForDisabledBB(test.getType())
                          .getIconCSSClass();
                  si =
                      new SubscriptionInfo(
                          subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
                }
                si.addSubscriptionListItem(subListItem);
              }
            }
          }
        }
      }
      if (si == null) {
        si = NotificationsManager.getInstance().getNoSubscriptionInfo();
      }
      return si;
    } catch (Exception e) {
      log.error("Error while creating assessment notifications", e);
      checkPublisher(p);
      return NotificationsManager.getInstance().getNoSubscriptionInfo();
    }
  }
 /** @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int) */
 @Override
 public final Object getValueAt(final int row, final int col) {
   final Property p = (Property) objects.get(row);
   switch (col) {
     case 0:
       final Identity id = p.getIdentity();
       return ((id != null) ? (p.getIdentity().getName()) : (null));
     case 1:
       return p.getResourceTypeName();
     case 2:
       return p
           .getResourceTypeId(); // may be null; in this case, the table renders nothing for this
       // cell;
     case 3:
       return p.getCategory();
     case 4:
       return p.getName();
     case 5:
       return p.getFloatValue();
     case 6:
       return p.getStringValue();
     case 7:
       return p.getTextValue();
     case 8:
       return p.getCreationDate().toString();
     case 9:
       return p.getLastModified().toString();
     case 10:
       return p.getLongValue();
     default:
       return "error";
   }
 }