public IDfSessionManager getMrcsSystemUserSession(Map parameters, String mrcsapp)
      throws Exception {
    /*-CONFIG-*/ String m = "getMrcsSystemUserSession - ";
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "accessing config factory...", null, null);
    StateTransitionConfigFactory sts = StateTransitionConfigFactory.getSTConfig();

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "looking up app's system user for mrcsapp " + mrcsapp, null, null);
    String sysuser = sts.getSystemUsername(mrcsapp);
    String syspass = sts.getSystemPassword(mrcsapp);

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

    String docbase = ((String[]) parameters.get("docbase_name"))[0];

    IDfSessionManager sMgr = null;
    DfLoginInfo loginInfo = new DfLoginInfo();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "setting identity to mrcs sysuser " + sysuser, null, null);
    loginInfo.setUser(sysuser);
    loginInfo.setPassword(syspass);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting MRCS sysuser session for mrcsapp", 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 getDBOSessionRunningAsServer(Map parameters) throws Exception {
    /*-CONFIG-*/ String m = "getDBOSessionRunningAsServer - ";
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(
          this, m + "getting user session so we can query for the dbo's name", null, null);

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

    String docbase = ((String[]) parameters.get("docbase_name"))[0];

    IDfSessionManager sMgr = null;
    DfLoginInfo loginInfo = new DfLoginInfo();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "setting identity to dbo user dm_dbo", null, null);
    loginInfo.setUser("dm_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;
  }
  // this is ripped from the dctm sample method
  public IDfSessionManager getUserSession(Map parameters) throws Exception {
    /*-CONFIG-*/ String m = "getUserSession - ";
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting data from parameters map", null, null);
    String user = ((String[]) parameters.get("user"))[0];
    String ticket = ((String[]) parameters.get("ticket"))[0];
    String docbase = ((String[]) parameters.get("docbase_name"))[0];

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting client objects", 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 user " + user, null, null);
    loginInfo.setUser(user);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "setting identity to ticket " + ticket, null, null);
    loginInfo.setPassword(ticket);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting session", null, null);
    // session = client.newSession(docbase, loginInfo);
    sMgr = client.newSessionManager();
    sMgr.setIdentity(docbase, loginInfo);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "returning", null, null);
    return sMgr;
  }
  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);
  }
  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;
  }