Document samples

Basics

Example of uuid:

  • Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method

At this point you can use all the Document methods from "document" class as is shown below:

ws.document.createDocument("1be884f4-5758-4985-94d1-f18bfe004db8", "logo.png", is);

Methods

createDocument

Description:

MethodReturn valuesDescription

createDocument(String uuid, String name, InputStream is)

Document

Creates a new document. Return an object Document with the properties of the created document.

The values of the uuid parameter should be a folder or record node UUID.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png");
            Document doc = ws.document.createDocument("1be884f4-5758-4985-94d1-f18bfe004db8", "logo.png", is);
            System.out.println(doc);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createDocument

Description:

MethodReturn valuesDescription

createDocument(String uuid, String name, InputStream is, long nodeClass)

Document

Creates a new document with nodeClass. Return an object Document with the properties of the created document.

The values of the uuid parameter should be a folder or record node UUID.

The nodeClass parameter should be a valid bussiness type ( serie ) value. A nodeClass with value 0 means there's no business type ( serie ) selected.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png");
            long nodeClass = 0;
            Document doc = ws.document.createDocument("1be884f4-5758-4985-94d1-f18bfe004db8", "logo.png", is, nodeClass);
            System.out.println(doc);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

deleteDocument

Description:

MethodReturn valuesDescription

deleteDocument(String uuid)

void

Delete a document.

When a document is deleted it is automatically moved to /okm:trash/userId folder.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.deleteDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDocumentProperties

Description:

MethodReturn valuesDescription

getDocumentProperties(String uuid)

Document

Return the document properties.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.getDocumentProperties("1ec49da9-1746-4875-ae32-9281d7303a62"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getContent

Description:

MethodReturn valuesDescription

getContent(String uuid)

InputStream

Retrieve document content - binary data - of the actual document version.

In case you sent the file across a Servlet response we suggest set the content length with:

Document doc = ws.getDocumentProperties("1ec49da9-1746-4875-ae32-9281d7303a62");
response.setContentLength(new Long(doc.getActualVersion().getSize()).intValue());

We've found wrong size problems while using:

response.setContentLength(is.available());

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OutputStream fos = new FileOutputStream("/home/openkm/logo.png");
            InputStream is = ws.document.getContent("1ec49da9-1746-4875-ae32-9281d7303a62");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getContentByVersion

Description:

MethodReturn valuesDescription

getContentByVersion(String uuid, String versionName)

InputStream

Retrieves a document content ( binary data ) from a specific document version.

In case you sent the file across a Servlet response we suggest set the content length with:

Document doc = ws.getDocumentProperties("1ec49da9-1746-4875-ae32-9281d7303a62");
response.setContentLength(new Long(doc.getActualVersion().getSize()).intValue());

We've found wrong size problems while using:

response.setContentLength(is.available());

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OutputStream fos = new FileOutputStream("/home/openkm/logo.png");
            InputStream is = ws.document.getContentByVersion("/okm:root/logo.png", "1.1");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDocumentChildren

Description:

MethodReturn valuesDescription

getDocumentChildren(String fldId)

List<Document>

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

The parameter fldId can be a folder or a record node UUID.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Document doc : ws.document.getDocumentChildren("1be884f4-5758-4985-94d1-f18bfe004db8")) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

renameDocument

Description:

MethodReturn valuesDescription

renameDocument(String uuid, String newName)

Document

Changes the name of a document.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Document doc = ws.document.renameDocument("1ec49da9-1746-4875-ae32-9281d7303a62", "logo_rename.png");
            System.out.print(doc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setProperties

Description:

MethodReturn valuesDescription

 setProperties(String uuid, String title, String description, String lang, List<String> keywords, List<String> categories)

void

Changes some document properties.

The parameter lang must be ISO 691-1 compliant.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<String> keywords = new ArrayList<>();
            keywords.add("test");
            keywords.add("invoice");

            List<String> categories = new ArrayList<>();
            categories.add("58c9b25f-d83e-4006-bd78-e26d7c6fb648");

            ws.document.setProperties("1ec49da9-1746-4875-ae32-9281d7303a62", "new title", "some description", "es", keywords, categories);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setLanguage

Description:

MethodReturn valuesDescription

setLanguage(String uuid, String lang)

void

Sets the document language.

The parameter lang must be ISO 691-1 compliant.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.setLanguage("1ec49da9-1746-4875-ae32-9281d7303a62", "en");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDocumentTitle

Description:

MethodReturn valuesDescription

setDocumentTitle(String uuid, String title)

void

Sets the document title.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.setDocumentTitle("1ec49da9-1746-4875-ae32-9281d7303a62", "Some title here");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

checkout

Description:

MethodReturn valuesDescription

 checkout(String uuid)

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.checkout("1ec49da9-1746-4875-ae32-9281d7303a62");
            // At this point the document is locked for other users except for the user who executed the action
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

cancelCheckout

Description:

MethodReturn valuesDescription

cancelCheckout(String uuid)

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            // At this point the document is locked for other users except for the user who executed the action
            ws.document.cancelCheckout("1ec49da9-1746-4875-ae32-9281d7303a62");
            // At this point other users are allowed to execute a checkout and modify the document
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forceCancelCheckout

Description:

MethodReturn valuesDescription

forceCancelCheckout(String uuid)

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            // At this point the document is locked for other users except for the user who executed the action
            ws.document.forceCancelCheckout("1ec49da9-1746-4875-ae32-9281d7303a62");
            // At this point other users are allowed to execute a checkout and modify the document
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isCheckedOut

Description:

MethodReturn valuesDescription

isCheckedOut(String docId)

Boolean

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println("Is the document checkout:" + ws.document.isCheckedOut("1ec49da9-1746-4875-ae32-9281d7303a62"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

checkin

Description:

MethodReturn valuesDescription

checkin(String uuid, 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.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/logo.png");
            ws.document.checkin("1ec49da9-1746-4875-ae32-9281d7303a62", is, "optional some comment");
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

checkin

Description:

MethodReturn valuesDescription

checkin(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 value of increment variable must be 1 or greater.

The valid values of increment variable depends on the VersionNumberAdapter you  have enabled.

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.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/logo.png");
            ws.document.checkin("1ec49da9-1746-4875-ae32-9281d7303a62", is, "optional some comment", 2);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

lockDocument

Description:

MethodReturn valuesDescription

lockDocument(String uuid)

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.lockDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

unlockDocument

Description:

MethodReturn valuesDescription

unlockDocument(String uuid)

void

Unlocks a locked document.

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.unlockDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forceUnlockDocument

Description:

MethodReturn valuesDescription

forceUnlockDocument(String uuid)

void

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.forceUnlockDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isLocked

Description:

MethodReturn valuesDescription

isLocked(String uuid)

Boolean

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println("Is document locked:" + ws.document.isLocked("1ec49da9-1746-4875-ae32-9281d7303a62"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getLockInfo

Description:

MethodReturn valuesDescription

getLockInfo(String uuid)

LockInfo

Returns an object with the Lock information

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.getLockInfo("1ec49da9-1746-4875-ae32-9281d7303a62"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purgeDocument

Description:

MethodReturn valuesDescription

purgeDocument(String uuid)

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.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.purgeDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

moveDocument

Description:

MethodReturn valuesDescription

moveDocument(String uuid, String dstId)

void

Move document into some folder or record.

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.moveDocument("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e", "8599eab7-ae61-4628-8010-1103d6950c63");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copyDocument

Description:

MethodReturn valuesDescription

copyDocument(String uuid, String dstId, String newName)

void

Copy a document into some folder or record.

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

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

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

See "extendedDocumentCopy" method for this feature.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.copyDocument("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e", "8599eab7-ae61-4628-8010-1103d6950c63", "new_logo.png");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getVersionHistorySize

Description:

MethodReturn valuesDescription

getVersionHistorySize(String uuid)

long

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

Example:

package com.openkm;

import java.util.Locale;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            String[] UNITS = new String[]{"B", "KB", "MB", "GB", "TB", "PB", "EB"};
            long bytes = ws.document.getVersionHistorySize("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e");
            String value = "";

            for (int i = 6; i > 0; i--) {
                double step = Math.pow(1024, i);
                if (bytes > step) {
                    value = String.format(Locale.ROOT, "%3.1f %s", bytes / step, UNITS[i]);
                }
            }

            if (value.isEmpty()) {
                value = Long.toString(bytes) + " " + UNITS[0];
            }

            System.out.println(value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isValidDocument

Description:

MethodReturn valuesDescription

isValidDocument(String docId)

Boolean

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.isValidDocument("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDocumentPath

Description:

MethodReturn valuesDescription

getDocumentPath(String uuid)

String

Converts a document UUID to document path.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.getDocumentPath("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDetectedLanguages

Description:

MethodReturn valuesDescription

getDetectedLanguages()

List<String>

Return a list of available document languages what OpenKM can identify.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (String lang : ws.document.getDetectedLanguages()) {
                System.out.println(lang);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extendedDocumentCopy

Description:

MethodReturn valuesDescription

extendedDocumentCopy(String nodeId, String dstId, String name, boolean categories, boolean keywords, boolean propertyGroups, boolean notes, boolean wiki, boolean security)

void

Copies a document with associated data into some folder or record.

The values of the nodeId parameter should be a Document UUID.

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

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 the wiki parameter is true the original value of the wiki will be copied.
  • When the security parameter is true the original value of the security will be copied.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.extendedDocumentCopy("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e", "8599eab7-ae61-4628-8010-1103d6950c63", "new_logo.png", true, true, true, true, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getExtractedText

Description:

MethodReturn valuesDescription

getExtractedText(String uuid)

String

Returns an String with the extracted text by text extractor process.

When a document is uploaded to OpenKM, it goes into text extraction queue. There's a crontab tab that periodically process this queue and extract document contents.

Unfortunately there is not a direct way to know if a document has been processed or not from the API, because this information is only stored at database level.

Althoughthis restriction, from API - only administrators users - can do database queries to retrieve this information. Check Repository samples for accessing database level.

More information at Statistics.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            String text = ws.document.getExtractedText("46762f90-82c6-4886-8d21-ad3017dd78a7");
            System.out.println(text);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getThumbnail

Description:

MethodReturn valuesDescription

 getThumbnail(String uuid, ThumbnailType type)

InputStream

Returns thumbnail image data.

Available types:

  • ThumbnailType.THUMBNAIL_PROPERTIES ( shown in properties view )
  • ThumbnailType.THUMBNAIL_LIGHTBOX ( shown in light box )
  • ThumbnailType.THUMBNAIL_SEARCH ( shown in search view )

Each thumbnail type has its own image dimensions.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.ThumbnailType;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OutputStream fos = new FileOutputStream("/home/openkm/invoice.png");
            InputStream is = ws.document.getThumbnail("46762f90-82c6-4886-8d21-ad3017dd78a7", ThumbnailType.THUMBNAIL_LIGHTBOX);
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createDocumentFromTemplate

Description:

MethodReturn valuesDescription

createDocumentFromTemplate(String uuid, String dstPath, String language, boolean categories,
            boolean keywords, boolean propertyGroups, boolean notes, boolean wiki, Map<String, String> properties)

Document

Creates a new document from the template and returns an object Document.

The uuid parameter is the UUID value of the template file.

The dstPath value is the document destination path.

The parameter language is optional.

When the template uses metadata groups to fill in fields, then these values are mandatory and must be set into properties parameter. 

For more information about Templates and metadata check: Creating templates.

Additional:

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

Example:

The example below is based on Creating PDF template sample.

package com.openkm;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.util.ISO8601;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties.put("okp:tpl.name", "Some name");
            Calendar cal = Calendar.getInstance();
            // Value must be converted to String ISO 8601 compliant
            properties.put("okp:tpl.bird_date", ISO8601.formatBasic(cal));
            properties.put("okp:tpl.language", "[ \"java\" ]");

            Document doc = ws.document.createDocumentFromTemplate("9fa9787e-d8b0-4ff7-905a-a89f0b228ec8", "/okm:root/test/document.pdf", "es", true, true, true, false, false, properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

}

updateDocumentFromTemplate

Description:

MethodReturn valuesDescription

updateDocumentFromTemplate(String uuid, String dstId, Map<String, String> properties) 

Document

Updates a document previously created from the template and returns an object Document.

The uuid value is the UUID value of the template file.

The dstId is the document to updated UUID.

This method only has sense when the template uses metadata groups to fill in fields.

For more information about Templates and metadata take a look at Creating templates .

Example:

The example below is based on Creating PDF template sample.

package com.openkm;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.util.ISO8601;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties.put("okp:tpl.name", "update Some name");
            Calendar cal = Calendar.getInstance();
            // Value must be converted to String ISO 8601 compliant
            properties.put("okp:tpl.bird_date", ISO8601.formatBasic(cal));
            properties.put("okp:tpl.language", "[ \"python\" ]");

            ws.document.updateDocumentFromTemplate("9fa9787e-d8b0-4ff7-905a-a89f0b228ec8", "058b9379-b441-454d-8590-00d5a280ce79", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAnnotations

Description:

MethodReturn valuesDescription

getAnnotations(String uuid, String versionName)  

String

Return the document annotations of some document version.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.getAnnotations("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e", "1.0"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDifferences

Description:

MethodReturn valuesDescription

getDifferences(String uuid, String versionName1, String versionName2)

InputStream

Return a PDF document with the differences between two document versions.

Example:

package com.openkm;

import java.io.FileOutputStream;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = ws.document.getDifferences("46762f90-82c6-4886-8d21-ad3017dd78a7", "1.0", "1.1");
            FileOutputStream fos = new FileOutputStream("/home/gnujavasergio/okm/out.pdf");
            IOUtils.copy(is, fos);
            is.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getCheckedOut

Description:

MethodReturn valuesDescription

getCheckedOut()

List<Document>

Return a list of documents checkout by the user.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (Document doc : ws.document.getCheckedOut()) {
                System.out.println(doc);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createDocument

Description:

MethodReturn valuesDescription

createDocument(String uuid, File file)

Document

Creates a new document and returns as a result an object Document with the properties of the created document.

The values of the uuid parameter should be a folder or record node UUID.

Example:

package com.openkm;

import java.io.File;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            File file = new File("/home/gnujavasergio/okm/logo.png");
            Document doc = ws.document.createDocument("151f3a54-f370-47d6-801a-d20faecec180", file);
            System.out.println(doc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDocumentNodeClass

Description:

MethodReturn valuesDescription

setDocumentNodeClass(String uuid, long ncId)

void

Set the NodeClass.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long ncId = 2;
            ws.document.setDocumentNodeClass("7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDocumentDispositionStage

Description:

MethodReturn valuesDescription

setDocumentDispositionStage(String uuid, long stage)

void

Set the disposition stage

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long stage = 1;
            ws.document.setDocumentDispositionStage("7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", stage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDocumentDescription

Description:

MethodReturn valuesDescription

setDocumentDescription(String uuid, String description)

void

Set a description.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.setDocumentDescription("7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createWizardDocument

Description:

MethodReturn valuesDescription

createWizardDocument(String uuid, String name, long nodeClass, InputStream is)

WizardNode

Create a new document with wizard.

The parameters uuid should be any valid folder or record UUID.

The WizardNode contains a list of pending actions what should be done to complete the process of document creation. These might be:

  • Add keyword
  • Add Categories
  • Add Metadata

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.WizardNode;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/gnujavasergio/okm/logo.png");
            WizardNode wn = ws.document.createWizardDocument("1f323e88-64ee-4f57-91e2-9276f8c603f9", "logo.png", 0, is);
            System.out.print(wn);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isOCRDataCaptureSupported

Description:

MethodReturn valuesDescription

isOCRDataCaptureSupported(String uuid)

boolean

Check if the node supports an OCR data capture.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            if (ws.document.isOCRDataCaptureSupported("b2f88679-e3fd-4f97-bf0e-abf76f9ec499")) {
                System.out.println("Yes supported OCR Data capture");
            } else {
                System.out.println("No supported OCR Data capture");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

recognize

Description:

MethodReturn valuesDescription

recognize(String uuid) 

OCRRecognise

Return an OCRRecognise object.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.OCRRecognise;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            OCRRecognise ocr = ws.document.recognize("b2f88679-e3fd-4f97-bf0e-abf76f9ec499");
            System.out.println(ocr);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

captureData

Description:

MethodReturn valuesDescription

captureData(String uuid,  long templateId) 

void

Proceed to the OCR data capture using OCR template identified by templateId.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            long templateId = 1;
            ws.document.captureData("f123a950-0329-4d62-8328-0ff500fd42db", templateId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getNumberOfPages

Description:

MethodReturn valuesDescription

getNumberOfPages(String uuid) 

int

Get the number of pages of a document.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println("The number of pages is : " + ws.document.getNumberOfPages("b2f88679-e3fd-4f97-bf0e-abf76f9ec499"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPageAsImage

Description:

MethodReturn valuesDescription

getPageAsImage(String uuid, int pageNumber, int maxWidth, int maxHeight) 

String

Return specific page as an image encoded as a String in b64.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.getPageAsImage("3fe350e2-69e8-4681-a97c-6ac4ba6c1524", 1, 150, 150));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getLiveEditRestrictedMimeTypes

Description:

MethodReturn valuesDescription

getLiveEditRestrictedMimeTypes() 

List<String>

Return a list of mymetypes what can not be used with liveedit feature.

Example:

package com.openkm;

import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<String> mymeTypes = ws.document.getLiveEditRestrictedMimeTypes();
            for (String mimeType : mymeTypes) {
                System.out.println(mimeType);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

liveEditCheckin

Description:

MethodReturn valuesDescription

liveEditCheckin(String uuid, String comment, int increment) 

void

It does a live edit checkin.

The method should be used only when the document has been edited by live edit.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.document.liveEditCheckin("8b9a32c8-db65-41c8-a2a0-af03761f60b6", "comment 1.1", 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

mergePdf

Description:

MethodReturn valuesDescription

mergePdf(String destinationUuid, String docName, List<String> uuids) 

void

Merge two or more PDF files.

The parameters destinationUuid should be any valid folder or record UUID.

Example:

package com.openkm;

import java.util.ArrayList;
import java.util.List;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<String> uuids = new ArrayList<>();
            uuids.add("3fe350e2-69e8-4681-a97c-6ac4ba6c1524");
            uuids.add("8b9a32c8-db65-41c8-a2a0-af03761f60b6");
            String fldUuid = "7213e597-c147-46c9-a90b-ac3966b3114b";
            ws.document.mergePdf(fldUuid, "MergePdf.pdf", uuids);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

liveEditSetContent

Description:

MethodReturn valuesDescription

liveEditSetContent(String uuid, InputStream is

Void

Update the content of the document edited with live edit feature.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/logo.png");
            ws.document.liveEditSetContent("1ec49da9-1746-4875-ae32-9281d7303a62", is);
            IOUtils.closeQuietly(is);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isAttachment

Description:

MethodReturn valuesDescription

isAttachment(String docId)

Boolean

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

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.isAttachment("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isConvertibleToPDF

Description:

MethodReturn valuesDescription

isConvertibleToPDF(String docId)

Boolean

Returns a boolean that indicates if the node is convertible to PDF or not.

In case of a node of type PDF file will be returned a false value.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.document.isConvertibleToPDF("9ed5c7b1-9314-4479-8f80-fd8e2b47f55e"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forceLockDocument

Description:

MethodReturn valuesDescription

forceLockDocument(String uuid)

LockInfo

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

This method allows to lock any document.

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

In case exist a previous lock it will be replaced by a new one. When parent is locked you must apply the lock from parent.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.LockInfo;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);            
            LockInfo lockInfo = ws.document.forceLockDocument("1ec49da9-1746-4875-ae32-9281d7303a62");
            System.out.println("Author:" + lockInfo.getOwner());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getDocumentPdf

Description:

MethodReturn valuesDescription

getDocumentPdf(String uuid)

InputStream

Returns a PDF of the document.

Example:

package com.openkm;

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

import org.apache.commons.io.IOUtils;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Document doc = ws.document.getDocumentProperties("7f6c5c0b-a66b-4782-9595-e14b402a18b0");
            InputStream is = ws.document.getDocumentPdf(doc.getUuid());
            OutputStream fos = new FileOutputStream("/home/openkm/book.pdf");
            IOUtils.copy(is, fos);
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(fos);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

saveDocumentAsPdf

Description:

MethodReturn valuesDescription

saveDocumentAsPdf(String uuid, String newName)

Document

Save the document as PDF in the OpenKM repository.

The value of the uuid parameter should be a folder or record node UUID.

 

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Document;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Document doc = ws.document.getDocumentProperties("7f6c5c0b-a66b-4782-9595-e14b402a18b0");
            Document docPdf = ws.document.saveDocumentAsPdf(doc.getUuid(), "book.pdf");
            System.out.println("Document pdf: " + docPdf.getPath());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}