Example #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);
  }
Example #2
0
  public String confirmDeleteItem() {

    ItemService delegate = new ItemService();
    String itemId = ContextUtil.lookupParam("itemid");

    ItemFacade itemf = delegate.getItem(Long.valueOf(itemId), AgentFacade.getAgentString());
    setItemToDelete(itemf);

    return "removeQuestion";
  }
Example #3
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";
  }