OKMDocument

Basics

On almost methods you'll see parameter named "docId". The value of this parameter can be some valid document UUID or path node.

Example of docId:

  • Using UUID -> "c41f9ea0-0d6c-45da-bae4-d72b66f42d0f";
  • Using path -> "/okm:root/sample.pdf"

When you'll see parameter named "fldId". The value of this parameter can be some valid folder UUID or path node.

Example of docId:

  • Using UUID -> "c6785440-0d6c-45da-1234-d9874563d0f";
  • Using path -> "/okm:root/folder1"

About the parameter named "dstId", the value of this parameter can be some valid folder UUID or path node.

Example of dstId:

  • Using UUID -> "c4455667-0d6c-45da-1234-d98564323e0";
  • Using path -> "/okm:root/folder2"

When is used parameter named "docPath" then the value of this paremeter can be some valid document .

Example of docPath:

  • Using path -> "/okm:root/sample.pdf"

Also on all methods you'll see parameter named "token". When accessing application across SOAP the login process returns a token, what is used to identify the user on all the exposed methods. From default application execution context you must use "null" value what indicates to the application must use the "user session".

On special cases you might be "promoted as Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

create

Description:

MethodReturn valuesDescription

create(String token, Document doc, InputStream is)

Document

Create a new document.

The parameter doc must be initialized with the OpenKM path value into the repository. Optionally you can also set keywords and title values.

The other parameteres are not taken in consideration for document creation.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        try {
            is = new FileInputStream("/home/user/sample.pdf");
            Document doc = new Document();
            doc.setPath("/okm:root/sample.pdf");
            // Optional
            doc.setTitle("sample document");
            doc.getKeywords().add("key1");
            doc.getKeywords().add("key2");
            // Create document
            doc = OKMDocument.getInstance().create(null, doc, is);
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

createSimple

Description:

MethodReturn valuesDescription

createSimple(String token, String docPath, InputStream is)

Document

Create a new document.

The parameter docPath must be initialized with the OpenKM path value into the repository.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        try {
            is = new FileInputStream("/home/user/sample.pdf");
            String docPath = "/okm:root/sample.pdf";
            Document doc = OKMDocument.getInstance().createSimple(null, docPath, is);
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

delete

Description:

MethodReturn valuesDescription

delete(String token, String docId)

void

Delete a document.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            // Delete document by path
            OKMDocument.getInstance().delete(null, "/okm:root/sample.pdf");
            // Delete document by uuid
            OKMDocument.getInstance().delete(null, "adc048d7-3791-4540-ae32-680629f73875");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProperties

Description:

MethodReturn valuesDescription

getProperties(String token, String docId)

Document

Return a document properties.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        try {
            Document doc = OKMDocument.getInstance().getProperties(null, "adc048d7-3791-4540-ae32-680629f73875");
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getContent

Description:

MethodReturn valuesDescription

getContent(String token, String docId, boolean checkout)

InputStream

Return the document content.

When paramer checkout is true, the document is marked for edition.

Example:

package com.openkm;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        OutputStream fos = null;
        try {
            is = OKMDocument.getInstance().getContent(null, "adc048d7-3791-4540-ae32-680629f73875", false);
            File tmp = new File("/home/user/sample.pdf");
            fos = new FileOutputStream(tmp);
            IOUtils.copy(is, fos);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        }
    }
}

getContentByVersion

Description:

MethodReturn valuesDescription

getContentByVersion(String token, String docId, String versionId)

InputStream

Return the document content by version.

The parameter versionIs is the name of the document version.

Example:

package com.openkm;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        OutputStream fos = null;
        try {
            is = OKMDocument.getInstance().getContentByVersion(null, "adc048d7-3791-4540-ae32-680629f73875", "1.1");
            File tmp = new File("/home/user/sample.pdf");
            fos = new FileOutputStream(tmp);
            IOUtils.copy(is, fos);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        }
    }
}

getChilds

Description:

MethodReturn valuesDescription

getChilds(String token, String fldId)

List<Document>

Returns a list of all documents which their parent is fldId.

The parameter fldId can be a folder node.

This method is deprecated in favour of getChildren method. We encourage do not using it, because on nearly future will be removed.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        try {
            for (Document doc : OKMDocument.getInstance().getChilds(null, "/okm:root/import")) {;
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

getChildren

Descripcion:

MethodReturn valuesDescription

getChildren(String token, String fldId)

List<Document>

Returns a list of all documents which their parent is fldId.

The parameter fldId can be a folder node.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        try {
            for (Document doc : OKMDocument.getInstance().getChildren(null, "/okm:root/import")) {;
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

rename

Description:

MethodReturn valuesDescription

rename(String token, String docId, String newName)

Document

Changes the name of a document.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        try {
            Document doc = OKMDocument.getInstance().rename(null, "/okm:root/samples.pdf","samples_renamed.pdf");
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

setProperties

Description:

MethodReturn valuesDescription

setProperties(String token, Document doc)

void

Changes some document properties.

Variables allowed to be changed:

  • Title
  • Description
  • Language
  • Associated categories
  • Associated keywords

Only not null and not empty variables will be taken in consideration.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Document;

public class Test {
    public static void main(String[] args) {
        try {
            Document doc = OKMDocument.getInstance().getProperties(null, "/okm:root/samples.pdf");
            doc.getKeywords().add("key1");
            doc.setDescription("some description");
            OKMDocument.getInstance().setProperties(null, doc);
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

checkout

Description:

MethodReturn valuesDescription

checkout(String token, String docId)

void

Marks the document for edition.

Only one user can modify a document at a time.

Before starting edition you must do a checkout action that locks the edition process for other users and allows edition only to the user who has executed the action.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().checkout(null, "/okm:root/samples.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

cancelCheckout

Description:

MethodReturn valuesDescription

cancelCheckout(String token, String docId)

void

Cancels a document edition.

This action can only be done by the user who previously executed the checkout action.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().cancelCheckout(null, "/okm:root/samples.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

forceCancelCheckout

Description:

MethodReturn valuesDescription

forceCancelCheckout(String token, String docId)

void

Cancels a document edition.

This method allows to cancel edition on any document.

It is not mandatory to execute this action by the same user who previously executed the checkout action.

This action can only be done by a super user ( user with ROLE_ADMIN ).

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().forceCancelCheckout(null, "/okm:root/samples.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

isCheckedOut

Description:

MethodReturn valuesDescription

isCheckedOut(String token, String docId)

void

Returns a boolean that indicates if the document is on edition or not.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

checkin

Description:

MethodReturn valuesDescription

checkin(String token, String docId, InputStream is, String comment)

Version

Updates a document with a new version and returns an object with new Version values.

Only the user who started the edition - checkout - is allowed to update the document.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.poi.util.IOUtils;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        try {
            is = new FileInputStream("/home/user/sample.pdf");
            OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", is, "optional comment");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

checkin

Description:

MethodReturn valuesDescription

checkin(String token, String docId, InputStream is, String comment, int increment)

Version

Updates a document with a new version and returns an object with new Version values.

The increment value depends on VersionNumeration implementation.

More information about VersionNumeration at Creating your own Version Number Adapter.

Only the user who started the edition - checkout - is allowed to update the document.

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import org.apache.poi.util.IOUtils;

import com.openkm.api.OKMDocument;
import com.openkm.vernum.VersionNumerationAdapter;

public class Test {
    public static void main(String[] args) {
        InputStream is = null;
        try {
            is = new FileInputStream("/home/user/sample.pdf");
            OKMDocument.getInstance().checkin(null, "/okm:root/samples.pdf", is, "optional comment", VersionNumerationAdapter.INCREASE_MINOR);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

isCheckedOut

Description:

MethodReturn valuesDescription

isCheckedOut(String token, String docId)

void

Returns a boolean that indicates if the document is on edition or not.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            System.out.println(OKMDocument.getInstance().isCheckedOut(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

getVersionHistory

Description:

MethodReturn valuesDescription

getVersionHistory(String token, String docId

List<Version>

Returns a list of all document versions.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.Version;

public class Test {
    public static void main(String[] args) {
        try {
            for (Version ver :OKMDocument.getInstance().getVersionHistory(null, "/okm:root/samples.pdf")) {
                System.out.println(ver);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

lock

Description:

MethodReturn valuesDescription

lock(String token, String docId

LockInfo

Locks a document and returns an object with the Lock information.

Only the user who locked the document is allowed to unlock.

A locked document cannot be modified by other users.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.LockInfo;

public class Test {
    public static void main(String[] args) {
        try {
            LockInfo lockInfo = OKMDocument.getInstance().lock(null, "/okm:root/samples.pdf"));
            System.out.println(lockInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

unlock

Description:

MethodReturn valuesDescription

unlock(String token, String docId

LockInfo

Unlocks a locked document.

Only the user who locked the document is allowed to unlock.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().unlock(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forceUnlock

Description:

MethodReturn valuesDescription

forceUnlock(String token, String docId

LockInfo

Unlocks a locked document.

This method allows to unlock any locked document.

It is not mandatory execute this action by the same user who previously executed the checkout lock action.

This action can only be done by a super user ( user with ROLE_ADMIN ).

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().forceUnlock(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isLocked

Description:

MethodReturn valuesDescription

isLocked(String token, String docId)

void

Returns a boolean that indicates if the document is locked or not.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            System.out.println(OKMDocument.getInstance().isLocked(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        } 
    }
}

getLockInfo

Description:

MethodReturn valuesDescription

getLockInfo(String token, String docId)

LockInfo

Returns an object with the Lock information.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.LockInfo;

public class Test {
    public static void main(String[] args) {
        try {
            LockInfo lockInfo = OKMDocument.getInstance().getLockInfo(null, "/okm:root/samples.pdf"));
            System.out.println(lockInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purge

Description:

MethodReturn valuesDescription

purge(String token, String docId)

void

The document is definitely removed from repository.

Usually you will purge documents into /okm:trash/userId - the personal trash user locations - but is possible to directly purge any document from the whole repository.

When a document is purged only will be able to be restored from a previously repository backup. The purge action removes the document definitely from the repository.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().purge(null, "/okm:root/samples.pdf"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

move

Description:

MethodReturn valuesDescription

move(String token, String docId, String dstId)

void

Move document into some folder.

The values of the dstId parameter should be a folder UUID or path.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().move(null, "/okm:root/samples.pdf", "/okm/root/temp"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copy

Description:

MethodReturn valuesDescription

copy(String token, String docId, String dstId)

void

Copy a document into some folder.

The values of the dstId parameter should be a folder UUID or path.

Only the binary data and the security grants are copied to destination, the metadata, keywords, etc. of the document are not copied.

See "extendedCopy" method for this feature.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().copy(null, "/okm:root/samples.pdf", "/okm/root/temp"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extendedCopy

Description:

MethodReturn valuesDescription

extendedCopy(String token, String docId, String dstId, String docName, ExtendedAttributes extAttr)

void

Copies a document with associated data into some folder.

The values of the dstId parameter should be a folder UUID or path.

When the parameter newName value is null, the document will preserve the same name.

By default only the binary data and the security grants, the metadata, keywords, etc. of the document are not copied.

Additional:

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original value of the notes will be copied.
  • When wiki parameter is true the original value of the wiki will be copied.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.bean.ExtendedAttributes;

public class Test {
    public static void main(String[] args) {
        try {
            ExtendedAttributes extAttr = new ExtendedAttributes();
            // copy keywords
            extAttr.setKeywords(true);
            OKMDocument.getInstance().extendedCopy(null, "/okm:root/samples.pdf", "/okm:root/temp", "samples_renamed.pdf", extAttr);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

restoreVersion

Description:

MethodReturn valuesDescription

restoreVersion(String token, String docId, String versionId)

void

Restores previously document version to actual version.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().restoreVersion(null, "/okm:root/samples.pdf", "1.2");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purgeVersionHistory

Description:

MethodReturn valuesDescription

purgeVersionHistory(String token, String docId)

void

Purges all the previous document versions except the actual version.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            OKMDocument.getInstance().purgeVersionHistory(null, "/okm:root/samples.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getVersionHistorySize

Description:

MethodReturn valuesDescription

getVersionHistorySize(String token, String docId)

long

Returns the sum in bytes of all documents into documents history.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;
import com.openkm.util.FormatUtil;

public class Test {
    public static void main(String[] args) {
        try {
            System.out.println(FormatUtil.formatSize(OKMDocument.getInstance().getVersionHistorySize(null, "/okm:root/samples.pdf")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isValid

Description:

MethodReturn valuesDescription

isValid(String token, String docId)

boolean

Returns a boolean that indicates if the node is a document or not.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            boolean valid = OKMDocument.getInstance().isValid(null, "/okm:root/samples.pdf");
            System.out.println(valid);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPath

Description:

MethodReturn valuesDescription

getPath(String token, String uuid)

String

Converts a document UUID to document path.

Example:

package com.openkm;

import com.openkm.api.OKMDocument;

public class Test {
    public static void main(String[] args) {
        try {
            String docPath = OKMDocument.getInstance().getPath(null, "f123a950-0329-4d62-8328-0ff500fd42dbg");
            System.out.println(docPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}