OKMPropertyGroup

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.

On most methods you'll see a parameter named "nodeId". The value of this parameter can be a valid document, folder, mail or record UUID.

Example of nodeId:

  • Using UUID -> "b153c4b7-3d1c-4589-bd42-0ed0f34fd338";

The class com.openkm.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 metada 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

Also on all methods you'll see parameter named "token". Because the Cron Task are executed in background without authentication, the methods used in this scenario might use the token parameter. From default application execution context you must use "null" value what indicates to the application must use the "user session".

On special cases you might be "promoted as Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

addGroup

Description:

MethodReturn valuesDescription

addGroup(String token, String nodeId, String grpName, Map<String, String> properties)

void

Adds an metadata group and its values to a node.

The grpName should be a valid Metadata group name.

It is not mandatory to set in the 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="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 com.google.gson.Gson;
import com.openkm.Config;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;
import com.openkm.util.ISO8601;

import java.util.*;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);

            Map<String, String> properties = new HashMap<>();
            Gson gson = new Gson();
            List<String> values = new ArrayList<>();
            values.add("t1");
            values.add("t2");
            properties.put("okp:technology.type", gson.toJson(values));
            properties.put("okp:technology.language", "[ \"java\" ]");
            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.important", String.valueOf(true));
            okmPropertyGroup.addGroup(null, "4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5", "okg:technology", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

removeGroup

Description:

MethodReturn valuesDescription

removeGroup(String token, String nodeId, 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.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            okmPropertyGroup.removeGroup(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okg:consulting");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGroups

Description:

MethodReturn valuesDescription

getGroups(String token, String nodeId)

List<PropertyGroup>

Retrieves a list of metadata groups assigned to a node.

Example:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;
import com.openkm.bean.PropertyGroup;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (PropertyGroup pg : okmPropertyGroup.getGroups(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338")) {
                System.out.println(pg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getAllGroups

Description:

MethodReturn valuesDescription

getAllGroups(String token)

List<PropertyGroup>

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

Example:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;
import com.openkm.bean.PropertyGroup;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (PropertyGroup pg : okmPropertyGroup.getAllGroups(null)) {
                System.out.println(pg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getUserGroups

Description:

MethodReturn valuesDescription

getUserGroups(String token)

List<PropertyGroup>

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

Example:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;
import com.openkm.bean.PropertyGroup;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (PropertyGroup pg : okmPropertyGroup.getUserGroups(null)) {
                System.out.println(pg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProperties

Description:

MethodReturn valuesDescription

getProperties(String token, String nodeId, String grpName)

Map<String, String>

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

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:

package com.openkm;

import java.util.Map;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            Map<String, String> properties = okmPropertyGroup.getProperties(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okg:consulting");
            for (String key : properties.keySet()) {
                System.out.println(key + ": " + properties.get(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

setProperties

Description:

MethodReturn valuesDescription

setProperties(String token, String nodeId, String grpName, Map<String, String> properties)

void

Changes the metadata group valuea of a node.

The grpName should be a valid Metadata group name.

It is not mandatory to set in the 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="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 com.google.gson.Gson;
import com.openkm.Config;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;
import com.openkm.util.ISO8601;

import java.util.*;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);

            Map<String, String> properties = new HashMap<>();
            Gson gson = new Gson();
            List<String> values = new ArrayList<>();
            values.add("t1");
            values.add("t2");
            properties.put("okp:technology.type", gson.toJson(values));
            properties.put("okp:technology.language", "[ \"java\" ]");
            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.important", String.valueOf(true));
            okmPropertyGroup.setProperties(null, "4a3b1c1b-c880-45a3-a6ff-2c8b7c5adfa5", "okg:technology", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getPropertyGroupForm

Description:

MethodReturn valuesDescription

getPropertyGroupForm(String token, 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.api.OKMPropertyGroup;
import com.openkm.bean.form.FormElement;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (FormElement fe : okmPropertyGroup.getPropertyGroupForm(null, "okg:consulting")) {
                System.out.println(fe);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

hasGroup

Description:

MethodReturn valuesDescription

hasGroup(String token, String nodeId, String grpName)

boolean

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

Example:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            boolean found = okmPropertyGroup.hasGroup(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okg:consulting");
            System.out.println(found);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSuggestions

Description:

MethodReturn valuesDescription

getSuggestions(String token, 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:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (String value : okmPropertyGroup.getSuggestions(null, "b153c4b7-3d1c-4589-bd42-0ed0f34fd338", "okg:technology",
                    "okp:technology.language")) {
                System.out.println(value);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

registerDefinition

Description:

MethodReturn valuesDescription

registerDefinition(String token, String pgDef, String pgName)

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 org.apache.commons.io.IOUtils;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        InputStream is = null;
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            is = new FileInputStream("/home/files/PropertyGroups.xml");
            String pgDef = IOUtils.toString(is);
            okmPropertyGroup.registerDefinition(null, pgDef, "test");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
}

getRegisteredDefinition

Description:

MethodReturn valuesDescription

getRegisteredDefinition(String token)

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.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            String pgDef = okmPropertyGroup.getRegisteredDefinition(null);
            System.out.println(pgDef);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGroups

Description:

MethodReturn valuesDescription

getGroups(String token, String nodeId, 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.api.OKMPropertyGroup;
import com.openkm.bean.PropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            for (PropertyGroup pg : okmPropertyGroup.getGroups(null, "82555dd1-bcc2-4e64-81cb-5f7c2b0d7801", "1.2")) {
                System.out.println(pg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGroupProperties

Description:

MethodReturn valuesDescription

getGroupProperties(String token, Long pgdId)

List<PropertyGroup>

Retrieves a list of metadata groups properties.

Example:

package com.openkm;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.PropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
            long pgdId = 1;
            for (PropertyGroup pg : okmPropertyGroup.getGroupProperties(null, pgdId)) {
                System.out.println(pg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProperties

Description:

MethodReturn valuesDescription

getProperties(String token, String nodeId, String grpName, Sring 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.Map;

import com.openkm.api.OKMPropertyGroup;
import com.openkm.util.ContextWrapper;

public class Test {

    public static void main(String[] args) {
        try {
            OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);

            Map<String, String> properties = okmPropertyGroup.getProperties(null, "82555dd1-bcc2-4e64-81cb-5f7c2b0d7801", "okg:tpl", "1.2");
            for (String key : properties.keySet()) {
                System.out.println(key + ": " + properties.get(key));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSuggestBoxKeyValue

Description:

MethodReturn valuesDescription

getSuggestBoxKeyValue(String token, String grpName, String propertyName, Sring key)

KeyValue

Retrieves an object that contains the key and value of the suggestbox.

Example:

package com.openkm;


import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.KeyValue; import com.openkm.util.ContextWrapper; public class Test { public static void main(String[] args) { try { OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
KeyValue kv = okmPropertyGroup.getSuggestBoxKeyValue(null, "okg:groupname", "okp:groupname.propertyname", "namekey"); System.out.println(kv.getKey() + ": " + kv.getValue()); } catch (Exception e) { e.printStackTrace(); } } }

 

getSuggestBoxKeyValuesFiltered

Description:

MethodReturn valuesDescription

getSuggestBoxKeyValuesFiltered(String token, String grpName, String propertyName, String filter)

List<KeyValue>

Retrieves a list of objects that contains the key and value of the suggestbox filtered by value.

Example:

package com.openkm;

import java.util.List;
import com.openkm.api.OKMPropertyGroup;
import com.openkm.bean.KeyValue; import com.openkm.util.ContextWrapper; public class Test { public static void main(String[] args) { try { OKMPropertyGroup okmPropertyGroup = ContextWrapper.getContext().getBean(OKMPropertyGroup.class);
List<KeyValue> kvList = okmPropertyGroup.getSuggestBoxKeyValuesFiltered(null, "okg:groupname", "okp:groupname.propertyname", "filter");
for (KeyValue kv : kvList) { System.out.println(kv.getKey() + ": " + kv.getValue()); }
} catch (Exception e) { e.printStackTrace(); } } }