From 6da7726327775cf7d82d3fb4ed780968fcfae2e8 Mon Sep 17 00:00:00 2001 From: vpj-cd Date: Mon, 8 Feb 2010 01:14:33 +0000 Subject: [PATCH] The document replication not working kind regards Victor Perez www.e-evolution.com Link to SF Tracker: http://sourceforge.net/support/tracker.php?aid=2947615 --- .../adempiere/model/ExportModelValidator.java | 62 ++++++++++++++----- .../compiere/model/MReplicationStrategy.java | 22 +++++++ 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/base/src/org/adempiere/model/ExportModelValidator.java b/base/src/org/adempiere/model/ExportModelValidator.java index 5f4b0e6b84..9e33cbc9d5 100644 --- a/base/src/org/adempiere/model/ExportModelValidator.java +++ b/base/src/org/adempiere/model/ExportModelValidator.java @@ -24,7 +24,7 @@ * - Trifon Trifonov (trifonnt@users.sourceforge.net) * * * * Sponsors: * -* - E-evolution (http://www.e-evolution.com) * +* - e-Evolution (http://www.e-evolution.com) * ***********************************************************************/ package org.adempiere.model; @@ -39,6 +39,7 @@ import org.compiere.model.PO; import org.compiere.model.X_AD_ReplicationDocument; import org.compiere.model.X_AD_ReplicationTable; import org.compiere.util.CLogger; +import org.compiere.util.Env; /** @@ -50,11 +51,15 @@ import org.compiere.util.CLogger; *
  • https://sourceforge.net/tracker/?func=detail&aid=2875989&group_id=176962&atid=879332 *
  • [ 2195090 ] Stabilization of replication *
  • https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2936561&group_id=176962 + *
  • BF2947615 The document recplicacion not working + *
  • https://sourceforge.net/tracker/?func=detail&aid=2947615&group_id=176962&atid=879332 * * @version $Id$ */ public class ExportModelValidator implements ModelValidator { + /** Context variable which says if replication is enabled */ + public static final String CTX_IsReplicationEnabled = "#IsReplicationEnabled"; /** Logger */ private static CLogger log = CLogger.getCLogger(ExportModelValidator.class); @@ -129,8 +134,8 @@ public class ExportModelValidator implements ModelValidator if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(rplTable.getReplicationType()) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(rplTable.getReplicationType())) { - MTable table = MTable.get (client.getCtx(), rplTable.getAD_Table_ID()); - engine.addModelChange(table.getTableName(), this); + String tableName = MTable.getTableName(client.getCtx(), rplTable.getAD_Table_ID()); + engine.addModelChange(tableName, this); } } } @@ -140,10 +145,9 @@ public class ExportModelValidator implements ModelValidator for (X_AD_ReplicationDocument rplDocument : rplStrategy.getReplicationDocuments()) { if (X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(rplDocument.getReplicationType()) || X_AD_ReplicationDocument.REPLICATIONTYPE_Reference.equals(rplDocument.getReplicationType())) - { - //MDocType docType = MDocType.get(client.getCtx(), rplDocuments[i].getC_DocType_ID()); - MTable table = MTable.get (client.getCtx(), rplDocument.getAD_Table_ID()); - engine.addDocValidate(table.getTableName(), this); + { + String tableName = MTable.getTableName(client.getCtx(), rplDocument.getAD_Table_ID()); + engine.addDocValidate(tableName, this); } } } @@ -167,10 +171,16 @@ public class ExportModelValidator implements ModelValidator || type == TYPE_AFTER_NEW || type == TYPE_BEFORE_DELETE) // After Change or After New { - expHelper.exportRecord( po, - MReplicationStrategy.REPLICATION_TABLE, - MReplicationStrategy.getReplicationTable(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(), - type); + X_AD_ReplicationTable replicationTable = MReplicationStrategy.getReplicationTable( + po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()); + if (replicationTable != null) + { + expHelper.exportRecord( + po, + MReplicationStrategy.REPLICATION_TABLE, + replicationTable.getReplicationType(), + type); + } } } @@ -188,7 +198,7 @@ public class ExportModelValidator implements ModelValidator */ public String docValidate (PO po, int type) { - log.info("po.get_TableName() = " + po.get_TableName()); + log.info("Replicate the Document = " + po.get_TableName() + " with Type = " + type); String result = null; if (expHelper != null) { try { @@ -196,13 +206,30 @@ public class ExportModelValidator implements ModelValidator || type == TIMING_AFTER_CLOSE || type == TIMING_AFTER_REVERSECORRECT || type == TIMING_AFTER_VOID - || type == TIMING_AFTER_PREPARE + //|| type == TIMING_AFTER_PREPARE ) { - expHelper.exportRecord( po, - MReplicationStrategy.REPLICATION_DOCUMENT , - MReplicationStrategy.getReplicationDocument(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(), - type); + X_AD_ReplicationDocument replicationDocument = null; + int C_DocType_ID = po.get_ValueAsInt("C_DocType_ID"); + if (C_DocType_ID > 0) + { + replicationDocument = MReplicationStrategy.getReplicationDocument( + po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID(), C_DocType_ID); + } + else + { + replicationDocument = MReplicationStrategy.getReplicationDocument( + po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()); + } + + + if (replicationDocument != null) { + expHelper.exportRecord( + po, + MReplicationStrategy.REPLICATION_DOCUMENT, + replicationDocument.getReplicationType(), + type); + } } } catch (Exception e) { @@ -223,6 +250,7 @@ public class ExportModelValidator implements ModelValidator */ public String login (int AD_Org_ID, int AD_Role_ID, int AD_User_ID) { + Env.setContext(Env.getCtx(), CTX_IsReplicationEnabled, true); m_AD_Org_ID = AD_Org_ID; m_AD_Role_ID = AD_Role_ID; m_AD_User_ID = AD_User_ID; diff --git a/base/src/org/compiere/model/MReplicationStrategy.java b/base/src/org/compiere/model/MReplicationStrategy.java index 005edbe44d..e841a184e7 100644 --- a/base/src/org/compiere/model/MReplicationStrategy.java +++ b/base/src/org/compiere/model/MReplicationStrategy.java @@ -27,6 +27,8 @@ import org.compiere.util.CLogger; * @author victor.perez@e-evolution.com, e-Evolution *
  • BF2875989 Deactivate replication records are include to replication *
  • https://sourceforge.net/tracker/?func=detail&aid=2875989&group_id=176962&atid=879332 + *
  • BF2947615 The document recplicacion not working + *
  • https://sourceforge.net/tracker/?func=detail&aid=2947615&group_id=176962&atid=879332 */ public class MReplicationStrategy extends X_AD_ReplicationStrategy { /** @@ -57,6 +59,7 @@ public class MReplicationStrategy extends X_AD_ReplicationStrategy { public Collection getReplicationTables() { String whereClause = new StringBuffer(X_AD_ReplicationTable.COLUMNNAME_AD_ReplicationStrategy_ID)+"=?"; // #1 return new Query(getCtx(), X_AD_ReplicationTable.Table_Name, whereClause, get_TrxName()) + .setClient_ID() .setParameters(new Object[]{getAD_ReplicationStrategy_ID()}) .setOnlyActiveRecords(true) .setApplyAccessFilter(false) @@ -70,6 +73,7 @@ public class MReplicationStrategy extends X_AD_ReplicationStrategy { public Collection getReplicationDocuments() { String whereClause = "AD_ReplicationStrategy_ID=?"; // #1 return new Query(getCtx(),X_AD_ReplicationDocument.Table_Name,whereClause,get_TrxName()) + .setClient_ID() .setParameters(new Object[]{getAD_ReplicationStrategy_ID()}) .setOnlyActiveRecords(true) .setApplyAccessFilter(false) @@ -86,6 +90,7 @@ public class MReplicationStrategy extends X_AD_ReplicationStrategy { { String whereClause = "AD_ReplicationStrategy_ID=? AND AD_Table_ID=?"; return new Query(ctx, X_AD_ReplicationTable.Table_Name, whereClause, null) + .setClient_ID() .setOnlyActiveRecords(true) .setApplyAccessFilter(false) .setParameters(new Object[]{AD_ReplicationStrategy_ID, AD_Table_ID}) @@ -102,11 +107,28 @@ public class MReplicationStrategy extends X_AD_ReplicationStrategy { { String whereClause = "AD_ReplicationStrategy_ID=? AND AD_Table_ID=?"; return new Query(ctx, X_AD_ReplicationDocument.Table_Name, whereClause, null) + .setClient_ID() .setOnlyActiveRecords(true) .setApplyAccessFilter(false) .setParameters(new Object[]{AD_ReplicationStrategy_ID, AD_Table_ID}) .first() ; } + + /** + * + * @param AD_Table_ID + * @return X_AD_ReplicationDocument Document to replication + */ + public static X_AD_ReplicationDocument getReplicationDocument(Properties ctx ,int AD_ReplicationStrategy_ID , int AD_Table_ID, int C_DocType_ID) + { + String whereClause = "AD_ReplicationStrategy_ID=? AND AD_Table_ID=? AND C_DocType_ID=?"; + return new Query(ctx, X_AD_ReplicationDocument.Table_Name, whereClause, null) + .setClient_ID() + .setOnlyActiveRecords(true) + .setApplyAccessFilter(false) + .setParameters(new Object[]{AD_ReplicationStrategy_ID, AD_Table_ID, C_DocType_ID}) + .first(); + } }