OKMPropertyGroup
Basics
In older OpenKM versions we named "Metadata Groups" as "Property Groups".
Although we understand this name does not help much to identify these methods with metadata ones, for historical reasons, we continue to maintain the nomenclature.
For more information about Metadata.
In 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. Metadata field values of type date are 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
Also on all methods you'll see a parameter named "token". Because Cron Tasks are executed in the background without authentication, the methods used in this scenario might use the token parameter. From the default application execution context you must use the "null" value, which indicates that the application must use the "user session".
In special cases you might be "promoted to Administrator" using the "administrator token".
String systemToken = DbSessionManager.getInstance().getSystemToken();
Methods
addGroup
Description:
Method | Return values | Description |
---|---|---|
addGroup(String token, String nodeId, String grpName, Map<String, String> properties) |
void |
Adds a metadata group and its values to a node. |
The grpName should be a valid Metadata group name. It is not mandatory to set all field values in the properties parameter; it is enough to include the fields whose values you wish to change. The sample below is based on this Metadata group definition:
To add several values on a metadata field of type multiple like this:
You should do:
Where \"t1\" and \"t2\" are valid values and character "," is used as separator. Another option:
|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
getAllGroups(String token) |
List<PropertyGroup> |
Retrieves a list of all metadata groups in 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:
Method | Return values | Description |
---|---|---|
getUserGroups(String token) |
List<PropertyGroup> |
Retrieves a list of all metadata groups for the user in 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:
Method | Return values | Description |
---|---|---|
getProperties(String token, String nodeId, String grpName) |
Map<String, String> |
Retrieves a list of all metadata group elements and their node values. |
The grpName should be a valid Metadata group name. The method is usually used to display form elements with their values to be shown or changed by users. |
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:
Method | Return values | Description |
---|---|---|
setProperties(String token, 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. It is not mandatory to set all field values in the properties parameter; it is enough to include the fields whose values you wish to change. The sample below is based on this Metadata group definition:
To add several values on a metadata field of type multiple like this:
You should do:
Where \"t1\" and \"t2\" are valid values and character "," is used as separator. Another option:
|
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:
Method | Return values | Description |
---|---|---|
getPropertyGroupForm(String token, String grpName) |
List<FormElement> |
Retrieves a list of all metadata group element definitions. |
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:
Method | Return values | Description |
---|---|---|
hasGroup(String token, String nodeId, String grpName) |
boolean |
Returns a boolean that indicates whether the node has a metadata group or not. |
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:
Method | Return values | Description |
---|---|---|
getSuggestions(String token, String nodeId, String grpName, String propName) |
List<String> |
Retrieves a list of suggested metadata field values. |
The propName parameter should be a Metadata Select field type. More information at Creating your own Suggestion Analyzer and Metadata Select field. The sample below is based on this Metadata group definition:
|
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:
Method | Return values | Description |
---|---|---|
registerDefinition(String token, String pgDef, String pgName) |
void |
Sets the XML Metadata groups definition into the repository. |
The method can only be executed by a super user (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:
Method | Return values | Description |
---|---|---|
getRegisteredDefinition(String token) |
String |
Returns the XML Metadata groups definition. |
The method can only be executed by a super user (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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
getGroupProperties(String token, Long pgdId) |
List<PropertyGroup> |
Retrieves a list of metadata group 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:
Method | Return values | Description |
---|---|---|
getProperties(String token, String nodeId, 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.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:
Method | Return values | Description |
---|---|---|
getSuggestBoxKeyValue(String token, String grpName, String propertyName, String key) |
KeyValue |
Retrieves an object that contains the key and value of the suggest box. |
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:
Method | Return values | Description |
---|---|---|
getSuggestBoxKeyValuesFiltered(String token, String grpName, String propertyName, String filter) |
List<KeyValue> |
Retrieves a list of objects that contain the key and value of the suggest box 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();
}
}
}