Relation samples
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.
Example of nodeId:
- Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
- Using path -> "/okm:root/logo.png"
Methods
getRelationTypes
Description:
Method | Return values | Description |
---|---|---|
getRelationTypes(String type) |
List<RelationType> |
Retrieves a list of all relations defined of a type. |
Available types values:
More information at Relation types. |
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, username, password);
try
{
foreach (RelationType type in ws.getRelationTypes(RelationType.PARENT_CHILD))
{
System.Console.WriteLine(type);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
addRelation
Description:
Method | Return values | Description |
---|---|---|
addRelation(String nodeAId, String nodeBId, long relTypeId) |
void |
Sets a relation between two nodes. |
The parameter nodeAId and nodeBId should be any valid document, folder, mail or record UUID or path. |
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, username, password);
try
{
foreach (RelationType type in ws.getRelationTypes(RelationType.BIDIRECTIONAL))
{
// looking for a relation named invoice
if (type.title.Equals("invoice"))
{
ws.addRelation("/okm:root/invoice.pdf", "/okm:root/budget.pdf", type.id);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteRelation
Description:
Method | Return values | Description |
---|---|---|
deleteRelation(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:
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, username, password);
try
{
foreach (RelationType type in ws.getRelationTypes(RelationType.BIDIRECTIONAL))
{
// looking for a relation named invoice
if (type.title.Equals("invoice"))
{
ws.deleteRelation(type.id);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getRelations
Description:
Method | Return values | Description |
---|---|---|
getRelations(String nodeId) |
RelationList |
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, username, password);
try
{
foreach (Relation relation in ws.getRelations("/okm:root/invoice.pdf"))
{
System.Console.WriteLine(relation);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getRelationGroups
Description:
Method | Return values | Description |
---|---|---|
getRelationGroups(String nodeId) |
List<RelationGroup> |
Retrieves a list of all relation groups 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, username, password);
try
{
foreach (RelationGroup rGroup in ws.getRelationGroups("/okm:root/invoice.pdf"))
{
System.Console.WriteLine(rGroup);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 makes sense to apply a relation type of RelationType.MANY_TO_MANY. More information at Relation types. |
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, username, password);
try
{
foreach (RelationType type in ws.getRelationTypes(RelationType.MANY_TO_MANY))
{
if (type.title.Equals("staple"))
{
ws.addRelationGroup("/okm:root/invoice.pdf", "staple group", type.id);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 to apply the type RelationType.MANY_TO_MANY. More information at Relation types. |
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, username, password);
try
{
foreach (RelationGroup rGroup in ws.getRelationGroups("/okm:root/invoice.pdf"))
{
if (rGroup.name.Equals("staple group"))
{
ws.addNodeToGroup("/okm:root/complaint.pdf", rGroup.id);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
deleteRelationGroup
Description:
Method | Return values | Description |
---|---|---|
deleteRelationGroup(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, username, password);
try
{
foreach (RelationGroup rGroup in ws.getRelationGroups("/okm:root/budget.pdf"))
{
if (rGroup.name.Equals("staple group"))
{
ws.deleteRelationGroup("/okm:root/complaint.pdf", rGroup.id);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
findRelationGroup
Description:
Method | Return values | Description |
---|---|---|
findRelationGroup(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, username, password);
try
{
long groupId = 2;
System.Console.WriteLine(ws.findRelationGroup(groupId));
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setRelationGroupName
Description:
Method | Return values | Description |
---|---|---|
setRelationGroupName(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, username, password);
try
{
long groupId = 2;
ws.setRelationGroupName(groupId, "new name");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}