public IDfSessionManager getMrcsSystemUserSessionFromObjectId(Map parameters, String objectid)
      throws Exception {
    /*-CONFIG-*/ String m = "getMrcsSystemUserSessionFromFirstAttachment - ";
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting docbase from parameters", null, null);
    String docbase = ((String[]) parameters.get("docbase_name"))[0];
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting user session", null, null);
    IDfSessionManager usersessionmgr = getUserSession(parameters);
    IDfSession usersession = usersessionmgr.getSession(docbase);

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting first attachment via user session", null, null);
    IDfSysObject attachment = (IDfSysObject) usersession.getObject(new DfId(objectid));

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting mrcsapp from first attachment", null, null);
    String mrcsapp = attachment.getString("mrcs_application");
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "mrcsapp: " + mrcsapp, null, null);

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "releasing session", null, null);
    usersessionmgr.release(usersession);
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "session released", null, null);

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "getting mrcs system session", null, null);
    IDfSessionManager syssession = getMrcsSystemUserSession(parameters, mrcsapp);

    return syssession;
  }
Exemplo n.º 2
0
  public void setAttachmentsContentTypeForElf(
      IDfSession idfSession,
      String[] attachmentIds,
      String strArticleFolderPath,
      String strStageName)
      throws DfException, XPathExpressionException, ParserConfigurationException, SAXException,
          IOException {
    DfLogger.debug(
        this,
        utilObj.getSpaces()
            + "setAttachmentsContentType :::: Length of Attachments : "
            + attachmentIds.length,
        null,
        null);
    String strDeliveryFolderName = "";
    String strStageFolderName = "";

    if (IConstants.ATTR_STAGE_NAME_200.equalsIgnoreCase(strStageName)) {
      strDeliveryFolderName =
          IConstants.PATH_AMPP_COPY_EDITING; // IConstants.PATH_AMPP_DELIVERY_FOLDER;
      strStageFolderName = IConstants.FOLDER_NAME_STAGE_200;
    } else {
      strDeliveryFolderName =
          IConstants.PATH_AMPP_COPY_EDITING; // IConstants.PATH_AMPP_DELIVERY_FOLDER;
      strStageFolderName = IConstants.FOLDER_NAME_STAGE_300;
    }

    for (int i = 0; i < attachmentIds.length; i++) {
      if (DfId.isObjectId(attachmentIds[i])) {

        DfLogger.debug(
            this, utilObj.getSpaces() + "Attachment ID : " + attachmentIds[i], null, null);

        IDfDocument idfDocument = (IDfDocument) idfSession.getObject(new DfId(attachmentIds[i]));
        if (idfDocument != null) {
          setContentTypeFromName(idfSession, idfDocument);

          idfDocument.fetch(null);
          setAttachmentToArticleForElf(
              idfSession,
              idfDocument,
              strArticleFolderPath,
              strStageFolderName,
              strDeliveryFolderName);
        }
      }
    }
  }
  public IDfWorkitem getWorkitem(IDfSessionManager sessionmgr, Map parameters) throws Exception {
    /*-CONFIG-*/ String m = "getWorkitem - ";
    /*-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 workitemid ", null, null);
    String workitemid = ((String[]) parameters.get("packageId"))[0];
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "get object from db", null, null);
    IDfWorkitem wi = (IDfWorkitem) session.getObject(new DfId(workitemid));
    /*-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 wi;
  }
 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);
  }
Exemplo n.º 6
0
  /**
   * This is the main method which processes AMPP received documents.
   *
   * @param idfSession
   * @param attachmentIds
   * @param strArticleFolderPath
   * @throws DfException
   */
  public void setAttachmentsContentTypeForAMPP(
      IDfSession idfSession,
      String[] attachmentIds,
      String strArticleFolderPath,
      String strStageName)
      throws DfException {
    DfLogger.debug(this, utilObj.getSpaces() + "setAttachmentsContentType ::::", null, null);
    String strDeliveryFolderName = "";
    String strStageFolderName = "";

    if (IConstants.ATTR_STAGE_NAME_200.equalsIgnoreCase(strStageName)) {
      strDeliveryFolderName =
          IConstants.PATH_AMPP_COPY_EDITING; // IConstants.PATH_AMPP_DELIVERY_FOLDER;
      strStageFolderName = IConstants.FOLDER_NAME_STAGE_200;
    } else {
      // Pramod | 30 Oct 2014 | All files will be stored under
      // Stage/Delivery Folder
      // strDeliveryFolderName = IConstants.PATH_AMPP_300_DELIVERY_FOLDER;
      strDeliveryFolderName =
          IConstants.PATH_AMPP_COPY_EDITING; // IConstants.PATH_AMPP_DELIVERY_FOLDER;
      strStageFolderName = IConstants.FOLDER_NAME_STAGE_300;
    }

    for (int i = 0; i < attachmentIds.length; i++) {
      if (DfId.isObjectId(attachmentIds[i])) {

        DfLogger.debug(
            this, utilObj.getSpaces() + "Attachment ID : " + attachmentIds[i], null, null);

        IDfDocument idfDocument = (IDfDocument) idfSession.getObject(new DfId(attachmentIds[i]));
        if (idfDocument != null) {

          DfLogger.debug(
              this,
              "File Path before setting content type : " + idfDocument.getFile(null),
              null,
              null);
          setContentTypeFromName(idfSession, idfDocument);
          idfDocument.save();
          idfDocument.fetch(null);
          setAttachmentToArticleForAMPP(
              idfSession,
              idfDocument,
              strArticleFolderPath,
              strStageFolderName,
              strDeliveryFolderName);
          if (idfDocument.isDeleted() != true) {
            idfDocument.save();
            DfLogger.debug(
                this,
                utilObj.getSpaces()
                    + "Attachment "
                    + idfDocument.getObjectName()
                    + " Processed and Saved successfully ",
                null,
                null);
          }
        }
      }
    }
  }
  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);
  }
  // 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);
    }
  }
Exemplo n.º 10
0
 /**
  * Execute the method task and all defined {@link fi.sardion.dctm.deploy.job.Job job} subtasks.
  *
  * <ul>
  *   <li>Created: 18 Sep 2010 19:10:07
  *   <li>Author: Christopher Harper, account: dmadmin
  * </ul>
  *
  * @since %since%
  */
 @Override
 public void execute() {
   final IDfSession session = getSession();
   try {
     if (isForThisRepository(session.getDocbaseName())) {
       final String qualification =
           new StringBuilder()
               .append(DCTMTask.DM_METHOD)
               .append(" where ")
               .append( //$NON-NLS-1$
                   DCTMTask.OBJECT_NAME)
               .append(" = '") // $NON-NLS-1$
               .append(getMethodName())
               .append('\'')
               .toString();
       IDfMethodObject method = (IDfMethodObject) session.getObjectByQualification(qualification);
       if (method == null) {
         log(
             String.format(
                 "Qualification %s din't return a method. Creating a new one.", //$NON-NLS-1$
                 new Object[] {qualification}));
         method = (IDfMethodObject) session.newObject(DCTMTask.DM_METHOD);
         method.setObjectName(getMethodName());
         method.grant(DCTMTask.DM_WORLD, IDfACL.DF_PERMIT_READ, ""); // $NON-NLS-1$
         // method.link(Method.METHOD_FOLDER);
         setReaplySettings(String.valueOf(true));
       } else {
         log(
             String.format(
                 "Found method with qualification %s.", //$NON-NLS-1$
                 new Object[] {qualification}));
       }
       if (reaplySettings()) {
         if (!method.isDirty()) {
           method.checkout();
           log(
               String.format(
                   "Modifying existing method %s values.", //$NON-NLS-1$
                   new Object[] {getMethodName()}));
         }
         method.setMethodVerb(getMethodVerb());
         method.setTimeoutMin(getTimeoutMin());
         method.setTimeoutMax(getTimeoutMax());
         method.setTimeoutDefault(getTimeoutDefault());
         method.setLaunchDirect(getLaunchDirect());
         method.setLaunchAsync(getLaunchAsync());
         method.setTraceLaunch(getTraceLaunch());
         method.setRunAsServer(getRunAsServer());
         method.setUseMethodContent(getUseMethodContent());
         method.setMethodType(getMethodType());
         method.setUseMethodServer(getUseMethodServer());
         method.setSuccessStatus(getSuccessStatus());
         method.setBoolean(DCTMTask.IS_RESTARTABLE, getIsRestartable());
         method.removeAll(DCTMTask.SUCCESS_RETURN_CODES);
         for (final Integer successReturnCode : getSuccessReturnCodes()) {
           method.appendInt(DCTMTask.SUCCESS_RETURN_CODES, successReturnCode.intValue());
         }
         method.removeAll(DCTMTask.METHOD_ARGS);
         for (final String methodArgument : getMethodArguments()) {
           method.appendString(DCTMTask.METHOD_ARGS, methodArgument);
         }
         method.removeAll(DCTMTask.A_EXTENDED_PROPERTIES);
         for (final String extededProperty : getExtendedProperties()) {
           method.appendString(DCTMTask.A_EXTENDED_PROPERTIES, extededProperty);
         }
       }
       if (method.isDirty()) {
         if (method.isCheckedOut()) {
           method = (IDfMethodObject) session.getObject(method.checkin(false, "")); // $NON-NLS-1$
         } else {
           method.save();
         }
       }
       if (isVerbose()) {
         log(
             String.format(
                 "########## METHOD OBJECT DUMP START ##########\n%s\n########### METHOD OBJECT DUMP END ###########", //$NON-NLS-1$
                 new Object[] {method.dump()}),
             Project.MSG_INFO);
       }
     } else {
       log(
           String.format(
               "This method %s was only defined for repositories %s and the current repository is %s.", //$NON-NLS-1$
               new Object[] {getMethodName(), getRepositories(), session.getDocbaseName()}));
     }
   } catch (final Throwable t) {
     printStack(t);
     log(
         String.format(
             "Shit!:\nclass: %s\nmessage: %s\nstack: %s", //$NON-NLS-1$
             new Object[] {
               t.getClass().getName(), t.getMessage(), t.getStackTrace()[0].toString()
             }));
   }
   for (final Job job : getJobs()) {
     job.setSession(session);
     job.setMethodname(getMethodName());
     job.execute();
   }
 }