PropertyGroup samples

Basics

From the 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.

The class com.openkm.sdk4j.util.ISO8601 should be used to set and parse metadata date fields. The metadata field of type date values is stored in the application in ISO-8601 basic format.

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

Calendar cal = ISO8601.parseBasic(metadataFieldValue);

To save the date value in the metadata field of type date use:

Calendar cal = Calendar.getInstance(); // Present date 
String metadataFieldValue = ISO8601.formatBasic(cal);
// metadataFieldValue can be saved into repository metadata field of type date

Suggested code sample

First, you must create the webservice object:

OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

Then should login using the method "login". You can access the "login" method from webservice object "ws" as is shown below:

ws.login(user, password);

Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API methods.

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

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

Methods

addPropertyGroup

Description:

MethodReturn valuesDescription

addPropertyGroup(String uuid, String grpName, Map<String, String> propertiesMap)

void

Adds an empty 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:

<?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="Date" name="okp:technology.date" type="date" />
    <input label="Comment" name="okp:technology.comment"/>
    <textarea label="Description" name="okp:technology.description"/>
    <checkbox label="Important" name="okp:technology.important"/>
    <input label="Link" type="link" name="okp:technology.link"/>
  </property-group>
</property-groups>
 

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

<select label="Type" name="okp:technology.type" type="multiple">
  <option label="Alfa" value="t1"/>
  <option label="Beto" value="t2"/>
  <option label="Omega" value="t3" />
</select>

You should do:

properties.put("okp:technology.type", "[\"t1\", \"t2\"]");

Where \"t1\" and \"t2\" are valid values and character "," is used as separator.

Another option:

Gson gson = new Gson();
List<String> values = new ArrayList<>();
values.add("t1");
values.add("t2");
properties.put("okp:technology.type", gson.toJson(values)); 

Example:

package com.openkm;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.util.ISO8601;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties.put("okp:technology.type", "[ \"t1\", \"t2\" ]");
            Calendar cal = Calendar.getInstance();
            // Value must be converted to String ISO 8601 compliant
            properties.put("okp:technology.date", ISO8601.formatBasic(cal));
            properties.put("okp:technology.comment", "comment sample");
            properties.put("okp:technology.description", "description sample");
            properties.put("okp:technology.language", "[ \"java\" ]");
            properties.put("okp:technology.important", String.valueOf(true));
            ws.propertyGroup.addPropertyGroup("4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5", "okg:technology", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

removePropertyGroup

Description:

MethodReturn valuesDescription

removePropertyGroup(String uuid, String grpName)

void

Removes a metadata group of a node.

The grpName should be a valid Metadata group name.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            ws.propertyGroup.removePropertyGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroups

Description:

MethodReturn valuesDescription

getPropertyGroups(String uuid)

List<PropertyGroup>

Retrieves a list of metadata groups assigned to a node.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.PropertyGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.propertyGroup.getPropertyGroups("8cd1e072-8595-4dd3-b121-41d622c43f08")) {
                System.out.println(pGroup);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAllPropertyGroups

Description:

MethodReturn valuesDescription

getAllPropertyGroups()

List<PropertyGroup>

Retrieves a list of all metadata groups set into the application.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.PropertyGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.propertyGroup.getAllPropertyGroups()) {
                System.out.println(pGroup);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupFormDefinition

Description:

MethodReturn valuesDescription

getPropertyGroupFormDefinition(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:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (FormElement fElement : ws.propertyGroup.getPropertyGroupFormDefinition("okg:consulting")) {
                System.out.println(fElement);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupFormDefinition

Description:

MethodReturn valuesDescription

getPropertyGroupFormDefinition(String grpName, String uuid)

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:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (FormElement fElement : ws.propertyGroup.getPropertyGroupFormDefinition("okg:consulting", "8cd1e072-8595-4dd3-b121-41d622c43f08")) {
                System.out.println(fElement);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupForm

Description:

MethodReturn valuesDescription

getPropertyGroupForm(String uuid, String grpName)

List<FormElement>

Retrieves a list of metadata values of a node.

The grpName should be a valid Metadata group name.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (FormElement fElement : ws.propertyGroup.getPropertyGroupForm("8cd1e072-8595-4dd3-b121-41d622c43f08","okg:consulting")) {
                System.out.println(fElement);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

setPropertyGroupProperties

Description:

MethodReturn valuesDescription

setPropertyGroupProperties(String uuid, String grpName, Map<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.

It is not mandatory to set in the properties parameterMap 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="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="Date" name="okp:technology.date" type="date" />
    <input label="Comment" name="okp:technology.comment"/>
    <textarea label="Description" name="okp:technology.description"/>
    <checkbox label="Important" name="okp:technology.important"/>
    <input label="Link" type="link" name="okp:technology.link"/>
  </property-group>
</property-groups>

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

<select label="Type" name="okp:technology.type" type="multiple">
  <option label="Alfa" value="t1"/>
  <option label="Beto" value="t2"/>
  <option label="Omega" value="t3" />
</select>

You should do:

properties.put("okp:technology.type", "[\"t1\", \"t2\"]");

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

Another option:

Gson gson = new Gson();
List<String> values = new ArrayList<>();
values.add("t1");
values.add("t2");
properties.put("okp:technology.type", gson.toJson(values));

Example:

package com.openkm;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;
import com.openkm.sdk4j.util.ISO8601;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties.put("okp:technology.type", "[ \"t1\", \"t2\" ]");
            Calendar cal = Calendar.getInstance();
            // Value must be converted to String ISO 8601 compliant
            properties.put("okp:technology.date", ISO8601.formatBasic(cal));
            properties.put("okp:technology.comment", "comment sample");
            properties.put("okp:technology.description", "description sample");
            properties.put("okp:technology.language", "[ \"java\" ]");
            properties.put("okp:technology.important", String.valueOf(true));
            ws.propertyGroup.setPropertyGroupProperties("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

hasPropertyGroup

Description:

MethodReturn valuesDescription

hasPropertyGroup(String uuid, String grpName)

Boolean

Returns a boolean that indicate if the node has or not a metadata group.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println("Have metadata group:" + ws.propertyGroup.hasPropertyGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getRegisteredPropertyGroupDefinition

Description:

MethodReturn valuesDescription

getRegisteredPropertyGroupDefinition()

String

Returns the XML Metada groups definition.

The method only can be executed by super user granted ( ROLE_ADMIN member user).

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.propertyGroup.getRegisteredPropertyGroupDefinition());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

registerPropertyGroupDefinition

Description:

MethodReturn valuesDescription

registerPropertyGroupDefinition(InputStream is, String name)

void

Set the XML Metada groups definition into the repository.

The method only can be executed by super user granted ( ROLE_ADMIN member user).

Example:

package com.openkm;

import java.io.FileInputStream;
import java.io.InputStream;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            InputStream is = new FileInputStream("/home/openkm/PropertyGroups.xml");
            ws.propertyGroup.registerPropertyGroupDefinition(is, "test");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupSuggestions

Description:

MethodReturn valuesDescription

getPropertyGroupSuggestions(String uuid, 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:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (String value : ws.propertyGroup.getPropertyGroupSuggestions("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:technology", "okp:technology.language")) {
                System.out.println(value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupProperties

Description:

MethodReturn valuesDescription

getPropertyGroupProperties(String uuid, String grpName)

Map<String, String>

Retrieves a map - (key,value) pairs - with Metada group values of a node.

Example:

package com.openkm;

import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties = ws.propertyGroup.getPropertyGroupProperties("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:technology");

            for (String key : properties.keySet()) {
                System.out.println(key + " > " + properties.get(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupsByVersion

Description:

MethodReturn valuesDescription

getPropertyGroupsByVersion(String uuid, String versionName)

List<PropertyGroup>

Retrieves a list of metadata groups assigned to a specific version of a node.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.PropertyGroup;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.propertyGroup.getPropertyGroupsByVersion("118cb06b-9df7-4d59-bed9-ba986a4f8e0b", "1.3")) {
                System.out.println(pGroup);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupPropertiesByVersion

Description:

MethodReturn valuesDescription

getPropertyGroupPropertiesByVersion(String uuid, String grpName, String versionName)

Map<String, String>

Retrieves a map - (key,value) pairs - with Metadata group values assigned to a specific version of a node.

Example:

package com.openkm;

import java.util.HashMap;
import java.util.Map;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties = ws.propertyGroup.getPropertyGroupPropertiesByVersion("118cb06b-9df7-4d59-bed9-ba986a4f8e0b", "okg:technology", "1.3");

            for (String key : properties.keySet()) {
                System.out.println(key + " > " + properties.get(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupByVersionForm

Description:

MethodReturn valuesDescription

getPropertyGroupByVersionForm(String uuid, String grpName, String versionName)

List<FormElement>

Retrieves a list of all metadata group elements definition for a specific version of a node.

The grpName should be a valid Metadata group name.

The method is usually used to display empty form elements for updating new metadata values.

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (FormElement fElement : ws.propertyGroup.getPropertyGroupByVersionForm("118cb06b-9df7-4d59-bed9-ba986a4f8e0b", "okg:consulting", "1.3")) {
                System.out.println(fElement);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroup

Description:

MethodReturn valuesDescription

getPropertyGroup(String grpName)

PropertyGroup

Retrieve the metadata group

Example:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.propertyGroup.getPropertyGroup("okg:consulting"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSuggestBoxKeyValue

Description:

MethodReturn valuesDescription

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:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            System.out.println(ws.propertyGroup.getPropertyGroup("okg:consulting"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSuggestBoxKeyValuesFiltered

Description:

MethodReturn valuesDescription

getSuggestBoxKeyValuesFiltered(String grpName, String propertyName, String filter)

Map<String, String>

Retrieves a map - (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:

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

import java.util.Map;

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> values = ws.propertyGroup.getSuggestBoxKeyValuesFiltered(Config.GROUP_CONSULTING, "okp:consulting.suggestbox", "pai");
            for (String key : values.keySet()) {
                String value = values.get(key);
                System.out.println(key + ":" + value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

validateField

MethodReturn valuesDescription

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

String

Return the validation message

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

Example of the Form validator implementation

More information at Creating your own Form Validator plugin.

In this example it will not be allowed two equal comments in the metadata field named okp:tecnology.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

package com.openkm;

import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.impl.OKMWebservices;

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

public class Test {

    public static void main(String[] args) {
        String host = "http://localhost:8080/openkm";
        String user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            List<String> uuids = new ArrayList<>();
            uuids.add("26ece92f-9708-4d3f-8033-18dc98b9e7f5");
            uuids.add("7984b622-7c5f-425a-9451-7611c0caf227");

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