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".
In special cases you might be "promoted to Administrator" using the "administrator token".
String systemToken = DbSessionManager.getInstance().getSystemToken();
Methods
setHome
Description:
| Method | Return values | Description |
|---|---|---|
|
setHome(String token, String nodeId) |
void |
Sets the user's home. |
|
By default, the user home value is "/okm:root".
|
||
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
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
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();
}
}
}