Relation samples
Basics
Section titled “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.
Methods
Section titled “Methods”getRelationTypes
Section titled “getRelationTypes”Description:
| Method | Return values | Description |
|---|---|---|
| getRelationTypes(String type) | RelationTypeList | Retrieves a list of all relations defined of a type. |
Available types values:
- RelationType.BIDIRECTIONAL
- RelationType.PARENT_CHILD
- RelationType.MANY_TO_MANY
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationType;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationType type : ws.getRelationTypes(RelationType.PARENT_CHILD).getList()) { System.out.println(type); } } catch (Exception e) { e.printStackTrace(); } }}addRelation
Section titled “addRelation”Description:
| Method | Return values | Description |
|---|---|---|
| addRelation(String nodeAId, String nodeBId, long relTypeId) | 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.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationType;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password); try { for (RelationType type : ws.getRelationTypes(RelationType.PARENT_CHILD).getList()) { // looking for a relation named invoice if (type.getTitleAToB().equals("invoice")) { ws.addRelation("/okm:root/invoice.pdf", "/okm:root/budget.pdf", type.getId()); } } } catch (Exception e) { e.printStackTrace(); } }}deleteRelation
Section titled “deleteRelation”Description:
| Method | Return values | Description |
|---|---|---|
| deleteRelation(long relationId) | void | Deletes a relation. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationType;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationType type : ws.getRelationTypes(RelationType.PARENT_CHILD).getList()) { // looking for a relation named invoice if (type.getTitle().equals("invoice")) { ws.deleteRelation(type.getId()); } } } catch (Exception e) { e.printStackTrace(); } }}getRelations
Section titled “getRelations”Description:
| Method | Return values | Description |
|---|---|---|
| getRelations(String nodeId) | RelationList | Retrieves a list of all relations of a node.. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Relation;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (Relation relation : ws.getRelations("/okm:root/invoice.pdf").getList()) { System.out.println(relation); } } catch (Exception e) { e.printStackTrace(); } }}getRelationGroups
Section titled “getRelationGroups”Description:
| Method | Return values | Description |
|---|---|---|
| getRelationGroups(String nodeId) | RelationGroupList | Retrieves a list of all relation groups of a node. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.Relation;import com.openkm.sdk4j.bean.RelationGroup;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationGroup rGroup : ws.getRelationGroups("/okm:root/invoice.pdf").getList()) { System.out.println(rGroup); } } catch (Exception e) { e.printStackTrace(); } }}addRelationGroup
Section titled “addRelationGroup”Description:
| Method | Return values | Description |
|---|---|---|
| addRelationGroup(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 RelationType.MANY_TO_MANY.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationType;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationType type : ws.getRelationTypes(RelationType.MANY_TO_MANY).getList()) { if (type.getTitle().equals("staple")) { ws.addRelationGroup("/okm:root/invoice.pdf", "staple group", type.getId()); } } } catch (Exception e) { e.printStackTrace(); } }}addNodeToGroup
Section titled “addNodeToGroup”Description:
| Method | Return values | Description |
|---|---|---|
| addNodeToGroup(String nodeId, long groupId) | void | Adds a node to an existing relation group. |
On a relation group only has sense apply the type RelationType.MANY_TO_MANY.
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationGroup;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationGroup rGroup : ws.getRelationGroups("/okm:root/invoice.pdf").getList()) { if (rGroup.getName().equals("staple group")) { ws.addNodeToGroup("/okm:root/complaint.pdf", rGroup.getId()); } } } catch (Exception e) { e.printStackTrace(); } }}deleteRelationGroup
Section titled “deleteRelationGroup”Description:
| Method | Return values | Description |
|---|---|---|
| deleteRelationGroup(String nodeId, long groupId) | void | Remove a node from a relation group. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;import com.openkm.sdk4j.bean.RelationGroup;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { for (RelationGroup rGroup : ws.getRelationGroups("/okm:root/invoice.pdf").getList()) { if (rGroup.getName().equals("staple group")) { ws.deleteRelationGroup("/okm:root/complaint.pdf", rGroup.getId()); } } } catch (Exception e) { e.printStackTrace(); } }}findRelationGroup
Section titled “findRelationGroup”Description:
| Method | Return values | Description |
|---|---|---|
| findRelationGroup(long groupId) | RelationGroup | Finds a relation group by id. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { long groupId = 11; System.out.println(ws.findRelationGroup(groupId)); } catch (Exception e) { e.printStackTrace(); } }}setRelationGroupName
Section titled “setRelationGroupName”Description:
| Method | Return values | Description |
|---|---|---|
| setRelationGroupName(long groupId, String groupName) | void | Changes the relation group name. |
Example:
package com.openkm;
import com.openkm.sdk4j.OKMWebservices;import com.openkm.sdk4j.OKMWebservicesFactory;
public class Test { public static void main(String[] args) { String host = "http://localhost:8080/OpenKM"; String username = "okmAdmin"; String password = "admin"; OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try { long groupId = 11; ws.setRelationGroupName(groupId, "new name"); } catch (Exception e) { e.printStackTrace(); } }}