Skip to content

Creating your own NodePaginator plugin

You can create your own NodePaginator.

Conditions:

  • The new NodePaginator class must implement the “NodePaginator” interface.
  • The new NodePaginator class must be declared under the package “com.openkm.plugin.paginate”.
  • The new NodePaginator class must be annotated with@PluginImplementation”.
  • The new NodePaginator class must extend BasePlugin.

NodePaginator interface:

package com.openkm.plugin.paginate;import com.openkm.bean.NodePaginatorConfig;import com.openkm.bean.PageInfo;import com.openkm.core.AccessDeniedException;import com.openkm.core.DatabaseException;import com.openkm.core.PathNotFoundException;import com.openkm.db.bean.NodeBase;import net.xeoh.plugins.base.Plugin;import java.util.List;/** * Node Paginator */public interface NodePaginator extends Plugin { PageInfo getChildrenPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) throws AccessDeniedException, PathNotFoundException, DatabaseException; NodePaginatorConfig getConfig() throws DatabaseException; PageInfo getChildrenByCategoryPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) throws AccessDeniedException, PathNotFoundException, DatabaseException; String getName();}

The new class must be loaded into the package com.openkm.plugin.paginate because the application plugins system will try to load it from there.

Method Type Description
getChildrenPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) PageInfo Get a paginated list of nodes from a parent (uuid). The PageInfo object contains the list of values for each column, including metadata columns.
getChildrenByCategoryPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) PageInfo Get a paginated list of nodes by category from a parent (uuid). The PageInfo object contains the list of values for each column, including metadata columns.
getConfig() NodePaginatorConfig Used to set visible columns and their names in case of metadata columns.
When the label of a column is not empty, the column is considered visible.
getName() String The name of the plugin.

Metadata XML definition:

Terminal window
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE property-groups PUBLIC "-//OpenKM//DTD Property Groups 3.7//EN"
"http://www.openkm.com/dtd/property-groups-3.7.dtd">
<property-groups>
<property-group label="Consulting" name="okg:consulting">
<input label="Input label 1" name="okp:consulting.input1" dbColumnSize="256"/>
<input label="Input label 2" name="okp:consulting.input2" dbColumnSize="512"/>
</property-group>
</property-groups>

TestNodePaginator class:

package com.openkm.plugin.paginate;
import com.openkm.bean.NodePaginatorConfig;
import com.openkm.bean.PageInfo;
import com.openkm.core.AccessDeniedException;
import com.openkm.core.Config;
import com.openkm.core.DatabaseException;
import com.openkm.core.PathNotFoundException;
import com.openkm.db.bean.NodeBase;
import com.openkm.db.bean.Profile;
import com.openkm.db.service.LegacySrv;
import com.openkm.db.service.NodeBaseSrv;
import com.openkm.db.service.ProfileSrv;
import com.openkm.plugin.BasePlugin;
import com.openkm.principal.PrincipalUtils;
import com.openkm.ws.rest.util.SimpleNodeBase;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@PluginImplementation
public class TestNodePaginator extends BasePlugin implements NodePaginator {
private static final Logger log = LoggerFactory.getLogger(TestNodePaginator.class);
private static final String PGRP_COLUMN_LABEL_01 = "Input 1";
private static final String PGRP_COLUMN_LABEL_02 = "Input 2";
private static final String PGRP_COLUMN_LABEL_03 = "Status";
private static final String PGRP_COLUMN_LABEL_04 = "Icon";
@Autowired
private NodeBaseSrv nodeBaseSrv;
@Autowired
private ProfileSrv profileSrv;
@Autowired
private LegacySrv legacySrv;
@Autowired
private Config cfg;
@Override
public PageInfo getChildrenPaginated(String uuid, int offset, int limit, String filter, String orderByField,
boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) throws AccessDeniedException,
PathNotFoundException, DatabaseException {
log.debug("getChildrenPaginated({}, {}, {}, {}, {}, {}, {})", uuid, offset, limit, filter, orderByField, orderAsc, filteredByNodeTypeList);
PageInfo pageInfo = nodeBaseSrv.getCommonChildrenPaginated(uuid, offset, limit, filter, orderByField, orderAsc, filteredByNodeTypeList);
// Only fill the metadata values when results size greater than 0
if (!pageInfo.getObjects().isEmpty()) {
setMetaDataColumns((List<SimpleNodeBase>) pageInfo.getObjects());
}
return pageInfo;
}
@Override
public PageInfo getChildrenByCategoryPaginated(String uuid, int offset, int limit, String filter, String orderByField,
boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) throws AccessDeniedException,
PathNotFoundException, DatabaseException {
PageInfo pageInfo = nodeBaseSrv.getCommonChildrenByCategoryPaginated(uuid, offset, limit, filter, orderByField,
orderAsc, filteredByNodeTypeList);
// Only fill the metadata values when results size greater than 0
if (!pageInfo.getObjects().isEmpty()) {
setMetaDataColumns((List<SimpleNodeBase>) pageInfo.getObjects());
}
return pageInfo;
}
@Override
public String getName() {
return "Consulting metadata sample";
}
private void setMetaDataColumns(List<SimpleNodeBase> nodes) throws DatabaseException {
Map<String, List<String>> rowValues = new HashMap<>();
StringBuilder query = new StringBuilder("select RGT_UUID, RGT_PRO_INPUT1, RGT_PRO_INPUT2 "
+ "from OKM_PGRP_CUR_CONSULTING where RGT_UUID in (");
// Create inFilter
StringBuilder inFilter = new StringBuilder();
for (SimpleNodeBase snb : nodes) {
if (inFilter.length() > 0) {
inFilter.append(",");
}
inFilter.append("'");
inFilter.append(snb.getUuid());
inFilter.append("'");
}
query.append(inFilter);
query.append(")");
log.info("Paginator query: {}", query);
// Convert list of values to map of list
for (List<String> row : legacySrv.executeSQL(query.toString())) {
List<String> cols = new ArrayList<>();
String uuid = row.get(0);
for (int i = 1; i < row.size(); i++) {
cols.add(row.get(i));
}
rowValues.put(uuid, cols);
}
// Set metadata field values
for (SimpleNodeBase node : nodes) {
if (rowValues.get(node.getUuid()) != null) {
node.setPgrpColumnValue1(rowValues.get(node.getUuid()).get(0));
node.setPgrpColumnValue2(rowValues.get(node.getUuid()).get(1));
node.setPgrpColumnValue3("<div class=\"bg-success text-white px-1\">found</div>");
node.setPgrpColumnValue4("<i v-if=\"account.item.active\" class=\"text-success mdi-1_5x mdi mdi-check\"></i>");
} else {
node.setPgrpColumnValue3("<div class=\"bg-danger text-white px-1\">lost</div>");
node.setPgrpColumnValue4("<i class=\"text-danger mdi-1_5x mdi mdi-clear\"></i>");
}
}
}
public NodePaginatorConfig getConfig() throws DatabaseException {
NodePaginatorConfig config = new NodePaginatorConfig();
config.setPgrpColumnLabel01(PGRP_COLUMN_LABEL_01);
config.setPgrpColumnLabel02(PGRP_COLUMN_LABEL_02);
config.setPgrpColumnLabel03(PGRP_COLUMN_LABEL_03);
config.setPgrpColumnLabel04(PGRP_COLUMN_LABEL_04);
// Use current profile configuration for other parameters except in case of system user
String user = PrincipalUtils.getUser();
if (!cfg.DEFAULT_SYSTEM_USER.equals(user)) {
Profile profile = profileSrv.findByUser(user);
config.setColumnMassiveVisible(profile.getPrfFileBrowser().getMassiveVisible());
config.setColumnIconVisible(profile.getPrfFileBrowser().getIconVisible());
config.setColumnNameVisible(profile.getPrfFileBrowser().getNameVisible());
config.setColumnTitleVisible(profile.getPrfFileBrowser().getTitleVisible());
config.setColumnLanguageVisible(profile.getPrfFileBrowser().getLanguageVisible());
config.setColumnSizeVisible(profile.getPrfFileBrowser().getSizeVisible());
config.setColumnLastModifiedVisible(profile.getPrfFileBrowser().getLastModifiedVisible());
config.setColumnAuthorVisible(profile.getPrfFileBrowser().getAuthorVisible());
config.setColumnVersionVisible(profile.getPrfFileBrowser().getVersionVisible());
}
return config;
}
}