Creating your own Option Select Values plugin
You can create your own Option Select Values.
Conditions:
- The new Option Select Values class must implement the “OptionSelectValues” interface.
- The new Option Select Values class must be declared in the package “com.openkm.plugin.form.values”.
- The new Option Select Values class must be annotated with “@PluginImplementation”.
- The new Option Select Values class must extend “BasePlugin”.
Option Select Values interface:
package com.openkm.plugin.form.values;
import com.openkm.bean.form.Option;import net.xeoh.plugins.base.Plugin;
import java.util.List;
/** * OptionSelectValues */public interface OptionSelectValues extends Plugin {
String getName();
List<Option> getOptions() throws OptionSelectException;}The new class must be loaded into the package com.openkm.plugin.form.values because the application plugin system will try to load it from there.
Method descriptions
Section titled “Method descriptions”| Method | Type | Description |
|---|---|---|
| getName() | String | Returns the name that will be shown in the plugins table. |
| getOptions() | List | Returns a list of options. |
Example of the Option Select Values implementation
Section titled “Example of the Option Select Values implementation”package com.openkm.plugin.form.values;
import com.openkm.api.OKMAuth;import com.openkm.bean.form.Option;import com.openkm.core.DatabaseException;import com.openkm.db.bean.DbUser;import com.openkm.plugin.BasePlugin;import com.openkm.principal.AuthException;import net.xeoh.plugins.base.annotations.PluginImplementation;import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;import java.util.List;
@PluginImplementationpublic class OptionSelectUserList extends BasePlugin implements OptionSelectValues {
@Autowired private OKMAuth okmAuth;
@Override public String getName() { return "User list"; }
@Override public List<Option> getOptions() throws OptionSelectException { List<Option> options = new ArrayList<>();
try { List<DbUser> userList = okmAuth.getUsers(null, true); for (DbUser user : userList) { Option option = new Option(); option.setLabel(user.getName()); option.setValue(user.getId()); options.add(option); } } catch (AuthException | DatabaseException e) { throw new OptionSelectException(e); }
return options; }}