Page 1 of 1

SOLVED: find method returns null document/null folder

PostPosted:Sat Jan 19, 2019 8:44 pm
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!

Re: find method returns null document/null folder

PostPosted:Mon Jan 21, 2019 9:13 am
by lnovoa
Hi!,
Can you pass the complete code with the instance to the sdk?

Re: find method returns null document/null folder

PostPosted:Mon Jan 21, 2019 2:28 pm
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();           
		} 
	}
}


Re: find method returns null document/null folder

PostPosted:Mon Jan 21, 2019 5:26 pm
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

Re: find method returns null document/null folder

PostPosted:Tue Jan 22, 2019 9:35 am
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!

Re: find method returns null document/null folder

PostPosted:Tue Jan 22, 2019 7:03 pm
by lnovoa
I can not see the capture, it is not attached correctly

Re: find method returns null document/null folder

PostPosted:Wed Jan 23, 2019 4:19 am
by m.carlzy
Hi,
Attached again the file.

Re: find method returns null document/null folder

PostPosted:Fri Jan 25, 2019 7:57 pm
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 ).

Re: find method returns null document/null folder

PostPosted:Mon Jan 28, 2019 12:13 pm
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!

Re: find method returns null document/null folder

PostPosted:Tue Jan 29, 2019 9:46 pm
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.

Re: find method returns null document/null folder

PostPosted:Wed Jan 30, 2019 11:00 am
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 5604 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 5604 times
I tested another scenario in UI:
Content = work
Capture_2.png
Capture_2.png (93.11 KiB) Viewed 5604 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 5604 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!

Re: find method returns null document/null folder

PostPosted:Sat Feb 02, 2019 11:27 am
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() );
}

Re: SOLVED: find method returns null document/null folder

PostPosted:Mon Feb 11, 2019 2:54 am
by m.carlzy
Hi jillort!
Thank you so much, after using SDK 1.2, my code is now working.