[ 2354040 ] Implementation Replication Mode, Type, Event

http://sourceforge.net/tracker/index.php?func=detail&aid=2354040&group_id=176962&atid=879335
This commit is contained in:
vpj-cd 2008-11-28 00:05:11 +00:00
parent 97d3b922c5
commit eaac0e16de
6 changed files with 156 additions and 83 deletions

View File

@ -65,9 +65,11 @@ public class ExportModelValidator implements ModelValidator
/** User */
private int m_AD_User_ID = -1;
/** Export Helper */
ExportHelper expHelper = null;
/** Replication Strategy **/
private int m_AD_ReplicationStrategy_ID = -1;
/** Export Helper */
ExportHelper expHelper = null;
/**
* Constructor.
@ -89,10 +91,12 @@ public class ExportModelValidator implements ModelValidator
log.info(client.toString());
MReplicationStrategy rplStrategy = null;
log.info("client.getAD_ReplicationStrategy_ID() = " + client.getAD_ReplicationStrategy_ID());
if (client.getAD_ReplicationStrategy_ID() > 0) {
rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), null);
m_AD_ReplicationStrategy_ID = client.getAD_ReplicationStrategy_ID();
log.info("client.getAD_ReplicationStrategy_ID() = " + m_AD_ReplicationStrategy_ID);
if (m_AD_ReplicationStrategy_ID > 0) {
rplStrategy = new MReplicationStrategy(client.getCtx(), m_AD_ReplicationStrategy_ID, null);
expHelper = new ExportHelper(client, rplStrategy);
}
// Add Tables
@ -101,16 +105,12 @@ public class ExportModelValidator implements ModelValidator
//engine.addModelChange(MOrder.Table_Name, this);
//engine.addModelChange(MOrderLine.Table_Name, this);
if (rplStrategy != null) {
X_AD_ReplicationTable[] rplTables = rplStrategy.getReplicationTables();
for (int i = 0; i < rplTables.length; i++) {
String rplType = rplTables[i].getReplicationType();
if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(rplType)
|| X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(rplType)
)
for (X_AD_ReplicationTable rplTable : rplStrategy.getReplicationTables()) {
if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(rplTable.getReplicationType())
|| X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(rplTable.getReplicationType()))
{
MTable table = MTable.get (client.getCtx(), rplTables[i].getAD_Table_ID());
MTable table = MTable.get (client.getCtx(), rplTable.getAD_Table_ID());
engine.addModelChange(table.getTableName(), this);
}
}
@ -118,17 +118,12 @@ public class ExportModelValidator implements ModelValidator
// Add Documents
// We want to be informed when Replication documents are created/updated/deleted!
if (rplStrategy != null) {
X_AD_ReplicationDocument[] rplDocuments = rplStrategy.getReplicationDocuments();
for (int i = 0; i < rplDocuments.length; i++) {
String rplType = rplDocuments[i].getReplicationType();
if (X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(rplType)
|| X_AD_ReplicationDocument.REPLICATIONTYPE_Reference.equals(rplType)
)
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(), rplDocuments[i].getAD_Table_ID());
MTable table = MTable.get (client.getCtx(), rplDocument.getAD_Table_ID());
engine.addDocValidate(table.getTableName(), this);
}
}
@ -146,16 +141,18 @@ public class ExportModelValidator implements ModelValidator
*/
public String modelChange (PO po, int type) throws Exception
{
String Mode = "Table";
log.info("po.get_TableName() = " + po.get_TableName());
if (expHelper != null) {
if ( type == TYPE_AFTER_CHANGE || type == TYPE_AFTER_NEW ) // After Change or After New
if ( type == TYPE_AFTER_CHANGE
|| type == TYPE_AFTER_NEW
|| type == TYPE_BEFORE_DELETE) // After Change or After New
{
expHelper.exportRecord(po, false);
} else if ( type == TYPE_BEFORE_DELETE ) // Before delete
{
expHelper.exportRecord(po, true);
}
expHelper.exportRecord( po,
MReplicationStrategy.REPLICATION_TABLE,
MReplicationStrategy.getReplicationDocument(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(),
type);
}
}
return null;
@ -176,13 +173,19 @@ public class ExportModelValidator implements ModelValidator
String result = null;
if (expHelper != null) {
try {
if ( type == TIMING_AFTER_COMPLETE
|| type == TIMING_AFTER_CLOSE
|| type == TIMING_AFTER_REVERSECORRECT
|| type == TIMING_AFTER_VOID
if ( type == TIMING_AFTER_COMPLETE
|| type == TIMING_AFTER_CLOSE
|| type == TIMING_AFTER_REVERSECORRECT
|| type == TIMING_AFTER_VOID
|| type == TIMING_AFTER_VOID
|| type == TIMING_AFTER_PREPARE
)
{
expHelper.exportRecord(po, false);
expHelper.exportRecord( po,
MReplicationStrategy.REPLICATION_DOCUMENT ,
MReplicationStrategy.getReplicationDocument(po.getCtx(), m_AD_ReplicationStrategy_ID, po.get_Table_ID()).getReplicationType(),
type);
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -107,12 +107,12 @@ public class ExportHelper {
m_dateFormat = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(Env.getAD_Language(ctx)));
}
/**
/**
* Process - Generate Export Format
* @return info
*/
@SuppressWarnings("unchecked")
public String exportRecord (PO po, boolean isDeleted) throws Exception
public String exportRecord (PO po, Integer ReplicationMode , String ReplicationType, Integer ReplicationEvent) throws Exception
{
MClient client = MClient.get (po.getCtx(), m_AD_Client_ID);
log.info("Client = " + client.toString());
@ -178,9 +178,9 @@ public class ExportHelper {
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
if (isDeleted) {
rootElement.setAttribute("deleted", "Y");
}
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap);
}
@ -225,7 +225,7 @@ public class ExportHelper {
* @return Document
*/
@SuppressWarnings("unchecked")
public Document exportRecord (MEXPFormat exportFormat, String where, boolean isDeleted) throws Exception
public Document exportRecord (MEXPFormat exportFormat, String where , Integer ReplicationMode , String ReplicationType, Integer ReplicationEvent) throws Exception
{
MClient client = MClient.get (exportFormat.getCtx(), m_AD_Client_ID);
MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
@ -278,9 +278,9 @@ public class ExportHelper {
}
rootElement.setAttribute("AD_Client_Value", client.getValue());
rootElement.setAttribute("Version", exportFormat.getVersion());
if (isDeleted) {
rootElement.setAttribute("deleted", "true");
}
rootElement.setAttribute("ReplicationMode", ReplicationMode.toString());
rootElement.setAttribute("ReplicationType", ReplicationType);
rootElement.setAttribute("ReplicationEvent", ReplicationEvent.toString());
outDocument.appendChild(rootElement);
generateExportFormat(rootElement, exportFormat, rs, po, po.get_ID(), variableMap);
}
@ -346,8 +346,10 @@ public class ExportHelper {
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else {
valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//valueString = m_dateFormat.format (Timestamp.valueOf (valueString));
//newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//Standard Japanese Format (default) works better (yyyy-mm-dd)
newElement.setAttribute("DateFormat", valueString);
}
}
@ -359,8 +361,10 @@ public class ExportHelper {
valueString = m_customDateFormat.format(Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_customDateFormat.toPattern()); // Add "DateForamt attribute"
} else {
valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//valueString = m_dateTimeFormat.format (Timestamp.valueOf (valueString));
//newElement.setAttribute("DateFormat", m_dateTimeFormat.toPattern()); // Add "DateForamt attribute
//Standard Japanese Format (default) works better (yyyy-mm-dd hh:mm:ss m.mm)
newElement.setAttribute("DateFormat", valueString);
}
}
}

View File

@ -32,6 +32,9 @@ import javax.xml.transform.stream.StreamResult;
//import org.adempiere.server.rpl.XMLHelper;
import org.compiere.Adempiere;
import org.compiere.model.MReplicationStrategy;
import org.compiere.model.ModelValidator;
import org.compiere.model.X_AD_ReplicationTable;
import org.compiere.process.ProcessInfo;
import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess;
@ -118,7 +121,7 @@ public class ModelExporter extends SvrProcess {
ExportHelper expHelper = new ExportHelper(getCtx(),p_AD_Client_ID);
MEXPFormat exportFormat = new MEXPFormat (getCtx(), p_EXP_Format_ID, get_TrxName() );
File file = new File(p_FileName);
Document doc = expHelper.exportRecord(exportFormat,"", false);
Document doc = expHelper.exportRecord(exportFormat,"", MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge,ModelValidator.TYPE_AFTER_CHANGE);
// Save the document to the disk file
TransformerFactory tranFactory = TransformerFactory.newInstance();

View File

@ -156,12 +156,12 @@ public class TopicExportProcessor implements IExportProcessor {
connection = connectionFactory.createConnection();
}
// connection.setClientID( clientID ); Commented by Victor as he had issue!
connection.setClientID( clientID );// Commented by Victor as he had issue!
connection.start();
// Create a Session
session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); //TODO - Trifon could be EXP_ProcessorParameter
// Create the destination (Topic or Queue)
Destination destination = session.createTopic(topicName);
@ -185,7 +185,7 @@ public class TopicExportProcessor implements IExportProcessor {
// Tell the producer to send the message
try
{
producer.send(message);
producer.send(destination, message);
session.commit();
log.info("JMS Message sent!");
}catch(JMSException ex)
@ -198,12 +198,13 @@ public class TopicExportProcessor implements IExportProcessor {
} finally {
// Clean up
if (session != null) {
try { session.close(); } catch (JMSException ex) { /* ignored */ }
try { session.close(); } catch (JMSException ex) {}
}
if (connection != null) {
try { connection.close(); } catch (JMSException ex) { /* ignored */ }
try { connection.close(); } catch (JMSException ex) {}
}
}
}
}

View File

@ -46,9 +46,14 @@ import org.compiere.model.MClient;
import org.compiere.model.MColumn;
import org.eevolution.model.MEXPFormat;
import org.eevolution.model.MEXPFormatLine;
import org.compiere.model.MReplicationStrategy;
import org.compiere.model.MTable;
import org.compiere.model.ModelValidator;
import org.compiere.model.PO;
import org.compiere.model.X_AD_Client;
import org.compiere.model.X_AD_ReplicationDocument;
import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine;
import org.eevolution.model.X_EXP_FormatLine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -58,7 +63,6 @@ import org.compiere.util.Msg;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* @author Trifon N. Trifonov
* @author Antonio Cañaveral, e-Evolution
@ -124,8 +128,13 @@ public class ImportHelper {
if (version == null || "".equals(version)) {
throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory"));
}
boolean isDelete=false;
isDelete=rootElement.getAttribute("deleted").equals("Y");
///Getting Attributes.
;
int ReplicationMode = new Integer(rootElement.getAttribute("ReplicationMode"));
String ReplicationType = rootElement.getAttribute("ReplicationType");
int ReplicationEvent = new Integer(rootElement.getAttribute("ReplicationEvent"));
MClient client = null;
client = getAD_ClientByValue(ctx, AD_Client_Value, trxName);
@ -157,16 +166,28 @@ public class ImportHelper {
log.info("expFormat = " + expFormat.toString());
PO po = importElement(ctx, result, rootElement, expFormat, trxName);
// Here must invoke other method else we get cycle...
boolean resultSave=false;
if(isDelete)
if(ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE ||
ReplicationEvent == ModelValidator.TYPE_BEFORE_DELETE_REPLICATION ||
ReplicationEvent == ModelValidator.TYPE_DELETE)
resultSave=po.delete(true);
else
resultSave = po.saveReplica(true);
result.append("ResultSave=").append(resultSave).append("; ");
if (resultSave) {
/*if (resultSave)
{
if(ReplicationMode == MReplicationStrategy.REPLICATION_DOCUMENT &&
ReplicationType == X_AD_ReplicationDocument.REPLICATIONTYPE_Merge)
{
String status = po.get_ValueAsString("DocStatus");
String action = po.get_ValueAsString("DocAction");
DocAction m_document;
m_document=(DocAction) po;
DocumentEngine engine = new DocumentEngine (m_document, status);
engine.processIt (action);
}
// Success in save
} else {
// Failed in save
@ -251,11 +272,17 @@ public class ImportHelper {
//referencedNode = (Element)nodeList.item(0);
log.info("referencedNode = " + referencedNode);
refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, formatLines[i].getValue(), trxName);
log.info("refRecord_ID = " + refRecord_ID);
value = new Integer(refRecord_ID);
if(referencedNode!=null)
{
refRecord_ID = getID(ctx, referencedExpFormat, referencedNode, formatLines[i].getValue(), trxName);
log.info("refRecord_ID = " + refRecord_ID);
value = new Integer(refRecord_ID);
}
else
{
log.info("NULL VALUE FOR " + xPath.toString());
value=null;
}
log.info("value=[" + value + "]");
} else if (MEXPFormatLine.TYPE_EmbeddedEXPFormat.equals(formatLines[i].getType())) {
boolean resSave = false;
@ -363,10 +390,14 @@ public class ImportHelper {
)
{
//
int intValue = Integer.parseInt(value.toString());
value = new Integer( intValue );
if(!value.toString().isEmpty())
{
int intValue = Integer.parseInt(value.toString());
value = new Integer( intValue );
}else
value=null;
log.info("Abut to set int value of column ["+column.getColumnName()+"]=["+value+"]");
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), intValue);
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value);
log.info("Set int value of column ["+column.getColumnName()+"]=["+value+"]");
} else if (column.getAD_Reference_ID() == DisplayType.Amount
|| column.getAD_Reference_ID() == DisplayType.Number
@ -375,8 +406,12 @@ public class ImportHelper {
)
{
//
double doubleValue = Double.parseDouble(value.toString());
value = new BigDecimal(doubleValue);
if(!value.toString().isEmpty())
{
double doubleValue = Double.parseDouble(value.toString());
value = new BigDecimal(doubleValue);
}else
value=null;
//value = new Double( doubleValue );
log.info("About to set BigDecimal value of column ["+column.getColumnName()+"]=["+value+"]");
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value);
@ -390,7 +425,10 @@ public class ImportHelper {
//
try {
log.info("About to set value of column ["+column.getColumnName()+"]=["+value+"]");
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), clazz.cast(value));
if(clazz == Boolean.class)
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), value);
else
po.set_ValueOfColumn(formatLines[i].getAD_Column_ID(), clazz.cast(value));
log.info("Set value of column ["+column.getColumnName()+"]=["+value+"]");
} catch (ClassCastException ex) {
ex.printStackTrace();
@ -486,6 +524,14 @@ public class ImportHelper {
log.info("--- iterate unique column with index = ["+i+"]");
MColumn column = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID());
log.info("column = ["+column+"]");
String valuecol=column.getColumnName();
if(column.getAD_Reference_ID() == DisplayType.Amount
|| column.getAD_Reference_ID() == DisplayType.Number
|| column.getAD_Reference_ID() == DisplayType.CostPrice
|| column.getAD_Reference_ID() == DisplayType.Quantity)
{
valuecol="Round("+valuecol+",2)";
}
if (MEXPFormatLine.TYPE_XMLElement.equals(uniqueFormatLines[i].getType())) {
// XML Element
@ -529,9 +575,9 @@ public class ImportHelper {
throw new Exception(Msg.getMsg(ctx, "EXPFormatLineNonValidType"));
}
if (i == 0) {
sql.append(" ").append(column.getColumnName()).append(" = ? ");
sql.append(" ").append(valuecol).append(" = ? ");
} else {
sql.append(" AND ").append(column.getColumnName()).append(" = ? ");
sql.append(" AND ").append(valuecol).append(" = ? ");
}
}
@ -544,13 +590,25 @@ public class ImportHelper {
MColumn col = MColumn.get(ctx, uniqueFormatLines[i].getAD_Column_ID());
if (col.getAD_Reference_ID() == DisplayType.DateTime
|| col.getAD_Reference_ID() == DisplayType.Date
)
|| col.getAD_Reference_ID() == DisplayType.Date)
{
Timestamp value = (Timestamp)handleDateTime(values[i], col , uniqueFormatLines[i]);
pstmt.setTimestamp(i+1, value);
}
else if(col.getAD_Reference_ID() == DisplayType.String)
{
String value = (String)values[i];
pstmt.setString(i+1, value);
}
else if(col.getAD_Reference_ID() == DisplayType.Amount
|| col.getAD_Reference_ID() == DisplayType.Number
|| col.getAD_Reference_ID() == DisplayType.CostPrice
|| col.getAD_Reference_ID() == DisplayType.Quantity)
{
BigDecimal value = new BigDecimal((String)values[i]);
pstmt.setBigDecimal(i+1, value.setScale(2, BigDecimal.ROUND_HALF_UP));
}
else
{
pstmt.setObject(i+1, values[i]);
@ -590,10 +648,11 @@ public class ImportHelper {
result = new Timestamp(m_customDateFormat.parse(valueString).getTime());
log.info("Custom Date Format; Parsed value = " + result.toString());
} else {
result = new Timestamp(m_dateFormat.parse(valueString).getTime());
log.info("Custom Date Format; Parsed value = " + result.toString());
}
//result = new Timestamp(m_dateFormat.parse(valueString).getTime());
//log.info("Custom Date Format; Parsed value = " + result.toString());
//NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats....
result = Timestamp.valueOf(valueString);
}
}
} else if (column.getAD_Reference_ID() == DisplayType.DateTime) {
if (valueString != null) {
@ -602,12 +661,15 @@ public class ImportHelper {
result = new Timestamp(m_customDateFormat.parse(valueString).getTime());
log.info("Custom Date Format; Parsed value = " + result.toString());
} else {
result = new Timestamp(m_dateTimeFormat.parse(valueString).getTime());
log.info("Custom Date Format; Parsed value = " + result.toString());
//result = new Timestamp(m_dateTimeFormat.parse(valueString).getTime());
//log.info("Custom Date Format; Parsed value = " + result.toString());
//NOW Using Standard Japanese Format yyyy-mm-dd hh:mi:ss.mil so don't care about formats....
result = Timestamp.valueOf(valueString);
}
}
}
return result;
}

View File

@ -207,7 +207,7 @@ public class TopicListener implements MessageListener {
{
if(conn.getClientID().equals(clientID))
{
log.config("Connection with clientID '" + clientID
log.warning("Connection with clientID '" + clientID
+ "' already exists");
return;
}else