OKMFolder

Basics

On almost methods you'll see parameter named "fldId". The value of this parameter can be some valid folder UUID.

Example of fldId:

  • Using UUID -> "b67fe3ae-bcca-4947-b8ea-0cc7aedd4474";

Also on all methods you'll see parameter named "token". Because the Cron Task are executed in background without authentication, the methods used in this scenario might use the token parameter. From default application execution context you must use "null" value what indicates to the application must use the "user session".

On special cases you might be "promoted as Administrator" using the "administrator token".

String systemToken = DbSessionManager.getInstance().getSystemToken();

Methods

create

Description:

MethodReturn valuesDescription

create(String token, Folder fld)

Folder

Creates a new folder and returns as a result an object Folder.

The variable path into the parameter fld, must be initializated. It indicates the folder path into OpenKM.

Folder fld = new Folder();
fld.setPath("/okm:root/test");

The other variables of the Folder ( fld ) will not take any effect on the folder creation.

We suggest using the method below to create the Folder Simply rather this one.

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

createSimple

Description:

MethodReturn valuesDescription

createSimple(String token, String fldPath)

Folder

Creates a new folder and returns as a result an object 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);
            String fldPath = "/okm:root/test";
            okmFolder.createSimple(null, fldPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

getProperties

Description:

MethodReturn valuesDescription

getProperties(String token, String fldId)

Folder

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

delete

Description:

MethodReturn valuesDescription

delete(String token, String fldId)

void

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

purge

Description:

MethodReturn valuesDescription

purge(String token, String fldId)

void

The folder is definitely removed from the repository.

Usually you will purge folders into /okm:trash/userId - the personal trash user locations - but it is possible to directly purge any folder from the whole repository.

When a folder is purged, it will  only be able to be restored from a previously repository backup. The purge action removes the folder definitely 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.delete(null, "9f64248c-e049-4706-b89e-6d725842c7f7");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

rename

Description:

MethodReturn valuesDescription

rename(String token, String fldId, String newName)

Folder

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

move

Description:

MethodReturn valuesDescription

move(String token, String fldId, String dstId)

void

Moves folder into some folder or record

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

copy

Description:

MethodReturn valuesDescription

copy(String token, String fldId, String dstId)

void

Copies a folder into a folder or record.

The values of the dstId parameter should be a folder or record UUID.

Only the security grants are copied to destination, the metadata, keywords, etc. of the folder are not copied.

See "extendedCopy" method for this feature.

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

copy

Description:

MethodReturn valuesDescription

copy(String token, String fldId, String dstId, String newName)

void

Copies a folder into a folder or record.

The values of the dstId parameter should be a folder or record UUID.

When parameter newName value is null, folder will preservate the same name.

Only the security grants are copied to destination, the metadata, keywords, etc. of the folder are not copied.

See "extendedCopy" method for this feature.

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

extendedCopy

Description:

MethodReturn valuesDescription

extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr)

void

Copies a folder with the associated data into some folder or record.

The values of the dstId parameter should be a folder or record UUID.

By default only the binary data and the security grants, the metadata, keywords, etc. of the folder are not copyed.

Additional extended attributes parameters:

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original values of the notes will be copied.
  • When the wiki parameter is true the original values of the wiki will be copied.

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

extendedCopy

Description:

MethodReturn valuesDescription

extendedCopy(String token, String fldId, String dstId, ExtendedAttributes extAttr, String newName)

void

Copies a folder with the associated data into some folder or record.

The values of the dstId parameter should be a folder or record UUID.

When parameter newName value is null, folder will preservate the same name.

By default only the binary data and the security grants, the metadata, keywords, etc. of the folder are not copyed.

Additional extended attributes parameters:

  • When the category parameter is true the original values of the categories will be copied.
  • When the keywords parameter is true the original values of the keywords will be copied.
  • When the propertyGroups parameter is true the original values of the metadata groups will be copied.
  • When the notes parameter is true the original values of the notes will be copied.
  • When the wiki parameter is true the original values of the wiki will be copied.

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

getChildren

Description:

MethodReturn valuesDescription

getChildren(String token, String fldId)

List<Folder>

Returns a list of all folders which their 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();
        }
    }
}

getContentInfo

Description:

MethodReturn valuesDescription

getContentInfo(String token, String fldId)

ContentInfo

Return and object ContentInfo with information about folder.

The ContentInfo object retrives information about:

  • The number of folders into.
  • The number of documents into.
  • The number of records into.
  • The number of mails into.
  • The size in bytes of all objects into the folder.

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

isValid

Description:

MethodReturn valuesDescription

isValid(String token, String fldId)

boolean

Returns a boolean that indicates if the node is a folder or not.

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

getPath

Description:

MethodReturn valuesDescription

getPath(String token, String uuid)

String

Convert folder UUID to 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();
        }
    }
}

setStyle

Description:

MethodReturn valuesDescription

setStyle(String token, String fldId, long styleId)

void

Set the folder style.

More information at Folder style.

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.setStyle(null, "/okm:root/test", 1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

createMissingFolders

Description:

MethodReturn valuesDescription

createMissingFolders(String token, String fldPath)

void

Create missing folders based on all the path nodes.

The method checks all subfolders and when detects some one is missing, it creates all missing subfolders from there.

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

addNodeClassChildren

Description:

MethodReturn valuesDescription

addNodeClassChildren(String token, String fldId, long ncId)

void

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

setDescription

Description:

MethodReturn valuesDescription

setDescription(String token, String uuid, String description)

void

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