OKMImport
Basics
Section titled “Basics”In most methods you’ll see a parameter named “parentUuid”. The value of this parameter can be a valid document UUID node.
Also, in all methods you’ll see a parameter named “token”. Because the Cron task is executed in the background without authentication, the methods used in this scenario might use the token parameter. From the default application execution context, you must use the “null” value, which indicates that the application must use the “user session”.
Methods
Section titled “Methods”createDocument
Section titled “createDocument”Description:
| Method | Return values | Description |
|---|---|---|
| createDocument(String token, String parentUuid, String docName, File file) | NodeDocument | Create a new document. |
- The parameter parentUuid must be a valid folder or record UUID.
- The parameter file is the file of the document.
Example:
package com.openkm;
import java.io.File;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); File file = new File("/home/openkm/sample.pdf"); NodeDocument nodeDoc = okmImport.createDocument(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "document.pdf", file); System.out.println(nodeDoc); } catch (Exception e) { e.printStackTrace(); } }}createDocument (with metadata)
Section titled “createDocument (with metadata)”Description:
| Method | Return values | Description |
|---|---|---|
| createDocument(String token, String parentUuid, String name, Calendar created, String author, File file) | NodeDocument | Create a new document preserving the original creation date and author. |
- The parameter parentUuid must be a valid folder or record UUID.
- Use this overload when migrating content from external systems and you need to preserve the original created date and author.
Example:
package com.openkm;
import java.io.File;import java.util.Calendar;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeDocument;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); File file = new File("/home/openkm/sample.pdf"); Calendar created = Calendar.getInstance(); NodeDocument nodeDoc = okmImport.createDocument(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "document.pdf", created, "okmAdmin", file); System.out.println(nodeDoc); } catch (Exception e) { e.printStackTrace(); } }}createFolder
Section titled “createFolder”Description:
| Method | Return values | Description |
|---|---|---|
| createFolder(String token, String parentUuid, String fldName) | NodeFolder | Create a new folder. |
- The parameter parentUuid must be a valid folder or record UUID.
- The parameter fldName is the name of the folder.
Example:
package com.openkm;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); NodeFolder nodeFld = okmImport.createFolder(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newFolderName"); System.out.println(nodeFld); } catch (Exception e) { e.printStackTrace(); } }}createFolder (with metadata)
Section titled “createFolder (with metadata)”Description:
| Method | Return values | Description |
|---|---|---|
| createFolder(String token, String parentUuid, String name, Calendar created, String author) | NodeFolder | Create a new folder preserving the original creation date and author. |
- The parameter parentUuid must be a valid folder or record UUID.
- Use this overload when migrating content from external systems and you need to preserve the original created date and author.
Example:
package com.openkm;
import java.util.Calendar;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeFolder;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); Calendar created = Calendar.getInstance(); NodeFolder nodeFld = okmImport.createFolder(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newFolderName", created, "okmAdmin"); System.out.println(nodeFld); } catch (Exception e) { e.printStackTrace(); } }}createRecord
Section titled “createRecord”Description:
| Method | Return values | Description |
|---|---|---|
| createRecord(String token, String parentUuid, String recName) | NodeRecord | Create a new record. |
- The parameter parentUuid must be a valid folder or record UUID.
- The parameter recName is the name of the record.
Example:
package com.openkm;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeRecord;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); NodeRecord nodeRec = okmImport.createRecord(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newRecordName"); System.out.println(nodeRec); } catch (Exception e) { e.printStackTrace(); } }}createRecord (with metadata)
Section titled “createRecord (with metadata)”Description:
| Method | Return values | Description |
|---|---|---|
| createRecord(String token, String parentUuid, String name, Calendar created, String author) | NodeRecord | Create a new record preserving the original creation date and author. |
- The parameter parentUuid must be a valid folder or record UUID.
- Use this overload when migrating content from external systems and you need to preserve the original created date and author.
Example:
package com.openkm;
import java.util.Calendar;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeRecord;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); Calendar created = Calendar.getInstance(); NodeRecord nodeRec = okmImport.createRecord(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", "newRecordName", created, "okmAdmin"); System.out.println(nodeRec); } catch (Exception e) { e.printStackTrace(); } }}createMail
Section titled “createMail”Description:
| Method | Return values | Description |
|---|---|---|
| createMail(String token, String parentUuid, File file) | NodeMail | Create a new mail. |
- The parameter parentUuid must be a valid folder or record UUID.
- The parameter file is the file of the mail.
Example:
package com.openkm;
import java.io.File;
import com.openkm.api.OKMImport;import com.openkm.db.bean.NodeMail;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); File file = new File("/home/openkm/message.eml"); NodeMail nodeMail = okmImport.createMail(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", file); System.out.println(nodeMail); } catch (Exception e) { e.printStackTrace(); } }}importFolder
Section titled “importFolder”Description:
| Method | Return values | Description |
|---|---|---|
| importFolder(String token, String parentUuid, File folder, int threads) | int | Import a local folder hierarchy. Returns the number of errors encountered during the import. |
- The parameter parentUuid must be a valid folder or record UUID.
- The value threads sets the number of concurrent threads used by the import feature. This value should never exceed the number of server cores. If you have 20 cores, a good starting point might be to use 10 threads; take into consideration that other software, such as the database and the OS, also use the hardware.
Example:
package com.openkm;
import java.io.File;
import com.openkm.api.OKMImport;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMImport okmImport = ContextWrapper.getContext().getBean(OKMImport.class); File fld = new File("/home/openkm/import/"); int errors = okmImport.importFolder(null, "0a19e616-1d11-4ef7-a7c7-f1e109f8ea3c", fld, 4); System.out.println("Import errors: " + errors); } catch (Exception e) { e.printStackTrace(); } }}