Ir al contenido
Otras versiones

Cargando…

Crear 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 en el paquete “com.openkm.plugin.paginate”.
  • La nueva clase NodePaginator debe estar anotada 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í.

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 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 de un padre (uuid). El objeto PageInfo contiene la lista de valores de cada columna, incluidas las columnas de metadatos.
getConfig() NodePaginatorConfig Se utiliza para establecer las columnas visibles y sus nombres en el caso de las columnas de metadatos.
Cuando la etiqueta de una columna no está vacía, la columna se considera visible.
getName() String El nombre del plugin.

Definición XML de metadatos:

Ventana de terminal
<?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:

/**
* 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;
}
}