Skip to content

OKMFolder

In almost all methods you’ll see a parameter named “fldId”. The value of this parameter can be a valid folder UUID.

Also, in all methods you’ll see a parameter named “token”. Because Cron tasks are executed in the background without authentication, methods used in this scenario might use the token parameter. In the default application execution context, you must use the “null” value, which indicates the application must use the “user session”.

Description:

Method Return values Description
create(String token, Folder fld) Folder Creates a new folder and returns a Folder object.
  • The variable path in the parameter fld must be initialized. It indicates the folder path in OpenKM.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
Folder fld = new Folder();
fld.setPath("/okm:root/test");
okmFolder.create(null, fld);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createWithPropertyGroup(String token, Folder fld, String grpName, Map<String, String> properties) Folder Same as create(), but also sets a metadata group’s properties on the folder in the same call, instead of a create() followed by a separate OKMPropertyGroup.addGroup() call.
  • The variable path in the parameter fld must be initialized, same as create(). The grpName should be a valid Metadata group name, and only the properties belonging to that group are applied - any other keys present in the properties map are ignored.

Example:

package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
Folder fld = new Folder();
fld.setPath("/okm:root/test");
Map<String, String> properties = new HashMap<>();
properties.put("okp:invoice.number", "INV-000");
// Create folder with metadata in a single atomic call
okmFolder.createWithPropertyGroup(null, fld, "okg:invoice", properties);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createSimple(String token, String fldPath) Folder Creates a new folder and returns a Folder object.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
String fldPath = "/okm:root/test";
okmFolder.createSimple(null, fldPath);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getProperties(String token, String fldId) Folder Returns the folder properties.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
Folder fld = okmFolder.getProperties(null, "9f64248c-e049-4706-b89e-6d725842c7f7");
System.out.println(fld);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
delete(String token, String fldId) void Deletes a folder.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.delete(null, "9f64248c-e049-4706-b89e-6d725842c7f7");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
purge(String token, String fldId) void The folder is permanently removed from the repository.
  • Usually you will purge folders in /okm:trash/userId - the user’s personal trash locations - but it is possible to directly purge any folder from the repository.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.purge(null, "9f64248c-e049-4706-b89e-6d725842c7f7");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
rename(String token, String fldId, String newName) Folder Renames a folder.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.rename(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "newname");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
move(String token, String fldId, String dstId) void Moves a folder into another folder or record.
  • The value of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.move(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
copy(String token, String fldId, String dstId) Folder Copies a folder into another folder or record.
  • The value of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.copy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
copy(String token, String fldId, String dstId, String newName) Folder Copies a folder into a folder or record.
  • The value of the dstId parameter should be a folder or record UUID.
  • When the newName parameter value is null, the folder will preserve the same name.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.copy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", "newname");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr) Folder Copies a folder with the associated data into another folder or record.
  • The value of the dstId parameter should be a folder or record UUID.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ExtendedAttributes extAttr = new ExtendedAttributes();
extAttr.setKeywords(true);
extAttr.setNotes(true);
extAttr.setCategories(true);
extAttr.setPropertyGroups(true);
okmFolder.extendedCopy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474", extAttr);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr, String newName) Folder Copies a folder with the associated data into some folder or record.
Deprecated: use extendedCopy(token, fldId, dstId, newName, extAttr) instead.
  • The value of the dstId parameter should be a folder or record UUID.
  • When the newName parameter value is null, the folder will preserve the same name.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ExtendedAttributes extAttr = new ExtendedAttributes();
extAttr.setKeywords(true);
extAttr.setNotes(true);
extAttr.setCategories(true);
extAttr.setPropertyGroups(true);
okmFolder.extendedCopy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474",
extAttr, "newname");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
extendedCopy(String token, String fldId, String dstId, String newName, ExtendedAttributes extAttr) Folder Copies a folder with the associated data into some folder or record, with a new name.
  • The value of the dstId parameter should be a folder or record UUID.
  • When the newName parameter value is null, the folder will preserve the same name.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ExtendedAttributes extAttr = new ExtendedAttributes();
extAttr.setKeywords(true);
extAttr.setNotes(true);
extAttr.setCategories(true);
extAttr.setPropertyGroups(true);
okmFolder.extendedCopy(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263", "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474",
"newname", extAttr);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getChildren(String token, String fldId) List Returns a list of all folders whose parent is fldId.
  • The parameter fldId can be a folder or a record node.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
for (Folder fld : okmFolder.getChildren(null, "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474")) {
System.out.println(fld);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getContentInfo(String token, String fldId) ContentInfo Returns a ContentInfo object with information about the folder.
  • The ContentInfo object retrieves information about:

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.bean.ContentInfo;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
ContentInfo ci = okmFolder.getContentInfo(null, "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474");
System.out.println(ci);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
isValid(String token, String fldId) boolean Returns a boolean that indicates whether the node is a folder.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
boolean valid = okmFolder.isValid(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263");
System.out.println(valid);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
getPath(String token, String uuid) String Converts a folder UUID to a folder path.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
String path = okmFolder.getPath(null, "7aceb86c-1dc8-4551-aebd-b7bd73d01263");
System.out.println(path);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createMissingFolders(String token, String fldPath) String Creates missing folders based on all the path nodes. Returns the UUID of the deepest created folder.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.createMissingFolders(null, "/okm:root/test/missing/from/here");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
addNodeClassChildren(String token, String fldId, long ncId) void Adds the NodeClass.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
long ncId = 2;
okmFolder.addNodeClassChildren(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", ncId);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
createFromTemplate(String token, String fldId, String dstPath, Map<String, String> properties, ExtendedAttributes extAttr) Folder Creates a new folder from a template and returns a Folder object.
  • The dstPath can be a folder or a record UUID.
  • When the template uses metadata groups to fill fields, the values are mandatory and must be set in the properties parameter.

Example:

package com.openkm;
import java.util.HashMap;
import java.util.Map;
import com.openkm.api.OKMFolder;
import com.openkm.bean.ExtendedAttributes;
import com.openkm.bean.Folder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
Map<String, String> properties = new HashMap<>();
Folder fld = okmFolder.createFromTemplate(null, "86633fe8-1b0d-48ac-a716-7685022adad8",
"/okm:root/destination", properties, new ExtendedAttributes());
System.out.println(fld);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
setDescription(String token, String uuid, String description) void Sets a description.

Example:

package com.openkm;
import com.openkm.api.OKMFolder;
import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) {
try {
OKMFolder okmFolder = ContextWrapper.getContext().getBean(OKMFolder.class);
okmFolder.setDescription(null, "7ce1b4a8-4ade-4dce-8d7d-4e99a6cd368b", "some description");
} catch (Exception e) {
e.printStackTrace();
}
}
}