예제 #1
0
  public ArrayList<SelectItem> getPublishedSelectActionList() {
    if (publishedActionList != null) {
      return publishedActionList;
    }

    ResourceLoader com =
        new ResourceLoader("org.sakaiproject.tool.assessment.bundle.CommonMessages");
    AuthorizationBean authorizationBean =
        (AuthorizationBean) ContextUtil.lookupBean("authorization");

    publishedActionList = new ArrayList<SelectItem>();
    boolean isEditAnyAssessment = authorizationBean.getEditAnyAssessment();
    boolean isEditOwnAssessment = authorizationBean.getEditOwnAssessment();

    if (isEditAnyAssessment || isEditOwnAssessment) {
      publishedActionList.add(new SelectItem("preview_published", com.getString("action_preview")));
      if (ServerConfigurationService.getBoolean("samigo.printAssessment", true)) {
        publishedActionList.add(new SelectItem("print_published", com.getString("action_print")));
      }
      publishedActionList.add(
          new SelectItem("settings_published", com.getString("settings_action")));
    }

    return publishedActionList;
  }
  /**
   * Standard process action method.
   *
   * @param event ActionEvent
   * @throws AbortProcessingException
   */
  public void processAction(ActionEvent event) throws AbortProcessingException {
    log.debug("QuestionScore LISTENER.");
    QuestionScoresBean bean = (QuestionScoresBean) ContextUtil.lookupBean("questionScores");

    // Reset the search field
    String defaultSearchString =
        ContextUtil.getLocalizedString(
            "org.sakaiproject.tool.assessment.bundle.EvaluationMessages",
            "search_default_student_search_string");
    bean.setSearchString(defaultSearchString);

    // we probably want to change the poster to be consistent
    String publishedId = ContextUtil.lookupParam("publishedId");

    AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization");
    AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
    PublishedAssessmentService pubService = new PublishedAssessmentService();
    Long pubId = new Long(publishedId);
    String assessmentOwner = pubService.getPublishedAssessmentOwner(pubId);
    if (!authzBean.isUserAllowedToGradeAssessment(publishedId, assessmentOwner, true)) {
      throw new IllegalArgumentException(
          "QuestionScoreListener unauthorized attempt to get scores for " + publishedId);
    }

    if (!questionScores(publishedId, bean, false)) {
      throw new RuntimeException("failed to call questionScores.");
    }
  }
예제 #3
0
  public ArrayList<SelectItem> getPendingSelectActionList2() {
    if (pendingActionList2 != null) {
      return pendingActionList2;
    }

    pendingActionList2 = new ArrayList<SelectItem>();
    ResourceLoader com =
        new ResourceLoader("org.sakaiproject.tool.assessment.bundle.CommonMessages");
    AuthorizationBean authorizationBean =
        (AuthorizationBean) ContextUtil.lookupBean("authorization");

    boolean isEditAnyAssessment = authorizationBean.getEditAnyAssessment();
    boolean isEditOwnAssessment = authorizationBean.getEditOwnAssessment();
    boolean isDeleteAnyAssessment = authorizationBean.getDeleteAnyAssessment();
    boolean isDeleteOwnAssessment = authorizationBean.getDeleteOwnAssessment();

    pendingActionList2.add(new SelectItem("select", com.getString("action_select")));
    if (isEditAnyAssessment || isEditOwnAssessment) {
      pendingActionList2.add(new SelectItem("edit_pending", com.getString("edit_action")));
      pendingActionList2.add(new SelectItem("preview_pending", com.getString("action_preview")));
      if (ServerConfigurationService.getBoolean("samigo.printAssessment", true)) {
        pendingActionList2.add(new SelectItem("print_pending", com.getString("action_print")));
      }
      pendingActionList2.add(new SelectItem("settings_pending", com.getString("settings_action")));
      pendingActionList2.add(new SelectItem("duplicate", com.getString("action_duplicate")));
      pendingActionList2.add(new SelectItem("export", com.getString("export_action")));
    }
    if (isDeleteAnyAssessment || isDeleteOwnAssessment) {
      pendingActionList2.add(new SelectItem("remove_pending", com.getString("remove_action")));
    }
    return pendingActionList2;
  }
예제 #4
0
  public Boolean getCanRemovePublishedAssessments() {
    if (canRemovePublishedAssessments == null) {
      AuthorizationBean authorizationBean =
          (AuthorizationBean) ContextUtil.lookupBean("authorization");

      boolean isDeleteAnyAssessment = authorizationBean.getDeleteAnyAssessment();
      boolean isDeleteOwnAssessment = authorizationBean.getDeleteOwnAssessment();
      if (isDeleteAnyAssessment || isDeleteOwnAssessment) {
        canRemovePublishedAssessments = Boolean.TRUE;
      } else {
        canRemovePublishedAssessments = Boolean.FALSE;
      }
    }

    return canRemovePublishedAssessments;
  }
  public void processAction(ActionEvent ae) throws AbortProcessingException {
    FacesContext context = FacesContext.getCurrentInstance();

    // #1 - read the assessmentId from the form
    String publishedAssessmentId =
        (String)
            FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRequestParameterMap()
                .get("publishedAssessmentId");
    log.debug("publishedAssessmentId = " + publishedAssessmentId);

    // #2 -  and use it to set author bean, goto removeAssessment.jsp
    PublishedAssessmentBean publishedAssessmentBean =
        (PublishedAssessmentBean) ContextUtil.lookupBean("publishedassessment");

    PublishedAssessmentService publishedAssessmentService = new PublishedAssessmentService();
    PublishedAssessmentFacade publishedAssessment =
        publishedAssessmentService.getPublishedAssessmentInfoForRemove(
            Long.valueOf(publishedAssessmentId));
    if (publishedAssessment != null) {
      // #3 - permission checking before proceeding - daisyf
      AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author");

      AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization");
      if (!authzBean.isUserAllowedToDeleteAssessment(
          publishedAssessmentId, publishedAssessment.getCreatedBy(), true)) {
        String err =
            (String)
                ContextUtil.getLocalizedString(
                    "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
                    "denied_delete_other_members_assessment_error");
        context.addMessage(null, new FacesMessage(err));
        author.setOutcome("author");
        return;
      }

      author.setOutcome("confirmRemovePublishedAssessment");

      publishedAssessmentBean.setAssessmentId(publishedAssessmentId);
      publishedAssessmentBean.setTitle(
          FormattedText.convertFormattedTextToPlaintext(publishedAssessment.getTitle()));
    } else {
      log.warn("publishedAssessment is null");
    }
  }
예제 #6
0
  public void processAction(ActionEvent ae) throws AbortProcessingException {
    FacesContext context = FacesContext.getCurrentInstance();
    // Map reqMap = context.getExternalContext().getRequestMap();
    // Map requestParams = context.getExternalContext().getRequestParameterMap();

    AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
    String assessmentId = assessmentBean.getAssessmentId();

    SectionBean sectionBean = (SectionBean) ContextUtil.lookupBean("sectionBean");
    // create an assessment based on the title entered and the assessment
    // template selected
    // #1 - read from form editpart.jsp
    String title =
        TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getSectionTitle())
            .trim();
    if (title == null || title.equals("")) {
      String err =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "empty_part_title_error");
      context.addMessage(null, new FacesMessage(err));
      sectionBean.setOutcome("editPart");
      return;
    }

    String description = sectionBean.getSectionDescription();
    String sectionId = sectionBean.getSectionId();

    AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author");
    isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow();

    // #1a. prepare sectionBean
    AssessmentService assessmentService = null;
    SectionFacade section = null;

    // permission check
    String creator;
    if (isEditPendingAssessmentFlow) {
      assessmentService = new AssessmentService();
      AssessmentFacade af = assessmentService.getBasicInfoOfAnAssessment(assessmentId);
      creator = af.getCreatedBy();
    } else {
      PublishedAssessmentService pubService = new PublishedAssessmentService();
      assessmentService = pubService;
      PublishedAssessmentFacade paf = pubService.getSettingsOfPublishedAssessment(assessmentId);
      creator = paf.getCreatedBy();
    }

    AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization");
    if (!authzBean.isUserAllowedToEditAssessment(
        assessmentId, creator, !isEditPendingAssessmentFlow)) {
      String err =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages",
              "denied_edit_assessment_error");
      context.addMessage(null, new FacesMessage(err));
      sectionBean.setOutcome("editPart");
      return;
    }

    if (isEditPendingAssessmentFlow) {
      EventTrackingService.post(
          EventTrackingService.newEvent(
              "sam.assessment.revise",
              "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId,
              true));
    } else {
      EventTrackingService.post(
          EventTrackingService.newEvent(
              "sam.pubassessment.revise",
              "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId,
              true));
    }

    boolean addItemsFromPool = false;

    sectionBean.setOutcome("editAssessment");

    if ((sectionBean.getType().equals("2")) && (sectionBean.getSelectedPool().equals(""))) {

      String selectedPool_err =
          ContextUtil.getLocalizedString(
              "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "selectedPool_error");
      context.addMessage(null, new FacesMessage(selectedPool_err));
      sectionBean.setOutcome("editPart");
      return;
    }

    if (isEditPendingAssessmentFlow
        && !("".equals(sectionBean.getType()))
        && ((SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL.toString())
            .equals(sectionBean.getType()))) {
      addItemsFromPool = true;

      if (validateItemsDrawn(sectionBean)) {
        section = getOrAddSection(assessmentService, assessmentId, sectionId);
      } else {
        sectionBean.setOutcome("editPart");
        return;
      }
    } else {
      section = getOrAddSection(assessmentService, assessmentId, sectionId);
    }

    if (section == null) {
      log.info("section == null - Should not come to here. Simply return.");
      log.info("assessmentId =" + assessmentId);
      log.info("sectionId =" + sectionId);
      return;
    }
    log.debug("**** section title =" + section.getTitle());
    log.debug("**** title =" + title);

    // title, description, and question ordering are editable for both pending and publish
    // assessments
    if (title != null) section.setTitle(title);
    section.setDescription(description);
    if (!("".equals(sectionBean.getQuestionOrdering())))
      section.addSectionMetaData(
          SectionDataIfc.QUESTIONS_ORDERING, sectionBean.getQuestionOrdering());

    if (isEditPendingAssessmentFlow) {
      if (!("".equals(sectionBean.getKeyword())))
        section.addSectionMetaData(
            SectionMetaDataIfc.KEYWORDS,
            TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getKeyword()));

      if (!("".equals(sectionBean.getObjective())))
        section.addSectionMetaData(
            SectionMetaDataIfc.OBJECTIVES,
            TextFormat.convertPlaintextToFormattedTextNoHighUnicode(
                log, sectionBean.getObjective()));

      if (!("".equals(sectionBean.getRubric())))
        section.addSectionMetaData(
            SectionMetaDataIfc.RUBRICS,
            TextFormat.convertPlaintextToFormattedTextNoHighUnicode(log, sectionBean.getRubric()));

      if (!("".equals(sectionBean.getType()))) {
        section.addSectionMetaData(SectionDataIfc.AUTHOR_TYPE, sectionBean.getType());
        if ((SectionDataIfc.RANDOM_DRAW_FROM_QUESTIONPOOL.toString())
            .equals(sectionBean.getType())) {
          if ((sectionBean.getNumberSelected() != null)
              && !("".equals(sectionBean.getNumberSelected()))) {
            section.addSectionMetaData(
                SectionDataIfc.NUM_QUESTIONS_DRAWN, sectionBean.getNumberSelected());
          }

          if (!("".equals(sectionBean.getSelectedPool()))) {
            section.addSectionMetaData(
                SectionDataIfc.POOLID_FOR_RANDOM_DRAW, sectionBean.getSelectedPool());
            String poolname = "";
            QuestionPoolService qpservice = new QuestionPoolService();
            QuestionPoolFacade poolfacade =
                qpservice.getPool(
                    new Long(sectionBean.getSelectedPool()), AgentFacade.getAgentString());
            if (poolfacade != null) {
              poolname = poolfacade.getTitle();
            }
            section.addSectionMetaData(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW, poolname);
          }

          section.addSectionMetaData(
              SectionDataIfc.RANDOMIZATION_TYPE, sectionBean.getRandomizationType());
        }
      }

      if (addItemsFromPool) {
        boolean hasRandomPartScore = false;
        Double score = null;
        String requestedScore = sectionBean.getRandomPartScore();
        if (requestedScore != null && !requestedScore.equals("")) {
          hasRandomPartScore = true;
          score = new Double(requestedScore);
        }
        boolean hasRandomPartDiscount = false;
        Double discount = null;
        String requestedDiscount = sectionBean.getRandomPartDiscount();
        if (requestedDiscount != null && !requestedDiscount.equals("")) {
          hasRandomPartDiscount = true;
          discount = new Double(requestedDiscount);
        }

        if (hasRandomPartScore && score != null) {
          section.addSectionMetaData(SectionDataIfc.POINT_VALUE_FOR_QUESTION, score.toString());
        } else {
          section.addSectionMetaData(SectionDataIfc.POINT_VALUE_FOR_QUESTION, "");
        }

        if (hasRandomPartDiscount && discount != null) {
          section.addSectionMetaData(
              SectionDataIfc.DISCOUNT_VALUE_FOR_QUESTION, discount.toString());
        } else {
          section.addSectionMetaData(SectionDataIfc.DISCOUNT_VALUE_FOR_QUESTION, "");
        }
      }
    }

    assessmentService.saveOrUpdateSection(section);

    if (addItemsFromPool) {
      // update random questions from question pool
      int success =
          assessmentService.updateRandomPoolQuestions(
              assessmentService.getSection(section.getSectionId().toString()));
      if (success != AssessmentService.UPDATE_SUCCESS) {
        if (success == AssessmentService.UPDATE_ERROR_DRAW_SIZE_TOO_LARGE) {
          // shouldn't get here since there is a check, but might as well verify
          String err =
              ContextUtil.getLocalizedString(
                  "org.sakaiproject.tool.assessment.bundle.AuthorMessages", "qdrawn_error");
          context.addMessage(
              null,
              new FacesMessage(
                  err
                      + " "
                      + section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN)));
        }
      }
    }

    // added by daisyf, 10/10/06
    updateAttachment(
        section.getSectionAttachmentList(), sectionBean.getAttachmentList(), section.getData());

    // #2 - goto editAssessment.jsp, so reset assessmentBean
    AssessmentIfc assessment =
        assessmentService.getAssessment(Long.valueOf(assessmentBean.getAssessmentId()));
    assessmentBean.setAssessment(assessment);
    assessmentService.updateAssessmentLastModifiedInfo(assessment);

    EventTrackingService.post(
        EventTrackingService.newEvent(
            "sam.assessment.revise",
            "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + section.getSectionId(),
            true));
  }
예제 #7
0
  /** delete specified Item */
  public String deleteItem() {
    ItemService delegate = new ItemService();
    Long deleteId = this.getItemToDelete().getItemId();
    ItemFacade itemf = delegate.getItem(deleteId, AgentFacade.getAgentString());
    // save the currSection before itemf.setSection(null), used to reorder question sequences
    SectionFacade currSection = (SectionFacade) itemf.getSection();
    Integer currSeq = itemf.getSequence();

    QuestionPoolService qpdelegate = new QuestionPoolService();
    if (qpdelegate.getPoolIdsByItem(deleteId.toString()) == null
        || qpdelegate.getPoolIdsByItem(deleteId.toString()).isEmpty()) {
      // if no reference to this item at all, ie, this item is created in assessment but not
      // assigned to any pool

      AuthorizationBean authzBean = (AuthorizationBean) ContextUtil.lookupBean("authorization");
      AssessmentService assessdelegate = new AssessmentService();
      AssessmentFacade af =
          assessdelegate.getBasicInfoOfAnAssessmentFromSectionId(currSection.getSectionId());
      if (!authzBean.isUserAllowedToEditAssessment(
          af.getAssessmentBaseId().toString(), af.getCreatedBy(), false)) {
        throw new IllegalArgumentException(
            "User does not have permission to delete item in assessment: "
                + af.getAssessmentBaseId());
      }

      delegate.deleteItem(deleteId, AgentFacade.getAgentString());
    } else {
      if (currSection == null) {
        // if this item is created from question pool
        QuestionPoolBean qpoolbean = (QuestionPoolBean) ContextUtil.lookupBean("questionpool");
        ItemFacade itemfacade = delegate.getItem(deleteId, AgentFacade.getAgentString());
        ArrayList items = new ArrayList();
        items.add(itemfacade);
        qpoolbean.setItemsToDelete(items);
        qpoolbean.removeQuestionsFromPool();
        return "editPool";
      } else {
        //
        // if some pools still reference to this item, ie, this item is
        // created in assessment but also assigned a a pool
        // then just set section = null
        itemf.setSection(null);
        delegate.saveItem(itemf);
      }
    }
    // An item has been deleted
    EventTrackingService.post(
        EventTrackingService.newEvent(
            "sam.assessment.item.delete",
            "/sam/" + AgentFacade.getCurrentSiteId() + "/removed itemId=" + deleteId,
            true));

    AssessmentService assessdelegate = new AssessmentService();
    // reorder item numbers

    SectionFacade sectfacade = assessdelegate.getSection(currSection.getSectionId().toString());
    Set itemset = sectfacade.getItemFacadeSet();
    // should be size-1 now.
    Iterator iter = itemset.iterator();
    while (iter.hasNext()) {
      ItemFacade itemfacade = (ItemFacade) iter.next();
      Integer itemfacadeseq = itemfacade.getSequence();
      if (itemfacadeseq.compareTo(currSeq) > 0) {
        itemfacade.setSequence(Integer.valueOf(itemfacadeseq.intValue() - 1));
        delegate.saveItem(itemfacade);
      }
    }

    //  go to editAssessment.jsp, need to first reset assessmentBean
    AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
    AssessmentFacade assessment = assessdelegate.getAssessment(assessmentBean.getAssessmentId());
    assessmentBean.setAssessment(assessment);
    assessdelegate.updateAssessmentLastModifiedInfo(assessment);
    // Assessment has been revised
    EventTrackingService.post(
        EventTrackingService.newEvent(
            "sam.asessment.revise",
            "/sam/"
                + AgentFacade.getCurrentSiteId()
                + "/removed itemId="
                + deleteId
                + "from assessmentId="
                + assessmentBean.getAssessmentId(),
            true));
    return "editAssessment";
  }