OKMRelation
Basics
On most methods you'll see parameter named "nodeId". The value of this parameter can be a valid document, folder, mail or record UUID or path.
Example of nodeId:
- Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
- Using path -> "/okm:root/logo.png"
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
getRelationTypes
Description:
Method | Return values | Description |
---|---|---|
getRelationTypes(String token, String type) |
List<RelationType> |
Retrieves a list of all relations defined of a type. |
Available types values:
More information at Relation types . |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.BIDIRECTIONAL)) {
System.out.println(rt);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
add
Description:
Method | Return values | Description |
---|---|---|
add(String token, String nodeAId, String nodeBId, long relationType) |
void |
Sets a relation between two nodes. |
The parameters nodeAId and nodeBId should be any valid document, folder, mail or record UUID or path. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.BIDIRECTIONAL)) {
// looking for a relation named invoice
if (rt.getTitleAToB().equals("invoice")) {
OKMRelation.getInstance().add(null, "/okm:root/invoice.pdf", "/okm:root/budget.pdf", rt.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
delete
Description:
Method | Return values | Description |
---|---|---|
delete(String token, long relationId) |
void |
Deletes a relation. |
Only when the relation will not be used by any node is able to be deleted, otherwise you'll get an error. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.BIDIRECTIONAL)) {
// looking for a relation named invoice
if (rt.getTitleAToB().equals("invoice")) {
OKMRelation.getInstance().delete(null, rt.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getRelations
Description:
Method | Return values | Description |
---|---|---|
getRelations(String token, String nodeId) |
List<Relation> |
Retrieves a list of all relations of a node. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.Relation;
public class Test {
public static void main(String[] args) {
try {
for (Relation relation : OKMRelation.getInstance().getRelations(null, "/okm:root/invoice.pdf")) {
System.out.println(relation);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
getRelationGroups
Description:
Method | Return values | Description |
---|---|---|
getRelationGroups(String token, String nodeId) |
List<RelationGroup> |
Retrieves a list of all relation groups of a node. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationGroup;
public class Test {
public static void main(String[] args) {
try {
for (RelationGroup rg : OKMRelation.getInstance().getRelationGroups(null, "/okm:root/invoice.pdf")) {
System.out.println(rg);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
addGroup
Description:
Method | Return values | Description |
---|---|---|
addGroup(String token, String nodeId, String groupName, long type) |
void |
Adds a relation group at a node. |
On a relation group only has sense to apply a relation type of NodeRelationType.MANY_TO_MANY. More information at Relation types . |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.MANY_TO_MANY)) {
if (rt.getTitle().equals("staple")) {
OKMRelation.getInstance().addGroup(null, "/okm:root/invoice.pdf", "staple group", rt.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
addNodeToGroup
Description:
Method | Return values | Description |
---|---|---|
addNodeToGroup(String token, String nodeId, long groupId) |
void |
Adds a node to an existing relation group. |
On a relation group only has sense to apply a relation type of NodeRelationType.MANY_TO_MANY. More information at Relation types . |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.MANY_TO_MANY)) {
if (rt.getTitle().equals("staple")) {
OKMRelation.getInstance().addNodeToGroup(null, "/okm:root/invoice.pdf", rt.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
deleteGroup
Description:
Method | Return values | Description |
---|---|---|
deleteGroup(String token, String nodeId, long groupId) |
void |
Remove a node from a relation group. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationType;
import com.openkm.dao.bean.NodeRelationType;
public class Test {
public static void main(String[] args) {
try {
for (RelationType rt : OKMRelation.getInstance().getRelationTypes(null, NodeRelationType.MANY_TO_MANY)) {
if (rt.getTitle().equals("staple")) {
OKMRelation.getInstance().deleteGroup(null, "/okm:root/invoice.pdf", rt.getId());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
findGroup
Description:
Method | Return values | Description |
---|---|---|
findGroup(String token, long groupId) |
RelationGroup |
Finds a relation group by id. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
import com.openkm.bean.RelationGroup;
public class Test {
public static void main(String[] args) {
try {
long groupId = 11;
RelationGroup rg = OKMRelation.getInstance().findGroup(null, groupId);
System.out.println(rg);
} catch (Exception e) {
e.printStackTrace();
}
}
}
setGroupName
Description:
Method | Return values | Description |
---|---|---|
setGroupName(String token, long groupId, String groupName) |
void |
Changes the relation group name. |
Example:
package com.openkm;
import com.openkm.api.OKMRelation;
public class Test {
public static void main(String[] args) {
try {
long groupId = 11;
OKMRelation.getInstance().setGroupName(null, groupId, "new name");
} catch (Exception e) {
e.printStackTrace();
}
}
}