OKMNote

Basics

In most methods you'll see a parameter named "nodeId". The value of this parameter can be a valid document, folder, mail, or record UUID.

Example of a nodeId:

  • Using UUID -> "b153c4b7-3d1c-4589-bd42-0ed0f34fd338"

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 "null" value, which indicates the application must use the "user session".

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

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

Methods

add

Description:

MethodReturn valuesDescription

add(String token, String nodeId, String text)

Note

Adds a note to a node and returns a Note object.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            Note note = okmNote.add(null, "f123a950-0329-4d62-8328-0ff500fd42db", "the note text");
            System.out.println(note);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

get

Description:

MethodReturn valuesDescription

get(String token, String noteId)

Note

Retrieves the note.

The noteId is a UUID.

The Node object has a variable named path; in that case, the path contains a UUID.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            for (Note note : okmNote.list(null, "f123a950-0329-4d62-8328-0ff500fd42db")) {
                Note data = okmNote.get(null, note.getPath());
                System.out.println(data);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

delete

Description:

MethodReturn valuesDescription

delete(String token, String noteId)

void

Deletes a note.

The noteId is a UUID.

The Node object has a variable named path; in that case, the path contains a UUID.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            for (Note note : okmNote.list(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338")) {
                okmNote.delete(null, note.getPath());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

set

Description:

MethodReturn valuesDescription

set(String token, String noteId, String text)

void

Changes the note's text.

The noteId is a UUID.

The Node object has a variable named path; in that case, the path contains a UUID.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            for (Note note : okmNote.list(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338")) {
                okmNote.set(null, note.getPath(), "new note");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

list

Description:

MethodReturn valuesDescription

list(String token, String nodeId)

List<Note>

Retrieves a list of all the notes for a node.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.Note;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            for (Note note : okmNote.list(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338")) {
                System.out.println(note);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getNoteHistories

Description:

MethodReturn valuesDescription

getNoteHistories(String token, String nodeId)

List<NoteHistory>

Returns the historical notes of a node.

Example:

package com.openkm;

import com.openkm.api.OKMNote;
import com.openkm.bean.NoteHistory;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMNote okmNote = ContextWrapper.getContext().getBean(OKMNote.class);
            for (NoteHistory noteHistory : okmNote.getNoteHistories(null, "3c68b3a1-c65c-4b1e-84b5-9ce2712ca573")) {
                System.out.println(noteHistory);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}