@WebMethod
 @Path("/setAssignmentAcceptUntil")
 @Produces("text/plain")
 @GET
 public String setAssignmentAcceptUntil(
     @WebParam(name = "sessionId", partName = "sessionId") @QueryParam("sessionId")
         String sessionId,
     @WebParam(name = "assignmentId", partName = "assignmentId") @QueryParam("assignmentId")
         String assignmentId) {
   LOG.info("setting accept until time for assignment: " + assignmentId);
   try {
     Session s = establishSession(sessionId);
     AssignmentEdit assignment = assignmentService.editAssignment(assignmentId);
     LOG.debug("got assignment: " + assignment.getTitle());
     LOG.debug("assignment closes: " + assignment.getDueTime());
     assignment.setCloseTime(assignment.getDueTime());
     assignmentService.commitEdit(assignment);
     LOG.debug("edit committed");
   } catch (Exception e) {
     LOG.error(
         "WS setAssignmentAcceptUntil(): " + e.getClass().getName() + " : " + e.getMessage());
     return e.getClass().getName() + " : " + e.getMessage();
   }
   return "success";
 }
  @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";
  }
  @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();
    }
  }