PropertyGroup samples

Basics

In an older OpenKM version, we called "Metadata Groups" "Property Groups".

Although we understand this name does not help much to identify these methods as metadata ones, for historical reasons we continue to maintain the nomenclature.

For more information about Metadata.

In most 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. Values of metadata fields of type date are stored in the application in ISO-8601 basic format.

To convert a retrieved metadata field of type date to a valid date, use:

DateTime date = ISO8601.parseBasic(metadataFieldValue);

To save a 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

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.newInstance(host);

Then you should log in using the "login" method. You can access the "login" method from the web service object "ws" as shown below:

ws.login(user, password);

Once you are logged in with the web service, the session is kept in the web service object. Then you can use the other API methods.

At this point you can use all the Property Group methods from the "propertyGroup" class as shown below:

ws.propertyGroup.addPropertyGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting", propertiesMap);

Methods

addPropertyGroup

Description:

Method Return values Description

addPropertyGroup(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 all field values in the propertiesMap parameter; it is enough to include only the fields whose values you wish to change.

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 to a metadata field of type multiple and to add a value to a metadata field of type simple 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>

<select label="Simple" name="okp:consulting.simple" type="simple">
<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]");
properties.Add("okp:consulting.simple", "[one]");

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.propertyGroup.addPropertyGroup("f0064cf3-4776-44c2-868a-f08697a6957e", "okg:consulting", props); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

removePropertyGroup

Description:

Method Return values Description

removePropertyGroup(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.propertyGroup.removePropertyGroup("f123a950-0329-4d62-8328-0ff500fd42db", "okg:consulting"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroups

Description:

Method Return values Description

getPropertyGroups(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.propertyGroup.getPropertyGroups("f123a950-0329-4d62-8328-0ff500fd42db")) { System.Console.WriteLine(pGroup.name); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getAllPropertyGroups

Description:

Method Return values Description

getAllPropertyGroups()

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.propertyGroup.getAllPropertyGroups()) { 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 element definitions.

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.propertyGroup.getPropertyGroupForm("okg:consulting")) { System.Console.WriteLine(fElement); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupForm

Description:

Method Return values Description

getPropertyGroupForm(String uuid, String grpName)

List<FormElement>

Retrieves a list of all metadata group element definitions.

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.propertyGroup.getPropertyGroupForm("f123a950-0329-4d62-8328-0ff500fd42db","okg:consulting")) { System.Console.WriteLine(fElement); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupFormDefinition

Description:

Method Return values Description

getPropertyGroupFormDefinition(String grpName)

List<FormElement>

Retrieves a list of all metadata group element definitions.

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.propertyGroup.getPropertyGroupFormDefinition("okg:consulting")) { System.Console.WriteLine(fElement); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupFormDefinition

Description:

Method Return values Description

getPropertyGroupFormDefinition(String uuid, String grpName)

List<FormElement>

Retrieves a list of all metadata group element definitions.

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.propertyGroup.getPropertyGroupFormDefinition("afe29d6e-7769-4d48-a4db-c5a24edfd5df", "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 to the node (see addGroup method); otherwise an error will be raised.

It is not mandatory to set all field values in the properties parameter; it is enough to include only the fields whose values you wish to change.

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 and to add value on a metadata field of type simple 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>

<select label="Simple" name="okp:consulting.simple" type="simple">
<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]");
properties.Add("okp:consulting.simple", "[one]");

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.propertyGroup.setPropertyGroupPropertiesSimple("f123a950-0329-4d62-8328-0ff500fd42db","okg:consulting", properties); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

hasPropertyGroup

Description:

Method Return values Description

hasPropertyGroup(String nodeId, String grpName)

Boolean

Returns a boolean that indicates whether the node has a metadata group or not.

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.propertyGroup.hasPropertyGroup("f123a950-0329-4d62-8328-0ff500fd42db","okg:consulting").ToString()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getRegisteredPropertyGroupDefinition

Description:

Method Return values Description

getRegisteredPropertyGroupDefinition()

String

Returns the XML metadata groups definition.

The method can only be executed by a user with superuser grants (ROLE_ADMIN).

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.propertyGroup.getRegisteredPropertyGroupDefinition()); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

registerPropertyGroupDefinition

Description:

Method Return values Description

registerPropertyGroupDefinition(InputStream is,  String pgName)

void

Sets the XML metadata groups definition in the repository.

The method can only be executed by a user with superuser grants (ROLE_ADMIN).

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.propertyGroup.registerPropertyGroupDefinition(fs,"okg:testing"); fs.Dispose(); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroupSuggestions

Description:

Method Return values Description

getPropertyGroupSuggestions(String nodeId, String grpName, String propName)

List<String>

Retrieves a list of 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);  
             try {
ws.login(user, password); foreach(String value in ws.propertyGroup.getPropertyGroupSuggestions("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) with metadata 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.propertyGroup.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) with metadata 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.propertyGroup.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()); } } } }

getPropertyGroupsByVersion

Description:

Method Return values Description

getPropertyGroupsByVersion(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.propertyGroup.getPropertyGroupsByVersion("f123a950-0329-4d62-8328-0ff500fd42db","1.1")) { System.Console.WriteLine(pGroup.name, "1.1"); } } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getPropertyGroup

Description:

Method Return values Description

getPropertyGroup(String grpName)

PropertyGroup

Gets the 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.propertyGroup.getPropertyGroup("okg:consulting"); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getSuggestBoxKeyValue

Description:

Method Return values Description

getSuggestBoxKeyValue(String grpName, String propertyName, String key)

String

Returns the suggestBox value for a key.


The propertyName parameter should be a Metadata Suggestbox field type.

More information at Metadata Suggestbox field

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 3.7//EN"
                                 "http://www.openkm.com/dtd/property-groups-3.7.dtd">
<property-groups>
  <property-group label="Consulting" name="okg:consulting">
     <suggestbox label="country" name="okp:consulting.suggestbox"
 	 	 width="200px" dialogTitle="Choose country" filterMinLen="3"
     	 filterQuery="select ct_id, ct_name from country where ct_name like '%{0}%' order by ct_name" 
     	 valueQuery="select ct_id, ct_name from country where ct_id='{0}'" />
  </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.impl;

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);
                String grpName = "okg:consulting";
String propertyName = "okp:consulting.suggestbox";
String key = "es";
String result = ws.propertyGroup.getSuggestBoxKeyValue(grpName, propertyName, key);
  Console.WriteLine("Value: " + result); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

getSuggestBoxKeyValuesFiltered

Description:

Method Return values Description

getSuggestBoxKeyValuesFiltered(String grpName, String propertyName, String filter)

Dictionary<String, String>

Retrieves a dictionary - (key, value) pairs - with suggestBox values.

The propertyName parameter should be a Metadata Suggestbox field type.

More information at Metadata Suggestbox field

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 3.7//EN"
                                 "http://www.openkm.com/dtd/property-groups-3.7.dtd">
<property-groups>
  <property-group label="Consulting" name="okg:consulting">
     <suggestbox label="country" name="okp:consulting.suggestbox"
 	 	 width="200px" dialogTitle="Choose country" filterMinLen="3"
     	 filterQuery="select ct_id, ct_name from country where ct_name like '%{0}%' order by ct_name" 
     	 valueQuery="select ct_id, ct_name from country where ct_id='{0}'" />
  </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.impl;

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);
                String grpName = "okg:consulting";
String propertyName = "okp:consulting.suggestbox";
String filter = "Port";
Dictionary<String, String> result = ws.propertyGroup.getSuggestBoxKeyValuesFiltered(grpName, propertyName, filter);
foreach(var item in result)
{
Console.WriteLine(item.key + ":" + item.value);
} } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }

validateField

Method Return values Description

validateField(String value, String className, List<String> uuids)

String

Returns the validation message

  • The "className" value must be the canonical class name of a class which implements the FieldValidator interface.

Example of a form validator implementation

More information at Creating your own Form Validator plugin.

In this example, two identical comments will not be allowed in the metadata field named okp:technology.comment

package com.openkm.plugin.form.validator;

import java.util.ArrayList;
import java.util.List;

import com.openkm.module.db.stuff.DbSessionManager;
import com.openkm.plugin.form.FieldValidator;
import org.springframework.beans.factory.annotation.Autowired;

import com.openkm.api.OKMRelation;
import com.openkm.bean.Relation;
import com.openkm.db.service.LegacySrv;
import com.openkm.plugin.BasePlugin;

import net.xeoh.plugins.base.annotations.PluginImplementation;

@PluginImplementation
public class DuplicateDocumentNumberValidator extends BasePlugin implements FieldValidator {

    @Autowired
    private LegacySrv legacySrv;

    @Autowired
    private OKMRelation okmRelation;

    @Override
    public String getName() {
        return "Duplicated document number";
    }

    @Override
    public String validate(String value, List<String> uuids) {
        String validate = "";

        String token = DbSessionManager.getInstance().getSystemToken();
        String sql = "SELECT RGT_UUID FROM OKM_PGRP_CUR_TECHNOLOGY WHERE RGT_PRO_COMMENT='" + value + "'";
        try {
            List<List<String>> result = legacySrv.executeSQL(sql);
            if (result.size() > 0) {
                if (uuids.isEmpty()) {
                    validate = "Duplicated document number";
                } else {
                    List<String> allowedUuids = new ArrayList<>();
                    for (String uuid : uuids) {
                        allowedUuids.add(uuid);
                        List<Relation> relations = okmRelation.getRelations(token, uuid);
                        for (Relation relation : relations) {
                            allowedUuids.add(relation.getNode());
                        }
                    }

                    for (List<String> resultList : result) {
                        if (!allowedUuids.contains(resultList.get(0))) {
                            validate = "Duplicated document number";
                        }
                    }
                }
            }
        } catch (Exception e) {
            validate = e.getMessage();
        }

        return validate;
    }
}

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.impl;

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);
                List<String> uuids = new List<string>();
uuids.Add("28ece92f-9708-4d3f-8033-18dc98b9e7f5");
uuids.Add("5484b622-7c5f-425a-9451-7611c0caf227");

String value = "test";
String className = "com.openkm.plugin.form.validator.DuplicateDocumentNumberValidator";
String message = ws.propertyGroup.validateField(value, className, uuids);
Console.WriteLine("Validate: " + message); } catch (Exception e) { System.Console.WriteLine(e.ToString()); } } } }