Creación de su propio plugin NodePaginator
Puede crear su propio NodePaginator.
Condiciones:
- La nueva clase NodePaginator debe implementar la interfaz “NodePaginator”.
- La nueva clase NodePaginator debe declararse bajo el paquete “com.openkm.plugin.paginate”.
- La nueva clase NodePaginator debe anotarse con “@PluginImplementation”.
- La nueva clase NodePaginator debe extender BasePlugin.
Interfaz NodePaginator:
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();}La nueva clase debe cargarse en el paquete com.openkm.plugin.paginate porque el sistema de plugins de la aplicación intentará cargarla desde ahí.
Descripción de los métodos
Sección titulada «Descripción de los métodos»| Método | Tipo | Descripción |
|---|---|---|
| getChildrenPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) | PageInfo | Obtiene una lista paginada de nodos a partir de un padre (uuid). El objeto PageInfo contiene la lista de valores de cada columna, incluidas las columnas de metadatos. |
| getChildrenByCategoryPaginated(String uuid, int offset, int limit, String filter, String orderByField, boolean orderAsc, List<Class<? extends NodeBase>> filteredByNodeTypeList) | PageInfo | Obtiene una lista paginada de nodos por categoría a partir de un padre (uuid). El objeto PageInfo contiene la lista de valores de cada columna, incluidas las columnas de metadatos. |
| getConfig() | NodePaginatorConfig | Se usa para establecer las columnas visibles y sus nombres en el caso de columnas de metadatos. Cuando la etiqueta de una columna no está vacía, la columna se considera visible. |
| getName() | String | El nombre del plugin. |
Ejemplo
Sección titulada «Ejemplo»Definición XML de metadatos:
<?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>Clase TestNodePaginator:
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;
@PluginImplementationpublic 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; }}