Exemple #1
0
 public String processCreateBack() {
   if (currentGradebook.getId() == null) {
     this.csv = null;
     currentGradebook.setStudents(null);
   }
   this.userPressedBack = true;
   return "create_gradebook";
 }
Exemple #2
0
  public String processGradebookUpdate() {
    try {
      if (!this.checkAccess()) {
        throw new PermissionException(
            SessionManager.getCurrentSessionUserId(), "syllabus_access_athz", "");
      }

    } catch (PermissionException e) {
      // logger.info(this + ".getEntries() in PostemTool " + e);
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              MessageUtils.getMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "error_permission",
                  (new Object[] {e.toString()}),
                  FacesContext.getCurrentInstance()));
      this.currentGradebook = null;
      this.csv = null;
      this.newTemplate = null;
      return "permission_error";
    }
    this.userId = SessionManager.getCurrentSessionUserId();
    this.siteId = ToolManager.getCurrentPlacement().getContext();

    Long currentGbId = ((Gradebook) gradebookTable.getRowData()).getId();
    currentGradebook = gradebookManager.getGradebookByIdWithHeadingsAndStudents(currentGbId);

    oldGradebook =
        gradebookManager.createEmptyGradebook(
            currentGradebook.getCreator(), currentGradebook.getContext());
    oldGradebook.setId(currentGradebook.getId());
    oldGradebook.setStudents(currentGradebook.getStudents());

    gradebooks = null;

    /*
     * if(new Boolean(true).equals(currentGradebook.getReleased())) {
     * this.release = "Yes"; } else { this.release = "No"; }
     */

    if (currentGradebook.getFileReference() != null) {
      attachment =
          EntityManager.newReference(
              contentHostingService.getReference(currentGradebook.getFileReference()));
    }

    this.csv = null;
    this.newTemplate = null;
    this.delimiter = COMMA_DELIM_STR;

    return "create_gradebook";
  }
Exemple #3
0
  public String processCreate() {

    try {
      if (!this.checkAccess()) {
        throw new PermissionException(
            SessionManager.getCurrentSessionUserId(), "syllabus_access_athz", "");
      }

    } catch (PermissionException e) {
      // logger.info(this + ".getEntries() in PostemTool " + e);
      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              MessageUtils.getMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "error_permission",
                  (new Object[] {e.toString()}),
                  FacesContext.getCurrentInstance()));
      this.currentGradebook = null;
      this.csv = null;
      this.newTemplate = null;
      // this.release = null;
      return "permission_error";
    }
    if (currentGradebook.getId() == null) {
      ArrayList gb = getGradebooks();
      Iterator gi = gb.iterator();
      while (gi.hasNext()) {
        if (((Gradebook) gi.next()).getTitle().equals(currentGradebook.getTitle())) {
          // To stay consistent, remove current messages when adding a new message
          // so as to only display one error message before returning
          PostemTool.clearMessages();
          PostemTool.populateMessage(
              FacesMessage.SEVERITY_ERROR, "duplicate_title", new Object[] {});
          return "create_gradebook";
        }
      }
    }
    if (currentGradebook.getTitle() == null || currentGradebook.getTitle().equals("")) {
      // To stay consistent, remove current messages when adding a new message
      // so as to only display one error message before returning
      PostemTool.clearMessages();
      PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, "missing_title", new Object[] {});
      return "create_gradebook";
    } else if (currentGradebook.getTitle().trim().length() > TITLE_MAX_LENGTH) {
      PostemTool.clearMessages();
      PostemTool.populateMessage(
          FacesMessage.SEVERITY_ERROR,
          "title_too_long",
          new Object[] {
            new Integer(currentGradebook.getTitle().trim().length()), new Integer(TITLE_MAX_LENGTH)
          });
      return "create_gradebook";
    }

    Reference attachment = getAttachmentReference();
    if (attachment == null) {
      return "create_gradebook";
    }

    if (!this.delimiter.equals(COMMA_DELIM_STR) && !this.delimiter.equals(TAB_DELIM_STR)) {
      PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, "invalid_delim", new Object[] {});
      return "create_gradebook";
    }

    if (attachment != null) {
      // logger.info("*** Non-Empty CSV!");
      try {

        char csv_delim = CSV.COMMA_DELIM;
        if (this.delimiter.equals(TAB_DELIM_STR)) {
          csv_delim = CSV.TAB_DELIM;
        }

        // Read the data

        ContentResource cr = contentHostingService.getResource(attachment.getId());
        // Check the type
        if (ResourceProperties.TYPE_URL.equalsIgnoreCase(cr.getContentType())) {
          // Going to need to read from a stream
          String csvURL = new String(cr.getContent());
          // Load the URL
          csv = URLConnectionReader.getText(csvURL);
          if (LOG.isDebugEnabled()) {
            LOG.debug(csv);
          }
        } else {
          csv = new String(cr.getContent());
          if (LOG.isDebugEnabled()) {
            LOG.debug(csv);
          }
        }
        CSV grades = new CSV(csv, withHeader, csv_delim);

        if (withHeader == true) {
          if (grades.getHeaders() != null) {

            List headingList = grades.getHeaders();
            for (int col = 0; col < headingList.size(); col++) {
              String heading = (String) headingList.get(col).toString().trim();
              // Make sure there are no blank headings
              if (heading == null || heading.equals("")) {
                PostemTool.populateMessage(
                    FacesMessage.SEVERITY_ERROR, "blank_headings", new Object[] {});
                return "create_gradebook";
              }
              // Make sure the headings don't exceed max limit
              if (heading.length() > HEADING_MAX_LENGTH) {
                PostemTool.populateMessage(
                    FacesMessage.SEVERITY_ERROR,
                    "heading_too_long",
                    new Object[] {new Integer(HEADING_MAX_LENGTH)});
                return "create_gradebook";
              }
            }
          }
        }

        if (grades.getStudents() != null) {
          if (!usernamesValid(grades)) {
            return "create_gradebook";
          }

          if (hasADuplicateUsername(grades)) {
            return "create_gradebook";
          }
        }

        if (this.newTemplate != null && this.newTemplate.trim().length() > 0) {
          if (this.newTemplate.trim().length() > TEMPLATE_MAX_LENGTH) {
            PostemTool.populateMessage(
                FacesMessage.SEVERITY_ERROR,
                "template_too_long",
                new Object[] {
                  new Integer(this.newTemplate.trim().length()), new Integer(TEMPLATE_MAX_LENGTH)
                });
            return "create_gradebook";
          }
        }

        if (withHeader == true) {
          if (grades.getHeaders() != null) {
            PostemTool.populateMessage(FacesMessage.SEVERITY_INFO, "has_headers", new Object[] {});
          }
        }
        if (grades.getStudents() != null) {
          PostemTool.populateMessage(
              FacesMessage.SEVERITY_INFO,
              "has_students",
              new Object[] {new Integer(grades.getStudents().size())});
        }
        if (withHeader == true) {
          currentGradebook.setHeadings(grades.getHeaders());
        }
        List slist = grades.getStudents();

        if (oldGradebook.getId() != null && !this.userPressedBack) {
          Set oldStudents = currentGradebook.getStudents();
          oldGradebook.setStudents(oldStudents);
        }

        currentGradebook.setStudents(new TreeSet());
        // gradebookManager.saveGradebook(currentGradebook);
        Iterator si = slist.iterator();
        while (si.hasNext()) {
          List ss = (List) si.next();
          String uname = ((String) ss.remove(0)).trim();
          // logger.info("[POSTEM] processCreate -- adding student " +
          // uname);
          gradebookManager.createStudentGradesInGradebook(uname, ss, currentGradebook);
          if (currentGradebook.getStudents().size() == 1) {
            currentGradebook.setFirstUploadedUsername(
                uname); // otherwise, the verify screen shows first in ABC order
          }
        }
      } catch (DataFormatException exception) {
        /*
         * TODO: properly subclass exception in order to allow for localized
         * messages (add getRowNumber/setRowNumber). Set exception message to be
         * key in .properties file
         */
        PostemTool.populateMessage(
            FacesMessage.SEVERITY_ERROR, exception.getMessage(), new Object[] {});
        return "create_gradebook";
      } catch (IdUnusedException e) {
        PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), new Object[] {});
        return "create_gradebook";
      } catch (TypeException e) {
        PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), new Object[] {});
        return "create_gradebook";
      } catch (PermissionException e) {
        PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), new Object[] {});
        return "create_gradebook";
      } catch (ServerOverloadException e) {
        PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), new Object[] {});
        return "create_gradebook";
      } catch (IOException e) {
        PostemTool.populateMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), new Object[] {});
        return "create_gradebook";
      }
    } else if (this.csv != null) {
      // logger.info("**** Non Null Empty CSV!");
      PostemTool.populateMessage(
          FacesMessage.SEVERITY_ERROR, "has_students", new Object[] {new Integer(0)});
      currentGradebook.setHeadings(new ArrayList());
      if (oldGradebook.getId() != null) {
        Set oldStudents = currentGradebook.getStudents();
        oldGradebook.setStudents(oldStudents);
      }

      currentGradebook.setStudents(new TreeSet());
    }

    if (this.newTemplate != null && this.newTemplate.trim().length() > 0) {
      currentGradebook.setTemplate(gradebookManager.createTemplate(newTemplate.trim()));
    } else if (this.newTemplate != null) {
      // logger.info("*** Non Null Empty Template!");
      currentGradebook.setTemplate(null);
    }

    /*
     * if("No".equals(this.release)) { currentGradebook.setReleased(new
     * Boolean(false)); //logger.info("Set to No, " +
     * currentGradebook.getReleased()); } else {
     * currentGradebook.setReleased(new Boolean(true)); //logger.info("Set to
     * Yes, " + currentGradebook.getReleased()); }
     */

    // gradebookManager.saveGradebook(currentGradebook);
    // logger.info(currentGradebook.getId());
    // currentGradebook = null;
    if ((this.csv != null && this.csv.trim().length() > 0)
        || (this.newTemplate != null && this.newTemplate.trim().length() > 0)) {
      this.csv = null;
      this.newTemplate = null;
      return "verify";
    }

    Iterator oi = oldGradebook.getStudents().iterator();
    while (oi.hasNext()) {
      gradebookManager.deleteStudentGrades((StudentGrades) oi.next());
    }
    this.userId = SessionManager.getCurrentSessionUserId();
    currentGradebook.setLastUpdated(new Timestamp(new Date().getTime()));
    currentGradebook.setLastUpdater(this.userId);
    gradebookManager.saveGradebook(currentGradebook);

    this.currentGradebook = null;
    this.oldGradebook = null;
    this.withHeader = true;
    // this.gradebooks = null;
    return "main";
  }