OKMBookmark
Used for managing bookmarks for users. For example, add or remove a bookmark on a node for a user.
Basics
In most methods you'll see a parameter named "nodeId". The value of this parameter can be a valid node UUID (folder, document, mail, record).
Example of nodeId:
- Using UUID -> "3887ae75-dd67-4019-b4d1-2f6962815403";
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. In the default application execution context you must use the "null" value, which indicates that the application should use the "user session".
In special cases you might be "promoted to Administrator" using the "administrator token".
String systemToken = DbSessionManager.getInstance().getSystemToken();
Methods
add
Description:
Method | Return values | Description |
---|---|---|
add(String token, String nodeId, String name) |
Bookmark |
Add a new bookmark for a node. |
The parameter name indicates the name that will be used to store the bookmark. Usually the same name as the nodeId is used. |
Example:
package com.openkm;
import com.openkm.api.OKMBookmark;
import com.openkm.db.bean.Bookmark;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMBookmark okmBookmark = ContextWrapper.getContext().getBean(OKMBookmark.class);
Bookmark bookmark = okmBookmark.add(null, "3887ae75-dd67-4019-b4d1-2f6962815403", "document.doc");
System.out.println(bookmark);
} catch (Exception e) {
e.printStackTrace();
}
}
}
get
Description:
Method | Return values | Description |
---|---|---|
get(String token, int bmId) |
Bookmark |
Gets the bookmark data. |
The parameter bmId is the value of the unique bookmark identifier. |
Example:
package com.openkm;
import com.openkm.api.OKMBookmark;
import com.openkm.db.bean.Bookmark;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMBookmark okmBookmark = ContextWrapper.getContext().getBean(OKMBookmark.class);
int bmId = 2;
Bookmark bookmark = okmBookmark.get(null, bmId);
System.out.println(bookmark);
} catch (Exception e) {
e.printStackTrace();
}
}
}
remove
Description:
Method | Return values | Description |
---|---|---|
remove(String token, int bmId) |
void |
Deletes a bookmark. |
The parameter bmId is the value of the unique bookmark identifier. |
Example:
package com.openkm;
import com.openkm.api.OKMBookmark;
public class Test {
public static void main(String[] args) {
try {
int bmId = 23;
OKMBookmark.getInstance().remove(null, bmId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
rename
Description:
Method | Return values | Description |
---|---|---|
rename(String token, int bmId, String newName) |
Bookmark |
Renames a bookmark. |
The parameter bmId is the value of the unique bookmark identifier. |
Example:
package com.openkm;
import com.openkm.api.OKMBookmark;
import com.openkm.db.bean.Bookmark;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMBookmark okmBookmark = ContextWrapper.getContext().getBean(OKMBookmark.class);
int bmId = 2;
Bookmark bookmark = okmBookmark.rename(null, bmId, "newname.doc");
System.out.println(bookmark);
} catch (Exception e) {
e.printStackTrace();
}
}
}
getAll
Description:
Method | Return values | Description |
---|---|---|
getAll(String token) |
List<Bookmark> |
Gets all the bookmarks of the logged-in user. |
Example:
package com.openkm;
import com.openkm.api.OKMBookmark;
import com.openkm.db.bean.Bookmark;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMBookmark okmBookmark = ContextWrapper.getContext().getBean(OKMBookmark.class);
for (Bookmark bookmark : okmBookmark.getAll(null)) {
System.out.println(bookmark);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}