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 under 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 of "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 application plugin system will try to load from there.

Do not miss the tag @PluginImplementation otherwise the application plugin system will not be able to retrieve the new class.

More information at: Register a new plugin.

Methods description

MethodTypeDescription

getName()

String

Return the name what will be shown at plugins table.

getOptions()

List<Option>

Return a list with the options.

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;

@PluginImplementation
public 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;
  }
}