private void getSelectedItems() throws Exception {

    Map map =
        new HashMap(
            FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap());
    int nList = getSrchDocList().size();
    boolean docExists;
    for (int cnt = 0; cnt < nList; cnt++) {
      docExists = false;
      Object obj = map.get("exhibitSearch:srchDocs:" + cnt + ":docSelChkBox");
      if (obj != null) {
        String value = ((String[]) obj)[0];
        if (value.equalsIgnoreCase("true")) {
          if (getConsntOrder().getConsntOrdExhbts().size() > 0) {
            for (ConsntOrdExhbt exhbt : getConsntOrder().getConsntOrdExhbts()) {
              if (exhbt.getId().getRegDocEt().getRegDocId()
                  == srchDocList.get(cnt).getRegDocId().longValue()) {
                docExists = true;
                break;
              }
            }
          }
          if (!docExists) {
            this.addFileAsExhibit(srchDocList.get(cnt), null);
          }
        }
      }
    }
    //        return selDocs;
  }
 public void addExhibit() {
   editFlag = true;
   getReqMap().put("showEditPopup", true);
   setAddNewExhibits(true);
   ConsntOrdExhbt exhb = new ConsntOrdExhbt();
   exhb.setExhbtTpCd(new Long(Constants.SUPPORT_DOC));
   setSelectedExhibit(exhb);
 }
  private void refreshAttchLst() throws Exception {

    if (null != getConsntOrder()) {
      for (ConsntOrdExhbt exhibit : getConsntOrder().getConsntOrdExhbts()) {
        UtilityService.getUtilityService().refresh(exhibit.getId().getRegDocEt());
      }
    }
  }
  public void exhibitsList(Set exhbList) {
    actnKeys = new ArrayList();
    if (exhbList != null) {

      actnList = new ArrayList();
      List tempList = new ArrayList(exhbList);

      // renumbering of the itemSeqNo
      for (int i = 0; i < tempList.size(); i++) {
        ConsntOrdExhbt exhb = (ConsntOrdExhbt) tempList.get(i);
        actnList.add(exhb);
        // cmplncItemActn.setSeqNo(actnList.size() - i);
        actnKeys.add(new SelectItem(exhb.getSeqNo()));
      }
    }
  }
  private void uploadFiles() throws Exception {
    String tempDocIds = "";
    long regDocId = 0;
    DocumentService docSrvc = DocumentService.getDocumentService();

    for (ConsntOrdExhbt exhibit : getConsntOrder().getConsntOrdExhbts()) {
      if (exhibit.getId().getRegDocEt().isToBeUploaded()) {
        regDocId = exhibit.getId().getRegDocEt().getRegDocId();
        tempDocIds += regDocId + ",";
      }
    }

    if (tempDocIds.length() > 0) {
      tempDocIds = tempDocIds.substring(0, tempDocIds.lastIndexOf(","));
    }

    this.setDocStoreURL(docSrvc.getEcmURL());
    this.setDocIdStr(tempDocIds);
    this.setDbSource(docSrvc.getDataSource());
    this.setDbUserNm(docSrvc.getDBUserName());
    this.setDbPwd(docSrvc.getDBPassword());
  }
  public void save() throws Exception {
    ConsentOrderService consentOrderService = ConsentOrderService.getConsentOrderService();
    this.reOrderActnSet();
    int idx;
    consntOrder.getConsntOrdExhbts().clear();
    Iterator it = actnList.iterator();

    while (it.hasNext()) {

      ConsntOrdExhbt exhb = (ConsntOrdExhbt) it.next();
      idx = actnList.indexOf(exhb);
      exhb.setSeqNo(idx + 1);
      if (0 == exhb.getId().getRegDocEt().getUsrId()) {
        exhb.getId().getRegDocEt().setUsrId(usrBean.getUsrId());
      }
      consntOrder.getConsntOrdExhbts().add(exhb);
    }

    if (isUploadDocs()) {
      uploadFiles(); // first saving the documents and setting upload info
      setUploadFilesFlag(true);
    }
    for (ConsntOrdExhbt exhibit : getConsntOrder().getConsntOrdExhbts()) {
      if (exhibit.getId().getRegDocEt().isToBeUploaded()) {
        DocumentService.getDocumentService().saveNoCommit(exhibit.getId().getRegDocEt());
        exhibit.getId().getRegDocEt().setToBeUploaded(false);
      }
    }
    log.info("Saving  Exhibits to the Consent Order");
    consentOrderService.saveConsentOrder(consntOrder);
    this.setDocName("");
    this.setFileName("");
    this.setSelectedFileListSize(0);
    this.setPreviousSelFiles(0);
    this.setAddNewExhibits(false);
    if (!isUploadDocs()) {
      this.addMessage(FacesMessage.SEVERITY_INFO, " Exhibits Saved successfully.");
    }
  }
 public void deleteExhibit() {
   ConsentOrderService.getConsentOrderService()
       .removeExhibit(consntOrder, selectedExhibit.getSeqNo());
 }
  private String addFileAsExhibit(ImageInfoDTO srchDoc, String path) throws Exception {
    ConsntOrdExhbt consntOrdExhbt = null;
    ConsntOrdExhbtId consntOrdExhbtId = null;
    RegDocEt docEt;
    long docId = 0;
    Date currDt = new Date();
    String newFileNm = "";
    File file = null;
    boolean replaceIFSfile = false; // flag will be updated by a method in ERegII
    if (path != null) {
      path = path.trim();
      file = new File(path);
    }

    consntOrdExhbt = new ConsntOrdExhbt();
    consntOrdExhbtId = new ConsntOrdExhbtId();
    if (isDetachFlag()) {
      UtilityService.getUtilityService().copyProperties(consntOrdExhbt, getSelectedExhibit());
    } else {
      consntOrdExhbt.setExhbtDt(currDt);
    }

    UtilityService utilSrvc = new UtilityService();
    if (!replaceIFSfile) {
      docEt = new RegDocEt();
      docId = utilSrvc.getKey("reg_doc_id");
      docEt.setRegDocId(docId);
    } else {
      // replacing the file in the existing regDocEt
      docEt = getSelectedExhibit().getId().getRegDocEt();
    }
    if (srchDoc != null) {
      docEt = DocumentService.getDocumentService().getRegDocEt(srchDoc.getRegDocId());
    } else { // local files
      docEt.setAppNm("ereg");

      if (!replaceIFSfile) {
        //                docEt.setCmplncItemId(getCmplncItemId());
        //                docEt.setDocTpCd(82L);
        newFileNm =
            docEt.getRegDocId() + "." + UtilityService.getUtilityService().getFileExtension(path);
      }
      if (!replaceIFSfile) { // to be placed appropriately
        docEt.setFileNm(newFileNm);
      }
    }

    if (file != null) {
      docEt.setUsrFileNm(path);
      docEt.setToBeUploaded(true);
      docEt.setContentId("EREG_" + docEt.getRegDocId()); // added on 0824
    }

    consntOrdExhbtId.setCmplncItemId(getCmplncItemId());
    consntOrdExhbtId.setRegDocEt(docEt);
    consntOrdExhbt.setId(consntOrdExhbtId);
    if (!isDetachFlag()) {
      consntOrdExhbt.setExhbtTpCd(
          new Long(Constants.SUPPORT_DOC)); // default is the supportive document
      consntOrdExhbt.setSeqNo(nextSequenceNumber());
    }
    if (isAddNewExhibits()) {
      consntOrdExhbt.setExhbtTpCd(
          getSelectedExhibit().getExhbtTpCd()); // default is the supportive document
      consntOrdExhbt.setExhbtDsc(getSelectedExhibit().getExhbtDsc());
      consntOrdExhbt.setExhbtNm(getSelectedExhibit().getExhbtNm());
    }
    if (srchDoc != null) {
      //            if (srchDoc.getDocCd() != null){ // docCd not available always and instead Image
      // Type is used.
      //                consntOrdExhbt.setExhbtDsc((String)tpCd.get(srchDoc.getDocCd()));
      //            }else{
      consntOrdExhbt.setExhbtDsc(srchDoc.getImageType() + "-" + srchDoc.getDocName());
      //            }
    }

    //        log.info("before "+consntOrder.getConsntOrdExhbts().size());
    if (isDetachFlag() && !replaceIFSfile) {
      deleteExhibit();
      setDetachFlag(false);
    }
    getConsntOrder().getConsntOrdExhbts().add(consntOrdExhbt);
    //        log.info("after "+consntOrder.getConsntOrdExhbts().size());

    return newFileNm;
  }
 public int compare(ConsntOrdExhbt firstExhb, ConsntOrdExhbt secondExhb) {
   return Long.valueOf(firstExhb.getSeqNo()).compareTo(Long.valueOf(secondExhb.getSeqNo()));
 }