Skip to content

Creating your own Suggestbox plugin

You can create your own Suggestbox.

Conditions:

  • The new Suggestbox class must implement the “SuggestBoxValues” interface.
  • The new Suggestbox class must be declared in the package “com.openkm.plugin.form.values”.
  • The new Suggestbox class must be annotated with@PluginImplementation”.
  • The new Suggestbox class must extend “BasePlugin”.

Suggestbox interface:

package com.openkm.plugin.form.values;
import com.openkm.bean.KeyValue;
import net.xeoh.plugins.base.Plugin;
import java.util.List;
public interface SuggestBoxValues extends Plugin {
String getName();
List<KeyValue> getSuggestBoxValuesByFilter(String filterValue) throws SuggestBoxException;
KeyValue getExactKeyValueByClassName(String value) throws SuggestBoxException;
}

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 Type Description
getName() String Returns the name that will be shown in the plugins table.
getSuggestBoxValuesByFilter(String filterValue) List Returns a list of KeyValue objects.
getExactKeyValueByClassName(String value) KeyValue Returns a KeyValue object.
package com.openkm.plugin.form.values;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.openkm.api.OKMAuth;
import com.openkm.bean.CommonUser;
import com.openkm.bean.KeyValue;
import com.openkm.plugin.BasePlugin;
import com.openkm.principal.PrincipalAdapterException;
@PluginImplementation
public class SuggestBoxUserList extends BasePlugin implements SuggestBoxValues {
@Autowired
private OKMAuth okmAuth;
@Override
public String getName() {
return "User list suggest box";
}
@Override
public List<KeyValue> getSuggestBoxValuesByFilter(String filterValue) throws SuggestBoxException {
List<KeyValue> list = new ArrayList<>();
try {
for (CommonUser user : okmAuth.getUsers(null)) {
if (user.getName().toLowerCase().contains(filterValue.toLowerCase())) {
KeyValue value = new KeyValue();
value.setKey(user.getId());
value.setValue(user.getName());
list.add(value);
}
}
} catch (PrincipalAdapterException e) {
throw new SuggestBoxException(e);
}
return list;
}
@Override
public KeyValue getExactKeyValueByClassName(String value) throws SuggestBoxException {
KeyValue keyValue = null;
try {
for (CommonUser user : okmAuth.getUsers(null)) {
if (user.equals(value)) {
keyValue = new KeyValue();
keyValue.setKey(user.getId());
keyValue.setValue(user.getName());
break;
}
}
} catch (PrincipalAdapterException e) {
throw new SuggestBoxException(e);
}
return keyValue;
}
}