OKMUserConfig
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 value “null”, which indicates that the application must use the “user session”.
Methods
Section titled “Methods”setHome
Section titled “setHome”Description:
| Method | Return values | Description |
|---|---|---|
| setHome(String token, String nodeId) | void | Sets the user’s home. |
Example:
package com.openkm;
import com.openkm.api.OKMUserConfig;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMUserConfig okmUserConfig = ContextWrapper.getContext().getBean(OKMUserConfig.class); okmUserConfig.setHome(null, "d168924d-e801-426d-a222-00124a1461bd"); // UUID of the folder to set as home } catch (Exception e) { e.printStackTrace(); } }}getConfig
Section titled “getConfig”Description:
| Method | Return values | Description |
|---|---|---|
| getConfig(String token) | UserConfig | Returns the user configuration. |
- Returned values are:
Example:
package com.openkm;
import com.openkm.api.OKMUserConfig;import com.openkm.db.bean.UserConfig;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMUserConfig okmUserConfig = ContextWrapper.getContext().getBean(OKMUserConfig.class); UserConfig uc = okmUserConfig.getConfig(null); System.out.println(uc); } catch (Exception e) { e.printStackTrace(); } }}setConfig
Section titled “setConfig”Description:
| Method | Return values | Description |
|---|---|---|
| setConfig(String token, UserConfig cfg) | void | Updates the user configuration. |
Example:
package com.openkm;
import com.openkm.api.OKMUserConfig;import com.openkm.db.bean.UserConfig;import com.openkm.util.ContextWrapper;
public class Test {
public static void main(String[] args) { try { OKMUserConfig okmUserConfig = ContextWrapper.getContext().getBean(OKMUserConfig.class); UserConfig uc = okmUserConfig.getConfig(null); // Modify config fields as needed okmUserConfig.setConfig(null, uc); } catch (Exception e) { e.printStackTrace(); } }}