/**
   * Attempt to process all the queued digest requests. Ones that cannot be processed now will be
   * returned to the queue.
   */
  protected void processQueue() {
    M_log.debug("Processing mail digest queue...");

    // setup a re-try queue
    List retry = new Vector();

    // grab the queue - any new stuff will be processed next time
    List queue = new Vector();
    synchronized (m_digestQueue) {
      queue.addAll(m_digestQueue);
      m_digestQueue.clear();
    }

    for (Iterator iQueue = queue.iterator(); iQueue.hasNext(); ) {
      DigestMessage message = (DigestMessage) iQueue.next();
      try {
        DigestEdit edit = edit(message.getTo());
        edit.add(message);
        commit(edit);
        // %%% could do this by pulling all for id from the queue in one commit -ggolden
      } catch (InUseException e) {
        M_log.warn("digest in use, will try send again at next digest attempt: " + e.getMessage());
        // retry next time
        retry.add(message);
      }
    }

    // requeue the retrys
    if (retry.size() > 0) {
      synchronized (m_digestQueue) {
        m_digestQueue.addAll(retry);
      }
    }
  }
예제 #2
0
  @Override
  public void setDefaultPrivacyState(String userId, String visibility) {
    if (userId == null) {
      log.warn("Cannot set priavacy status for a null userId");
      return;
    }

    if (visibility == null) {
      visibility = PrivacyManager.VISIBLE;
    }

    PreferencesEdit editPref;
    try {
      editPref = preferencesService.edit(userId);

      ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS);
      props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility);

      preferencesService.commit(editPref);
    } catch (PermissionException e) {
      log.warn(
          "You do not have the appropriate permissions to edit preferences for user: "******". "
              + e.getMessage());
    } catch (InUseException e) {
      log.warn(
          "Preferences for user: "******" are currently being edited. " + e.getMessage());
    } catch (IdUnusedException e) {
      try {
        editPref = preferencesService.add(userId);

        ResourcePropertiesEdit props = editPref.getPropertiesEdit(PRIVACY_PREFS);
        props.addProperty(PrivacyManager.DEFAULT_PRIVACY_KEY, visibility);

        preferencesService.commit(editPref);
      } catch (PermissionException e1) {
        // TODO Auto-generated catch block
        log.warn(
            "You do not have the appropriate permissions to edit preferences for user: "******". "
                + e1.getMessage());
      } catch (IdUsedException e1) {
        log.warn(
            "No preferences for user: "******" found intially, attempted to add new preferences. "
                + e1.getMessage());
      }
    }
  }
 public boolean updateScore(String submissionId) {
   boolean saved = false;
   SecurityAdvisor sa =
       new SecurityAdvisor() {
         public SecurityAdvice isAllowed(String userId, String function, String reference) {
           if (AssignmentService.SECURE_GRADE_ASSIGNMENT_SUBMISSION.equals(function)
               || AssignmentService.SECURE_UPDATE_ASSIGNMENT.equals(function)
               || AssignmentService.SECURE_ACCESS_ASSIGNMENT.equals(function)
               || AssignmentService.SECURE_ACCESS_ASSIGNMENT_SUBMISSION.equals(function)) {
             return SecurityAdvice.ALLOWED;
           } else {
             return SecurityAdvice.PASS;
           }
         }
       };
   try {
     securityService.pushAdvisor(sa);
     // first check that submission exists and that it can be graded/override score
     AssignmentSubmission submission = assignmentService.getSubmission(submissionId);
     // only override grades that have never been graded or was last graded by this service
     // this prevents this service from overriding instructor set grades, which take precedent.
     if (submission != null
         && (submission.getGraded() == false
             || submission.getGradedBy() == null
             || "".equals(submission.getGradedBy().trim())
             || AssignmentPeerAssessmentService.class
                 .getName()
                 .equals(submission.getGradedBy().trim()))) {
       List<PeerAssessmentItem> items =
           getPeerAssessmentItems(
               submissionId, submission.getAssignment().getContent().getFactor());
       if (items != null) {
         // scores are stored w/o decimal points, so a score of 3.4 is stored as 34 in the DB
         // add all the scores together and divide it by the number of scores added.  Then round.
         Integer totalScore = 0;
         int denominator = 0;
         for (PeerAssessmentItem item : items) {
           if (!item.isRemoved() && item.getScore() != null) {
             totalScore += item.getScore();
             denominator++;
           }
         }
         if (denominator > 0) {
           totalScore = Math.round(totalScore / denominator);
         } else {
           totalScore = null;
         }
         String totleScoreStr = null;
         if (totalScore != null) {
           totleScoreStr = totalScore.toString();
         }
         boolean changed = false;
         if ((totleScoreStr == null || "".equals(totleScoreStr))
             && (submission.getGrade() == null || "".equals(submission.getGrade()))) {
           // scores are both null, nothing changed
         } else if ((totleScoreStr != null && !"".equals(totleScoreStr))
             && (submission.getGrade() == null || "".equals(submission.getGrade()))) {
           // one score changed, update
           changed = true;
         } else if ((totleScoreStr == null || "".equals(totleScoreStr))
             && (submission.getGrade() != null && !"".equals(submission.getGrade()))) {
           // one score changed, update
           changed = true;
         } else if (!totleScoreStr.equals(submission.getGrade())) {
           changed = true;
         }
         if (changed) {
           AssignmentSubmissionEdit edit = assignmentService.editSubmission(submissionId);
           edit.setGrade(totleScoreStr);
           edit.setGraded(true);
           edit.setGradedBy(AssignmentPeerAssessmentService.class.getName());
           edit.setGradeReleased(false);
           assignmentService.commitEdit(edit);
           saved = true;
         }
       }
     }
   } catch (IdUnusedException e) {
     log.error(e.getMessage(), e);
   } catch (InUseException e) {
     log.error(e.getMessage(), e);
   } catch (PermissionException e) {
     log.error(e.getMessage(), e);
   } finally {
     // remove advisor
     if (sa != null) {
       securityService.popAdvisor(sa);
     }
   }
   return saved;
 }