• SOLVED: find method returns null document/null folder

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #47285  by m.carlzy
 
Hi,
I'm trying to use OpenKM as DMS. Version of OpenKM is 6.3.6 (Community) and I use sdk4j-1.1 for java implementation.
I'm running some issues when I use find method (or any find methods in that matter) in my code as it always return null for document and folder.

Code is as follows:
Code: Select all
	   QueryParams qParams = new QueryParams();
           qParams.setDomain(QueryParams.DOCUMENT | QueryParams.FOLDER);
  
           Map<String, String> searchMap = new HashMap<>();            
           searchMap.put("okp:modal.customer", "Anna");                        
           searchMap.put("okp:modal.product", "Payments");
           searchMap.put("okp:modal.condition", "Recurring");
           
           qParams.setProperties(searchMap);
            
            for (QueryResult qr : ws.find(qParams)) {
                System.out.println(qr);
            }          
When running the application, it will return the following output:
Code: Select all
{document=null, folder=null, excerpt=, score=87}
{document=null, folder=null, excerpt=, score=87}
I recheck documentation and sdk4j is compatible with 6.3.6, result size is correct however I need the document which is I cannot use because it returns null. Appreciate if someone could point out what's wrong.

Thanks!
Last edited by m.carlzy on Mon Feb 11, 2019 2:53 am, edited 1 time in total.
 #47299  by m.carlzy
 
Hello Inovoa,
Here's my code:
Code: Select all
package com.dms.openkm;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map; 

import com.openkm.sdk4j.OKMWebservices; 
import com.openkm.sdk4j.OKMWebservicesFactory; 
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.bean.QueryParams;
import com.openkm.sdk4j.bean.QueryResult;
public class Test {    
	public static void main(String[] args) {        
		String host = "http://localhost:8080/OpenKM";       
		String username = "okmAdmin";        
		String password = "admin";        
		try {         
			OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); 

			QueryParams qParams = new QueryParams();
            qParams.setDomain(QueryParams.DOCUMENT | QueryParams.FOLDER);
            

            Map<String, String> searchMap = new HashMap<>();            
            searchMap.put("okp:modal.customer", "Anna");                        
            searchMap.put("okp:modal.product", "Payments");
            searchMap.put("okp:modal.condition", "Recurring");
            
        	List<QueryResult> searchResult = new ArrayList<QueryResult>();
            qParams.setProperties(searchMap);
            
            searchResult = ws.find(qParams);
            System.out.println(searchResult.size());
            
            for (QueryResult qr : ws.find(qParams)) {
                Document document = qr.getDocument();
            	qr.setDocument(document); //returns null
                System.out.println(qr);
            }           
			      
		} catch (Exception e) {           
			e.printStackTrace();           
		} 
	}
}

 #47301  by lnovoa
 
Hi!,

First of all I do not understand why you do this:
Code: Select all
 Document document = qr.getDocument();
qr.setDocument(document); //returns null
And secondly, you have looked at whether you can get the Node object ?, this object can cast with Document.

Try to do a simple search first.
And when you are debugging attached a screenshot of the results obtained

https://docs.openkm.com/kcenter/view/sd ... mples.html
 #47312  by m.carlzy
 
Hi lnovoa,
I got some incorrect lines on my code, it should be only:
Code: Select all
 Document document = qr.getDocument();

The idea is that once I got the Query Result, I would like to get the information of each so I could use it on my application, something like:
Code: Select all
 for (QueryResult qr : ws.find(qParams)) {
            	Document document = qr.getDocument();
            	String description = document.getDescription();
            	String mimetype = document.getMimeType();
}
However, query results only have the following - document,folder,score,excerpt.
Please see attached debug screen.
Image

Is there a way on how I can obtain the information of each result?

Thank you!
 #47342  by jllort
 
The result seems right, the object might retrieve a list of documents or folder, but the result of your query are empty ( null ).

Be sure from OpenKM side executing the same query you really get results ( I suggest first try from there ), share with us some screenshot if they result results from there. Ensure the name of the metadata fields are right written. Finally check the values are "Anna" ( might be you are in confusion with value and label ).
 #47358  by m.carlzy
 
Hi jllort,
Sorry I'm quite struggling with this, when you say the result of your query are empty, what does it mean?

do you mean I need to write an sql statement aside from this?
Code: Select all
(QueryResult qr : ws.find(qParams))
how can we process QueryResult? Is there a sample way aside from System.out.print(qr).
Sorry, I'm trying to get OpenKM to integrate with my system and can't still make it work.

Really appreciate your help.
Thanks!
 #47369  by jllort
 
I think you are getting a QueryResult without documents, folder or mails, your query seems does not return values, that's why the getDocument() etc... are null.

I suggest first try your query from OpenKM UI, and then from API. Also I suggest start from basic query to more complex ... step by step, if you try the query with all parameters will be more diffictult identify the missing step or the error. The results from UI must be exactly the same as you get from the API.
 #47374  by m.carlzy
 
Hi jillort,
Thank you, I tried your suggestion. First I tested it on OpenKM UI - Basic Search.
Basic_Search.png
Basic_Search.png (116.77 KiB) Viewed 5616 times
As you can see above, there are results. So my assumption is that the same results will return by QueryResult with document details.

I tried basic search similar above using below codes with the same parameters I used in UI:
Code: Select all
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT);
qParams.setName("*Work*");
List<QueryResult> searchResult = ws.find(qParams);
But still document is null on the searchResult during debug:
Capture_1.PNG
Capture_1.PNG (54.81 KiB) Viewed 5616 times
I tested another scenario in UI:
Content = work
Capture_2.png
Capture_2.png (93.11 KiB) Viewed 5616 times
then I used the code:
Code: Select all
QueryParams qParams = new QueryParams();
qParams.setDomain(QueryParams.DOCUMENT);
qParams.setContent("work");
List<QueryResult> searchResult = ws.find(qParams);
Capture_3.PNG
Capture_3.PNG (57.16 KiB) Viewed 5616 times
Only excerpt has been populated.

I'm not sure if my expectation is correct but is QueryResult should have return document value at this point?
Kindly advise.

Thanks!
 #47388  by jllort
 
You should use SDK for JAVA version 1.2, we have done some improvement in the REST and now we are not returning a single Node Object. I will change the documentation section what indicates the compatibility coverage for version 1.1 until that change was applied.

Here the sample what is working:
Code: Select all
QueryParams qp = new QueryParams();
qp.setDomain(QueryParams.DOCUMENT);
qp.setName("*.pdf");
List<QueryResult> results = ws.find(qp);
System.out.println(results.size());
for (QueryResult qr : results) {
	System.out.println(qr.getNode() );
}

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.