public void schedulePeerReview(String assignmentId) {
   // first remove any previously scheduled reviews:
   removeScheduledPeerReview(assignmentId);
   // now schedule a time for the review to be setup
   Assignment assignment;
   try {
     assignment = assignmentService.getAssignment(assignmentId);
     if (!assignment.getDraft() && assignment.getAllowPeerAssessment()) {
       Time assignmentCloseTime = assignment.getCloseTime();
       Time openTime = null;
       if (assignmentCloseTime != null) {
         openTime = timeService.newTime(assignmentCloseTime.getTime());
       }
       // Schedule the new notification
       if (openTime != null) {
         scheduledInvocationManager.createDelayedInvocation(
             openTime,
             "org.sakaiproject.assignment.api.AssignmentPeerAssessmentService",
             assignmentId);
       }
     }
   } catch (IdUnusedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (PermissionException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
  /** {@inheritDoc} */
  public boolean canViewAllPurposeItem(Assignment a) {
    boolean rv = false;

    if (a != null) {
      AssignmentAllPurposeItem aItem = getAllPurposeItem(a.getId());
      if (aItem != null) {
        if (!aItem.getHide()) {
          Time now = TimeService.newTime();
          Date releaseDate = aItem.getReleaseDate();
          Date retractDate = aItem.getRetractDate();

          if (releaseDate == null && retractDate == null) {
            // no time limitation on showing the item
            rv = true;
          } else if (releaseDate != null && retractDate == null) {
            // has relase date but not retract date
            rv = now.getTime() > releaseDate.getTime();
          } else if (releaseDate == null && retractDate != null) {
            // has retract date but not release date
            rv = now.getTime() < retractDate.getTime();
          } else if (now != null) {
            // both releaseDate and retract date are not null
            // has both release and retract dates
            rv = now.getTime() > releaseDate.getTime() && now.getTime() < retractDate.getTime();
          }
        } else {
          rv = false;
        }
      }

      if (rv) {
        // reset rv
        rv = false;

        // need to check role/user permission only if the above time test returns true
        List<String> access = getAccessListForAllPurposeItem(aItem);
        User u = m_userDirectoryService.getCurrentUser();
        if (u != null) {
          if (access.contains(u.getId())) rv = true;
          else {
            try {
              String role =
                  m_authzGroupService.getUserRole(
                      u.getId(), m_siteService.siteReference(a.getContext()));
              if (access.contains(role)) rv = true;
            } catch (Exception e) {
              Log.warn(
                  this
                      + ".callViewAllPurposeItem() Hibernate cannot access user role for user id= "
                      + u.getId());
              return rv;
            }
          }
        }
      }
    }

    return rv;
  }
示例#3
0
  private void addFolder(ContentCollection n, ResourceDefinition rp, int depth)
      throws SDataException {
    put("available", n.isAvailable());
    put("hidden", n.isHidden());
    if (!n.isHidden()) {
      Time releaseDate = n.getReleaseDate();
      if (releaseDate != null) {
        put("releaseDate", releaseDate.getTime());
      }
      Time retractDate = n.getRetractDate();
      if (retractDate != null) {
        put("retractDate", retractDate.getTime());
      }
    }

    ContentCollection cc = (ContentCollection) n;
    put("members", cc.getMemberCount());
    if (depth >= 0) {

      Map<String, Object> nodes = new HashMap<String, Object>();
      // list of IDs
      List<?> l = cc.getMembers();

      int i = 0;
      for (int k = 0; k < l.size(); k++) {
        String memberID = (String) l.get(k);
        ContentEntity cn = null;
        try {
          cn = contentHostingService.getResource(memberID);
        } catch (Exception idex) {
          try {
            String collectionPath = memberID;
            if (!collectionPath.endsWith("/")) {
              collectionPath = collectionPath + "/";
            }
            cn = contentHostingService.getCollection(collectionPath);
          } catch (Exception ex) {

          }
        }
        if (cn != null) {

          try {
            Map<String, Object> m = new CHSNodeMap(cn, depth, rp);
            m.put("position", String.valueOf(i));
            nodes.put(getName(cn), m);
          } catch (SDataAccessException sdae) {
            // hide the item from the list
            continue;
          }
        }
        i++;
      }
      put("nitems", nodes.size());
      put("items", nodes);
    }
  }
  /** Create the live properties for the azGroup. */
  protected void addLiveProperties(BaseAuthzGroup azGroup) {
    String current = sessionManager().getCurrentSessionUserId();

    azGroup.m_createdUserId = current;
    azGroup.m_lastModifiedUserId = current;

    Time now = timeService().newTime();
    azGroup.m_createdTime = now;
    azGroup.m_lastModifiedTime = (Time) now.clone();
  }
 /**
  * Compute a time range based on a specific time.
  *
  * @return The time range that encloses the specific time.
  */
 protected TimeRange computeRange(Time time) {
   // set the period to "today" (local!) from day start to next day start, not end inclusive
   TimeBreakdown brk = time.breakdownLocal();
   brk.setMs(0);
   brk.setSec(0);
   brk.setMin(0);
   brk.setHour(0);
   Time start = timeService().newTimeLocal(brk);
   Time end = timeService().newTime(start.getTime() + 24 * 60 * 60 * 1000);
   return timeService().newTimeRange(start, end, true, false);
 }
  /** @inheritDoc */
  public void notify(Notification notification, Event event) {
    // get the message
    Reference ref = EntityManager.newReference(event.getResource());
    AnnouncementMessageEdit msg = (AnnouncementMessageEdit) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // do not do notification for hidden (draft) messages
    if (hdr.getDraft()) return;

    // Put here since if release date after now, do not notify
    // since scheduled notification has been set.
    Time now = TimeService.newTime();

    if (now.after(hdr.getDate())) {
      super.notify(notification, event);
    }
  }
  /**
   * There must be a better way of doing this as this hard codes the services in surely there should
   * be some whay of looking up the serivce and making the getSummary part of an interface. TODO:
   * Add an interface beside EntityProducer to generate summaries Make this discoverable
   *
   * @param m
   * @param site
   * @param toolIdentifier
   * @return
   */
  private boolean summarizeTool(Map m, Site site, String toolIdentifier) {
    if (site == null) return false;

    setTemporaryPlacement(site);
    Map newMap = null;

    /*
     * This is a new, cooler way to do this (I hope) chmaurer... (ieb) Yes:)
     * All summaries now through this interface
     */

    // offer to all EntityProducers
    for (Iterator i = EntityManager.getEntityProducers().iterator(); i.hasNext(); ) {
      EntityProducer ep = (EntityProducer) i.next();
      if (ep instanceof EntitySummary) {
        try {
          EntitySummary es = (EntitySummary) ep;

          // if this producer claims this tool id
          if (ArrayUtil.contains(es.summarizableToolIds(), toolIdentifier)) {
            String summarizableReference =
                es.getSummarizableReference(site.getId(), toolIdentifier);
            newMap = es.getSummary(summarizableReference, 5, 30);
          }
        } catch (Throwable t) {
          log.warn(
              "Error encountered while asking EntitySummary to getSummary() for: " + toolIdentifier,
              t);
        }
      }
    }

    if (newMap != null) {
      return (MapUtil.copyHtml(m, "rssDescription", newMap, Summary.PROP_DESCRIPTION)
          && MapUtil.copy(m, "rssPubdate", newMap, Summary.PROP_PUBDATE));
    } else {
      Time modDate = site.getModifiedTime();
      // Yes, some sites have never been modified
      if (modDate != null) {
        m.put("rssPubDate", (modDate.toStringRFC822Local()));
      }
      return false;
    }
  }
示例#8
0
  /**
   * @param n
   * @throws RepositoryException
   */
  private void addFile(ContentResource n) {
    ResourceProperties rp = n.getProperties();
    Calendar lastModified = new GregorianCalendar();
    try {
      Time lastModifiedTime = rp.getTimeProperty(ResourceProperties.PROP_MODIFIED_DATE);
      lastModified.setTimeInMillis(lastModifiedTime.getTime());
    } catch (EntityPropertyNotDefinedException e) {
      // default to now
    } catch (EntityPropertyTypeException e) {
      // default to now
    }
    long contentLength = n.getContentLength();
    String mimeType = n.getContentType();
    put("lastModified", lastModified.getTime());
    put("mimeType", mimeType);
    put("length", String.valueOf(contentLength));

    put("available", n.isAvailable());
    put("hidden", n.isHidden());
    if (!n.isHidden()) {
      Time releaseDate = n.getReleaseDate();
      if (releaseDate != null) {
        put("releaseDate", releaseDate.getTime());
      }
      Time retractDate = n.getRetractDate();
      if (retractDate != null) {
        put("retractDate", retractDate.getTime());
      }
    }
  }
 /** @inheritDoc */
 public String toString() {
   return "["
       + ((m_id == null) ? "" : m_id)
       + " | "
       + ((m_server == null) ? "" : m_server)
       + " | "
       + ((m_user == null) ? "" : m_user)
       + " | "
       + ((m_ip == null) ? "" : m_ip)
       + " | "
       + ((m_userAgent == null) ? "" : m_userAgent)
       + " | "
       + m_start.toStringGmtFull()
       + " ]";
 }
    /** @inheritDoc */
    public List getMessages(Time period) {
      synchronized (m_ranges) {
        // find the range
        String range = computeRange(period).toString();
        /*
         * http://jira.sakaiproject.org/jira/browse/SAK-11841
         * If the current date/time gets out of sync with the stored date/time periods then
         * messages will sit in the queue forever and cause looping in the code which will
         * never resolve itself, to keep this from happening I am adding in an extra
         * check as a stopgap which will do the reverse check in the case that nothing
         * is retrieved, this really ugly and needs to be done a better way
         * (which means a way that is not so fragile) -AZ
         */
        List msgs = (List) m_ranges.get(range);
        if (msgs == null) {
          // nothing found so go through all ranges and hack the range strings
          SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmm");
          for (Iterator iterator = m_ranges.keySet().iterator(); iterator.hasNext(); ) {
            String rangeKey = (String) iterator.next();
            Date startDate;
            try {
              startDate = formatter.parse(range.substring(0, 12));
              long difference = Math.abs(period.getTime() - startDate.getTime());
              if (difference < (12 * 60 * 60 * 1000)) {
                // within 12 hours of the correct period so use this one
                msgs = (List) m_ranges.get(rangeKey);
                break;
              }
            } catch (ParseException e) {
              M_log.warn(
                  "Failed to parse first 12 chars from '"
                      + rangeKey
                      + "' into a date, aborting the attempt to find close data matches",
                  e);
            }
          }
        }

        List rv = new Vector();
        if (msgs != null) {
          rv.addAll(msgs);
        }

        return rv;
      }
    }
  /**
   * Compare these objects based on my property and ascending settings. Collections sort lower than
   * Resources.
   *
   * @param o1 The first object, ContentCollection or ContentResource
   * @param o2 The second object, ContentCollection or ContentResource
   * @return The compare result: -1 if o1 < o2, 0 if they are equal, and 1 if o1 > o2
   */
  public int compare(Object o1, Object o2) {
    String property = m_property;

    // PROP_CONTENT_PRIORITY is special because it allows
    // intermixing folders and files.
    if (property.equals(ResourceProperties.PROP_CONTENT_PRIORITY)) {
      Entity entity1 = (Entity) o1;
      Entity entity2 = (Entity) o2;
      String str1 = entity1.getProperties().getProperty(property);
      String str2 = entity2.getProperties().getProperty(property);

      if (str1 == null || str2 == null) {
        // ignore -- default to a different sort
      } else {
        try {
          Integer rank1 = new Integer(str1);
          Integer rank2 = new Integer(str2);
          return m_ascending ? rank1.compareTo(rank2) : rank2.compareTo(rank1);
        } catch (NumberFormatException e) {
          // ignore -- default to a different sort
        }
      }
      // if unable to do a priority sort, sort by title
      property = ResourceProperties.PROP_DISPLAY_NAME;
    }

    // collections sort lower than resources
    if ((o1 instanceof ContentCollection) && (o2 instanceof ContentResource)) {
      return (m_ascending ? -1 : 1);
    }
    if ((o1 instanceof ContentResource) && (o2 instanceof ContentCollection)) {
      return (m_ascending ? 1 : -1);
    }

    if (property.equals(ResourceProperties.PROP_CONTENT_LENGTH)
        && o1 instanceof ContentCollection) {
      int size1 = ((ContentCollection) o1).getMemberCount();
      int size2 = ((ContentCollection) o2).getMemberCount();
      int rv = ((size1 < size2) ? -1 : ((size1 > size2) ? 1 : 0));
      if (!m_ascending) rv = -rv;
      return rv;
    }

    // ok, they are both the same: resources or collections

    // try a numeric interpretation
    try {
      long l1 = ((Entity) o1).getProperties().getLongProperty(property);
      long l2 = ((Entity) o2).getProperties().getLongProperty(property);
      int rv = ((l1 < l2) ? -1 : ((l1 > l2) ? 1 : 0));
      if (!m_ascending) rv = -rv;
      return rv;
    } catch (Exception ignore) {
    }

    // try a Time interpretation
    try {
      Time t1 = ((Entity) o1).getProperties().getTimeProperty(property);
      Time t2 = ((Entity) o2).getProperties().getTimeProperty(property);
      int rv = t1.compareTo(t2);
      if (!m_ascending) rv = -rv;
      return rv;
    } catch (Exception ignore) {
    }

    // do a formatted interpretation - case insensitive
    if (o1 == null) return -1;
    if (o2 == null) return +1;

    int rv = 0;
    if (m_smart_sort) {
      rv =
          compareLikeMacFinder(
              ((Entity) o1).getProperties().getPropertyFormatted(property),
              ((Entity) o2).getProperties().getPropertyFormatted(property));
    } else {
      rv =
          ((Entity) o1)
              .getProperties()
              .getPropertyFormatted(property)
              .compareTo(((Entity) o2).getProperties().getPropertyFormatted(property));
    }
    return m_ascending ? rv : -rv;
  } // compare
示例#12
0
 /** @inheritDoc */
 public Time getEnd() {
   return this.usageSessionServiceAdaptor.timeService().newTime(m_end.getTime());
 }
示例#13
0
 /** @inheritDoc */
 public Time getStart() {
   return this.usageSessionServiceAdaptor.timeService().newTime(m_start.getTime());
 }
示例#14
0
  @WebMethod
  @Path("/getAssignmentsForContext")
  @Produces("text/plain")
  @GET
  public String getAssignmentsForContext(
      @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);

      // ok will this give me a list of assignments for the course
      LOG.info("assignment list requested for " + context);

      Iterator assignments = assignmentService.getAssignmentsForContext(context);
      Document dom = Xml.createDocument();
      Node all = dom.createElement("assignments");
      dom.appendChild(all);

      while (assignments.hasNext()) {
        Assignment thisA = (Assignment) assignments.next();
        LOG.debug("got " + thisA.getTitle());
        if (!thisA.getDraft()) {
          AssignmentContent asCont = thisA.getContent();

          LOG.debug("about to start building xml doc");
          Element uElement = dom.createElement("assignment");
          uElement.setAttribute("id", thisA.getId());
          uElement.setAttribute("title", thisA.getTitle());
          LOG.debug("added title and id");
          if (asCont != null) {
            Integer temp = new Integer(asCont.getTypeOfGrade());
            String gType = temp.toString();
            uElement.setAttribute("gradeType", gType);
          }

          /* these need to be converted to strings
           */

          LOG.debug("About to get dates");

          Time dueTime = thisA.getDueTime();
          Time openTime = thisA.getOpenTime();
          Time closeTime = thisA.getCloseTime();
          LOG.debug("got dates");
          DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");

          if (openTime != null) {
            LOG.debug("open time is " + openTime.toString());
            uElement.setAttribute("openTime", format.format(new Date(openTime.getTime())));
          }
          if (closeTime != null) {
            LOG.debug("close time is " + closeTime.toString());
            uElement.setAttribute("closeTime", format.format(new Date(closeTime.getTime())));
          }

          if (dueTime != null) {
            LOG.debug("due time is " + dueTime.toString());
            uElement.setAttribute("dueTime", format.format(new Date(dueTime.getTime())));
          }

          LOG.debug("apending element to parent");
          all.appendChild(uElement);
        } else {
          LOG.debug("this is a draft assignment");
        }
      }
      String retVal = Xml.writeDocumentToString(dom);
      return retVal;
    } catch (Exception e) {
      LOG.error(
          "WS getAssignmentsForContext(): " + e.getClass().getName() + " : " + e.getMessage());
    }

    return "<assignments/ >";
  }
示例#15
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
示例#16
0
  @WebMethod
  @Path("/createAssignment")
  @Produces("text/plain")
  @GET
  public String createAssignment(
      @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
          String sessionId,
      @WebParam(name = "context", partName = "context") @QueryParam("context") String context,
      @WebParam(name = "title", partName = "title") @QueryParam("title") String title,
      @WebParam(name = "dueTime", partName = "dueTime") @QueryParam("dueTime") long dueTime,
      @WebParam(name = "openTime", partName = "openTime") @QueryParam("openTime") long openTime,
      @WebParam(name = "closeTime", partName = "closeTime") @QueryParam("closeTime") long closeTime,
      @WebParam(name = "maxPoints", partName = "maxPoints") @QueryParam("maxPoints") int maxPoints,
      @WebParam(name = "gradeType", partName = "gradeType") @QueryParam("gradeType") int gradeType,
      @WebParam(name = "instructions", partName = "instructions") @QueryParam("instructions")
          String instructions,
      @WebParam(name = "subType", partName = "subType") @QueryParam("subType") int subType) {

    LOG.info("creating assignment in " + context);
    try {
      Session s = establishSession(sessionId);
      AssignmentEdit assign = assignmentService.addAssignment(context);

      Time dt = timeService.newTime(dueTime);
      Time ot = timeService.newTime(openTime);
      Time ct = timeService.newTime(closeTime);

      LOG.debug("time is " + dt.toStringGmtFull());

      // set the values for the assignemnt
      assign.setTitle(title);
      assign.setDraft(false);
      assign.setDueTime(dt);
      assign.setOpenTime(ot);
      assign.setCloseTime(ct);

      // we need a contentedit for the actual contents of the assignment - this will do for now

      AssignmentContentEdit asCont = assignmentService.addAssignmentContent(context);
      assign.setContent(asCont);
      /*
       *3 - points
       */

      // int gradeType = 3;
      int maxGradePoints = maxPoints;
      LOG.debug("max points are" + maxGradePoints);
      /*
       * 1 - text
       * 2 - attachment
       */
      int typeofSubmission = subType;
      asCont.setTitle(title);
      asCont.setTypeOfGrade(gradeType);
      asCont.setMaxGradePoint(maxGradePoints);
      asCont.setTypeOfSubmission(typeofSubmission);
      asCont.setInstructions(instructions);
      asCont.setIndividuallyGraded(true);
      asCont.setReleaseGrades(true);
      assignmentService.commitEdit(asCont);

      // setupo the submission
      // AssignmentSubmissionEdit ae = as.addSubmission(context,assign.getId());
      // clear it
      // ae.clearSubmitters();
      // ae.clearSubmittedAttachments();
      // ae.clearFeedbackAttachments();
      // as.commitEdit(ae);

      assignmentService.commitEdit(assign);
      // do GB integration
      String aReference = assign.getReference();

      integrateGradebook(aReference, null, "add", title, maxGradePoints, dt, null, null, context);

      Calendar c = null;
      try {
        c = calendarService.getCalendar("/calendar/calendar/" + context + "/main");
      } catch (Exception e) {
        c = null;
      }

      if (c != null) {
        CalendarEventEdit cee = c.addEvent();
        cee.setDescription(
            "Assignment " + title + " " + "is due on " + dt.toStringLocalFull() + ". ");
        cee.setDisplayName("Due " + title);
        cee.setType("Deadline");
        cee.setRange(timeService.newTimeRange(dt.getTime(), 0 * 60 * 1000));
        c.commitEvent(cee);
      } else {
        LOG.warn("WS createAssignment(): no calendar found");
      }

      return assign.getId();
    } catch (Exception e) {
      LOG.warn("WS createAssignment(): " + e.getClass().getName() + " : " + e.getMessage());
      return e.getClass().getName() + " : " + e.getMessage();
    }
  }