Example #1
0
  @WebMethod
  @Path("/undeleteAssignments")
  @Produces("text/plain")
  @GET
  public String undeleteAssignments(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "context", partName = "context") @QueryParam("context") String context) {
    try {
      // establish the session
      Session s = establishSession(sessionId);

      Iterator assingments = assignmentService.getAssignmentsForContext(context);
      while (assingments.hasNext()) {
        Assignment ass = (Assignment) assingments.next();
        ResourceProperties rp = ass.getProperties();

        try {
          String deleted = rp.getProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

          LOG.info("Assignment " + ass.getTitle() + " deleted status: " + deleted);
          if (deleted != null) {
            AssignmentEdit ae = assignmentService.editAssignment(ass.getId());
            ResourcePropertiesEdit rpe = ae.getPropertiesEdit();
            LOG.info("undeleting" + ass.getTitle() + " for site " + context);
            rpe.removeProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);

            assignmentService.commitEdit(ae);
          }
        } catch (IdUnusedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (PermissionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InUseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } catch (Exception e) {
      LOG.error("WS undeleteAssignments(): " + e.getClass().getName() + " : " + e.getMessage());
      return e.getClass().getName() + " : " + e.getMessage();
    }

    return "success";
  }
Example #2
0
  /**
   * @param assignmentRef
   * @param associateGradebookAssignment
   * @param addUpdateRemoveAssignment
   * @param newAssignment_title
   * @param newAssignment_maxPoints
   * @param newAssignment_dueTime
   * @param submissionRef
   * @param updateRemoveSubmission
   * @param context
   */
  protected void integrateGradebook(
      String assignmentRef,
      String associateGradebookAssignment,
      String addUpdateRemoveAssignment,
      String newAssignment_title,
      int newAssignment_maxPoints,
      Time newAssignment_dueTime,
      String submissionRef,
      String updateRemoveSubmission,
      String context) {
    // add or remove external grades to gradebook
    // a. if Gradebook does not exists, do nothing, 'cos setting should have been hidden
    // b. if Gradebook exists, just call addExternal and removeExternal and swallow any exception.
    // The
    //    exception are indication that the assessment is already in the Gradebook or there is
    // nothing
    //    to remove.
    String gradebookUid = context;
    boolean gradebookExists = isGradebookDefined(context);

    String assignmentToolTitle = "Assignments";

    if (gradebookExists) {
      boolean isExternalAssignmentDefined =
          gradebookExternalAssessmentService.isExternalAssignmentDefined(
              gradebookUid, assignmentRef);
      boolean isExternalAssociateAssignmentDefined =
          gradebookExternalAssessmentService.isExternalAssignmentDefined(
              gradebookUid, associateGradebookAssignment);
      boolean isAssignmentDefined =
          gradebookService.isAssignmentDefined(gradebookUid, associateGradebookAssignment);

      if (addUpdateRemoveAssignment != null) {
        if (addUpdateRemoveAssignment.equals("add")
            || (addUpdateRemoveAssignment.equals("update")
                && !gradebookService.isAssignmentDefined(gradebookUid, newAssignment_title))) {
          // add assignment into gradebook
          try {
            // add assignment to gradebook
            gradebookExternalAssessmentService.addExternalAssessment(
                gradebookUid,
                assignmentRef,
                null,
                newAssignment_title,
                newAssignment_maxPoints / 10,
                new Date(newAssignment_dueTime.getTime()),
                "Assignment");
          } catch (AssignmentHasIllegalPointsException e) {
            // addAlert(state, rb.getString("addtogradebook.illegalPoints"));
          } catch (ConflictingAssignmentNameException e) {
            // try to modify assignment title, make sure there is no such assignment in the
            // gradebook, and insert again
            boolean trying = true;
            int attempts = 1;
            String titleBase = newAssignment_title;
            while (trying
                && attempts < MAXIMUM_ATTEMPTS_FOR_UNIQUENESS) // see end of loop for condition that
            // enforces attempts <= limit)
            {
              String newTitle = titleBase + "-" + attempts;

              if (!gradebookService.isAssignmentDefined(gradebookUid, newTitle)) {
                try {
                  // add assignment to gradebook
                  gradebookExternalAssessmentService.addExternalAssessment(
                      gradebookUid,
                      assignmentRef,
                      null,
                      newTitle,
                      newAssignment_maxPoints / 10,
                      new Date(newAssignment_dueTime.getTime()),
                      "Assignment");
                  trying = false;
                } catch (Exception ee) {
                  // try again, ignore the exception
                }
              }

              if (trying) {
                attempts++;
                if (attempts >= MAXIMUM_ATTEMPTS_FOR_UNIQUENESS) {
                  // add alert prompting for change assignment title
                  // addAlert(state, rb.getString("addtogradebook.nonUniqueTitle"));
                }
              }
            }
          } catch (ConflictingExternalIdException e) {
            // ignore
          } catch (GradebookNotFoundException e) {
            // ignore
          } catch (Exception e) {
            // ignore
          }
        } // (addUpdateRemoveAssignment.equals("add") || (
        // addUpdateRemoveAssignment.equals("update") && !g.isAssignmentDefined(gradebookUid,
        // newAssignment_title)))
      } // addUpdateRemoveAssignment != null

      if (updateRemoveSubmission != null) {
        try {
          Assignment a = assignmentService.getAssignment(assignmentRef);

          if (updateRemoveSubmission.equals("update")
              && a.getProperties().getProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK) != null
              && !a.getProperties()
                  .getProperty(NEW_ASSIGNMENT_ADD_TO_GRADEBOOK)
                  .equals(AssignmentService.GRADEBOOK_INTEGRATION_NO)
              && a.getContent().getTypeOfGrade() == Assignment.SCORE_GRADE_TYPE) {
            if (submissionRef == null) {
              // bulk add all grades for assignment into gradebook
              Iterator submissions = assignmentService.getSubmissions(a).iterator();

              Map m = new HashMap();

              // any score to copy over? get all the assessmentGradingData and copy over
              while (submissions.hasNext()) {
                AssignmentSubmission aSubmission = (AssignmentSubmission) submissions.next();
                if (aSubmission.getGradeReleased()) {
                  User[] submitters = aSubmission.getSubmitters();
                  String submitterId = submitters[0].getId();
                  String gradeString = StringUtils.trimToNull(aSubmission.getGrade(false));
                  Double grade =
                      gradeString != null ? Double.valueOf(displayGrade(gradeString)) : null;
                  m.put(submitterId, grade);
                }
              }

              // need to update only when there is at least one submission
              if (m.size() > 0) {
                if (associateGradebookAssignment != null) {
                  if (isExternalAssociateAssignmentDefined) {
                    // the associated assignment is externally maintained
                    gradebookExternalAssessmentService.updateExternalAssessmentScores(
                        gradebookUid, associateGradebookAssignment, m);
                  } else if (isAssignmentDefined) {
                    // the associated assignment is internal one, update records one by one
                    submissions = assignmentService.getSubmissions(a).iterator();
                    while (submissions.hasNext()) {
                      AssignmentSubmission aSubmission = (AssignmentSubmission) submissions.next();
                      User[] submitters = aSubmission.getSubmitters();
                      String submitterId = submitters[0].getId();
                      String gradeString = StringUtils.trimToNull(aSubmission.getGrade(false));
                      String grade =
                          (gradeString != null && aSubmission.getGradeReleased())
                              ? displayGrade(gradeString)
                              : null;
                      gradebookService.setAssignmentScoreString(
                          gradebookUid,
                          associateGradebookAssignment,
                          submitterId,
                          grade,
                          assignmentToolTitle);
                    }
                  }
                } else if (isExternalAssignmentDefined) {
                  gradebookExternalAssessmentService.updateExternalAssessmentScores(
                      gradebookUid, assignmentRef, m);
                }
              }
            } else {
              try {
                // only update one submission
                AssignmentSubmission aSubmission =
                    (AssignmentSubmission) assignmentService.getSubmission(submissionRef);
                User[] submitters = aSubmission.getSubmitters();
                String gradeString = StringUtils.trimToNull(aSubmission.getGrade(false));

                if (associateGradebookAssignment != null) {
                  if (gradebookExternalAssessmentService.isExternalAssignmentDefined(
                      gradebookUid, associateGradebookAssignment)) {
                    // the associated assignment is externally maintained
                    gradebookExternalAssessmentService.updateExternalAssessmentScore(
                        gradebookUid,
                        associateGradebookAssignment,
                        submitters[0].getId(),
                        (gradeString != null && aSubmission.getGradeReleased())
                            ? displayGrade(gradeString)
                            : null);
                  } else if (gradebookService.isAssignmentDefined(
                      gradebookUid, associateGradebookAssignment)) {
                    // the associated assignment is internal one, update records
                    gradebookService.setAssignmentScoreString(
                        gradebookUid,
                        associateGradebookAssignment,
                        submitters[0].getId(),
                        (gradeString != null && aSubmission.getGradeReleased())
                            ? displayGrade(gradeString)
                            : null,
                        assignmentToolTitle);
                  }
                } else {
                  gradebookExternalAssessmentService.updateExternalAssessmentScore(
                      gradebookUid,
                      assignmentRef,
                      submitters[0].getId(),
                      (gradeString != null && aSubmission.getGradeReleased())
                          ? displayGrade(gradeString)
                          : null);
                }
              } catch (Exception e) {
                LOG.warn("Cannot find submission " + submissionRef + ": " + e.getMessage());
              }
            } // submissionref != null

          } else if (updateRemoveSubmission.equals("remove")) {
            if (submissionRef == null) {
              // remove all submission grades (when changing the associated entry in Gradebook)
              Iterator submissions = assignmentService.getSubmissions(a).iterator();

              // any score to copy over? get all the assessmentGradingData and copy over
              while (submissions.hasNext()) {
                AssignmentSubmission aSubmission = (AssignmentSubmission) submissions.next();
                User[] submitters = aSubmission.getSubmitters();
                if (isExternalAssociateAssignmentDefined) {
                  // if the old associated assignment is an external maintained one
                  gradebookExternalAssessmentService.updateExternalAssessmentScore(
                      gradebookUid, associateGradebookAssignment, submitters[0].getId(), null);
                } else if (isAssignmentDefined) {
                  gradebookService.setAssignmentScoreString(
                      gradebookUid,
                      associateGradebookAssignment,
                      submitters[0].getId(),
                      null,
                      assignmentToolTitle);
                }
              }
            } else {
              // remove only one submission grade
              try {
                AssignmentSubmission aSubmission =
                    (AssignmentSubmission) assignmentService.getSubmission(submissionRef);
                User[] submitters = aSubmission.getSubmitters();
                gradebookExternalAssessmentService.updateExternalAssessmentScore(
                    gradebookUid, assignmentRef, submitters[0].getId(), null);
              } catch (Exception e) {
                LOG.warn("Cannot find submission " + submissionRef + ": " + e.getMessage());
              }
            }
          }
        } catch (Exception e) {
          LOG.warn("Cannot find assignment: " + assignmentRef + ": " + e.getMessage());
        }
      } // updateRemoveSubmission != null
    } // if gradebook exists
  } // integrateGradebook
Example #3
0
  @WebMethod
  @Path("/setAssignmentGradeCommentforUser")
  @Produces("text/plain")
  @GET
  public String setAssignmentGradeCommentforUser(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "assignmentId", partName = "assignmentId") @QueryParam("assignmentId")
          String assignmentId,
      @WebParam(name = "userId", partName = "userId") @QueryParam("userId") String userId,
      @WebParam(name = "comment", partName = "comment") @QueryParam("comment") String comment,
      @WebParam(name = "grade", partName = "grade") @QueryParam("grade") String grade) {
    // establish the session

    try {
      Session s = establishSession(sessionId);

      LOG.info(
          "User "
              + s.getUserEid()
              + " setting assignment grade/comment for "
              + userId
              + " on "
              + assignmentId
              + " to "
              + grade);

      User user = userDirectoryService.getUserByEid(userId);
      if (user == null) {
        return "user does not exist";
      }

      Assignment assign = assignmentService.getAssignment(assignmentId);
      String aReference = assign.getReference();

      if (!securityService.unlock(
          AssignmentService.SECURE_GRADE_ASSIGNMENT_SUBMISSION, aReference)) {
        LOG.warn("User " + s.getUserEid() + " does not have permission to set assignment grades");
        return "failure: no permission";
      }

      LOG.info(
          "Setting assignment grade/comment for "
              + userId
              + " on "
              + assignmentId
              + " to "
              + grade);

      AssignmentSubmission sub = assignmentService.getSubmission(assignmentId, user);
      AssignmentSubmissionEdit asEdit = null;
      String context = assign.getContext();

      if (sub == null) {
        asEdit = assignmentService.addSubmission(context, assignmentId, user.getId());
      } else {
        asEdit = assignmentService.editSubmission(sub.getReference());
      }

      asEdit.setFeedbackComment(comment);
      asEdit.setGrade(grade);
      asEdit.setGraded(true);
      asEdit.setGradeReleased(true);
      assignmentService.commitEdit(asEdit);

      // If necessary, update the assignment grade in the Gradebook

      String sReference = asEdit.getReference();

      String associateGradebookAssignment =
          StringUtils.trimToNull(
              assign
                  .getProperties()
                  .getProperty(AssignmentService.PROP_ASSIGNMENT_ASSOCIATE_GRADEBOOK_ASSIGNMENT));

      // update grade in gradebook
      integrateGradebook(
          aReference,
          associateGradebookAssignment,
          null,
          null,
          -1,
          null,
          sReference,
          "update",
          context);

    } catch (Exception e) {
      LOG.error(
          "WS setAssignmentGradeCommentforUser(): Exception while setting assignment grade/comment for "
              + userId
              + " on "
              + assignmentId
              + " to "
              + grade,
          e);
      return e.getClass().getName() + " : " + e.getMessage();
    }

    return "success";
  }