コード例 #1
0
  public ExtendedTimeService(PublishedAssessmentFacade publishedAssessment) {
    PublishedAssessmentService assessmentService = new PublishedAssessmentService();
    PublishedAssessmentFacade metaPublishedAssessment =
        assessmentService.getPublishedAssessmentQuick(
            publishedAssessment.getPublishedAssessmentId().toString());
    if (!assessmentInitialized(publishedAssessment)) {
      publishedAssessment = metaPublishedAssessment;
    }
    authzGroupService = ComponentManager.get(AuthzGroupService.class);

    // Grab the site id from the publishedAssessment because the user may
    // not be in a site
    // if they're taking the test via url.
    PublishedAssessmentService publishedAssessmentService = new PublishedAssessmentService();
    String pubId = publishedAssessment.getPublishedAssessmentId().toString();
    siteId = publishedAssessmentService.getPublishedAssessmentSiteId(pubId);

    this.metaString = extractMetaString(metaPublishedAssessment);
    this.hasExtendedTime = (metaString != null);
    if (this.hasExtendedTime) {
      this.timeLimit = extractExtendedTime();
      this.startDate = determineDate(1, publishedAssessment.getStartDate(), publishedAssessment);
      this.dueDate = determineDate(2, publishedAssessment.getDueDate(), publishedAssessment);
      this.retractDate =
          determineDate(3, publishedAssessment.getRetractDate(), publishedAssessment);
    } else {
      this.timeLimit = 0;
      this.startDate = publishedAssessment.getStartDate();
      this.dueDate = publishedAssessment.getDueDate();
      this.retractDate = publishedAssessment.getRetractDate();
    }
  }
コード例 #2
0
  /**
   * 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
  /**
   * Update the grading of the assessment.
   *
   * @param ag the assessment grading.
   * @param g the Gradebook Service
   * @throws java.lang.Exception
   */
  public void updateExternalAssessmentScore(AssessmentGradingIfc ag, GradebookService g)
      throws Exception {
    boolean testErrorHandling = false;
    // log.info("GradebookService instance=" + g);
    PublishedAssessmentService pubService = new PublishedAssessmentService();
    GradingService gradingService = new GradingService();
    PublishedAssessmentIfc pub =
        (PublishedAssessmentIfc)
            gradingService.getPublishedAssessmentByAssessmentGradingId(
                ag.getAssessmentGradingId().toString());

    String gradebookUId = pubService.getPublishedAssessmentOwner(pub.getPublishedAssessmentId());
    if (gradebookUId == null) {
      return;
    }

    // SAM-1562 We need to round the float score and covert to a double -DH
    float fScore = MathUtils.round(ag.getFinalScore(), 2);
    Double score = Float.valueOf(fScore).doubleValue();
    log.info("rounded:  " + ag.getFinalScore() + " to: " + score.toString());
    g.updateExternalAssessmentScore(
        gradebookUId, ag.getPublishedAssessmentId().toString(), ag.getAgentId(), score);
    if (testErrorHandling) {
      throw new Exception("Encountered an error in update ExternalAssessmentScore.");
    }
  }
コード例 #4
0
 private void setMaxDisplayedScoreRows(QuestionScoresBean bean, boolean isValueChange) {
   PublishedAssessmentService pubService = new PublishedAssessmentService();
   String itemId = ContextUtil.lookupParam("itemId");
   if (ContextUtil.lookupParam("newItemId") != null
       && !ContextUtil.lookupParam("newItemId").trim().equals("")) {
     itemId = ContextUtil.lookupParam("newItemId");
   }
   Long itemType = pubService.getItemType(itemId);
   // For audiio question, default the paging number to 5
   if (isValueChange) {
     if (itemType.equals(Long.valueOf("7"))) {
       bean.setAudioMaxDisplayedScoreRows(bean.getMaxDisplayedRows());
       bean.setHasAudioMaxDisplayedScoreRowsChanged(true);
     } else {
       bean.setOtherMaxDisplayedScoreRows(bean.getMaxDisplayedRows());
     }
   } else {
     if (itemType.equals(Long.valueOf("7"))) {
       if (bean.getHasAudioMaxDisplayedScoreRowsChanged()) {
         bean.setMaxDisplayedRows(bean.getAudioMaxDisplayedScoreRows());
       } else {
         bean.setMaxDisplayedRows(5);
         bean.setAudioMaxDisplayedScoreRows(5);
       }
     } else {
       bean.setMaxDisplayedRows(bean.getOtherMaxDisplayedScoreRows());
     }
   }
 }
コード例 #5
0
  public void updateExternalAssessmentScores(
      Long publishedAssessmentId, final Map studentUidsToScores, GradebookService g)
      throws Exception {
    boolean testErrorHandling = false;
    PublishedAssessmentService pubService = new PublishedAssessmentService();
    String gradebookUId = pubService.getPublishedAssessmentOwner(publishedAssessmentId);
    if (gradebookUId == null) {
      return;
    }
    g.updateExternalAssessmentScores(
        gradebookUId, publishedAssessmentId.toString(), studentUidsToScores);

    if (testErrorHandling) {
      throw new Exception("Encountered an error in update ExternalAssessmentScore.");
    }
  }
  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");
    }
  }
コード例 #7
0
  private void populateSections(
      PublishedAssessmentIfc publishedAssessment,
      QuestionScoresBean bean,
      TotalScoresBean totalBean,
      ArrayList scores,
      PublishedAssessmentService pubService) {
    ArrayList sections = new ArrayList();
    log.debug(
        "questionScores(): populate sctions publishedAssessment.getSectionArraySorted size = "
            + publishedAssessment.getSectionArraySorted().size());
    Iterator iter = publishedAssessment.getSectionArraySorted().iterator();
    int i = 1;
    while (iter.hasNext()) {
      SectionDataIfc section = (SectionDataIfc) iter.next();
      ArrayList items = new ArrayList();
      PartData part = new PartData();
      boolean isRandomDrawPart =
          pubService.isRandomDrawPart(
              publishedAssessment.getPublishedAssessmentId(), section.getSectionId());
      part.setIsRandomDrawPart(isRandomDrawPart);
      part.setPartNumber("" + i);
      part.setId(section.getSectionId().toString());

      if (isRandomDrawPart) {
        if (section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN) != null) {
          int numberToBeDrawn =
              Integer.parseInt(
                  section.getSectionMetaDataByLabel(SectionDataIfc.NUM_QUESTIONS_DRAWN));
          part.setNumberQuestionsDraw(numberToBeDrawn);
        }
        PublishedAssessmentService publishedAssessmentService = new PublishedAssessmentService();
        HashSet itemSet =
            publishedAssessmentService.getPublishedItemSet(
                publishedAssessment.getPublishedAssessmentId(), section.getSectionId());
        section.setItemSet(itemSet);
      } else {
        GradingService gradingService = new GradingService();
        HashSet itemSet =
            gradingService.getItemSet(
                publishedAssessment.getPublishedAssessmentId(), section.getSectionId());
        section.setItemSet(itemSet);
      }
      Iterator iter2 = section.getItemArraySortedForGrading().iterator();
      int j = 1;
      while (iter2.hasNext()) {
        ItemDataIfc item = (ItemDataIfc) iter2.next();
        PartData partitem = new PartData();

        partitem.setPartNumber("" + j);
        partitem.setId(item.getItemId().toString());
        log.debug("*   item.getId = " + item.getItemId());
        partitem.setLinked(true);

        // Iterator iter3 = scores.iterator();
        items.add(partitem);
        j++;
      }
      log.debug("questionScores(): items size = " + items.size());
      part.setQuestionNumberList(items);
      sections.add(part);
      i++;
    }
    log.debug("questionScores(): sections size = " + sections.size());
    bean.setSections(sections);
  }
コード例 #8
0
  /**
   * This will populate the QuestionScoresBean with the data associated with the particular
   * versioned assessment based on the publishedId.
   *
   * @todo Some of this code will change when we move this to Hibernate persistence.
   * @param publishedId String
   * @param bean QuestionScoresBean
   * @return boolean
   */
  public boolean questionScores(
      String publishedId, QuestionScoresBean bean, boolean isValueChange) {
    log.debug("questionScores()");
    try {
      PublishedAssessmentService pubService = new PublishedAssessmentService();
      PublishedItemService pubItemService = new PublishedItemService();
      // get the PublishedAssessment based on publishedId
      QuestionScoresBean questionBean =
          (QuestionScoresBean) ContextUtil.lookupBean("questionScores");
      PublishedAssessmentIfc publishedAssessment = questionBean.getPublishedAssessment();
      if (publishedAssessment == null) {
        publishedAssessment = pubService.getPublishedAssessment(publishedId);
        questionBean.setPublishedAssessment(publishedAssessment);
      }
      // build a hashMap (publishedItemId, publishedItem)
      HashMap publishedItemHash = pubService.preparePublishedItemHash(publishedAssessment);
      log.debug("questionScores(): publishedItemHash.size = " + publishedItemHash.size());
      // build a hashMap (publishedItemTextId, publishedItemText)
      HashMap publishedItemTextHash = pubService.preparePublishedItemTextHash(publishedAssessment);
      log.debug("questionScores(): publishedItemTextHash.size = " + publishedItemTextHash.size());
      HashMap publishedAnswerHash = pubService.preparePublishedAnswerHash(publishedAssessment);
      // re-attach session and load all lazy loaded parent/child stuff

      //			Set<Long> publishedAnswerHashKeySet = publishedAnswerHash.keySet();
      //
      //			for (Long key : publishedAnswerHashKeySet) {
      //				AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(key);
      //
      //				if (!Hibernate.isInitialized(answer.getChildAnswerSet())) {
      //					pubItemService.eagerFetchAnswer(answer);
      //				}
      //			}
      log.debug("questionScores(): publishedAnswerHash.size = " + publishedAnswerHash.size());
      HashMap agentResultsByItemGradingIdMap = new HashMap();

      GradingService delegate = new GradingService();

      TotalScoresBean totalBean = (TotalScoresBean) ContextUtil.lookupBean("totalScores");

      if (ContextUtil.lookupParam("sortBy") != null
          && !ContextUtil.lookupParam("sortBy").trim().equals(""))
        bean.setSortType(ContextUtil.lookupParam("sortBy"));

      String itemId = ContextUtil.lookupParam("itemId");
      if (ContextUtil.lookupParam("newItemId") != null
          && !ContextUtil.lookupParam("newItemId").trim().equals("")
          && !ContextUtil.lookupParam("newItemId").trim().equals("null"))
        itemId = ContextUtil.lookupParam("newItemId");

      if (ContextUtil.lookupParam("sortAscending") != null
          && !ContextUtil.lookupParam("sortAscending").trim().equals("")) {
        bean.setSortAscending(
            Boolean.valueOf(ContextUtil.lookupParam("sortAscending")).booleanValue());
      }

      String which = bean.getAllSubmissions();
      if (which == null && totalBean.getAllSubmissions() != null) {
        // use totalscore's selection
        which = totalBean.getAllSubmissions();
        bean.setAllSubmissions(which);
      }

      totalBean.setSelectedSectionFilterValue(
          bean.getSelectedSectionFilterValue()); // set section pulldown

      if (bean.getSelectedSARationaleView() == null) {
        // if bean.showSARationaleInLine is null, then set inline to be
        // the default
        bean.setSelectedSARationaleView(QuestionScoresBean.SHOW_SA_RATIONALE_RESPONSES_INLINE);
      }

      if ("true".equalsIgnoreCase(totalBean.getAnonymous())) {
        boolean groupRelease =
            publishedAssessment
                .getAssessmentAccessControl()
                .getReleaseTo()
                .equals(AssessmentAccessControl.RELEASE_TO_SELECTED_GROUPS);
        if (groupRelease) {
          totalBean.setSelectedSectionFilterValue(
              TotalScoresBean.RELEASED_SECTIONS_GROUPS_SELECT_VALUE);
        } else {
          totalBean.setSelectedSectionFilterValue(TotalScoresBean.ALL_SECTIONS_SELECT_VALUE);
        }
      }

      bean.setPublishedId(publishedId);
      Date dueDate = null;

      HashMap map =
          getItemScores(Long.valueOf(publishedId), Long.valueOf(itemId), which, isValueChange);
      log.debug("questionScores(): map .size = " + map.size());
      ResourceLoader rb = null;
      ArrayList allscores = new ArrayList();
      Iterator keyiter = map.keySet().iterator();
      while (keyiter.hasNext()) {
        allscores.addAll((ArrayList) map.get(keyiter.next()));
      }

      log.debug("questionScores(): allscores.size = " + allscores.size());

      // /

      // now we need filter by sections selected
      ArrayList scores = new ArrayList(); // filtered list
      Map useridMap = totalBean.getUserIdMap(TotalScoresBean.CALLED_FROM_QUESTION_SCORE_LISTENER);
      bean.setUserIdMap(useridMap);
      log.debug("questionScores(): useridMap.size = " + useridMap.size());

      /*
       * if ("true".equalsIgnoreCase(totalBean.getAnonymous())){ // skip
       * section filter if it is anonymous grading, SAK-4395,
       * scores.addAll(allscores); }
       */
      if (totalBean.getReleaseToAnonymous()) {
        // skip section filter if it's published to anonymous users
        scores.addAll(allscores);
      } else {
        Iterator allscores_iter = allscores.iterator();
        // get the Map of all users(keyed on userid) belong to the
        // selected sections
        while (allscores_iter.hasNext()) {
          // AssessmentGradingData data = (AssessmentGradingData)
          // allscores_iter.next();
          ItemGradingData idata = (ItemGradingData) allscores_iter.next();
          // String agentid =
          // idata.getAssessmentGrading().getAgentId();
          String agentid = idata.getAgentId();
          // now we only include scores of users belong to the
          // selected sections
          if (useridMap.containsKey(agentid)) {
            scores.add(idata);
          }
        }
      }

      log.debug("questionScores(): scores.size = " + scores.size());

      Iterator iter = scores.iterator();
      ArrayList agents = new ArrayList();

      log.debug("questionScores(): calling populateSections ");

      populateSections(
          publishedAssessment, bean, totalBean, scores, pubService); // set up the Q1, Q2... links
      if (!iter.hasNext()) {
        // this section has no students
        log.debug("questionScores(): this section has no students");
        bean.setAgents(agents);
        bean.setAllAgents(agents);
        bean.setTotalPeople(Integer.toString(bean.getAgents().size()));
        bean.setAnonymous(totalBean.getAnonymous());
        // return true;
      }

      // List them by item and assessmentgradingid, so we can
      // group answers by item and save them for update use.

      HashMap scoresByItem = new HashMap();
      while (iter.hasNext()) {
        ItemGradingData idata = (ItemGradingData) iter.next();
        ItemTextIfc pubItemText =
            (ItemTextIfc) publishedItemTextHash.get(idata.getPublishedItemTextId());
        AnswerIfc pubAnswer = (AnswerIfc) publishedAnswerHash.get(idata.getPublishedAnswerId());

        ArrayList temp =
            (ArrayList)
                scoresByItem.get(idata.getAssessmentGradingId() + ":" + idata.getPublishedItemId());
        if (temp == null) temp = new ArrayList();

        // Very small numbers, so bubblesort is fast
        Iterator iter2 = temp.iterator();
        ArrayList newList = new ArrayList();
        boolean added = false;
        while (iter2.hasNext()) {
          ItemGradingData tmpData = (ItemGradingData) iter2.next();
          ItemTextIfc tmpPublishedText =
              (ItemTextIfc) publishedItemTextHash.get(tmpData.getPublishedItemTextId());
          AnswerIfc tmpAnswer = (AnswerIfc) publishedAnswerHash.get(tmpData.getPublishedAnswerId());

          if (pubAnswer != null
              && tmpAnswer != null
              && !added
              && (pubItemText.getSequence().intValue() < tmpPublishedText.getSequence().intValue()
                  || (pubItemText.getSequence().intValue()
                          == tmpPublishedText.getSequence().intValue()
                      && pubAnswer.getSequence().intValue()
                          < tmpAnswer.getSequence().intValue()))) {
            newList.add(idata);
            added = true;
          }
          newList.add(tmpData);
        }
        if (!added) newList.add(idata);
        scoresByItem.put(
            idata.getAssessmentGradingId() + ":" + idata.getPublishedItemId(), newList);
      }
      log.debug("questionScores(): scoresByItem.size = " + scoresByItem.size());
      bean.setScoresByItem(scoresByItem);

      try {
        bean.setAnonymous(
            publishedAssessment
                    .getEvaluationModel()
                    .getAnonymousGrading()
                    .equals(EvaluationModel.ANONYMOUS_GRADING)
                ? "true"
                : "false");
      } catch (RuntimeException e) {
        // log.info("No evaluation model.");
        bean.setAnonymous("false");
      }

      // below properties don't seem to be used in jsf pages,
      try {
        bean.setLateHandling(
            publishedAssessment.getAssessmentAccessControl().getLateHandling().toString());
      } catch (Exception e) {
        // log.info("No access control model.");
        bean.setLateHandling(AssessmentAccessControl.NOT_ACCEPT_LATE_SUBMISSION.toString());
      }
      try {
        bean.setDueDate(publishedAssessment.getAssessmentAccessControl().getDueDate().toString());
        dueDate = publishedAssessment.getAssessmentAccessControl().getDueDate();
      } catch (RuntimeException e) {
        // log.info("No due date.");
        bean.setDueDate(new Date().toString());
      }
      try {
        bean.setMaxScore(publishedAssessment.getEvaluationModel().getFixedTotalScore());
      } catch (RuntimeException e) {
        double score = (double) 0.0;
        Iterator iter2 = publishedAssessment.getSectionArraySorted().iterator();
        while (iter2.hasNext()) {
          SectionDataIfc sdata = (SectionDataIfc) iter2.next();
          Iterator iter3 = sdata.getItemArraySortedForGrading().iterator();
          while (iter3.hasNext()) {
            ItemDataIfc idata = (ItemDataIfc) iter3.next();
            if (idata.getItemId().equals(Long.valueOf(itemId)))
              score = idata.getScore().doubleValue();
          }
        }
        bean.setMaxScore(score);
      }

      // need to get id from somewhere else, not from data. data only
      // contains answered items , we want to return all items.
      // ItemDataIfc item = (ItemDataIfc) publishedItemHash.get(data.getPublishedItemId());
      ItemDataIfc item = (ItemDataIfc) publishedItemHash.get(Long.valueOf(itemId));

      if (item != null) {
        log.debug("item!=null steting type id = " + item.getTypeId().toString());
        bean.setTypeId(item.getTypeId().toString());
        bean.setItemId(item.getItemId().toString());
        bean.setPartName(item.getSection().getSequence().toString());
        bean.setItemName(item.getSequence().toString());
        item.setHint("***"); // Keyword to not show student answer
        // for short answer/ essey question, if there is a model short
        // answer for this question
        // set haveModelShortAnswer to true
        if (item.getTypeId().equals(Long.valueOf(5))) {
          Iterator iterator = publishedAnswerHash.values().iterator();
          while (iterator.hasNext()) {
            PublishedAnswer publishedAnswer = (PublishedAnswer) iterator.next();
            if (publishedAnswer.getItem().getItemId().equals(item.getItemId())) {
              if (publishedAnswer.getText() == null || publishedAnswer.getText().equals("")) {
                bean.setHaveModelShortAnswer(false);
              } else {
                bean.setHaveModelShortAnswer(true);
              }
              break;
            }
          }
        }
      } else {
        log.debug("item==null ");
      }

      ArrayList deliveryItems = new ArrayList(); // so we can use the var
      if (item != null) deliveryItems.add(item);
      bean.setDeliveryItem(deliveryItems);

      if (ContextUtil.lookupParam("roleSelection") != null) {
        bean.setRoleSelection(ContextUtil.lookupParam("roleSelection"));
      }

      if (bean.getSortType() == null) {
        if (bean.getAnonymous().equals("true")) {
          bean.setSortType("totalAutoScore");
        } else {
          bean.setSortType("lastName");
        }
      }

      // recordingData encapsulates the inbeanation needed for recording.
      // set recording agent, agent assessmentId,
      // set course_assignment_context value
      // set max tries (0=unlimited), and 30 seconds max length

      // String courseContext = bean.getAssessmentName() + " total ";

      // Note this is HTTP-centric right now, we can't use in Faces
      // AuthoringHelper authoringHelper = new AuthoringHelper();
      // authoringHelper.getRemoteUserID() needs servlet stuff
      // authoringHelper.getRemoteUserName() needs servlet stuff

      /* Dump the grading and agent information into AgentResults */
      iter = scoresByItem.values().iterator();
      while (iter.hasNext()) {
        AgentResults results = new AgentResults();
        // Get all the answers for this question to put in one grading
        // row
        ArrayList answerList = (ArrayList) iter.next();
        results.setItemGradingArrayList(answerList);

        Iterator iter2 = answerList.iterator();
        ArrayList itemGradingAttachmentList = new ArrayList();
        HashMap<Long, Set<String>> fibmap = new HashMap<Long, Set<String>>();
        while (iter2.hasNext()) {
          ItemGradingData gdata = (ItemGradingData) iter2.next();
          results.setItemGrading(gdata);
          itemGradingAttachmentList.addAll(gdata.getItemGradingAttachmentList());
          agentResultsByItemGradingIdMap.put(gdata.getItemGradingId(), results);

          ItemTextIfc gdataPubItemText =
              (ItemTextIfc) publishedItemTextHash.get(gdata.getPublishedItemTextId());
          AnswerIfc gdataAnswer = (AnswerIfc) publishedAnswerHash.get(gdata.getPublishedAnswerId());

          // This all just gets the text of the answer to display
          String answerText = noAnswer;
          String rationale = "";
          String fullAnswerText = noAnswer;

          // if question type = MC, MR, Survey, TF, Matching, if user
          // has not submit an answer
          // answerText = noAnswer. These question type do not use the
          // itemGrading.answerText field for
          // storing answers, thye use temGrading.publishedAnswerId to
          // make their selection
          if (bean.getTypeId().equals("1")
              || bean.getTypeId().equals("2")
              || bean.getTypeId().equals("12")
              || bean.getTypeId().equals("3")
              || bean.getTypeId().equals("4")
              || bean.getTypeId().equals("9")
              || bean.getTypeId().equals("13")) {
            if (gdataAnswer != null) answerText = gdataAnswer.getText();
          } else {
            // this handles the other question types: SAQ, File
            // upload, Audio, FIB, Fill in Numeric
            // These question type use itemGrading.answetText to
            // store information about their answer
            if ((bean.getTypeId().equals("8")
                    || bean.getTypeId().equals("11")
                    || bean.getTypeId().equals("14"))
                && gdataAnswer == null) {
              answerText = "";
            } else if (bean.getTypeId().equals("14")) { // gopalrc - EMI
              answerText = gdataPubItemText.getSequence() + ": " + gdataAnswer.getLabel();
            } else {
              answerText = gdata.getAnswerText();
            }
          }

          if ("4".equals(bean.getTypeId())) {
            if (rb == null) {
              rb = new ResourceLoader("org.sakaiproject.tool.assessment.bundle.EvaluationMessages");
            }
            if ("true".equals(answerText)) {
              answerText = rb.getString("true_msg");
            } else if ("false".equals(answerText)) {
              answerText = rb.getString("false_msg");
            }
          }

          if (bean.getTypeId().equals("9")) {
            if (gdataPubItemText == null) {
              // the matching pair is deleted
              answerText = "";
            } else {
              answerText = gdataPubItemText.getSequence() + ":" + answerText;
            }
          }

          if (bean.getTypeId().equals("8")) {
            if (gdataAnswer != null && gdataAnswer.getSequence() != null) {
              answerText = gdataAnswer.getSequence() + ":" + answerText;
            }
          }

          if (bean.getTypeId().equals("11")) {
            if (gdataAnswer != null && gdataAnswer.getSequence() != null) {
              answerText = gdataAnswer.getSequence() + ":" + answerText;
            }
          }
          if (bean.getTypeId().equals("13")) {
            if (gdataPubItemText == null) {
              answerText = "";
            } else {
              int answerNo = gdataPubItemText.getSequence().intValue();
              answerText = answerNo + ":" + answerText;
            }
          }
          // file upload
          if (bean.getTypeId().equals("6")) {
            gdata.setMediaArray(delegate.getMediaArray2(gdata.getItemGradingId().toString()));
          }

          // audio recording
          if (bean.getTypeId().equals("7")) {
            ArrayList mediaList = delegate.getMediaArray2(gdata.getItemGradingId().toString());
            setDurationIsOver(item, mediaList);
            gdata.setMediaArray(mediaList);
          }
          if (bean.getTypeId().equals("16")) {
            if (gdataPubItemText == null) {
              // the matching pair is deleted
              answerText = "";
            } else {
              answerText = gdataPubItemText.getSequence() + ":" + answerText;
            }
          }
          if (answerText == null) answerText = noAnswer;
          else {
            if (gdata.getRationale() != null && !gdata.getRationale().trim().equals(""))
              rationale = "\nRationale: " + gdata.getRationale();
          }
          // Huong's temp commandout
          // answerText = answerText.replaceAll("<.*?>", "");
          answerText = answerText.replaceAll("(\r\n|\r)", "<br/>");
          rationale = rationale.replaceAll("<.*?>", "");
          rationale = rationale.replaceAll("(\r\n|\r)", "<br/>");
          fullAnswerText = answerText; // this is the
          // non-abbreviated answers
          // for essay questions

          int answerTextLength =
              ServerConfigurationService.getInt("samigo.questionScore.answerText.length", 1000);
          if (bean.getTypeId().equals("5")) {
            answerTextLength = 35;
          }

          // Fix for SAK-6932: Strip out all HTML tags except image tags
          if (answerText.length() > answerTextLength) {
            String noHTMLAnswerText;
            noHTMLAnswerText = answerText.replaceAll("<((..?)|([^iI][^mM][^gG].*?))>", "");

            int index = noHTMLAnswerText.toLowerCase().indexOf("<img");
            if (index != -1) {
              answerText = noHTMLAnswerText;
            } else {
              if (noHTMLAnswerText.length() > answerTextLength) {
                answerText = noHTMLAnswerText.substring(0, answerTextLength) + "...";
              } else {
                answerText = noHTMLAnswerText;
              }
            }
          }
          /*
           * // no need to shorten it if (rationale.length() > 35)
           * rationale = rationale.substring(0, 35) + "...";
           */

          // SAM-755-"checkmark" indicates right, add "X" to indicate wrong
          if (gdataAnswer != null) {
            String checkmarkGif = "<img src='/samigo-app/images/delivery/checkmark.gif'>";
            String crossmarkGif = "<img src='/samigo-app/images/crossmark.gif'>";

            if (bean.getTypeId().equals("8") || bean.getTypeId().equals("11")) {
              answerText = FormattedText.escapeHtml(answerText, true);
              if (gdata.getIsCorrect() == null) {
                boolean result = false;
                if (bean.getTypeId().equals("8")) {
                  result = delegate.getFIBResult(gdata, fibmap, item, publishedAnswerHash);
                } else {
                  result = delegate.getFINResult(gdata, item, publishedAnswerHash);
                }

                if (result) {
                  answerText = checkmarkGif + answerText;
                } else {
                  answerText = crossmarkGif + answerText;
                }
              } else {
                if (gdata.getIsCorrect().booleanValue()) {
                  answerText = checkmarkGif + answerText;
                } else {
                  answerText = crossmarkGif + answerText;
                }
              }
            } else if (bean.getTypeId().equals("15")) { // CALCULATED_QUESTION
              answerText = FormattedText.escapeHtml(answerText, true);
              // need to do something here for fill in the blanks
              if (gdataAnswer.getScore() > 0) {
                // if score is 0, there is no way to tell if user got the correct answer
                // by using "autoscore"... wish there was a better way to tell if its correct or not
                Double autoscore = gdata.getAutoScore();
                if (!(Double.valueOf(0)).equals(autoscore)) {
                  answerText = checkmarkGif + answerText;
                } else if (Double.valueOf(0).equals(autoscore)) {
                  answerText = crossmarkGif + answerText;
                }
              }
            } else if (!bean.getTypeId().equals("3")) {
              if ((gdataAnswer.getIsCorrect() != null && gdataAnswer.getIsCorrect())
                  || (gdataAnswer.getPartialCredit() != null
                      && gdataAnswer.getPartialCredit() > 0)) {
                answerText = checkmarkGif + answerText;
              } else if (gdataAnswer.getIsCorrect() != null && !gdataAnswer.getIsCorrect()) {
                answerText = crossmarkGif + answerText;
              }
            }
          }

          // -- Got the answer text --
          if (!answerList.get(0).equals(gdata)) { // We already have
            // an agentResults
            // for this one
            results.setAnswer(results.getAnswer() + "<br/>" + answerText);
            if (gdata.getAutoScore() != null) {
              results.setTotalAutoScore(
                  Double.toString(
                      (Double.valueOf(results.getExactTotalAutoScore())).doubleValue()
                          + gdata.getAutoScore().doubleValue()));
            } else {
              results.setTotalAutoScore(
                  Double.toString(
                      (Double.valueOf(results.getExactTotalAutoScore())).doubleValue()));
            }
            results.setItemGradingAttachmentList(itemGradingAttachmentList);
          } else {
            results.setItemGradingId(gdata.getItemGradingId());
            results.setAssessmentGradingId(gdata.getAssessmentGradingId());
            if (gdata.getAutoScore() != null) {
              // for example, if an assessment has one fileupload
              // question, the autoscore = null
              results.setTotalAutoScore(gdata.getAutoScore().toString());
            } else {
              results.setTotalAutoScore(Double.toString(0));
            }
            results.setComments(FormattedText.convertFormattedTextToPlaintext(gdata.getComments()));
            results.setAnswer(answerText);
            results.setFullAnswer(fullAnswerText);
            results.setRationale(rationale);
            results.setSubmittedDate(gdata.getSubmittedDate());

            AgentFacade agent = new AgentFacade(gdata.getAgentId());
            // log.info("Rachel: agentid = " + gdata.getAgentId());
            results.setLastName(agent.getLastName());
            results.setFirstName(agent.getFirstName());
            results.setEmail(agent.getEmail());
            if (results.getLastName() != null && results.getLastName().length() > 0)
              results.setLastInitial(results.getLastName().substring(0, 1));
            else if (results.getFirstName() != null && results.getFirstName().length() > 0)
              results.setLastInitial(results.getFirstName().substring(0, 1));
            else results.setLastInitial("Anonymous");
            results.setIdString(agent.getIdString());
            results.setAgentEid(agent.getEidString());
            results.setAgentDisplayId(agent.getDisplayIdString());
            log.debug("testing agent getEid agent.getFirstname= " + agent.getFirstName());
            log.debug("testing agent getEid agent.getid= " + agent.getIdString());
            log.debug("testing agent getEid agent.geteid = " + agent.getEidString());
            log.debug(
                "testing agent getDisplayId agent.getdisplayid = " + agent.getDisplayIdString());

            results.setRole(agent.getRole());
            results.setItemGradingAttachmentList(itemGradingAttachmentList);
            agents.add(results);
          }
        }
      }

      // log.info("Sort type is " + bean.getSortType() + ".");
      bs = new BeanSort(agents, bean.getSortType());
      if ((bean.getSortType()).equals("assessmentGradingId")
          || (bean.getSortType()).equals("totalAutoScore")
          || (bean.getSortType()).equals("totalOverrideScore")
          || (bean.getSortType()).equals("finalScore")) {
        bs.toNumericSort();
      } else {
        bs.toStringSort();
      }

      if (bean.isSortAscending()) {
        log.debug("sortAscending");
        agents = (ArrayList) bs.sort();
      } else {
        log.debug("!sortAscending");
        agents = (ArrayList) bs.sortDesc();
      }

      // log.info("Listing agents.");
      bean.setAgents(agents);
      bean.setAllAgents(agents);
      bean.setTotalPeople(Integer.valueOf(bean.getAgents().size()).toString());
      bean.setAgentResultsByItemGradingId(agentResultsByItemGradingIdMap);
    } catch (RuntimeException e) {
      e.printStackTrace();
      return false;
    }

    return true;
  }
コード例 #9
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));
  }