OKMRecord

Basics

In almost all methods you'll see a parameter named "recId". The value of this parameter can be a valid record UUID.

Example of a recId:

  • Using UUID -> "7f867772-7476-4176-b86f-bdeb8bce1c5f".

Also, in all methods you'll see a parameter named "token". Because Cron Tasks are 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 value "null", which indicates the application must use the "user session".

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

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

Methods

create

Description:

MethodReturn valuesDescription

create(String token, Record rec)

Record

Creates a new record and returns a Record object.

The variable path in the parameter rec must be initialized. It indicates the folder path in OpenKM.

Record rec = new Record();
rec.setPath("/okm:root/PKI-100200");

The other variables of the Record (rec) will not have any effect on the record creation.

We suggest using the method below to create the Record simply rather than this one.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            Record rec = new Record();
            rec.setPath("/okm:root/test");
            okmRecord.create(null, rec);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createSimple

Description:

MethodReturn valuesDescription

createSimple(String token, String recPath)

Record

Creates a new record and returns a Record object.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            String recPath = "/okm:root/PKI-100200";
            okmRecord.createSimple(null, recPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProperties

Description:

MethodReturn valuesDescription

getProperties(String token, String recId)

Record

Returns the record properties.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            Record rec = okmRecord.getProperties(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
            System.out.println(rec);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

delete

Description:

MethodReturn valuesDescription

delete(String token, String recId)

void

Deletes a record.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.delete(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

purge

Description:

MethodReturn valuesDescription

purge(String token, String recId)

void

The record is permanently removed from the repository.

Usually you will purge folders in /okm:trash/userId - the users' personal trash locations - but it is possible to directly purge any record from the repository.

When a record is purged, it can only be restored from a previous repository backup. The purge action removes the record permanently from the repository.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.purge(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

rename

Description:

MethodReturn valuesDescription

rename(String token, String recId, String newName)

Record

Renames a record.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.rename(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "newname");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

move

Description:

MethodReturn valuesDescription

move(String token, String recId, String dstId)

void

Moves a record into a folder or record.

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

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.move(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copy

Description:

MethodReturn valuesDescription

copy(String token, String recId, String dstId)

void

Copies a record into a folder or record.

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

Only the binary data and the security grants are copied to the 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.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.copy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

copy

Description:

MethodReturn valuesDescription

copy(String token, String recId, String dstId, String newName)

void

Copies a record into a folder or record.

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

When the newName parameter value is null, the folder will preserve 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 "extendedCopy" method for this feature.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.copy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b6848ac2-345f-454e-964a-eba4dcc020e6", "newname");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

extendedCopy

Description:

MethodReturn valuesDescription

extendedCopy(String token, String recId, String dstId, String newName, ExtendedAttributes extAttr)

void

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

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

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

By default only the binary data and the security grants are copied; 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.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            ExtendedAttributes extAttr = new ExtendedAttributes();
            extAttr.setKeywords(true);
            extAttr.setCategories(true);
            extAttr.setNotes(true);

            okmRecord.extendedCopy(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "PKI-100201", extAttr);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

isValid

Description:

MethodReturn valuesDescription

isValid(String token, String recId)

boolean

Returns a boolean that indicates whether the node is a record.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            boolean valid = okmRecord.isValid(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
            System.out.println(valid);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPath

Description:

MethodReturn valuesDescription

getPath(String token, String recId)

String

Converts a folder UUID to a record path.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            String path = okmRecord.getPath(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
            System.out.println(path);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getChildren

Description:

MethodReturn valuesDescription

getChildren(String token, String fldId)

List<Record>

Returns a list of all records whose parent is fldId.

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

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.bean.Record;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            for (Record rec : okmRecord.getChildren(null, "b6848ac2-345f-454e-964a-eba4dcc020e6")) {
                System.out.println(rec);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

lock

Description:

MethodReturn valuesDescription

lock(String token, String recId)

LockInfo

Locks a record and returns an object with the lock information.

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

A locked record cannot be modified by other users.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.lock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

unlock

Description:

MethodReturn valuesDescription

unlock(String token, String recId)

LockInfo

Unlocks a locked record.

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

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.unlock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

forceUnlock

Description:

MethodReturn valuesDescription

forceUnlock(String token, String recId)

void

Unlocks a locked record.

This method allows unlocking any locked record.

It is not mandatory that the same user who performed the checkout lock action executes this action.

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

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.forceUnlock(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setTitle

Description:

MethodReturn valuesDescription

setTitle(String token, String recId, String title)

void

Sets a record's title.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);
            okmRecord.setTitle(null, "7f867772-7476-4176-b86f-bdeb8bce1c5f", "new title");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setNodeClass

Description:

MethodReturn valuesDescription

setNodeClass(String token, String recId, long ncId)

void

Sets the NodeClass.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);

            long ncId = 2;
            okmRecord.setNodeClass(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDispositionStage

Description:

MethodReturn valuesDescription

setDispositionStage(String token, String recId, long stage)

void

Sets the disposition stage

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);

            long stage = 1;
            okmRecord.setDispositionStage(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", stage);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

addNodeClassChildren

Description:

MethodReturn valuesDescription

addNodeClassChildren(String token, String recId, long ncId)

void

Adds the NodeClass of the record to the parent folders.

Used for navigation purposes to evaluate when a folder contains a node of a given node class.

The method propagates the node class value to the parent containers (folders) to indicate there's a node of this type.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);

            long ncId = 2;
            okmRecord.addNodeClassChildren(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setDescription

Description:

MethodReturn valuesDescription

setDescription(String token, String uuid, String description)

void

Sets a description.

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);

            okmRecord.setDescription(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createWizard

Description:

MethodReturn valuesDescription

createWizard(String token, String recPath, String title, long nodeClass)

WizardNode

Creates a new record using a wizard.

The parameter recPath should be a valid folder or record UUID.

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

  • Add a keyword
  • Add categories
  • Add metadata

Example:

package com.openkm;

import com.openkm.api.OKMRecord;
import com.openkm.bean.WizardNode;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMRecord okmRecord = ContextWrapper.getContext().getBean(OKMRecord.class);

            WizardNode wn = okmRecord.createWizard(null, "1f323e88-64ee-4f57-91e2-9276f8c603f9", "PKI-100200", 0);
            System.out.print(wn);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}