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.

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 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 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

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:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             ws.addGroup("/okm:root/logo.pdf", "okg:consulting"); } catch (Exception e) { e.printStackTrace(); } } }

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:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             ws.removeGroup("/okm:root/logo.pdf", "okg:consulting"); } catch (Exception e) { e.printStackTrace(); } } }

getGroups

Description:

MethodReturn valuesDescription

getGroups(String nodeId)

List<PropertyGroup>

Retrieves a list of metadata groups assigned to a node.

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (PropertyGroup pGroup : ws.getGroups("/okm:root/logo.pdf")) {                 System.out.println(pGroup);             } } catch (Exception e) { e.printStackTrace(); } } }

getAllGroups

Description:

MethodReturn valuesDescription

getAllGroups()

List<PropertyGroup>

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

Example:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (PropertyGroup pGroup : ws.getAllGroups()) {                 System.out.println(pGroup);             } } catch (Exception e) { e.printStackTrace(); } } }

getPropertyGroupProperties

Description:

MethodReturn valuesDescription

getPropertyGroupProperties(String nodeId, String grpName)

List<FormElement>

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 com.openkm.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.form.FormElement;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (FormElement fElement : ws.getPropertyGroupProperties("/okm:root/logo.pdf", "okg:consulting")) {                 System.out.println(fElement);             } } catch (Exception e) { e.printStackTrace(); } } }

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:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             for (FormElement fElement : ws.getPropertyGroupForm("okg:consulting")) {                 System.out.println(fElement);             } } catch (Exception e) { e.printStackTrace(); } } }

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.

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 parameter ofeList all FormElement, it 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:

package com.openkm;

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

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             // Modify with a full FormElement list             List<FormElement> fElements = ws.getPropertyGroupProperties("/okm:root/logo.pdf","okg:consulting");             for (FormElement fElement : fElements) {                 if (fElement.getName().equals("okp:consulting.name")) {                     Input name = (Input) fElement;                     name.setValue("new value");                 }             }
                         ws.setPropertyGroupProperties("/okm:root/logo.pdf", "okg:consulting", fElements);
                         // Same modification with only affected FormElement             fElements = new ArrayList<>();             Input name = new Input();             name.setName("okp:consulting.name");             name.setValue("new value");             fElements.add(name);             ws.setPropertyGroupProperties("/okm:root/logo.pdf","okg:consulting", fElements); } catch (Exception e) { e.printStackTrace(); } } }

setPropertyGroupPropertiesSimple

Description:

MethodReturn valuesDescription

setPropertyGroupPropertiesSimple(String nodeId, 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 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.put("okp:consulting.multiple", "one;two");

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

Example:

package com.openkm;

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

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             Map<String, String> properties = new HashMap<>();             properties.put("okp:consulting.name", "new name");             
            // Date fields must be saved with basic ISO 8601 format             properties.put("okp:consulting.date", ISO8601.formatBasic(Calendar.getInstance()));             ws.setPropertyGroupPropertiesSimple("/okm:root/logo.pdf","okg:consulting", properties); } catch (Exception e) { e.printStackTrace(); } } }

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:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             System.out.println("Have metadata group:" + ws.hasGroup("/okm:root/logo.pdf", "okg:consulting")); } catch (Exception e) { e.printStackTrace(); } } }

getRegisteredDefinition

Description:

MethodReturn valuesDescription

getRegisteredDefinition()

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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
         try {             System.out.println(ws.getRegisteredDefinition()); } catch (Exception e) { e.printStackTrace(); } } }

registerDefinition

Description:

MethodReturn valuesDescription

registerDefinition(InputStream is)

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.sdk4j.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             InputStream is = new FileInputStream("/home/files/PropertyGroups.xml");             ws.registerDefinition(is);             IOUtils.closeQuietly(is); } catch (Exception e) { e.printStackTrace(); } } }

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:

package com.openkm;

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

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             for (String value : ws.getSuggestions("/okm:root/logo.pdf","okg:technology", "okp:technology.language")) {                 System.out.println(value);             } } catch (Exception e) { e.printStackTrace(); } } }

getPropertyGroupPropertiesSimple

Description:

MethodReturn valuesDescription

getPropertyGroupPropertiesSimple(String nodeId, 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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

public class Test {
    public static void main(String[] args) {
        String host = "http://localhost:8080/OpenKM";
        String username = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.newInstance(host, username, password);
try {             Map<String, String> properties = new HashMap<>();             properties = ws.getPropertyGroupPropertiesSimple("/okm:root/logo.pdf","okg:technology");             
            for (String key : properties.keySet()) {                 System.out.println(key + "> " + properties.get(key));             } } catch (Exception e) { e.printStackTrace(); } } }