Esempio n. 1
0
  public void objectsChanged(int mode, IDfPersistentObject[] objects) {

    // String selected = (String)combo.getSelectedItem();

    for (int i = 0; i < objects.length; i++) {
      if (objects[i] instanceof IDfSysObject) {
        IDfSysObject sys = (IDfSysObject) objects[i];

        try {

          if (mode == ApiObjectChanged.DELETED) {
            tree.objectDelete(sys.getObjectId());
          } else {

            for (int j = 0; j < sys.getFolderIdCount(); j++) {
              IDfFolder folderObject =
                  (IDfFolder) con.getExistingObject(((IDfSysObject) objects[i]).getFolderId(j));

              String folder = folderObject.getString("r_folder_path");

              // if ( folder.startsWith( selected ) ||
              // "[All]".equals( selected ) ) {
              if (mode == ApiObjectChanged.CREATED) tree.objectAdd(objects[i]);
              else if (mode == ApiObjectChanged.CHANGED) tree.objectUpdate(objects[i]);
              // }
            }
          }
        } catch (DfException e) {
          e.printStackTrace();
        }
      }
    }
  }
Esempio n. 2
0
  private void addFallBackResult(Inquiry request, IndexQuery query, IndexQueryResult result) {
    try {
      Set<String> attributes = new HashSet<>();
      for (ResultField resultField : request.getResultfields()) {
        attributes.add(resultField.getName());
      }
      Map<String, String> noData = getFallbackDataProvider().getNoResultData(attributes);
      if (noData == null || noData.isEmpty()) {
        return;
      }

      Item item = new Item();
      for (ResultField resultField : request.getResultfields()) {
        String attrName = resultField.getName();
        String value = noData.get(resultField.getName());
        RField rField = new RField().withName(attrName).withValue(value);
        item.withRfields(rField);
      }
      item.setObjectname(getAttributeMapping().getDefaultType());
      item.setMediastatus("m");

      if (request.getImages() == YNBool.Y) {
        ImageProcessor imageProcessor =
            new ImageProcessor(request, query, getFallbackDataProvider());
        imageProcessor.processNoResultImage(item);
      }

      result.withItems(item);
    } catch (DfException ex) {
      Logger.error(ex.getMessage(), ex);
      handleException(ex, result);
    }
  }
Esempio n. 3
0
  private IndexQueryResult processSearchRequest(Inquiry request, IndexQuery query) {
    IndexQueryResult result = new IndexQueryResult().withQueryname(query.getQueryname());

    try {
      int maxRows = _maxRows;
      if (request.getMaxrows() != null) {
        int requestRows = request.getMaxrows();
        if (requestRows != 0 && requestRows < maxRows) {
          maxRows = requestRows;
        }
      }

      boolean hasMore =
          invokeInSession(
              request.getSecurityToken(),
              new IndexQueryInvoker(
                  request,
                  query,
                  result,
                  getAttributeMapping(),
                  getFallbackDataProvider(),
                  maxRows));

      if (hasMore) {
        Logger.debug("Result contains more than " + maxRows + " rows, adding limit reached flag");
        result.setLimitreached(new LimitReached());
      }
    } catch (DfException ex) {
      Logger.error(ex.getMessage(), ex);
      handleException(ex, result);
    }
    return result;
  }
Esempio n. 4
0
 @Override
 protected void sqlDrop(final String tableName, final IDfSession session) {
   try {
     final String query = "select * from dm_dbo." + tableName + " enable(return_top 1) ";
     DeployUtil.execDqlVoid(query, session);
     LOGGER.info("Drop: " + tableName);
     final String qr =
         "execute exec_sql with query=" + DeployUtil.prepareForExecSQL("drop view " + tableName);
     DeployUtil.execDqlVoid(qr, session);
   } catch (final DfException e) {
     LOGGER.warn("Problem dropping view. Skipped: " + e.getMessage());
   }
 }
  private int getExecutionCountForLogs(IDfDocument idfLogObject) {
    int executionCount = 0;
    try {
      executionCount = idfLogObject.getInt(IConstants.ATTR_LOG_EXECUTION_COUNT);

      DfLogger.debug(this, "Old Execution Count : " + executionCount, null, null);

      executionCount = executionCount >= 2 ? 0 : executionCount + 1;
      DfLogger.debug(this, "New Execution Count : " + executionCount, null, null);
    } catch (DfException e) {
      DfLogger.error(this, e.getStackTraceAsString(), null, null);
      throw new RuntimeException(e.getMessage());
    }
    return executionCount;
  }
  /**
   * Checks whether breeze output is correct for all articles. In case there are errors from Breeze
   * it generates the list of articles with Error.
   *
   * @param issue
   * @return
   */
  private String identifyErrorneouArticleFromBreeze(Issue issue) {
    log.debug("identifyErrorneouArticleFromBreeze: Start; Issue: " + issue);
    StringBuilder strb = new StringBuilder();
    // strb.append(IConstants.MSG_AAU_REJECT_ARTICLE_LIST);
    List<Article> issueArticles = issue.getArticles();

    for (Object element : issueArticles) {
      Article article = (Article) element;

      if (article.getString(Article.ARTICLE_STATUS).equalsIgnoreCase(IConstants.MSG_ERROR_PDF_GEN)
          || article
              .getString(Article.ARTICLE_STATUS)
              .equalsIgnoreCase(IConstants.MSG_BREEZE_FILE_MISSING)
          || article
              .getString(Article.ARTICLE_STATUS)
              .equalsIgnoreCase(IConstants.MSG_CORRUPT_PACKAGE_BREEZE)
          || article
              .getString(Article.ARTICLE_STATUS)
              .equalsIgnoreCase(IConstants.MSG_ERROR_UNEXPECTED_FILES)) {

        try {
          strb.append(
              (article.getObjectName().substring(0, article.getObjectName().lastIndexOf("_")))
                  + ",");
        } catch (DfException e) {
          // TODO Auto-generated catch block
          log.debug("Error while fetching the Object name for article in Issue: " + issue);
          e.printStackTrace();
        }
      }
    }

    String errorArticleList = strb.toString().substring(0, strb.toString().lastIndexOf(","));
    log.debug("identifyErrorneouArticleFromBreeze: End; Issue: " + issue);
    return errorArticleList;
  }
  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 boolean onCommitChanges() {
    /*-CONFIG-*/ String m = "onCommitChanges-";

    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "get State Transition config", null, null);
    StateTransitionConfigFactory config = StateTransitionConfigFactory.getSTConfig();
    /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
      DfLogger.debug(this, m + "get MRCS config task definition", null, null);
    MrcsWorkflowTask t = config.getMrcsWorkflowTask(m_mrcsapp, m_processname, m_taskname);

    boolean canCommit = false;
    try {
      AutoSelectSinglePath();

      // perform basic CFR part 11 checks: must have valid user/pass/reason, user is user that is
      // logged in, password is valid, reason is not empty/null
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "check form and user/pass/reason validations", null, null);
      String validation = performValidation();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(
            this, m + "result: " + (validation == null ? "valid" : validation), null, null);
      if (validation != null) {
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(this, m + "User/Pass/Reason error detected: " + validation, null, null);
        setErrorMessage(validation);
        return false;
      }

      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "get refs to signing controls", null, null);
      Text usernameCtrl = (Text) getControl(QADocForwardWFT.USERNAME_CONTROL_NAME, Text.class);
      Password passwordCtrl =
          (Password) getControl(QADocForwardWFT.PASSWORD_CONTROL_NAME, Password.class);
      DropDownList rsnListCtrl =
          (DropDownList) getControl(QADocForwardWFT.REASONSELECT_CONTROL_NAME, DropDownList.class);
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + "get refs to signing controls", null, null);
      String username = usernameCtrl.getValue();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + " -- user: "******" -- pass: "******"null" : "#########"), null, null);
      String reason = rsnListCtrl.getValue();
      /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
        DfLogger.debug(this, m + " -- reason: " + reason, null, null);

      // HACK the class hierarchy: set Password on superclass, otherwise it won't successfully
      // complete when calling super.onCommitChanges()
      Password passwdCtrl = (Password) getControl("__PASSWORD_CONTROL_NAME");
      passwdCtrl.setValue(password);

      try {
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(this, m + "check for signature validations", null, null);
        if (t.MethodConfiguration != null
            && t.MethodConfiguration.containsKey("SignatureValidations")) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "signature validations detected", null, null);
          List signvalidations = (List) t.MethodConfiguration.get("SignatureValidations");
          Map context = new HashMap();
          List errmsgs = new ArrayList();
          boolean vflag = false;
          for (int i = 0; i < signvalidations.size(); i++) {
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "running signing validation plugin #" + i, null, null);
            MrcsPlugin plugin = (MrcsPlugin) signvalidations.get(i);
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "-- instantiating - " + plugin.PluginClassName, null, null);
            // we'll reuse IMrcsWorkflowValidation as the plugin interface, even though it lacks the
            // task name, which I guess we could hardcode in the MRCS config for the task if need
            // be...
            ISignatureValidation vplug =
                (ISignatureValidation) Class.forName(plugin.PluginClassName).newInstance();
            /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
              DfLogger.debug(this, m + "-- exec", null, null);
            if (!vplug.validate(
                getDfSession().getSessionManager(),
                getDfSession().getDocbaseName(),
                m_mrcsapp,
                m_processname,
                m_task,
                m_primarypackage,
                username,
                password,
                reason,
                errmsgs,
                plugin.PluginConfiguration,
                context)) {
              // break immediately? Or run through all of them?
              vflag = false;
              /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
                DfLogger.debug(this, m + "-- VALIDATION FAILURE", null, null);
              break;
            }
          }
          if (vflag) // validation failed if true...
          {
            for (int ii = 0; ii < errmsgs.size(); ii++) setErrorMessage((String) errmsgs.get(ii));
            return false;
          }
        }
      } catch (Exception e) {
        /*-ERROR-*/ DfLogger.error(this, m + "Error in Signature Validations", null, e);
        throw new WrapperRuntimeException(e);
      }

      // now, I'm pretty sure that super.canCommitChanges() is a dangerous point-of-no-return call
      // that actually has side effects, despite its stateless-implying name,
      // so we should make sure as we can that the signing info has been verified at this point, by
      // checking audit records, rendition presence, number of signatures, etc
      if (super.canCommitChanges()) {
        // I'm pretty sure this super.onCommitChanges call is point-of-no-return: the task will be
        // completed and the workflow will proceed with the next task
        // if they are automatic. This can create race conditions with stuff that happens after the
        // task is done, such as workflow plugins, etc. If you get an error
        // message with "can't find object reference" of something like 4d017f38XXXXX, then the
        // workflow completed and cleaned itself before the plugins/signing
        // could complete in time.

        // THEREFORE, we will sign first (signing multiple documents can take...awhile...), THEN
        // commit changes
        if (m_task.isSignOffRequired()) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this,
                m
                    + "onCommitChanges is signing the document - I don't think this should ever happen for FinishWFT",
                null,
                null);
          try {
            if (t.MethodConfiguration != null
                && t.MethodConfiguration.containsKey("SignatureService")) {
              MrcsPlugin signingplugin = (MrcsPlugin) t.MethodConfiguration.get("SignatureService");
              ISignatureService signplug =
                  (ISignatureService) Class.forName(signingplugin.PluginClassName).newInstance();
              /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
                DfLogger.debug(this, m + "-- exec signing", null, null);
              signplug.sign(
                  getDfSession().getSessionManager(),
                  getDfSession().getDocbaseName(),
                  m_mrcsapp,
                  m_processname,
                  m_task,
                  m_primarypackage,
                  username,
                  password,
                  reason,
                  signingplugin.PluginConfiguration,
                  null);
            }
          } catch (Exception e) {
            /*-ERROR-*/ DfLogger.error(this, m + "Error in Signature Service", null, e);
            throw new WrapperRuntimeException(e);
          }
        }

        canCommit = super.onCommitChanges();
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this,
              m + "canCommit (after validation and performing super call) : " + canCommit,
              null,
              null);
      } else {
        canCommit = false;
      }
      if (canCommit) {

        // uses Actions as a pluginlayer...
        // IN GENERAL these are a bad idea, due to the race conditions documented in the comments
        // above...
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this, " MRCS:FinishWFT: onCommitChanges : get ref to workflow defn", null, null);
        IDfId workflowid = m_task.getWorkflowId();
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this,
              " MRCS:FinishWFT: onCommitChanges : look up workflow object (IDfWorkflow)",
              null,
              null);
        IDfWorkflow workflow = (IDfWorkflow) getDfSession().getObject(workflowid);
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this,
              " MRCS:FinishWFT: onCommitChanges : look up process object (IDfProcess)",
              null,
              null);
        IDfProcess wfdef = (IDfProcess) getDfSession().getObject(workflow.getProcessId());
        /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
          DfLogger.debug(
              this,
              " MRCS:FinishWFT: onCommitChanges : workflow name: " + wfdef.getObjectName(),
              null,
              null);
        MrcsWorkflowTask mrcstask =
            config.getMrcsWorkflowTask(m_mrcsapp, wfdef.getObjectName(), m_task.getTaskName());
        if (mrcstask.Actions != null) {
          Map context = new HashMap();
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(
                this,
                " MRCS:FinishWFT: onCommitChanges : executing client-side plugins",
                null,
                null);
          for (int k = 0; k < mrcstask.Actions.size(); k++) {
            try {
              /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
                DfLogger.debug(
                    this,
                    " MRCS:FinishWFT: onCommitChanges : executing plugin " + (k + 1),
                    null,
                    null);
              MrcsPlugin plugin = (MrcsPlugin) mrcstask.Actions.get(k);
              /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
                DfLogger.debug(
                    this,
                    " MRCS:FinishWFT: onCommitChanges : -- class: " + plugin.PluginClassName,
                    null,
                    null);
              IMrcsWorkflowActionPlugin wfaction =
                  (IMrcsWorkflowActionPlugin) Class.forName(plugin.PluginClassName).newInstance();
              wfaction.execute(
                  getDfSession().getSessionManager(),
                  getDfSession().getDocbaseName(),
                  m_task,
                  workflow,
                  m_mrcsapp,
                  plugin.PluginConfiguration,
                  context);
            } catch (Exception e) {
              /*-ERROR-*/ DfLogger.error(
                  this, m + "error in MRCS 4.2 client-side workflow actions", null, e);
              setErrorMessage("MSG_UNEXPECTED_ERROR", new Object[] {e.getMessage()}, e);
              throw new WrapperRuntimeException("error in MRCS workflow actions", e);
            }
          }
        }
        if (canCommit)
          setMessage("MSG_FINISH_SUCCESS", new Object[] {super.getString("MSG_OBJECT")});
      } // commit & esign ends
    } catch (DfException e1) {
      /*-ERROR-*/ DfLogger.error(
          this, "MRCS:FinishWFT.onCommitChanges - DfException occurred: ", null, e1);
      canCommit = false;
      try {
        if (m_task.getCompleteErrStatus() == 4) {
          /*-DEBUG-*/ if (DfLogger.isDebugEnabled(this))
            DfLogger.debug(this, m + "Exception occurred:Incorrect Password " + e1, null, null);
          setErrorMessage("MSG_INCORRECT_PASSWORD");
          return false;
        }
        /*
         * else if(){ [DM_SYSOBJECT_E_ESIGN_SIGNATURE_METHOD_FAILED }
         */
        else {
          /*-ERROR-*/ DfLogger.error(
              this,
              "MRCS:FinishWFT.onCommitChanges - Exception occurred:Unexpected Error ",
              null,
              e1);
          setErrorMessage("MSG_UNEXPECTED_ERROR", new Object[] {e1.getMessage()}, e1);
          return false;
        }
      } catch (DfException e2) {
        /*-ERROR-*/ DfLogger.error(this, m + "error in exception handling code", null, e2);
        throw new WrapperRuntimeException(e2);
      }
    }

    return canCommit;
  }
  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);
  }
Esempio n. 12
0
  public void selectedEvent(NodeValue[] value, int mode, JComponent src, int x, int y) {

    try {
      if (value == null) {
        if (mode == Listener.MODE_HOT_SELECT) {
          ApiObjectHotSelect[] list = (ApiObjectHotSelect[]) node.getApi(ApiObjectHotSelect.class);
          if (list == null) return;

          for (int i = 0; i < list.length; i++)
            try {
              list[i].apiObjectHotSelected(con, null, null);
            } catch (Throwable t) {
              t.printStackTrace();
            }
        }
        return;
      }

      final IDfPersistentObject[] obj = new IDfPersistentObject[value.length];
      final IDfPersistentObject[] parents = new IDfPersistentObject[value.length];

      for (int i = 0; i < value.length; i++) {
        obj[i] = con.getPersistentObject(value[i].getId());
        if (value[i].getParentId() != null)
          parents[i] = con.getPersistentObject(value[i].getParentId());
      }

      if (mode == Listener.MODE_HOT_SELECT) {
        final ApiObjectHotSelect[] list =
            (ApiObjectHotSelect[]) node.getApi(ApiObjectHotSelect.class);
        if (list == null) return;

        for (int i = 0; i < list.length; i++)
          try {
            if (!list[i].equals(TreePlugin.this)) list[i].apiObjectDepricated();
          } catch (Throwable t) {
            t.printStackTrace();
          }

        timer.schedule(
            new TimerTask() {

              public void run() {
                for (int i = 0; i < list.length; i++)
                  try {
                    if (!list[i].equals(TreePlugin.this))
                      list[i].apiObjectHotSelected(con, parents, obj);
                  } catch (Throwable t) {
                    t.printStackTrace();
                  }
              }
            },
            1);
      } else if (mode == Listener.MODE_SELECT) {
        /*
         * final ApiObjectSelect[] list =
         * (ApiObjectSelect[])node.getApi( ApiObjectSelect.class ); if (
         * list == null ) return;
         *
         * timer.schedule( new TimerTask() {
         *
         * public void run() { for ( int i = 0; i < list.length; i++ )
         * try { list[i].apiObjectSelected( con, obj ); } catch (
         * Throwable t ) { t.printStackTrace(); } }
         *
         * },1);
         */
      } else if (mode == Listener.MODE_MENU) {
        ObjectWorkerTool.showMenu(node, con, obj, src, x, y);
      }

    } catch (DfException e) {
      e.printStackTrace();
    }
  }