Page 1 of 1
Automatic sorting
PostPosted:Fri Feb 20, 2015 8:00 am
by Aku
Hello,
i want files sort into a directory automatically, while importing.
- If the document contains the text "Invoice", it should be sort in the directory "Invoices".
- If the document contains the text "delivery", it should be sort into "deliveries".
I have created a "Automation rule" with the Event "Document move" and "post".
Then i add the action "Execute Scripting".
- Now I need the source code, with which I can move the files.
-> maybe like:
Code: Select allif(file.contains("Invoice")) {
file.moveTo("Invoices");
}
if(file.contains("Delivery")) {
file.moveTo("Deliveries");
}
Thanks
André
Re: Automatic sorting
PostPosted:Sat Feb 21, 2015 9:57 am
by jllort
Really what you want is catalog automatically documents based on document name.
All what you need is here
http://doxygen.openkm.com/openkm/de/de7 ... ument.html
Basically something like
Code: Select allString docPath = OKMDocument.getInstance().getProperties(null,uuid).getPath();
String name = docPath.substring(docPath.lastIndexOf("/")+1));
etc...
OKMDocument.getInstance().move(null, uuid, "/okm:root/etc...");
Re: Automatic sorting
PostPosted:Mon Feb 23, 2015 6:37 am
by Aku
Thanks.
I tried following code in Eclipse on Friday, with this site:
-
http://wiki.openkm.com/index.php/SDK_for_Java_2.2
Code: Select allpackage openkm;
import java.io.IOException;
import com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.bean.Folder;
import com.openkm.sdk4j.exception.*;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
connection();
}
private void connection() {
String host = "http://myIP:8080/OpenKM/";
String user = "myUser";
String password = "myPass";
OKMWebservices ws = OKMWebservicesFactory.newInstance(host, user, password);
getDocuments(ws);
}
public void getDocuments(OKMWebservices ws) {
try {
for (Folder fld : ws.getFolderChildren("/okm:root")) {
System.out.println(fld.getPath());
for (Document doc : ws.getDocumentChildren(fld.getPath())) {
String uuid = doc.getUuid();
System.out.println("\t" + uuid);
String extractedText = ws.getExtractedText(uuid);
System.out.println("\t\t" + extractedText);
}
}
} catch (DatabaseException e) {
e.printStackTrace();
} catch (WebserviceException e) {
e.printStackTrace();
} catch (PathNotFoundException e) {
e.printStackTrace();
} catch (UnknowException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Now i get the Document id's, but i can`t get the extracted text. I get this error in tomcat cmd:
Code: Select all2015-02-23 07:36:10,511 [http-bio-0.0.0.0-8080-exec-12] INFO org.springframework.ldap.core.LdapTemplate- The returnObjFlag of supplied SearchControls is not set but a ContextMapper is used - setting flag to true
2015-02-23 07:36:10,714 [http-bio-0.0.0.0-8080-exec-12] INFO org.springframework.ldap.core.LdapTemplate- The returnObjFlag of supplied SearchControls is not set but a ContextMapper is used - setting flag to true
2015-02-23 07:36:10,854 [http-bio-0.0.0.0-8080-exec-12] INFO org.springframework.ldap.core.LdapTemplate- The returnObjFlag of supplied SearchControls is not set but a ContextMapper is used - setting flag to true
2015-02-23 07:36:10,870 [http-bio-0.0.0.0-8080-exec-12] WARN org.apache.cxf.jaxrs.utils.JAXRSUtils- No operation matching request path "/OpenKM/services/rest/document/getExtractedText" is found, Relative Path: /getExtractedText, HTTP Method: GET, ContentType: application/xml, Accept: text/plain;charset=UTF-8,. Please enable FINE/TRACE log level for more details.
2015-02-23 07:36:10,870 [http-bio-0.0.0.0-8080-exec-12] WARN org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper- WebApplicationException has been caught : no cause is available
In Eclipse i get this error:
Code: Select all/okm:root/Lieferscheine
3ef7d162-21ed-43ad-9027-e1e22c5ace9d
com.openkm.sdk4j.exception.UnknowException: HTTP error code 404:
at com.openkm.sdk4j.impl.DocumentImpl.getExtractedText(DocumentImpl.java:1886)
at com.openkm.sdk4j.OKMWebservice20.getExtractedText(OKMWebservice20.java:523)
at openkm.Main.getDocuments(Main.java:38)
at openkm.Main.connection(Main.java:27)
at openkm.Main.<init>(Main.java:18)
at openkm.Main.main(Main.java:14)
Re: Automatic sorting
PostPosted:Wed Feb 25, 2015 6:16 pm
by jllort
For OpenKM 6.3 community must use sdk 1.1 as is indicated into compatibility table (
http://wiki.openkm.com/index.php/SDK_for_Java ). Do not use sdk 2.2 for community.
Re: Automatic sorting
PostPosted:Thu Feb 26, 2015 6:17 am
by Aku
Okay, thank you. I will try it immediately.

Re: Automatic sorting
PostPosted:Thu Feb 26, 2015 6:40 am
by Aku
There is no method like "getExtractedText(uuid)".
Exactly this method I wanted to use.
Re: Automatic sorting
PostPosted:Fri Feb 27, 2015 5:16 pm
by jllort
Sorry but I confirmed the method is not exposed in community version, is only present in professional version. Should modify source code for expose this method across webservices. I can give you some clues about what classes must be modified if you want.
Re: Automatic sorting
PostPosted:Mon Mar 02, 2015 5:55 am
by Aku
Thanks, that would be very helpful. Then I can try it

Re: Automatic sorting
PostPosted:Wed Mar 04, 2015 10:29 pm
by jllort
Re: Automatic sorting
PostPosted:Thu Mar 05, 2015 10:38 am
by Aku
Thanks.
1. Which of the functions is necessary for my use?
- I need a function like "getExtractedText()"
I have a uuid (e.g.: 72e5884a-9413-4941-9483-2e9f9d18b25f ).
- From this uuid I would like to read the extracted text.
2. Where can I test this function?
- In Administrator -> Scripting???
André
Re: Automatic sorting
PostPosted:Sat Mar 07, 2015 5:03 pm
by jllort
In class NodeDocumentDAO you get the method getExtractedText, but you will only get some text if document has yet procesed by queue, otherwise it will be empty. In same class with findByPk(String uuid) you'll be able to know if document is yet processed or not based on textExtracted value ( NodeDocument ). In case will be false, then you can force to process it.
Something like it:
Code: Select all // Get doc version uuid
NodeDocumentVersion currentVersion = NodeDocumentVersionDAO.getInstance().findCurrentVersion(uuid);
String docVerUuuid = currentVersion.getUuid();
// Document extractor
TextExtractorWork tew = new TextExtractorWork();
tew.setDocUuid(uuid);
tew.setDocPath(docPath);
tew.setDocVerUuid(docVerUuuid);
// Execute extractor
NodeDocumentDAO.getInstance().textExtractorHelper(tew);
Re: Automatic sorting
PostPosted:Mon Mar 09, 2015 5:57 am
by Aku
Thanks, i will try it.
André

Re: Automatic sorting
PostPosted:Mon Mar 09, 2015 1:02 pm
by Aku
Hello,
i have tried it.
I have added the first two lines into "Administration/Scripting"...
- I have changed the uuid to a available uuid.
Code: Select all// Get doc version uuid
NodeDocumentVersion currentVersion = NodeDocumentVersionDAO.getInstance().findCurrentVersion("f55974c5-924f-4425-b3f1-8b865c262430");
I get this error:
Code: Select allSourced file: inline evaluation of: ``// Get doc version uuid NodeDocumentVersion currentVersion = NodeDocumentVersio . . . '' : Typed variable declaration : Class: NodeDocumentVersion not found in namespace : at Line: 2 : in file: inline evaluation of: ``// Get doc version uuid NodeDocumentVersion currentVersion = NodeDocumentVersio . . . '' : NodeDocumentVersion
I am using the 6.3.0 Community version.
- Is it possible with it?
Thanks,
André
Re: Automatic sorting
PostPosted:Thu Mar 12, 2015 7:56 am
by jllort
Seems you forget some import. My suggestion is download openkm portable environment
http://sourceforge.net/projects/openkmportabledev/ and do not work on scripting view, for example add you code as crontab task ( and debug ) or as automation task. The portable dev environment comes with small samples.