Content Management and Capture

 View Only
  • 1.  Content Navigator Plugin - Request filter ("/p8/deleteItem") compilation issue

    Posted Thu May 25, 2023 01:21 PM

    Hi All,

    Requirement: I have enabled "Delete" action in the Action Menu. I want to restrict the "Delete" if the document status is approved. Otherwise, it should be possible to delete the document.

    What I have done So far:
    1. I achieved this requirement using request filter service "/p8/deleteItem". I moved the changes to UAT and PROD. All looks good.

    Issue:
    1. The java project has other navigator customizations including this requirement. There is a bug in another customization.
    2. To fix that issue, I opened the java project. It is showing compilation issue in the request filter service "/p8/deleteItem". But there was no error in this filter service before. In fact, the filter service is working fine in DEV, UAT and PROD.
    3. Below is the requester filter service code.  Highlighted the compilation code in Bold. Can you guys try this code(at least the line which is showing compilation error) and let me know if it shows the compilation error.

    public JSONObject filter(PluginServiceCallbacks callbacks, HttpServletRequest request, JSONArtifact jsonRequest) throws Exception {
    JSONObject loReturnJSONObject = null;
    if(moObjectStore==null) {
    moObjectStore = callbacks.getP8ObjectStore(callbacks.getRepositoryId());
    }
    String lsLoggedInUserName = request.getUserPrincipal() == null ? null : request.getUserPrincipal().getName();
    ContentEngineUtil loContentEngineUtil = new ContentEngineUtil(moConfigReader);
    BankAccountValueObject loBankAccountValueObject;
    for(Map.Entry<String,String[]> loLineMapEntry: request.getParameterMap().entrySet()) {//Compilation error is "Type mismatch: cannot convert from element type Object to Map.Entry<String,String[]>"
    String lsKeyName = loLineMapEntry.getKey();
    if(lsKeyName.equalsIgnoreCase(PluginConstants.DOCID)) {
    for(int i=0;i<loLineMapEntry.getValue().length;i++) {
    String[] loSplitValues = loLineMapEntry.getValue()[i].split(",");
    String lsDocID = loSplitValues[2]; 
    // 1.Checks if the document status is Approved.
    Document loDocument = loContentEngineUtil.doFetchDocument(moObjectStore, new Id(lsDocID));
    loBankAccountValueObject = loContentEngineUtil.doFetchDocumentProperties(loDocument);
    if(loContentEngineUtil.isDocumentStatusApproved(new Id(lsDocID), loBankAccountValueObject.getEvidenceStatus())) {
    // 1.1.If yes, deletion will not happen
    loReturnJSONObject = new JSONObject();
    }
    // 1.2.If no, deletion will happen. Audit record will be inserted in to table
    else {
    DatabaseUtil loDatabaseUtil = new DatabaseUtil(moConfigReader);
    Connection loConnection = loDatabaseUtil.getDatabaseConnection();
    loBankAccountValueObject.setEvidence_Deleted_By(lsLoggedInUserName);
    loBankAccountValueObject.setEvidence_DeletedDate(new Date());
    loDatabaseUtil.doInsertDocumentAudit(loBankAccountValueObject, loConnection);
    loDatabaseUtil.closeDataBaseConnection(loConnection);
    }
    }
    }
    }
    return loReturnJSONObject;
    }






    ------------------------------
    RAVI KUMAR
    ------------------------------


  • 2.  RE: Content Navigator Plugin - Request filter ("/p8/deleteItem") compilation issue

    Posted Thu May 25, 2023 07:25 PM

    Normally, I'd do this in the content engine itself rather than the user interface.  It's a classic use case for a Marking Set.  The marking set has the list of values "Approved","Not approved","Draft" ...etc and the marking removes the delete bit from the object security if it's set to approved.  It means you're building the security into the objects themselves rather than coding it in the UI.



    ------------------------------
    David Alfredson
    ------------------------------



  • 3.  RE: Content Navigator Plugin - Request filter ("/p8/deleteItem") compilation issue

    IBM Champion
    Posted Fri May 26, 2023 03:16 AM

    I totally agree with David. This is a functionality that should be implemented in the backend!

    From the compiler's point of view, it does not know what types the entries have. 
    So iterate over the objects and cast them to your expected entry type. Then the compiler is satisfied... 

    for(Object o: request.getParameterMap().entrySet()) {
    	Map.Entry e = (Map.Entry<String, String[]>) o;
    }


    But I would take the compiler error seriously. With the cast you can get problems at runtime, if no String[] is returned as value.
    If you have posted the whole code, I can recommend to revise it again: Why do you iterate over all parameters if only PluginConstants.DOCID is needed? The following would be enough:

    String[] loSplitValues = (String[]) request.getParameter(PluginConstants.DOCID);

    The current code (handling the request parameterMap) doesn't seem to be safe for new releases of the ICN (e.g. if the request for /p8/deleteItem changes).



    ------------------------------
    Christoph Sünderkamp
    ------------------------------



  • 4.  RE: Content Navigator Plugin - Request filter ("/p8/deleteItem") compilation issue

    Posted Fri May 26, 2023 11:56 AM

    Hi Christoph,

    One point I forgot mention is that we have migrated to latest Content Navigator meanwhile. I am using latest navigatorAPI.jar. This is the only change in the java project. I think that might be causing the compilation issue. Thank you very much for pointing out that. I used your below suggested line. Now it looks good. Thank you once again.

    String[] loSplitValues = (String[]) request.getParameter(PluginConstants.DOCID);

    "



    ------------------------------
    RAVI KUMAR
    ------------------------------



  • 5.  RE: Content Navigator Plugin - Request filter ("/p8/deleteItem") compilation issue

    Posted Fri May 26, 2023 11:53 AM

    Hi David,

    Thank you for the suggestion. I will implement in the future.



    ------------------------------
    RAVI KUMAR
    ------------------------------