Ejemplo de historial de cambios de metadatos
Descripción
Sección titulada «Descripción»Este ejemplo se basa en la funcionalidad de Automatización. En el fondo hay un plugin llamado SaveMetadataHistory que escucha los eventos “set metadata group” (que se lanzan cada vez que se modifica cualquier nodo de todo el repositorio). El plugin SaveMetadataHistory recupera los valores de los metadatos y los guarda en otra tabla para conservarlos a lo largo del tiempo.
Pasos de instalación
Sección titulada «Pasos de instalación»- Descargue el archivo SaveMetadataHistory.jar y cópielo en su $TOMCAT_HOME/plugins
- Reinicie la aplicación OpenKM.
- Vaya a Administration > Tools > Plugins y compruebe que el plugin com.openkm.automation.action.SaveMetadataHistory aparece en la lista de plugins com.openkm.automation.Action.
- Vaya a Administration > Automation y cree una nueva regla:
- Elija el evento “set metadata group”.
- Elija en “post”.
- Establezca el nombre, por ejemplo “Save metadata history”.
- Establezca el valor de orden a 0.
- Deje la casilla exclusive desactivada.
- Active la casilla active.
- Haga clic en el botón “Create”.
- Haga clic en “Definition” (el icono de filtro) para establecer la definición de la regla.
- Elija “SaveMetadataHistory” en la lista de valores de añadir Action.
- Haga clic en el icono “Add” de la derecha. Se mostrará una tabla con los campos de SaveMetadataHistory.
- Active la casilla active.
- Haga clic en el botón “Create”.
- Vaya a Administration > Tools > Database Query y ejecute la consulta para crear la tabla:
CREATE TABLE OKM_NODE_PROPERTY_VERSION ( NPG_ID bigint(20) NOT NULL AUTO_INCREMENT, NPG_UUID varchar(64) COLLATE utf8_bin NOT NULL, NPG_GROUP varchar(64) COLLATE utf8_bin NOT NULL, NPG_NAME varchar(64) COLLATE utf8_bin NOT NULL, NPG_VALUE varchar(20000) COLLATE utf8_bin DEFAULT NULL, NPG_VERSION varchar(64) COLLATE utf8_bin NOT NULL, NPG_AUTHOR varchar(64) COLLATE utf8_bin NOT NULL, PRIMARY KEY (NPG_ID), UNIQUE KEY NPG_NODE (NPG_UUID,NPG_GROUP,NPG_NAME, NPG_VERSION));Código JAVA
Sección titulada «Código JAVA»package com.openkm.automation.action;
import java.text.SimpleDateFormat;import java.util.Map;import java.util.Map.Entry;
import net.xeoh.plugins.base.annotations.PluginImplementation;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;
import com.ibm.icu.util.Calendar;import com.openkm.automation.Action;import com.openkm.automation.AutomationUtils;import com.openkm.dao.LegacyDAO;import com.openkm.dao.bean.Automation;import com.openkm.spring.PrincipalUtils;
/** * SaveMetadataHistory */@PluginImplementationpublic class SaveMetadataHistory implements Action { private static Logger log = LoggerFactory.getLogger(SaveMetadataHistory.class);
@Override public void executePre(Map<String, Object> env, Object... params) throws Exception { }
@Override @SuppressWarnings("unchecked") public void executePost(Map<String, Object> env, Object... params) throws Exception { String uuid = AutomationUtils.getUuid(env); if (env.containsKey(AutomationUtils.PROPERTY_GROUP_NAME) && env.containsKey(AutomationUtils.PROPERTY_GROUP_PROPERTIES)) { String userId = PrincipalUtils.getUser(); String grpName = (String) env.get(AutomationUtils.PROPERTY_GROUP_NAME); Map<String, String> nodProps = (Map<String, String>) env.get(AutomationUtils.PROPERTY_GROUP_PROPERTIES); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SS"); String version = sdf.format(Calendar.getInstance().getTime()); String sql = "INSERT INTO OKM_NODE_PROPERTY_VERSION (NPG_UUID, NPG_GROUP, NPG_NAME, NPG_VALUE, NPG_VERSION, NPG_AUTHOR) VALUES (?, ?, ?, ?, ?, ?)"; for (Entry<String, String> prop : nodProps.entrySet()) { //long npgId = DatabaseMetadataDAO.getNextSequenceValue("OKM_NODE_PROPERTY_VERSION", "NPG_ID"); //LegacyDAO.executeSQL(sql, npgId, uuid, grpName, prop.getKey(), prop.getValue(), version, userId); LegacyDAO.executeSQL(sql, uuid, grpName, prop.getKey(), prop.getValue(), version, userId); } } }
@Override public boolean hasPost() { return true; }
@Override public boolean hasPre() { return false; }
@Override public String getName() { return "SaveMetadataHistory"; }
@Override public String getParamType00() { return Automation.PARAM_TYPE_EMPTY; }
@Override public String getParamSrc00() { return Automation.PARAM_SOURCE_EMPTY; }
@Override public String getParamDesc00() { return ""; }
@Override public String getParamType01() { return Automation.PARAM_TYPE_EMPTY; }
@Override public String getParamSrc01() { return Automation.PARAM_SOURCE_EMPTY; }
@Override public String getParamDesc01() { return ""; }
@Override public String getParamType02() { return Automation.PARAM_TYPE_EMPTY; }
@Override public String getParamSrc02() { return Automation.PARAM_SOURCE_EMPTY; }
@Override public String getParamDesc02() { return ""; }}