Skip to content
Other versions

Loading…

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 plugin 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 object PageInfo 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 object PageInfo 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:

/**
* OpenKM, Open Document Management System (http://www.openkm.com)
* Copyright (c) Paco Avila & Josep Llort
* <p>
* No bytes were intentionally harmed during the development of this application.
* <p>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
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_1 = "Input 1";
private static final String PGRP_COLUMN_LABEL_2 = "Input 2";
@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().size() > 0) {
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().size() > 0) {
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));
}
}
}
public NodePaginatorConfig getConfig() throws DatabaseException {
NodePaginatorConfig config = new NodePaginatorConfig();
config.setPgrpColumnLabel1(PGRP_COLUMN_LABEL_1);
config.setPgrpColumnLabel2(PGRP_COLUMN_LABEL_2);
// 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;
}
}