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 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 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="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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> propertiesMap = new HashMap<>();
            propertiesMap.put("okp:consulting.name", "new name");
            // Date fields must be saved with basic ISO 8601 format
            propertiesMap.put("okp:consulting.date", ISO8601.formatBasic(Calendar.getInstance()));
            propertiesMap.put("okp:consulting.comment", "new comment");

            ws.addGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting", propertiesMap);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

removeGroup

Description:

MethodReturn valuesDescription

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

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.removeGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getGroups

Description:

MethodReturn valuesDescription

getGroups(String uuid)

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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.getGroups("8cd1e072-8595-4dd3-b121-41d622c43f08")) {
                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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.getAllGroups()) {
                System.out.println(pGroup);
            }
        } 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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (FormElement fElement : ws.getPropertyGroupForm("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="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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            Map<String, String> properties = new HashMap<>();
            properties.put("okp:consulting.name", "set name");
            // Date fields must be saved with basic ISO 8601 format
            properties.put("okp:consulting.date", ISO8601.formatBasic(Calendar.getInstance()));
            properties.put("okp:consulting.comment", "set comment");

            ws.setPropertyGroupProperties("8cd1e072-8595-4dd3-b121-41d622c43f08", "okg:consulting", properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

hasGroup

Description:

MethodReturn valuesDescription

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

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.hasGroup("8cd1e072-8595-4dd3-b121-41d622c43f08", "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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

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

registerDefinition

Description:

MethodReturn valuesDescription

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

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.registerDefinition(is, "test");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getSuggestions

Description:

MethodReturn valuesDescription

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

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

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

getGroupsByVersion

Description:

MethodReturn valuesDescription

getGroupsByVersion(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.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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

        try {
            ws.login(user, password);
            for (PropertyGroup pGroup : ws.getGroupsByVersion("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.OKMWebservices;
import com.openkm.sdk4j.OKMWebservicesFactory;

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

getGroup

Description:

MethodReturn valuesDescription

getGroup(String grpName)

PropertyGroup

Retrieve the 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 user = "okmAdmin";
        String password = "admin";
        OKMWebservices ws = OKMWebservicesFactory.getInstance(host);

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