PropertyGroup samples

Basics

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

Althought we understand this name not helps a lot to identifiying these methods with metadata ones, for historical reason, we continue mantaining the nomenclature.

For more information about Metadata.

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

Example of nodeId:

  • Using UUID -> "f123a950-0329-4d62-8328-0ff500fd42db";
  • Using path -> "/okm:root/logo.png"

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

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

Calendar cal = ISO8601.parseBasic(metadataFieldValue);

To save date value into 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 values of a node.

The grpName should be a valid Metadata group name.

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

Example:

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.

Is not mandatory set into parameter ofeList all FormElement, is enough with the form Elements 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.

Is not mandatory set into properties parameter all fields values, is enough with the fields you wish to change its values.

The sample below is based on this Metadata group definition:

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

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

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

You should do:

properties.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(); } } }

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();
        }
    }
}