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 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);
    }
  }
  // implement the default configurable method - execute listed actions in workflow task
  public void execute(Map parameters, OutputStream outputstream) throws Exception {
    /*-CONFIG-*/ String m = "MrcsConfigurableMethod.execute - ";

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting docbase from JSM parameters", null, null);
    String[] paramvals = (String[]) parameters.get("docbase_name");
    String docbase = paramvals[0];
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "  ~~docbase: " + docbase, null, null);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting packageId from JSM parameters", null, null);
    paramvals =
        (String[])
            parameters.get(
                "packageId"); // OOTB docbasic promote method thinks this is workitemid...
    String packageid = paramvals[0];
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "  ~~packageId: " + packageid, null, null);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting 'mode' from JSM parameters", null, null);
    paramvals = (String[]) parameters.get("mode");
    String mode = paramvals[0];
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "  ~~MODE: " + mode, null, null);

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting mrcs system session", null, null);
    IDfSessionManager sessionmgr = getMrcsSystemUserSessionFromFirstAttachment(parameters);
    IDfSession session = sessionmgr.getSession(docbase);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "session DMCL id: " + session.getDMCLSessionId(), null, null);

    // get workitem
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "retreive workitem (the 'packageid')", null, null);
    IDfWorkitem workitem = (IDfWorkitem) session.getObject(new DfId(packageid));
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(
          this, m + "...retrieved workitem " + packageid + "? " + (workitem != null), null, null);

    // acquire if not mode 0. ?what? - it's what the docbasic thingy does
    if ("0".equals(mode)) {
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "mode is 0, acquiring workitem...", null, null);
      workitem.acquire();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "...acquired", null, null);
    }
    try {

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "get attachment", null, null);
      IDfSysObject attachment = getFirstAttachment(sessionmgr, parameters);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "mrcsapplication of attachment", null, null);
      String mrcsapp = attachment.getString("mrcs_application");
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + " -- is: " + mrcsapp, null, null);

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "get workflow object " + workitem.getWorkflowId(), null, null);
      IDfWorkflow workflow = (IDfWorkflow) session.getObject(workitem.getWorkflowId());

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "get process object " + workflow.getProcessId(), null, null);
      IDfProcess process = (IDfProcess) session.getObject(workflow.getProcessId());

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "workflow process name and task name", null, null);
      String workflowname = process.getObjectName();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "-- workflow process name: " + workflowname, null, null);
      String taskname = workitem.getActivity().getObjectName();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "-- workitem activity name: " + taskname, null, null);

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "locate configuration of task in mrcs config", null, null);
      StateTransitionConfigFactory stconfig = StateTransitionConfigFactory.getSTConfig();

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "look up MRCS task definition", null, null);
      MrcsWorkflowTask mrcstask = stconfig.getMrcsWorkflowTask(mrcsapp, workflowname, taskname);

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(
            this,
            m + "getting server plugins list (ServerPlugins key in the MethodConfiguration)",
            null,
            null);
      List actionlist = (List) mrcstask.MethodConfiguration.get("ServerPlugins");

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "EXEC plugins", null, null);
      if (actionlist != null) {
        Map context = new HashMap();
        for (int i = 0; i < actionlist.size(); i++) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "running plugin #" + i, null, null);
          MrcsPlugin plugin = (MrcsPlugin) actionlist.get(i);
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "-- instantiating - " + plugin.PluginClassName, null, null);
          IMrcsWorkflowServerPlugin doit =
              (IMrcsWorkflowServerPlugin) Class.forName(plugin.PluginClassName).newInstance();
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "-- doit!", null, null);
          doit.execute(
              sessionmgr,
              docbase,
              workitem,
              workflow,
              process,
              mrcsapp,
              plugin.PluginConfiguration,
              context);
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "-- done!", null, null);
        }
      }

    } catch (Exception e) {
      /*-ERROR-*/ DfLogger.error(this, m + "error in promoting workitem packages...", null, e);
      sessionmgr.release(session);
      throw e;
    }

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "completing workitem...", null, null);
    workitem.complete();

    /*-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);
  }
  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);
    }
  }