Relation samples
Basics
Section titled “Basics”On most methods, you’ll see the parameter named “nodeId”. The value of this parameter can be a valid document, folder, mail or record UUID or path.
Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then you should log in using the method “login”. You can access the “login” method from the webservice object “ws” as shown below:
ws.login(user, password);At this point, you can use all the Relation methods from the “relation” class as shown below:
ws.relation.getRelationTypes(RelationType.BIDIRECTIONAL);Methods
Section titled “Methods”getRelationTypes
Section titled “getRelationTypes”Description:
| Method | Return values | Description |
|---|---|---|
| getRelationTypes(String type) | List |
Retrieves a list of all relations defined for a type. |
Available types:
- RelationType.BIDIRECTIONAL
- RelationType.PARENT_CHILD
- RelationType.MANY_TO_MANY
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationType type in ws.relation.getRelationTypes(RelationType.PARENT_CHILD)){System.Console.WriteLine(type);}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}Description:
| Method | Return values | Description |
|---|---|---|
| add(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.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationType type in ws.relation.getRelationTypes(RelationType.BIDIRECTIONAL)){// looking for a relation named invoiceif (type.title.Equals("invoice")){ws.relation.add("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", "055e4384-7c70-4456-b32b-f5a55a79861f", type.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}delete
Section titled “delete”Description:
| Method | Return values | Description |
|---|---|---|
| delete(long relationId) | void | Deletes a relationship. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationType type in ws.relation.getRelationTypes(RelationType.BIDIRECTIONAL)){// looking for a relation named invoiceif (type.title.Equals("invoice")){ws.relation.delete(type.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getRelations
Section titled “getRelations”Description:
| Method | Return values | Description |
|---|---|---|
| getRelations(String uuid) | List |
Retrieves a list of all relations of a node. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (Relation relation in ws.relation.getRelations("055e4384-7c70-4456-b32b-f5a55a79861f")){System.Console.WriteLine(relation);}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getRelationGroups
Section titled “getRelationGroups”Description:
| Method | Return values | Description |
|---|---|---|
| getRelationGroups(String uuid) | List |
Retrieves a list of all relation groups for a node. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationGroup rGroup in ws.relation.getRelationGroups("055e4384-7c70-4456-b32b-f5a55a79861f")){System.Console.WriteLine(rGroup.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}addGroup
Section titled “addGroup”Description:
| Method | Return values | Description |
|---|---|---|
| addGroup(String nodeId, String groupName, long type) | void | Adds a relation group to a node. |
For a relation group, it only makes sense to apply the relation type RelationType.MANY_TO_MANY.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationType type in ws.relation.getRelationTypes(RelationType.MANY_TO_MANY)){if (type.title.Equals("staple")){ws.relation.addGroup("055e4384-7c70-4456-b32b-f5a55a79861f", "staple group", type.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}addNodeToGroup
Section titled “addNodeToGroup”Description:
| Method | Return values | Description |
|---|---|---|
| addNodeToGroup(String nodeId, long groupId) | void | Adds a node to an existing relation group. |
A relation group only makes sense with the relation type RelationType.MANY_TO_MANY.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationGroup rGroup in ws.relation.getRelationGroups("055e4384-7c70-4456-b32b-f5a55a79861f")){if (rGroup.name.Equals("staple group")){ws.relation.addNodeToGroup("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", rGroup.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}deleteGroup
Section titled “deleteGroup”Description:
| Method | Return values | Description |
|---|---|---|
| deleteGroup(long groupId) | void | Removes a node from a relation group. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationGroup rGroup in ws.relation.getRelationGroups("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")){if (rGroup.name.Equals("staple group")){ws.relation.deleteGroup(rGroup.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getGroup
Section titled “getGroup”Description:
| Method | Return values | Description |
|---|---|---|
| getGroup(long groupId) | RelationGroup | Finds a relation group by ID. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);RelationGroup rg = new RelationGroup();foreach (RelationGroup rGroup in ws.getRelationGroups("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")){if (rGroup.name.Equals("staple group3")){rg = ws.relation.getGroup(rGroup.id);break;}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}setGroupName
Section titled “setGroupName”Description:
| Method | Return values | Description |
|---|---|---|
| setGroupName(long groupId, String groupName) | void | Changes the relation group name. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);RelationGroup rg = new RelationGroup();foreach (RelationGroup rGroup in ws.relation.getRelationGroups("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")){if (rGroup.name.Equals("staple group3")){ws.relation.setGroupName(rGroup.id, "newGroup");rg = ws.relation.getGroup(rGroup.id);break;}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getAllRelationGroups
Section titled “getAllRelationGroups”Description:
| Method | Return values | Description |
|---|---|---|
| getAllRelationGroups(int relationTypeId, String filter, int offset, int limit) | RelationGroupResultSet | Retrieves a list of all relation groups. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);int relationTypeId = 1;String filter = "";RelationGroupResultSet resultSet = ws.relation.getAllRelationGroups(relationTypeId, filter, 0, 10);foreach (RelationGroup relationGroup in resultSet.results){Console.WriteLine(relationGroup.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}deleteItemFromGroup
Section titled “deleteItemFromGroup”Description:
| Method | Return values | Description |
|---|---|---|
| deleteItemFromGroup(String nodeId, long groupId) | void | Removes a node from a relation group. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (RelationGroup rGroup in ws.relation.getRelationGroups("50b7a5b9-89d2-430e-bbc9-6a6e01662a71")){if (rGroup.name.Equals("staple group3")){ws.relation.deleteItemFromGroup("50b7a5b9-89d2-430e-bbc9-6a6e01662a71", rGroup.id);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}