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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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:
|
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:
Method | Return values | Description |
---|---|---|
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:
To add several values on a metadata field of type multiple like this:
You should do:
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:
Method | Return values | Description |
---|---|---|
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:
Method | Return values | Description |
---|---|---|
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();
}
}
}