Ejemplo n.º 1
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();
    }
  }