• Basic file system document importer

  • 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.
 #50505  by rbtucker09
 
Hello, I'm having some trouble getting basic document importer working. My install is on Docker. This is the cron bash script I'm using:
Code: Select all
import com.openkm.core.*;
import com.openkm.api.*;
import java.io.*;
import com.openkm.module.db.stuff.DbSessionManager;
 
String token = DbSessionManager.getInstance().getSystemToken();
OKMDocument document = OKMDocument.getInstance();
OKMFolder folder = OKMFolder.getInstance();
 
public void autoImport(String okmPath, File fldpath){
  try {
    print("Scanning " + fldpath.getName() + "<br>");
    for (File file : fldpath.listFiles()) {
      print("Importing " + file.getName() + "<br>");
	try {
	  if (file.isDirectory()) {
	    try {
	      folder.createSimple(token, okmPath + file.getName());
	    } catch (ItemExistsException ie) {
	      print("folder already exists<br>");
	      // Folder already exists - just ignore exception
	    }
	    autoImport( okmPath + file.getName() + "/", file);
	  } else {
	    // Check if file is still being written to
	    long length = file.length();
	    Thread.sleep(1000);
	    if (file.length() > length) continue;  // Skip file this time
	    document.createSimple(token, okmPath + file.getName(), new FileInputStream(file));
	  }
	  print("Created " + okmPath + file.getName() + "<br>");
	} catch (Exception e) {
	  print ("Exception:" + e + "<br>");
	  // Something bad happened to prevent import. Skip to next file.
	 continue;
	}
       file.delete();
     }
  } catch (Exception e) {
    print("Exception: " + e + "<br>");
  }
}

autoImport("/okm:root/Scans/", new File(“/media/scans”));
This is the error I get from the script evaluation:
Code: Select all
bsh.EvalError: Sourced file: inline evaluation of: ``import com.openkm.core.*; import com.openkm.api.*; import java.io.*; import c . . . '' Token Parsing Error: Lexical error at line 44, column 41. Encountered: "\u201c" (8220), after : "" : at Line: 10 : in file: inline evaluation of: ``import com.openkm.core.*; import com.openkm.api.*; import java.io.*; import c . . . '' : public void autoImport ( String okmPath , File fldpath ) {
Any help is greatly appreciated!
 #50528  by jllort
 
In the script is written character “ either " ( is not the same for JAVA compiler ). Try with ( take a look at the difference ):
Code: Select all
import com.openkm.core.*;
import com.openkm.api.*;
import java.io.*;
import com.openkm.module.db.stuff.DbSessionManager;
 
String token = DbSessionManager.getInstance().getSystemToken();
OKMDocument document = OKMDocument.getInstance();
OKMFolder folder = OKMFolder.getInstance();
 
public void autoImport(String okmPath, File fldpath){
  try {
    print("Scanning " + fldpath.getName() + "<br>");
    for (File file : fldpath.listFiles()) {
      print("Importing " + file.getName() + "<br>");
	try {
	  if (file.isDirectory()) {
	    try {
	      folder.createSimple(token, okmPath + file.getName());
	    } catch (ItemExistsException ie) {
	      print("folder already exists<br>");
	      // Folder already exists - just ignore exception
	    }
	    autoImport( okmPath + file.getName() + "/", file);
	  } else {
	    // Check if file is still being written to
	    long length = file.length();
	    Thread.sleep(1000);
	    if (file.length() > length) continue;  // Skip file this time
	    document.createSimple(token, okmPath + file.getName(), new FileInputStream(file));
	  }
	  print("Created " + okmPath + file.getName() + "<br>");
	} catch (Exception e) {
	  print ("Exception:" + e + "<br>");
	  // Something bad happened to prevent import. Skip to next file.
	 continue;
	}
       file.delete();
     }
  } catch (Exception e) {
    print("Exception: " + e + "<br>");
  }
}

autoImport("/okm:root/Scans/", new File("/media/scans"));
The error indicate the exact line and column what it raises the error. There're easiest way to upload files like hot folder https://www.youtube.com/watch?v=zLRjkNr ... e=emb_logo if you explain your scenario might be we can find the easiest way for you.

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.