Example #1
0
  public void execute(
      PluginNode pNode, DMConnection pCon, IDfPersistentObject[] pTargets, ALogger pLogger)
      throws Exception {

    for (int t = 0; t < pTargets.length; t++) {

      IDfSysObject obj = (IDfSysObject) pTargets[t];
      String id = obj.getObjectId().toString();
      String dql =
          "select f.dos_extension,f.name "
              + "FROM dm_sysobject (ALL) s, dmr_content r, dm_store t, dm_format f "
              + "WHERE r_object_id = ID('"
              + id
              + "') "
              + "AND ANY (parent_id=ID('"
              + id
              + "') AND page = 0) "
              + "AND r.storage_id=t.r_object_id "
              + "AND f.r_object_id=r.format";

      IDfQuery query = pCon.createQuery(dql);
      IDfCollection res = query.execute(pCon.getSession(), IDfQuery.READ_QUERY);

      while (res.next()) {

        try {
          String name = res.getString("name");
          pLogger.out.println(">>> " + name + "@" + ObjectTool.getName(obj));
          String ext = res.getString("dos_extension");
          ByteArrayInputStream stream = obj.getContentEx2(name, 0, null);
          String content = AFile.readFile(stream);
          stream.close();

          for (Enumeration i = properties.keys(); i.hasMoreElements(); ) {
            String key = (String) i.nextElement();
            content = content.replaceAll(key, properties.getProperty(key));
          }

          content = AFile.readFile(fileHeader) + content + AFile.readFile(fileFooter);

          File f =
              new File(
                  tmpDir,
                  obj.getObjectName()
                      + "_"
                      + obj.getString("language_code")
                      + "_"
                      + name
                      + "."
                      + ext);
          pLogger.out.println("--- WRITE: " + f.getAbsolutePath());
          AFile.writeFile(f, content);

        } catch (Exception e) {
          pLogger.out.println(e.toString());
        }
      }
      res.close();
    }
  }
 public IDfSysObject getFirstAttachment(IDfSessionManager sessionmgr, Map parameters)
     throws Exception {
   /*-CONFIG-*/ String m = "getFirstAttachment - ";
   /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
     DfLogger.debug(this, m + "get session", null, null);
   String docbase = ((String[]) parameters.get("docbase_name"))[0];
   IDfSession session = sessionmgr.getSession(docbase);
   /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
     DfLogger.debug(this, m + "get workitem interface", null, null);
   IDfWorkitem wi = getWorkitem(sessionmgr, parameters);
   /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
     DfLogger.debug(this, m + "iterate through packages", null, null);
   IDfCollection packages = wi.getPackages("");
   IDfSysObject pkg = null;
   if (packages.next()) {
     /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
       DfLogger.debug(
           this,
           m + "check if there are packages in the r_component_id multivalue attr",
           null,
           null);
     if (packages.getValueCount("r_component_id") > 0) {
       /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
         DfLogger.debug(this, m + "getting the first component id", null, null);
       IDfId id = packages.getRepeatingId("r_component_id", 0);
       /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
         DfLogger.debug(this, m + "retrieving component " + id, null, null);
       pkg = (IDfSysObject) session.getObject(id);
       /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
         DfLogger.debug(this, m + "component: " + pkg, null, null);
     }
   }
   packages.close();
   /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
     DfLogger.debug(this, m + "releasing session", null, null);
   sessionmgr.release(session);
   /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
     DfLogger.debug(this, m + "session released", null, null);
   return pkg;
 }
  public void convert() throws Exception {
    // EFS:
    //  r_current_state: 2 == In-Approval, so 3 == Approved, 4 == ?Effective?
    //  a_content_type = 'pdf'

    IDfSession session = null;
    IDfSessionManager sMgr = null;
    try {
      IDfClientX clientx = new DfClientX();

      IDfClient client = clientx.getLocalClient();

      sMgr = client.newSessionManager();

      IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
      loginInfoObj.setUser("mradmin");
      loginInfoObj.setPassword("mr2006");
      loginInfoObj.setDomain(null);

      sMgr.setIdentity("MRCS_Dev", loginInfoObj);
    } catch (DfException dfe) {
      dfe.printStackTrace();
    }

    // don't want to convert approved/effective copies...crap...
    //  - must not be in an "Approved" or "Effective" folder?

    // SELECT count(*) FROM m_mrcs_central_document WHERE a_content_type = 'pdf' AND any i_folder_id
    // NOT IN (SELECT r_object_id FROM dm_folder WHERE object_name = 'Effective');
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this)) DfLogger.debug(this, " ", null, null);

    session = sMgr.getSession("MRCS_Dev");

    // get list of objects that are pdfs...
    // - should try folder clauses too...
    // - previous versions????
    String pdfdocs =
        "SELECT r_object_id FROM m_mrcs_central_document WHERE a_content_type = 'pdf' and object_name like '--test--%'";

    IDfQuery qry = new DfQuery();
    qry.setDQL(pdfdocs);

    IDfCollection myObj1 = (IDfCollection) qry.execute(session, IDfQuery.DF_READ_QUERY);

    while (myObj1.next()) {
      sMgr.beginTransaction();
      try {
        String curid = myObj1.getString("r_object_id");
        // look up object
        IDfDocument doc = (IDfDocument) session.getObject(new DfId(curid));

        String objname = doc.getObjectName();
        String fullpath = doc.getPath(0);
        String format = doc.getFormat().getName();
        String doctype = doc.getTypeName();

        // check that it's not a popped off copy (i_folder_id[0] != 'Approved') seems to be the only
        // indicator of this...
        IDfFolder folder = (IDfFolder) session.getObject(doc.getFolderId(0));
        String foldername = folder.getObjectName();

        if (!"Approved".equals(foldername)) {

          // check it's state
          String statename =
              doc
                  .getCurrentStateName(); // Approved or Effective are only active docs with
                                          // renditions
          String filename = doc.getFile(null);
          // if In-Progress: simply switch the content type
          if ("In-Progress".equals(statename)
              || "Approved".equals(statename)
              || "Effective".equals(statename)) {
            // change format - make sure this doesn't "zero out" the content or something else
            // weird.
            doc.setContentType("acro");
            doc.setFile(filename);
          }

          // clone content as rendition for approved and effective
          if ("Approved".equals(statename) || "Effective".equals(statename)) // In-Approval too?
          {
            doc.addRendition(filename, "pdf");
          }

          doc.save();
        }
      } catch (Exception e) {
        sMgr.abortTransaction();
        throw e;
      }
      sMgr.commitTransaction();
    }
    myObj1.close();

    sMgr.release(session);
  }
  private void setAttachmentToArticleForElf(
      IDfSession idfSession,
      IDfDocument idfAttachmentDocObj,
      String strArticleFolderPath,
      String strStageFolderName,
      String strDeliveryFolderName) {
    DfLogger.debug(
        this, utilObj.getSpaces() + "Inside method setAttachmentToArticleForElf.", null, null);
    Boolean isCheckedOut = false;
    IDfDocument docObj = null;
    String strObjectName = "";
    boolean isLogObject = false;
    boolean isImageObject = false;
    String strObjectType = "";
    String strItemType = "";
    String strLogCategory = "";
    String strLogType = "";

    StringBuilder strFolderPah = new StringBuilder(strArticleFolderPath + "/" + strStageFolderName);

    try {
      strObjectName = idfAttachmentDocObj.getObjectName();
      DfLogger.debug(null, "strObjectName-->" + strObjectName, null, null);

      if (strObjectName.toLowerCase().contains(IConstants.STR_CHECK_PDF_ONLINE)
          && strObjectName.toLowerCase().endsWith(".pdf")) {

        strItemType = IConstants.ITEM_TYPE_CHECK_PDF_ONLINE;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER);
      } else if (strObjectName.toLowerCase().contains(IConstants.STR_CHECK_PDF_PRINT)
          && strObjectName.toLowerCase().endsWith(".pdf")) {

        strItemType = IConstants.ITEM_TYPE_CHECK_PDF_PRINT;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER);
      } else if (strObjectName.toLowerCase().contains(IConstants.STR_COLOR_ON_PAGE_PRINT)
          && strObjectName.toLowerCase().endsWith(".pdf")) {

        strItemType = IConstants.ITEM_TYPE_COLOR_ON_PAGE_PRINT;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER);
      } else if (strObjectName.toLowerCase().contains(IConstants.ELF_FILE_PREFIX_METADATA_XML)
          && strObjectName.endsWith(".xml")) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_ELF_METADATA;

        isLogObject = true;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER + "/" + IConstants.FOLDER_NAME_LOGS);
      } else if (strObjectName.toLowerCase().contains(IConstants.IMAGE_RENDITION_HTML)
          && (strObjectName.toLowerCase().endsWith(".jpg")
              || strObjectName.toLowerCase().endsWith(".gif"))) {

        strItemType = IConstants.ITEM_TYPE_ONLINE_IMAGE;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER + "/" + IConstants.ONLINE_FOLDER);
        isImageObject = true;
        DfLogger.debug(this, "isImageObject : " + isImageObject, null, null);
      } else if (strObjectName.toLowerCase().contains(IConstants.ELF_FILE_PREFIX_ERROR_XML)
          && strObjectName.endsWith(".xml")) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_ELF_MESSAGES;
        isLogObject = true;
        strFolderPah.append(IConstants.PATH_GRAPHICS_FOLDER + "/" + IConstants.FOLDER_NAME_LOGS);
      } else {

        // idfAttachmentDocObj.destroy();
        idfAttachmentDocObj.mark("DELETE");
        idfAttachmentDocObj.save();

        DfLogger.warn(
            this,
            "Unexpected file received : "
                + strObjectName
                + " | no operations required on Object.. ",
            null,
            null);
        return;
      }

      DfLogger.debug(this, "setAttachmentToArticle folder path : " + strFolderPah, null, null);

      if (!isLogObject) {
        docObj =
            (IDfDocument)
                idfSession.getObjectByQualification(
                    strObjectType
                        + " where Folder('"
                        + strFolderPah
                        + "') "
                        + " and object_name = '"
                        + idfAttachmentDocObj.getObjectName()
                        + "' and item_type='"
                        + strItemType
                        + "'");

        DfLogger.debug(
            this,
            strObjectType
                + " where Folder('"
                + strFolderPah
                + "') "
                + " and object_name = '"
                + idfAttachmentDocObj.getObjectName()
                + "' and item_type='"
                + strItemType
                + "'",
            null,
            null);
      } else {
        docObj =
            (IDfDocument)
                idfSession.getObjectByQualification(
                    strObjectType
                        + " where Folder('"
                        + strFolderPah
                        + "') "
                        + " and "
                        + IConstants.ATTR_LOG_CATEGORY
                        + " = '"
                        + strLogCategory
                        + "'");

        DfLogger.debug(
            this,
            strObjectType
                + " where Folder('"
                + strFolderPah
                + "') "
                + " and "
                + IConstants.ATTR_LOG_CATEGORY
                + " = '"
                + strLogCategory
                + "'",
            null,
            null);
      }

      if (docObj != null) {

        DfLogger.debug(
            this,
            utilObj.getSpaces()
                + "Existing version found.Creating new version inside Article Folder",
            null,
            null);
        // [TODO] see if checking of "if checked out" can be added in
        // executeCheckoutOperation
        if (docObj.isCheckedOut()) {
          docObj.cancelCheckout();
        }
        isCheckedOut = utilObj.executeCheckoutOperation(docObj);

        if (isCheckedOut) {
          IDfDocument idfNewVersion =
              utilObj.executeCheckinOperation(idfSession, docObj, idfAttachmentDocObj);
          if (idfNewVersion != null) {

            idfNewVersion.save();

            // idfAttachmentDocObj.destroy();
            // Pramod | Attachment object is no longer required on
            // creation of new version so it will be marked as
            // DELETE and will be deleted at the end of the
            // processing
            idfAttachmentDocObj.mark("DELETE");
            idfAttachmentDocObj.save();

            DfLogger.info(
                this,
                " ---------------------- "
                    + idfAttachmentDocObj.getObjectName()
                    + " Marked as to be deleted ",
                null,
                null);
          }
        }
      } else {
        DfLogger.debug(
            this,
            utilObj.getSpaces() + "New document processing. Linking to article folder",
            null,
            null);

        if (isLogObject == true) {
          DfLogger.debug(this, "Object Name of log file : " + strObjectName, null, null);
          IDfQuery qry = new DfQuery();
          String strObjId = idfAttachmentDocObj.getObjectId().getId();
          qry.setDQL(
              "change "
                  + IConstants.TYPE_WORKITEM_OBJECT
                  + " objects to dm_document where r_object_id='"
                  + strObjId
                  + "'");
          IDfCollection idfColl1 = qry.execute(idfSession, IDfQuery.DF_EXEC_QUERY);
          if (null != idfColl1 && IDfCollection.DF_CLOSED_STATE != idfColl1.getState()) {
            idfColl1.close();
          }
          qry.setDQL(
              "change dm_document objects to "
                  + IConstants.TYPE_LOG_OBJECT
                  + " where r_object_id='"
                  + strObjId
                  + "'");

          IDfCollection idfColl2 = qry.execute(idfSession, IDfQuery.DF_EXEC_QUERY);
          if (null != idfColl2 && IDfCollection.DF_CLOSED_STATE != idfColl2.getState()) {
            idfColl2.close();
          }
          idfAttachmentDocObj.fetch(null);
          idfAttachmentDocObj.setString(IConstants.ATTR_LOG_TYPE, strLogType);
          idfAttachmentDocObj.setString(IConstants.ATTR_LOG_CATEGORY, strLogCategory);
          idfAttachmentDocObj.setObjectName(strObjectName);
          idfAttachmentDocObj.save();
        }

        IDfACL folderAcl = idfSession.getFolderByPath(strFolderPah.toString()).getACL();

        if (isImageObject && strObjectName.split("_").length == 5) {
          idfAttachmentDocObj.setTitle(strObjectName.split("_")[3]);
        }

        idfAttachmentDocObj.setACL(folderAcl);
        idfAttachmentDocObj.unlink(idfAttachmentDocObj.getFolderId(0).toString());
        idfAttachmentDocObj.link(strFolderPah.toString());
        setWorkitemMetadata(idfAttachmentDocObj);

        idfAttachmentDocObj.save();
      }
      DfLogger.debug(
          this,
          utilObj.getSpaces() + "Method processAttachments completed successfully.",
          null,
          null);
    } catch (RuntimeException ex) {
      DfLogger.error(this, ex.getMessage(), null, null);
      throw ex;
    } catch (DfException e) {
      DfLogger.error(this, "Error occured in processing attachment: " + e.getMessage(), null, e);
    }
  }
  /**
   * Handles versioning for AMPP documents. Major version will be created if document of particular
   * type already exists in Article Delivery Folder.
   *
   * @param idfSession
   * @param idfAttachmentDocObj
   * @param strArticleFolderPath
   */
  private void setAttachmentToArticleForAMPP(
      IDfSession idfSession,
      IDfDocument idfAttachmentDocObj,
      String strArticleFolderPath,
      String strStageFolderName,
      String strDeliveryFolderName) {
    DfLogger.debug(this, utilObj.getSpaces() + "Inside method processAttachments.", null, null);
    Boolean isCheckedOut = false;
    IDfDocument docObj = null;
    String strObjectName = "";
    boolean isLogObject = false;
    String strObjectType = "";
    String strItemType = "";
    String strLogCategory = "";
    String strLogType = "";

    StringBuilder strFolderPah = new StringBuilder(strArticleFolderPath + "/" + strStageFolderName);

    try {
      strObjectName = idfAttachmentDocObj.getObjectName();

      if (strObjectName.toLowerCase().contains(IConstants.AMPP_FILE_SUFFIX_ARTICLE_XML)) {

        strItemType = IConstants.AMPP_WORKITEM_VALUE_XML;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_AMPP_COPY_EDITING);
      } else if (strObjectName.toLowerCase().contains(IConstants.FILE_SUFFIX_ARTICLE_PDF)) {

        strItemType = IConstants.AMPP_WORKITEM_VALUE_ONLINE_PDF;
        strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
        strFolderPah.append(IConstants.PATH_AMPP_COPY_EDITING);
      } else if (strObjectName
          .toLowerCase()
          .contains(IConstants.AMPP_FILE_SUFFIX_VALIDATION_LOGL)) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_AMPP_CC;
        isLogObject = true;
        strFolderPah.append(IConstants.PATH_COPY_EDITING_LOG_FOLDER);
      } else if (strObjectName.toLowerCase().contains(IConstants.AMPP_FILE_PREFX_ERROR_LOG)
          && strObjectName.endsWith(".xml")) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_AMPP_MESSAGES;
        strLogType = IConstants.LOG_TYPE_FAILURE;
        isLogObject = true;
        strFolderPah.append(
            IConstants.PATH_COPY_EDITING_FOLDER + "/" + IConstants.FOLDER_NAME_LOGS);
      } else if (strObjectName.toLowerCase().contains(IConstants.BREEZE_FILE_SUFFIX_ERROR_LOG)
          && strObjectName.endsWith(".txt")) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_BREEZE;
        isLogObject = true;
        strFolderPah.append(
            IConstants.PATH_COPY_EDITING_FOLDER + "/" + IConstants.FOLDER_NAME_LOGS);
      } else if (strObjectName.toLowerCase().contains(IConstants.BREEZE_FILE_SUFFIX_SUCCESS_LOG)
          && strObjectName.endsWith(".txt")) {

        strObjectType = IConstants.TYPE_LOG_OBJECT;
        strLogCategory = IConstants.ATTR_LOG_CATEGORY_BREEZE;
        isLogObject = true;
        strFolderPah.append(
            IConstants.PATH_COPY_EDITING_FOLDER + "/" + IConstants.FOLDER_NAME_LOGS);
      } else if (strObjectName.toLowerCase().contains(IConstants.AMPP_FILE_SUFFIX_STYLED_DOC)) {

        for (String strExtensions : IConstants.AMPP_FILE_EXT_STYLED_DOC) {
          if (strObjectName.contains("." + strExtensions)) {
            strItemType = IConstants.AMPP_WORKITEM_VALUE_DOC;
            strObjectType = IConstants.TYPE_WORKITEM_OBJECT;
            strFolderPah.append(IConstants.PATH_COPY_EDITING_FOLDER);
            break;
          }
        }
      } else {
        idfAttachmentDocObj.destroy();
        throw new RuntimeException(
            "Unexpected file received : " + strObjectName + " | Destroyed Object.. ");
      }

      DfLogger.debug(this, "setAttachmentToArticle folder path : " + strFolderPah, null, null);

      if (!isLogObject) {
        docObj =
            (IDfDocument)
                idfSession.getObjectByQualification(
                    strObjectType
                        + " where Folder('"
                        + strFolderPah
                        + "') "
                        + " and item_type='"
                        + strItemType
                        + "'");
      } else {
        docObj =
            (IDfDocument)
                idfSession.getObjectByQualification(
                    strObjectType
                        + " where Folder('"
                        + strFolderPah
                        + "') "
                        + " and "
                        + IConstants.ATTR_LOG_CATEGORY
                        + " = '"
                        + strLogCategory
                        + "'");
      }

      idfAttachmentDocObj.getFile(null);

      if (docObj != null) {

        DfLogger.debug(
            this,
            utilObj.getSpaces()
                + "Existing version found.Creating new version inside Delivery Folder",
            null,
            null);
        // [TODO] see if checking of "if checked out" can be added in
        // executeCheckoutOperation
        if (docObj.isCheckedOut()) {
          docObj.cancelCheckout();
        }
        isCheckedOut = utilObj.executeCheckoutOperation(docObj);

        if (isCheckedOut) {
          utilObj.executeCheckinOperation(idfSession, docObj, idfAttachmentDocObj);
        }
      } else {
        DfLogger.debug(
            this,
            utilObj.getSpaces() + "New document processing. Linking to article folder",
            null,
            null);

        if (isLogObject == true) {
          DfLogger.debug(this, "Object Name of log file : " + strObjectName, null, null);
          IDfQuery qry = new DfQuery();
          String strObjId = idfAttachmentDocObj.getObjectId().getId();
          qry.setDQL(
              "change "
                  + IConstants.TYPE_WORKITEM_OBJECT
                  + " objects to dm_document where r_object_id='"
                  + strObjId
                  + "'");
          DfLogger.debug(this, qry.getDQL(), null, null);

          IDfCollection idfColl1 = qry.execute(idfSession, IDfQuery.DF_EXEC_QUERY);
          if (null != idfColl1 && IDfCollection.DF_CLOSED_STATE != idfColl1.getState()) {
            idfColl1.close();
          }

          qry.setDQL(
              "change dm_document objects to "
                  + IConstants.TYPE_LOG_OBJECT
                  + " where r_object_id='"
                  + strObjId
                  + "'");
          DfLogger.debug(this, qry.getDQL(), null, null);

          IDfCollection idfColl2 = qry.execute(idfSession, IDfQuery.DF_EXEC_QUERY);
          if (null != idfColl2 && IDfCollection.DF_CLOSED_STATE != idfColl2.getState()) {
            idfColl2.close();
          }
          idfAttachmentDocObj.fetch(null);
          idfAttachmentDocObj.setString(IConstants.ATTR_LOG_TYPE, strLogType);
          idfAttachmentDocObj.setString(IConstants.ATTR_LOG_CATEGORY, strLogCategory);
          idfAttachmentDocObj.setObjectName(strObjectName);
          idfAttachmentDocObj.save();
        }

        IDfACL folderAcl = idfSession.getFolderByPath(strFolderPah.toString()).getACL();
        DfLogger.debug(this, folderAcl.getObjectName(), null, null);

        idfAttachmentDocObj.setACL(folderAcl);
        idfAttachmentDocObj.unlink(idfAttachmentDocObj.getFolderId(0).toString());
        idfAttachmentDocObj.link(strFolderPah.toString());
        setWorkitemMetadata(idfAttachmentDocObj);
      }
      DfLogger.debug(
          this,
          utilObj.getSpaces() + "Method processAttachments completed successfully.",
          null,
          null);
    } catch (DfException e) {
      DfLogger.error(this, "Error occured in processing attachment: " + e.getMessage(), null, e);
    }
  }
  public void onInit(ArgumentList args) {
    /*-CONFIG-*/ String m = "onInit-";
    try {
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "calling super()", null, null);
      super.onInit(args);

      // do we need to setclientevent(onOk)?
      // setClientEvent("onOk", args);

      m_task = getWorkflowTask();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(
            this,
            m + "workflowtask: " + (m_task == null ? null : m_task.getActivityId().getId()),
            null,
            null);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(ESignHelper.class))
        DfLogger.debug(this, m + "getting first attachment - first get workitem", null, null);
      IDfWorkitem wi = (IDfWorkitem) getDfSession().getObject(m_task.getId("item_id"));
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(ESignHelper.class))
        DfLogger.debug(this, m + " _ GET ATTACHMENT COLLECTION", null, null);
      IDfCollection attachments = wi.getAttachments();
      attachments.next();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(ESignHelper.class))
        DfLogger.debug(this, m + " - get r_comp_id", null, null);
      IDfId firstattachment = attachments.getId("r_component_id");
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(ESignHelper.class))
        DfLogger.debug(this, m + " - look up doc " + firstattachment.getId(), null, null);
      m_primarypackage = (IDfDocument) getDfSession().getObject(firstattachment);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(ESignHelper.class))
        DfLogger.debug(this, m + " - get doc's mrcsapp", null, null);
      m_mrcsapp = m_primarypackage.getString("mrcs_application");
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "MRCS app: " + m_mrcsapp, null, null);

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(
            this, m + "getting activity name and process name for config lookup", null, null);
      m_taskname = m_task.getActivityName();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + " -- taskname: " + m_taskname, null, null);
      m_processname =
          ((IDfProcess) getDfSession().getObject(m_task.getProcessId())).getObjectName();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + " -- process: " + m_processname, null, null);

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "Check if signoff controls are needed", null, null);
      if (m_task.isSignOffRequired()) {
        // Obtain the resons for signing and initialize the Control
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this,
              m + "signoff is required for this task - initializing reason list dropdown",
              null,
              null);
        DropDownList rsnListCtrl =
            (DropDownList) getControl(QADocFinishWFT.REASONSELECT_CONTROL_NAME, DropDownList.class);
        ESignHelper.initReasonList(m_mrcsapp, rsnListCtrl);
      } else {
        // setMessage("MSG_SIGN_NOTREQUIRED");
        // setValid(true);
      }
    } catch (Exception ex1) {
      /*-ERROR-*/ DfLogger.error(this, m + "Exception in initialization of FinishWFT", null, ex1);
      throw new RuntimeException("Exception in initialization of MRCS FinishWFT component", ex1);
    }
  }
  public void convert() throws Exception {

    // select all documents and look for retired and obsolete versions
    // eff = 3 obs = 4 ret = 6 for NPP
    // app = 2 for efs?
    String query =
        "SELECT r_object_id FROM m_mrcs_efs_central_document WHERE r_current_state = 4 OR r_current_state = 6";

    IDfSession session = null;
    IDfSessionManager sMgr = null;
    try {
      IDfClientX clientx = new DfClientX();

      IDfClient client = clientx.getLocalClient();

      sMgr = client.newSessionManager();

      IDfLoginInfo loginInfoObj = clientx.getLoginInfo();
      loginInfoObj.setUser("mradmin");
      loginInfoObj.setPassword("mr2006");
      loginInfoObj.setDomain(null);

      sMgr.setIdentity("MRCS_Dev", loginInfoObj);
    } catch (DfException dfe) {
      dfe.printStackTrace();
    }
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this)) DfLogger.debug(this, " ", null, null);

    // get list of objects that are pdfs...

    IDfQuery qry = new DfQuery();
    qry.setDQL(query);

    IDfCollection myObj1 = (IDfCollection) qry.execute(session, IDfQuery.DF_READ_QUERY);

    IDfTypedObject serverConfig = session.getServerConfig();
    String aclDomain = serverConfig.getString("operator_name");
    IDfACL obsoleteacl = session.getACL(aclDomain, "mrcs_central_archived");
    IDfACL retiredacl = session.getACL(aclDomain, "mrcs_central_retired_doc");

    while (myObj1.next()) {
      String curid = myObj1.getString("r_object_id");
      // look up object
      IDfDocument doc = (IDfDocument) session.getObject(new DfId(curid));

      // check that it's not a popped off copy (i_folder_id[0] != 'Approved') seems to be the only
      // indicator of this...
      IDfFolder folder = (IDfFolder) session.getObject(doc.getFolderId(0));
      String foldername = folder.getObjectName();

      // don't do this for approved copies...
      if (!"Approved".equals(foldername)) {

        // check it's state
        String statename = doc.getCurrentStateName();
        String chronicleid = doc.getChronicleId().getId();
        // if In-Progress: simply switch the content type
        if ("Obsolete".equals(statename)) {
          String previousquery =
              "SELECT r_object_id FROM dm_document(all) where i_chronicle_id = '"
                  + chronicleid
                  + "'";
          IDfQuery prevqry = new DfQuery();
          prevqry.setDQL(previousquery);
          IDfCollection previousversions =
              (IDfCollection) prevqry.execute(session, IDfQuery.DF_READ_QUERY);
          while (previousversions.next()) {

            String previd = previousversions.getString("r_object_id");
            // look up object
            IDfDocument prevdoc = (IDfDocument) session.getObject(new DfId(previd));
            // unlock
            sMgr.beginTransaction();
            try {
              prevdoc.setString("r_immutable_flag", "FALSE");
              prevdoc.save();

              prevdoc.fetch(prevdoc.getTypeName()); // necessary?	    	    	
              // set flags obsolete = true,retired = false
              prevdoc.setBoolean("retired", false);
              prevdoc.setBoolean("obsolete", true);
              // set acl
              prevdoc.setACL(obsoleteacl);
              prevdoc.setString("r_immutable_flag", "TRUE");
              prevdoc.save();
            } catch (Exception e) {
              sMgr.abortTransaction();
              throw e;
            }
            sMgr.commitTransaction();
          }
          previousversions.close();
        }

        if ("Effective".equals(statename)) {
          String previousquery =
              "SELECT r_object_id FROM dm_document(all) where i_chronicle_id = '"
                  + chronicleid
                  + "'";
          IDfQuery prevqry = new DfQuery();
          prevqry.setDQL(query);
          IDfCollection previousversions =
              (IDfCollection) qry.execute(session, IDfQuery.DF_READ_QUERY);
          while (previousversions.next()) {

            String previd = previousversions.getString("r_object_id");
            // look up object
            IDfDocument prevdoc = (IDfDocument) session.getObject(new DfId(previd));
            // unlock
            String currentstate = prevdoc.getCurrentStateName();
            if ("Retired".equals(currentstate)) {
              sMgr.beginTransaction();
              try {
                prevdoc.setString("r_immutable_flag", "FALSE");
                prevdoc.save();
                prevdoc.fetch(prevdoc.getTypeName()); // necessary?	    	    	
                // set flags obsolete = true,retired = false
                prevdoc.setBoolean("retired", true);
                prevdoc.setBoolean("obsolete", false);
                // set acl
                prevdoc.setACL(retiredacl);
                prevdoc.setString("r_immutable_flag", "TRUE");
                prevdoc.save();
              } catch (Exception e) {
                sMgr.abortTransaction();
                throw e;
              }
              sMgr.commitTransaction();
            }
          }
          previousversions.close();
        }
      }
    }
    myObj1.close();

    sMgr.release(session);
  }
  public IDfSessionManager getDBOSession() throws Exception {
    // this uses the user to get Mrcs Config to look up the DBO!
    /*-CONFIG-*/ String m = "getDBOSession - ";
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "ST Config lookup...", null, null);
    StateTransitionConfigFactory sts = StateTransitionConfigFactory.getSTConfig();

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(
          this, m + "getting config session so we can query for the dbo's name", null, null);
    IDfSessionManager usersessionmgr = sts.cfgSession();
    IDfSession usersession = usersessionmgr.getSession(sts.cfgDocbase());
    String docbase = usersession.getDocbaseName();
    String dbo = usersession.getDocbaseOwnerName();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "quick dbo name: " + dbo, null, null);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "create query objects for lookup", null, null);
    String dboquery = "select r_install_owner from dm_server_config";
    IDfCollection col = null;
    IDfQuery q = new DfQuery();
    q.setDQL(dboquery);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "executing " + dboquery, null, null);
    col = q.execute(usersession, IDfQuery.DF_READ_QUERY);
    if (col.next()) {
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "query successful, reading dbo's name", null, null);
      dbo = col.getString("r_install_owner");
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "DBO name via query: " + dbo, null, null);
      col.close();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "releasing user session", null, null);
      usersessionmgr.release(usersession);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "user session released", null, null);
    } else {
      col.close();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "releasing user session", null, null);
      usersessionmgr.release(usersession);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "user session released", null, null);
      throw new RuntimeException("r_install_owner not retrievable from docbase");
    }

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "creating DCTM client object", null, null);
    IDfClient client = DfClient.getLocalClient();
    IDfSessionManager sMgr = null;
    DfLoginInfo loginInfo = new DfLoginInfo();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "setting identity to dbo user " + dbo, null, null);
    loginInfo.setUser(dbo);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting DBO session", null, null);
    sMgr = client.newSessionManager();
    sMgr.setIdentity(docbase, loginInfo);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "returning", null, null);
    return sMgr;
  }
  public IDfSessionManager getDBOSession(Map parameters) throws Exception {
    /*-CONFIG-*/ String m = "getDBOSession - ";
    String docbase = ((String[]) parameters.get("docbase_name"))[0];

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(
          this, m + "getting user session so we can query for the dbo's name", null, null);
    IDfSessionManager usersessionmgr = getUserSession(parameters);
    IDfSession usersession = usersessionmgr.getSession(docbase);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "quick dbo name: " + usersession.getDocbaseOwnerName(), null, null);
    String dbo = usersession.getDocbaseOwnerName();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "create query objects", null, null);
    String dboquery = "select r_install_owner from dm_server_config";
    IDfCollection col = null;
    IDfQuery q = new DfQuery();
    q.setDQL(dboquery);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "executing " + dboquery, null, null);
    col = q.execute(usersession, IDfQuery.DF_READ_QUERY);
    if (col.next()) {
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "query successful, reading dbo's name", null, null);
      dbo = col.getString("r_install_owner");
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "DBO name via query: " + dbo, null, null);
      col.close();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "releasing user session", null, null);
      usersessionmgr.release(usersession);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "user session released", null, null);
    } else {
      col.close();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "releasing user session", null, null);
      usersessionmgr.release(usersession);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "user session released", null, null);
      throw new RuntimeException("r_install_owner not retrievable from docbase");
    }

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "creating DCTM client object", null, null);
    IDfClient client = DfClient.getLocalClient();

    IDfSessionManager sMgr = null;
    DfLoginInfo loginInfo = new DfLoginInfo();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "setting identity to dbo user " + dbo, null, null);
    loginInfo.setUser(dbo);
    // loginInfo.setPassword("");
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting DBO session", null, null);
    sMgr = client.newSessionManager();
    sMgr.setIdentity(docbase, loginInfo);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "returning", null, null);
    return sMgr;
  }
  public void execute(
      IDfSessionManager sMgr,
      String docbase,
      IDfWorkitem task,
      IDfWorkflow workflow,
      IDfProcess process,
      String mrcsapp,
      Map config,
      Map context) {
    /*-CONFIG-*/ String m = "QADocFormGenerateAcrobatRenditionOnServer.execute - ";
    GenerateAcrobatRendition gar = new GenerateAcrobatRendition();
    IDfSession session = null;
    try {
      session = sMgr.getSession(docbase);
      // get attachment...
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "getting ATTACHMENT collection for workitem", null, null);
      IDfCollection attachments = task.getAttachments();
      while (attachments.next()) {
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(this, m + "--NEXT ATTACHMENT--", null, null);
        for (int i = 0; i < attachments.getAttrCount(); i++) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "attr:    " + attachments.getAttr(i).getName(), null, null);
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this, m + "type:    " + attachments.getAttr(i).getDataType(), null, null);
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this, m + "repeats: " + attachments.getAttr(i).isRepeating(), null, null);
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this, m + "val:     " + attachments.getValueAt(i).asString(), null, null);
        }
        String compid = attachments.getString("r_component_id");
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(this, m + "--ATTACHMENT id: " + compid, null, null);
        if (compid != null) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "--getting ATTACHMENT from docbase", null, null);
          IDfDocument attacheddoc = (IDfDocument) session.getObject(new DfId(compid));
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this,
                m
                    + "--pkgdoc retrieved: "
                    + attacheddoc.getObjectName()
                    + " - "
                    + attacheddoc.getObjectId().getId(),
                null,
                null);

          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "--getting most recent version of attachment", null, null);
          IDfDocument pkgdoc =
              (IDfDocument)
                  session.getObjectByQualification(
                      "dm_document where i_chronicle_id = '"
                          + attacheddoc.getChronicleId().getId()
                          + "'");
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this,
                m
                    + "--most recent retrieved: "
                    + pkgdoc.getObjectName()
                    + " - "
                    + pkgdoc.getObjectId().getId(),
                null,
                null);

          try {
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "CALLING render plugin", null, null);
            gar.render(session, pkgdoc, config);
            // need to save...this may cause deadlock errors if in a transaction?
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "saving doc changes", null, null);
            pkgdoc.save();
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "doc save complete", null, null);

          } catch (Exception e) {
            /*-ERROR-*/ DfLogger.error(
                this, m + "error while loading or executing promotion service module", null, e);
            throw e;
          }
        }
      }

    } catch (Exception dfe) {
      /*-ERROR-*/ DfLogger.error(this, m + "ERROR in generate rendtion on server event", null, dfe);
      throw new RuntimeException(
          "Error in workflow plugin - generate rendition on server event plugin", dfe);
    } finally {
      sMgr.release(session);
    }
  }