SOLVED: find method returns null document/null folder

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.
Post Reply
m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

SOLVED: find method returns null document/null folder

Post by m.carlzy » Sat Jan 19, 2019 8:44 pm

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.

lnovoa
Expert Boarder
Expert Boarder
Posts: 119
Joined: Tue Mar 27, 2018 8:00 am

Re: find method returns null document/null folder

Post by lnovoa » Mon Jan 21, 2019 9:13 am

Hi!,
Can you pass the complete code with the instance to the sdk?

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

Re: find method returns null document/null folder

Post by m.carlzy » Mon Jan 21, 2019 2:28 pm

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();           
		} 
	}
}


lnovoa
Expert Boarder
Expert Boarder
Posts: 119
Joined: Tue Mar 27, 2018 8:00 am

Re: find method returns null document/null folder

Post by lnovoa » Mon Jan 21, 2019 5:26 pm

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

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

Re: find method returns null document/null folder

Post by m.carlzy » Tue Jan 22, 2019 9:35 am

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!

lnovoa
Expert Boarder
Expert Boarder
Posts: 119
Joined: Tue Mar 27, 2018 8:00 am

Re: find method returns null document/null folder

Post by lnovoa » Tue Jan 22, 2019 7:03 pm

I can not see the capture, it is not attached correctly

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

Re: find method returns null document/null folder

Post by m.carlzy » Wed Jan 23, 2019 4:19 am

Hi,
Attached again the file.
Attachments
debug.PNG

jllort
Moderator
Moderator
Posts: 10455
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: find method returns null document/null folder

Post by jllort » Fri Jan 25, 2019 7:57 pm

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 ).

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

Re: find method returns null document/null folder

Post by m.carlzy » Mon Jan 28, 2019 12:13 pm

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!

jllort
Moderator
Moderator
Posts: 10455
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: find method returns null document/null folder

Post by jllort » Tue Jan 29, 2019 9:46 pm

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.

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

Re: find method returns null document/null folder

Post by m.carlzy » Wed Jan 30, 2019 11:00 am

Hi jillort,
Thank you, I tried your suggestion. First I tested it on OpenKM UI - Basic Search.
Basic_Search.png
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
I tested another scenario in UI:
Content = work
Capture_2.png
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
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!

jllort
Moderator
Moderator
Posts: 10455
Joined: Fri Dec 21, 2007 11:23 am
Location: Sineu - ( Illes Balears ) - Spain
Contact:

Re: find method returns null document/null folder

Post by jllort » Sat Feb 02, 2019 11:27 am

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() );
}

m.carlzy
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: Sat Jan 19, 2019 8:26 pm

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

Post by m.carlzy » Mon Feb 11, 2019 2:54 am

Hi jillort!
Thank you so much, after using SDK 1.2, my code is now working.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests