Content Management and Capture

Content Management and Capture

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
Expand all | Collapse all

make a search template invisible

  • 1.  make a search template invisible

    Posted Wed September 09, 2020 10:18 PM

    The search templates can be viewed under All Searches in the same repository. I would like to choose only certain search templates that can be accessed in one desktop and invisible for others. I know you can save a search template for a user group, but in my case the same user group can access to both desktops. I do want to hide the search template in one desktop and display in in another. Thank you for any advice on how to do that.



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 2.  RE: make a search template invisible

    Posted Thu September 10, 2020 09:18 AM

    Hi Xiao Bing,

    What I can thik is to use a plugin to do it. Write a plugin response filter extend getSearchTemplates service. Filter the search templates in this response filter based on desktops. If you can't get desktop ID from the response filter, you can get it from the request filter. Then use session.setAttribute to add it into the request and get it from response filter. Don't forget to remove it from session after you use it.

    Thanks,

    Jason



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 3.  RE: make a search template invisible

    Posted Thu September 10, 2020 01:00 PM

    as jason said, you will have to use new plugin, with responseFilter, "getSearchTemplates".

    but you will also have to use one more responseFilter, of "/user".

    if the request.getParameter("type").equals("recentSearches"),

    you will have to take care of that case also.



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 4.  RE: make a search template invisible

    Posted Tue September 15, 2020 06:55 PM

    Jason and Ariks, thank you for your replies. I tried to add a new response filter, but not sure if I was on the right path. In the meantime, I could not find much info about extending getSearchTemplates service. I am not quite sure what I am doing. I need more help from you guys. So far I got this to start with.

    package com.ibm.ecm.extension.icnfilter;

    import javax.servlet.http.HttpServletRequest;

    import com.ibm.ecm.extension.PluginResponseFilter;

    import com.ibm.ecm.extension.PluginServiceCallbacks;

    import com.ibm.ecm.extension.PluginRequestFilter;

    import com.ibm.ecm.extension.PluginService;

    import com.ibm.json.java.JSONObject;

    import com.ibm.json.java.JSONArray;

    public class ICNGetSearchTemplateResponseFilter extends PluginResponseFilter {

    public String[] getFilteredServices() {

    return new String[] { "/p8/getSearchTemplates" };

    }

    public void filter(String serverType, PluginServiceCallbacks callbacks,

    HttpServletRequest request, JSONObject jsonResponse) throws Exception {

    String templateName = request.getParameter("template_name");

    if (templateName.equalsIgnoreCase("IAP 1099 PDF Search"))

    {

    }

    }

    }



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 5.  RE: make a search template invisible

    Posted Wed September 16, 2020 05:19 AM

    please read the ibm redbook,

    response filter section,

    inside the "public void filter" you will have to edit(iterate and edit) the JsonResponse, and remove the unnecessary searches, it will hide them.

    on the jsonResponse you will see a list of stored search, you will have to check if to remove the search from the search list or keep it.



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 6.  RE: make a search template invisible

    Posted Thu September 17, 2020 11:15 PM

    Ariks


    Thank you for your suggestion. I followed redbook and made code changes. I am still not sure how to retrieve the search template and hide one of search template in my choice. Please look at the code so far I got. I need your help. There is not much help in the red book.


    public class GetSearchTemplates extends PluginResponseFilter {


    /**

    * Returns an array of the services that are extended by this filter.

    * <code>String</code> array of names of the services. These are

    *     the servlet paths or Struts action names.

    */

    public String[] getFilteredServices() {

    return new String[] { "/cm/getSearchTemplates","/p8/getSearchTemplates" };

    }

    public void filter(String serverType, PluginServiceCallbacks callbacks,

    HttpServletRequest request, JSONObject jsonResponse) throws Exception {

    JSONResultSetResponse jsonResultSetResponse = (JSONResultSetResponse) jsonResponse;

    int i = 0;

    for (i = 0; i < jsonResultSetResponse.getRowCount(); i++) {

    JSONResultSetRow row = jsonResultSetResponse.getRow(i);

    String templateName = (String) row.get("Document Name");


    if (templateName != null && templateName.equalsIgnoreCase("IAP 1099 PDF Search")) {

    row.put("hidden", true);

    }

    }

    }

    }



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 7.  RE: make a search template invisible

    Posted Fri September 18, 2020 11:05 PM

    Tried to retrieve all search templates. The code below still does not work. Can anyone help review it?

    public class GetSearchTemplatesFilter extends PluginResponseFilter {

    public String[] getFilteredServices() {

    return new String[] { "/cm/getSearchTemplates","/p8/getSearchTemplates" };

    }

    public void filter(String serverType, PluginServiceCallbacks callbacks,

    HttpServletRequest request, JSONObject jsonResponse) throws Exception {

    String templateNm = "IAP 1099 PDF Search";

    JSONResultSetResponse jsonResultSetResponse = (JSONResultSetResponse) jsonResponse;

    int i = 0;

    for (i = 0; i < jsonResultSetResponse.getRowCount(); i++) {

    JSONObject jsonST = (JSONObject)jsonResultSetResponse.get(i);

    if (jsonST.get("Containment Name").toString().equalsIgnoreCase(templateNm)) {

    jsonST.remove(i);

    }

    }

    }



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 8.  RE: make a search template invisible

    Posted Mon September 21, 2020 06:16 AM

    if(serverType.equals("/p8/getSearchTemplates")&&request.getParameter("desktop")!=null){

    JSONArray rowsSearchResJsonArr = (JASONArray)jsonResponse.get("rows");

    String desktopName = request.getParameter("desktop");

    for(int i = 0 ; i<rowsSearchResJsonArr.size();i++){

    JSONResultSetRow row =(JSONResultSetRow)rowsSearchResJsonArr.get(i);

    if(row.get("template").equals("StoredSearch")&& ***add your condition to keep the search or remove it){

    rowsSearchResJsonArr.remove(i);

    i--;

    }

    }

    }

    else if(serverType.equals("/user")){

    //*****add your logic also for "user" filter that perform when the user open the search feature;

    }



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 9.  RE: make a search template invisible

    Posted Mon September 21, 2020 11:15 PM

    Ariks


    Thank you so much for the code you provided me. It works. I added my stuff in and it looks like below. The part for Filter Recent Search List is still not working yet, but the most important part for Filtering All Search list works well. I am still working on it, but really want to say thank you for it.


    public void filter(String serverType, PluginServiceCallbacks callbacks,

    HttpServletRequest request, JSONObject jsonResponse) throws Exception {

    String templateNm = "IAP 1099 PDF Search";

    //Filter All Search list

    if(serverType.equals("/p8/getSearchTemplates") && request.getParameter("desktop")!=null){


    JSONArray rowsSearchResJsonArr = (JSONArray)jsonResponse.get("rows");

    String desktopName = request.getParameter("desktop");

    if (desktopName.equalsIgnoreCase("FileNetQAT2") || desktopName.equalsIgnoreCase("FileNetQAT1") ||

    desktopName.equalsIgnoreCase("FileNetTRN2")) {


    for(int i = 0 ; i<rowsSearchResJsonArr.size();i++){

    JSONResultSetRow row =(JSONResultSetRow)rowsSearchResJsonArr.get(i);

    if(row.get("template").equals("StoredSearch") && row.get("name").equals(templateNm)){

    rowsSearchResJsonArr.remove(i);

    i--;

    }

    }

    }

    else if (desktopName.equalsIgnoreCase("IAP1099QAT")){

    for(int i = 0 ; i<rowsSearchResJsonArr.size();i++){

    JSONResultSetRow row =(JSONResultSetRow)rowsSearchResJsonArr.get(i);

    if(row.get("template").equals("StoredSearch") && !row.get("name").equals(templateNm)){

    rowsSearchResJsonArr.remove(i);

    i--;

    }

    }

    } //end if desktop

    }

    //Filter Recent Search list

    else if(serverType.equals("/user")){

    JSONArray rowsSearchRecJsonArr = (JSONArray)jsonResponse.get("rows");

    //String desktopName = request.getParameter("desktop");

    //

    if (request.getParameter("type").equalsIgnoreCase("recentSearches") ) {

    //rowsSearchRecJsonArr.remove(i);

    for(int i = 0 ; i<rowsSearchRecJsonArr.size();i++){

    JSONResultSetRow row =(JSONResultSetRow)rowsSearchRecJsonArr.get(i);

    if(row.get("template").equals("StoredSearch") && row.get("name").equals(templateNm)){

    rowsSearchRecJsonArr.remove(i);

    i--;

    }

    }

    }

    }

    }



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 10.  RE: make a search template invisible

    Posted Tue September 22, 2020 06:01 AM

    You are welcome,

    for the "user" filter to be execute, you will have to add it to the getFilteredServices() list.


    public class GetSearchTemplatesFilter extends PluginResponseFilter {

    public String[] getFilteredServices() {

    return new String[] { "/cm/getSearchTemplates","/p8/getSearchTemplates","/user" };

    }


    second, consider to manage the search list by using the plugin configuration pane and not hard-coded , it will help you in the future while you will add new desktop or new search.

    you can see how to create plugin config pane by the redbook



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration


  • 11.  RE: make a search template invisible

    Posted Tue September 22, 2020 05:11 PM

    That was my question about how to externalize desktop names and search template name with plugin. Thank you for the info about Configuration Pan. I definitely will look into it and get it implemented in my project.



    #IBMContentNavigator(ICN)
    #Support
    #SupportMigration