• Automatic sorting

  • OpenKM has many interesting features, but requires some configuration process to show its full potential.
OpenKM has many interesting features, but requires some configuration process to show its full potential.
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.
 #31355  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 all
if(file.contains("Invoice")) {
	file.moveTo("Invoices");
}
if(file.contains("Delivery")) {
	file.moveTo("Deliveries");
}
Thanks
André
 #31372  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 all
String docPath = OKMDocument.getInstance().getProperties(null,uuid).getPath();
String name = docPath.substring(docPath.lastIndexOf("/")+1));
etc...
OKMDocument.getInstance().move(null, uuid, "/okm:root/etc...");
 #31393  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 all
package 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 all
2015-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)
 #31425  by Aku
 
Okay, thank you. I will try it immediately.
:)
 #31426  by Aku
 
There is no method like "getExtractedText(uuid)".

Exactly this method I wanted to use.
 #31448  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.
 #31476  by Aku
 
Thanks, that would be very helpful. Then I can try it :)
 #31501  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é
 #31531  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);
 #31544  by Aku
 
Thanks, i will try it.

André :)
 #31545  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 all
Sourced 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é
 #31577  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.

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.