예제 #1
0
  /* called by SamigoJsfTool.java on exit from file picker */
  public void setItemAttachment() {
    AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author");
    boolean isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow();
    ItemService service = null;
    if (isEditPendingAssessmentFlow) {
      service = new ItemService();
    } else {
      service = new PublishedItemService();
    }
    ItemDataIfc itemData = null;
    // itemId == null => new questiion
    if (this.itemId != null) {
      try {
        itemData = service.getItem(this.itemId);
      } catch (Exception e) {
        log.warn(e.getMessage());
      }
    }

    // list returns contains modified list of attachments, i.e. new
    // and old attachments. This list will be
    // persisted to DB if user hit Save on the Item Modifying page.
    List list = prepareItemAttachment(itemData, isEditPendingAssessmentFlow);
    setAttachmentList(list);
  }
예제 #2
0
  public void processAction(ActionEvent ae) throws AbortProcessingException {
    AssessmentBean assessmentBean = (AssessmentBean) ContextUtil.lookupBean("assessmentBean");
    SectionBean sectionBean = (SectionBean) ContextUtil.lookupBean("sectionBean");
    String sectionId =
        (String)
            FacesContext.getCurrentInstance()
                .getExternalContext()
                .getRequestParameterMap()
                .get("sectionId");

    if (sectionId != null) {
      sectionBean.setSectionId(sectionId);
    } else {
      // i am afraid on returning from removal, EditPartListener is accled to
      // to re-populate the part
      // so i can't read sectionId from a form. - daisyf
      sectionId = sectionBean.getSectionId();
    }
    AuthorBean author = (AuthorBean) ContextUtil.lookupBean("author");
    isEditPendingAssessmentFlow = author.getIsEditPendingAssessmentFlow();

    // log.info("**SectionId = "+sectionId);
    // #1a. prepare sectionBean
    AssessmentService assessmentService = null;
    SectionFacade section = null;
    if (isEditPendingAssessmentFlow) {
      EventTrackingService.post(
          EventTrackingService.newEvent(
              "sam.assessment.revise",
              "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId,
              true));
      assessmentService = new AssessmentService();
    } else {
      EventTrackingService.post(
          EventTrackingService.newEvent(
              "sam.pubassessment.revise",
              "siteId=" + AgentFacade.getCurrentSiteId() + ", sectionId=" + sectionId,
              true));
      assessmentService = new PublishedAssessmentService();
    }
    section = assessmentService.getSection(sectionId);
    section.setAssessment(assessmentBean.getAssessment());
    sectionBean.setSection(section);
    sectionBean.setSectionTitle(FormattedText.convertFormattedTextToPlaintext(section.getTitle()));
    sectionBean.setSectionDescription(section.getDescription());

    sectionBean.setNoOfItems(String.valueOf(section.getItemSet().size()));
    populateMetaData(section, sectionBean);

    // todo: get poolsavailable and then add the current pool used, because we need to show it as
    // one of the choices.

    /* Huong moved to getPoolsAvailable in SectionBean.java
        ArrayList poolidlist = sectionBean.getPoolsAvailable();
          String currpoolid= sectionBean.getSelectedPool();   // current pool used for random draw
        if (!("".equals(currpoolid)) && (currpoolid !=null)) {
    	//System.out.println("current pool id not null or empty");
        //now we need to get the poolid and displayName
          QuestionPoolService delegate = new QuestionPoolService();//
          QuestionPoolFacade pool= delegate.getPool(new Long(currpoolid), AgentFacade.getAgentString());//
        // now add the current pool used  to the list, so it's available in the pulldown
          poolidlist.add(new SelectItem((pool.getQuestionPoolId().toString()), pool.getDisplayName()));//
          //System.out.println("added editing pool: "+ pool.getDisplayName());//
          sectionBean.setPoolsAvailable(poolidlist);//
        }
    */

    boolean hideRandom = false;
    if ((sectionBean.getType() == null)
        || sectionBean.getType().equals(SectionDataIfc.QUESTIONS_AUTHORED_ONE_BY_ONE.toString())) {
      int itemsize = Integer.parseInt(sectionBean.getNoOfItems());
      if (itemsize > 0) {
        hideRandom = true;
      }
    }
    sectionBean.setHideRandom(hideRandom);
  }
예제 #3
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));
  }