PropertyGroup samples
Basics
From an older OpenKM version we named "Metadata Groups" as "Property Groups".
Although we understand this name does not help a lot to identify these methods with metadata ones, for historical reason, we continue maintaining the nomenclature.
For more information about Metadata.
On almost methods, you'll see the parameter named "nodeId". The value of this parameter can be a valid document, folder, mail or record UUID .
Example of nodeId:
- Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db"
The class com.openkm.sdk4j.util.ISO8601 should be used to set and parse metadata date fields. The metadata field of type date values are stored into application in ISO-8601 basic format.
To convert retrieved metadata field of type date to a valid date use:
DateTime date = ISO8601.parseBasic(metadataFieldValue);
To save date value into the metadata field of type date use:
DateTime date = DateTime.now; // Present date
String metadataFieldValue = ISO8601.formatBasic(date);
// metadataFieldValue can be saved into repository metadata field of type date
Methods
addGroup
Description:
Method | Return values | Description |
---|---|---|
addGroup(String nodeId, String grpName, Dictionary<String, String> propertiesMap) |
void |
Adds a metadata group to a node. |
The grpName should be a valid Metadata group name. It is not mandatory to set in the propertiesMap parameter all fields values, is enough with the fields you wish to change its values. The sample below is based on this Metadata group definition:
To add several values on a metadata field of type multiple and to add value on a metadata field of type simple like this:
You should do:
Where "one" and "two" are valid values, the character "," is used as a separator and the options should go between "[" "]". |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.util;
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);
Dictionary<string, string> props = new Dictionary<string, string>();
DateTime date = DateTime.Now;
props.Add("okp:consulting.name", "test");
props.Add("okp:consulting.date", ISO8601.formatBasic(date));
props.Add("okp:consulting.important", "true");
props.Add("okp:consulting.comment", "test");
ws.addGroup("f0064cf3-4776-44c2-868a-f08697a6957e", "okg:consulting", props);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
removeGroup
Description:
Method | Return values | Description |
---|---|---|
removeGroup(String nodeId, String grpName) |
void |
Removes a metadata group of a node. |
The grpName should be a valid Metadata group name. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
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);
ws.removeGroup("f123a950-0329-4d62-8328-0ff500fd42db", "okg:consulting");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getGroups
Description:
Method | Return values | Description |
---|---|---|
getGroups(String nodeId) |
List<PropertyGroup> |
Retrieves a list of metadata groups assigned to 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 (PropertyGroup pGroup in ws.getGroups("f123a950-0329-4d62-8328-0ff500fd42db"))
{
System.Console.WriteLine(pGroup.name);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getAllGroups
Description:
Method | Return values | Description |
---|---|---|
getAllGroups() |
List<PropertyGroup> |
Retrieves a list of all metadata groups set into the application. |
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 (PropertyGroup pGroup in ws.getAllGroups())
{
System.Console.WriteLine(pGroup.name);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getPropertyGroupForm
Description:
Method | Return values | Description |
---|---|---|
getPropertyGroupForm(String grpName) |
List<FormElement> |
Retrieves a list of all metadata group elements definition. |
The grpName should be a valid Metadata group name. The method is usually used to display empty form elements for creating new metadata values. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.bean.form;
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 (FormElement fElement in ws.getPropertyGroupForm("okg:consulting"))
{
System.Console.WriteLine(fElement);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setPropertyGroupProperties
Description:
Method | Return values | Description |
---|---|---|
setPropertyGroupProperties(String nodeId, String grpName, Dictionary<String, String> properties) |
void |
Changes the metadata group values of a node. |
The grpName should be a valid Metadata group name. Before changing metadata, you should have the group added in the node ( see addGroup method ) otherwise will be raised and error. Is not mandatory set into properties parameter all fields values, is enough with the fields you wish to change its values. The sample below is based on this Metadata group definition:
To add several values on a metadata field of type multiple and to add value on a metadata field of type simple like this:
You should do:
Where "one" and "two" are valid values, the character "," is used as a separator and the options should go between "[" "]". |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using com.openkm.sdk4csharp.bean;
using com.openkm.sdk4csharp.util;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
Dictionary<String, String> properties = new Dictionary<String, String>();
properties.Add("okp:consulting.name", "new name");
//The date fields must be saved with basic ISO 8601 format
properties.Add("okp:consulting.date", ISO8601.formatBasic(DateTime.Now));
ws.setPropertyGroupPropertiesSimple("f123a950-0329-4d62-8328-0ff500fd42db","okg:consulting", properties);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
hasGroup
Description:
Method | Return values | Description |
---|---|---|
hasGroup(String nodeId, String grpName) |
Boolean |
Returns a boolean that indicates if the node has or not a metadata group. |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
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);
System.Console.WriteLine("Have metadata group:"+ ws.hasGroup("f123a950-0329-4d62-8328-0ff500fd42db","okg:consulting").ToString());
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getRegisteredDefinition
Description:
Method | Return values | Description |
---|---|---|
getRegisteredDefinition() |
String |
Return the XML Metada groups definition. |
The method only can be executed by a superuser grants ( ROLE_ADMIN member user). |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
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);
System.Console.WriteLine(ws.getRegisteredDefinition());
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
registerDefinition
Description:
Method | Return values | Description |
---|---|---|
registerDefinition(InputStream is, String pgName) |
void |
Sets the XML Metadata groups definition into the repository.. |
The method can only be executed by superuser grants ( ROLE_ADMIN member user). |
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
using System.IO;
namespace OKMRest
{
public class Program
{
static void Main(string[] args)
{
String host = "http://localhost:8180/openkm";
String username = "okmAdmin";
String password = "admin";
OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try
{
ws.login(user, password);
FileStream fs = new FileStream("E:\\PropertyGroups.xml",FileMode.Open);
ws.registerDefinition(fs,"okg:testing");
fs.Dispose();
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getSuggestions
Description:
Method | Return values | Description |
---|---|---|
getSuggestions(String nodeId, String grpName, String propName) |
List<String> |
Retrieves a list of a suggested metadata field values. |
The propName parameter should be a Metadata Select field type. More information at Creating your own Suggestion Analyzer and Metadata Select field.
The sample below is based on this Metadata group definition:
|
Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.openkm.sdk4csharp;
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(String value in ws.getSuggestions("f123a950-0329-4d62-8328-0ff500fd42db","okg:technology", "okp:technology.language"))
{
System.Console.WriteLine(value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getPropertyGroupProperties
Description:
Method | Return values | Description |
---|---|---|
getPropertyGroupProperties(String nodeId, String grpName) |
Dictionary<String, String> |
Retrieves a dictionary- (key,value) pairs - with Metada group values 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);
Dictionary<String, String> properties = new Dictionary<String, String>();
properties = ws.getPropertyGroupProperties("f123a950-0329-4d62-8328-0ff500fd42db","okg:technology");
foreach (KeyValuePair<String, String> pair in properties)
{
System.Console.WriteLine(pair.Key + "-> " + pair.Value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getPropertyGroupPropertiesByVersion
Description:
Method | Return values | Description |
---|---|---|
getPropertyGroupPropertiesByVersion(String nodeId, String grpName,String versionName) |
Dictionary<String, String> |
Retrieves a dictionary- (key,value) pairs - with Metada group values 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);
Dictionary<String, String> properties = new Dictionary<String, String>();
properties = ws.getPropertyGroupPropertiesByVersion("f123a950-0329-4d62-8328-0ff500fd42db","okg:technology","1.1");
foreach (KeyValuePair<String, String> pair in properties)
{
System.Console.WriteLine(pair.Key + "-> " + pair.Value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getGroupsByVersion
Description:
Method | Return values | Description |
---|---|---|
getGroupsByVersion(String nodeId, String versionName) |
List<PropertyGroup> |
Retrieves a list of metadata groups assigned to 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 (PropertyGroup pGroup in ws.getGroupsByVersion("f123a950-0329-4d62-8328-0ff500fd42db","1.1"))
{
System.Console.WriteLine(pGroup.name, "1.1");
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getGroup
Description:
Method | Return values | Description |
---|---|---|
getGroup(String grpName) |
PropertyGroup |
Get property group definition. |
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);
PropertyGroup pg = ws.getGroup("okg:consulting");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}