PropertyGroup samples

Basics

From older OpenKM version we named "Metadata Groups" as "Property Groups".

Although we understand this name does not helps a lot to identifying these methods with metadata ones, for historical reason, we continue maintaining the nomenclature.

For more information about Metadata.

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"

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 metada field of type date to a valid date use:

DateTime date = ISO8601.parseBasic(metadataFieldValue);

To save date value into 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:

MethodReturn valuesDescription

addGroup(String nodeId, String grpName)

void

Adds an empty metadata group to 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, username, password);
             try { ws.addGroup("/okm:root/logo.png", "okg:consulting"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

removeGroup

Description:

MethodReturn valuesDescription

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, username, password);
             try { ws.removeGroup("/okm:root/logo.png", "okg:consulting"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getGroups

Description:

MethodReturn valuesDescription

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, username, password);
             try { foreach (PropertyGroup pGroup in ws.getGroups("/okm:root/logo.png")) { System.Console.WriteLine(pGroup); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getAllGroups

Description:

MethodReturn valuesDescription

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, username, password);
             try { foreach (PropertyGroup pGroup in ws.getAllGroups()) { System.Console.WriteLine(pGroup); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupProperties

Description:

MethodReturn valuesDescription

getPropertyGroupProperties(String nodeId, String grpName)

List<FormElement>

Retrieve a list of all metadata group elements and its values of a node.

The grpName should be a valid Metadata group name.

The method is usually used to display form elements with its values to be shown or changed by used.

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, username, password);
             try { foreach(FormElement fElement in ws.getPropertyGroupProperties("/okm:root/logo.png", "okg:consulting")) { System.Console.WriteLine(fElement); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupForm

Description:

MethodReturn valuesDescription

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, username, password);
             try { foreach (FormElement fElement in ws.getPropertyGroupForm("okg:consulting")) { System.Console.WriteLine(fElement); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setPropertyGroupProperties

Description:

MethodReturn valuesDescription

setPropertyGroupProperties(String nodeId, String grpName, List<FormElement> ofeList)

void

Changes the metadata group values of a node.

The grpName should be a valid Metadata group name.

Is not mandatory to set into parameter ofeList all FormElement, is enought with the formElements you wish to change its values.

The sample below is based on this Metadata group definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.0//EN"
                                 "http://www.openkm.com/dtd/property-groups-2.0.dtd">
<property-groups>
  <property-group label="Consulting" name="okg:consulting">
    <input label="Name" type="text" name="okp:consulting.name"/>
    <input label="Date" type="date" name="okp:consulting.date" />
    <checkbox label="Important" name="okp:consulting.important"/>
    <textarea label="Comment" name="okp:consulting.comment"/>
  </property-group>
</property-groups>

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;
using com.openkm.sdk4csharp.bean.form;

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, username, password);
             try { // Modify with a full FormElement list List<FormElement> fElements = ws.getPropertyGroupProperties("/okm:root/logo.pdf","okg:consulting"); foreach (FormElement fElement in fElements) { if (fElement.name.Equals("okp:consulting.name")) { Input name = (Input) fElement; name.value = "new value"; } }
                 ws.setPropertyGroupProperties("/okm:root/logo.pdf","okg:consulting", fElements);
                 // Same modification with only affected FormElement fElements = new List<FormElement>(); Input n = new Input(); n.name = "okp:consulting.name"; n.value = "new value"; fElements.Add(n); ws.setPropertyGroupProperties("/okm:root/logo.pdf","okg:consulting", fElements); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

setPropertyGroupPropertiesSimple

Description:

MethodReturn valuesDescription

setPropertyGroupPropertiesSimple(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.

Is not mandatory to 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:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.0//EN"
                                 "http://www.openkm.com/dtd/property-groups-2.0.dtd">
<property-groups>
  <property-group label="Consulting" name="okg:consulting">
    <input label="Name" type="text" name="okp:consulting.name"/>
    <input label="Date" type="date" name="okp:consulting.date" />
    <checkbox label="Important" name="okp:consulting.important"/>
    <textarea label="Comment" name="okp:consulting.comment"/>
  </property-group>
</property-groups>

To add several values on a metadata field of type multiple like this:

<select label="Multiple" name="okp:consulting.multiple" type="multiple">
  <option label="One" value="one"/>
  <option label="Two" value="two"/>
  <option label="Three" value="three" />
</select>

You should do: 

properties.Add("okp:consulting.multiple", "one;two");

 Where "one" and "two" are valid values and character ";" is used as separator.

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, username, password);
             try { 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("/okm:root/logo.pdf","okg:consulting", properties); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

hasGroup

Description:

MethodReturn valuesDescription

hasGroup(String nodeId, String grpName)

Boolean

Returns a boolean that indicate 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, username, password);
             try { System.Console.WriteLine("Have metadata group:"+ws.hasGroup("/okm:root/logo.png","okg:consulting")); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupPropertiesSimple

Description:

MethodReturn valuesDescription

getPropertyGroupPropertiesSimple(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, username, password);

try
{
Dictionary<String, String> properties = new Dictionary<String, String>();
properties = ws.getPropertyGroupPropertiesSimple("/okm:root/logo.pdf","okg:technology");

foreach (KeyValuePair<String, String> pair in properties)
{
System.Console.WriteLine(pair.Key + "-> " + pair.Value);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}

getSuggestions

Description:

MethodReturn valuesDescription

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.

The sample below is based on this Metadata group definition:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 2.0//EN"
                                 "http://www.openkm.com/dtd/property-groups-2.0.dtd">
<property-groups>
  <property-group label="Technology" name="okg:technology">
    <select label="Type" name="okp:technology.type" type="multiple">
      <option label="Alfa" value="t1"/>
      <option label="Beta" value="t2" />
      <option label="Omega" value="t3" />
    </select>
    <select label="Language" name="okp:technology.language" type="simple">
      <option label="Java" value="java"/>
      <option label="Python" value="python"/>
      <option label="PHP" value="php" />
    </select>
    <input label="Comment" name="okp:technology.comment"/>
    <textarea label="Description" name="okp:technology.description"/>
    <input label="Link" type="link" name="okp:technology.link"/>
  </property-group>
</property-groups>

 

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, username, password);
            
            try
            {
                foreach(String value in ws.getSuggestions("/okm:root/logo.png","okg:technology", "okp:technology.language")) 
                {
                     System.Console.WriteLine(value);
                }
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}

registerDefinition

Description:

MethodReturn valuesDescription

registerDefinition(InputStream is)

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, username, password);
            
            try
            {
                 FileStream fs = new FileStream("E:\\PropertyGroups.xml",FileMode.Open);
                 ws.registerDefinition(fs);
                 fs.Dispose();
            } 
            catch (Exception e)
            {
                System.Console.WriteLine(e.ToString());
            } 
        }
    }
}