use of org.adempiere.process.rpl.exp.ExportHelper in project adempiere by adempiere.
the class ImportHelper method importXMLDocument.
/**
* Import XML Document
* @param result
* @param documentToBeImported
* @param trxName
* @throws Exception
* @throws SQLException
* @throws XPathExpressionException
*/
public void importXMLDocument(StringBuffer result, Document documentToBeImported, String trxName) throws Exception, SQLException, XPathExpressionException {
Element rootElement = documentToBeImported.getDocumentElement();
// Find which Export format to Load...
String AD_Client_Value = null;
AD_Client_Value = rootElement.getAttribute("AD_Client_Value");
log.info("AD_Client_Value = " + AD_Client_Value);
if (AD_Client_Value == null || Util.isEmpty(AD_Client_Value)) {
throw new Exception(Msg.getMsg(ctx, "XMLClientValueMandatory"));
}
String version = null;
version = rootElement.getAttribute("Version");
log.info("Version = " + version);
if (version == null || Util.isEmpty(version)) {
throw new Exception(Msg.getMsg(ctx, "XMLVersionAttributeMandatory"));
}
///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);
if (client == null) {
throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
}
log.info("XML ROOT AD_Client = " + client.toString());
String EXP_Format_Value = null;
EXP_Format_Value = rootElement.getNodeName();
log.info("EXP_Format_Value = " + EXP_Format_Value);
MEXPFormat expFormat = null;
expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, client.getAD_Client_ID(), version, trxName);
if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
// Fall back to SYSTEM Client.
// Try to search Export format defined for SYSTEM Client!!!
MClient systemClient = null;
systemClient = MClient.get(ctx, 0);
if (systemClient == null) {
throw new Exception(Msg.getMsg(ctx, "XMLClientNotFound"));
}
log.info("SYSTEM Client = " + systemClient.toString());
expFormat = MEXPFormat.getFormatByValueAD_Client_IDAndVersion(ctx, EXP_Format_Value, systemClient.getAD_Client_ID(), version, trxName);
}
if (expFormat == null || expFormat.getEXP_Format_ID() == 0) {
throw new Exception(Msg.getMsg(ctx, "EXPFormatNotFound"));
}
log.info("expFormat = " + expFormat.toString());
isChanged = false;
PO po = importElement(ctx, result, rootElement, expFormat, ReplicationType, trxName);
if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent)
;
else if (!po.is_Changed() && !isChanged) {
log.info("Object not changed = " + po.toString());
return;
}
if (po != null) {
Env.setContext(po.getCtx(), "#AD_Client_ID", po.getAD_Client_ID());
if (MReplicationStrategy.REPLICATION_TABLE == ReplicationMode) {
// Here must invoke other method else we get cycle...
if (ModelValidator.TYPE_BEFORE_DELETE == ReplicationEvent || ModelValidator.TYPE_BEFORE_DELETE_REPLICATION == ReplicationEvent || ModelValidator.TYPE_DELETE == ReplicationEvent) {
po.deleteEx(true);
} else {
if (X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(ReplicationType)) {
MReplicationStrategy rplStrategy = new MReplicationStrategy(client.getCtx(), client.getAD_ReplicationStrategy_ID(), po.get_TrxName());
ExportHelper expHelper = new ExportHelper(client, rplStrategy);
expHelper.exportRecord(po, MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge, ModelValidator.TYPE_AFTER_CHANGE);
po.saveReplica(true);
} else if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(ReplicationType) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType)) {
po.saveReplica(true);
} else /*else if (X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(ReplicationType))
{
//Do nothing??
}*/
if (X_AD_ReplicationTable.REPLICATIONTYPE_Local.equals(ReplicationType)) {
//Do nothing??
} else {
// Replication Type is not one of the possible values...ERROR
throw new Exception(Msg.getMsg(ctx, "EXPReplicationTypeNonValidType"));
}
}
} else if (MReplicationStrategy.REPLICATION_DOCUMENT == ReplicationMode && X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(ReplicationType) && po instanceof DocAction) {
DocAction document = (DocAction) po;
String action = document.getDocAction();
String status = document.getDocStatus();
log.info("Document:" + document.toString() + " DocStauts:" + status + " DocAction:" + action);
if (ModelValidator.TIMING_AFTER_REVERSECORRECT == ReplicationEvent) {
if (status.equals(DocAction.STATUS_Reversed) && action.equals(DocAction.ACTION_None)) {
po.saveEx();
return;
}
}
if ((action.equals(DocAction.ACTION_Complete) && status.equals(DocAction.STATUS_InProgress)) || (action.equals(DocAction.ACTION_Close) && status.equals(DocAction.STATUS_Completed))) {
if (!document.processIt(action)) {
log.info("PO.toString() = can not " + po.get_Value("DocAction"));
}
po.saveEx();
} else {
po.saveEx();
return;
}
}
}
result.append("Save Successful ;");
}
use of org.adempiere.process.rpl.exp.ExportHelper in project adempiere by adempiere.
the class ExportModelValidator method loadReplicationStrategy.
public void loadReplicationStrategy(Properties ctx) {
MClient m_client = MClient.get(Env.getCtx(), clientId);
/*replicationStrategyId = MRole.get(m_client.getCtx(), roleId).get_ValueAsInt("AD_ReplicationStrategy_ID");
if(replicationStrategyId <= 0)
{
replicationStrategyId = MOrg.get(m_client.getCtx(), orgId).getAD_ReplicationStrategy_ID();
}
if(replicationStrategyId <= 0)
{
replicationStrategyId = m_client.getAD_ReplicationStrategy_ID();
log.info("client.getAD_ReplicationStrategy_ID() = " + replicationStrategyId);
}
if (replicationStrategyId > 0) {
replicationStrategy = new MReplicationStrategy(m_client.getCtx(), replicationStrategyId, null);
if(!replicationStrategy.isActive())
{
return;
}
exportHelper = new ExportHelper(m_client, replicationStrategy);
}*/
// Add Tables
// We want to be informed when records in Replication tables are created/updated/deleted!
//engine.addModelChange(MBPartner.Table_Name, this);
//engine.addModelChange(MOrder.Table_Name, this);
//engine.addModelChange(MOrderLine.Table_Name, this);
MReplicationStrategy.getByOrgAndRole(ctx, orgId, roleId, null).stream().filter(replicationStrategy -> replicationStrategy != null).forEach(replicationStrategy -> {
for (X_AD_ReplicationTable rplTable : replicationStrategy.getReplicationTables()) {
if (X_AD_ReplicationTable.REPLICATIONTYPE_Merge.equals(rplTable.getReplicationType()) || X_AD_ReplicationTable.REPLICATIONTYPE_Broadcast.equals(rplTable.getReplicationType()) || X_AD_ReplicationTable.REPLICATIONTYPE_Reference.equals(rplTable.getReplicationType())) {
String tableName = MTable.getTableName(replicationStrategy.getCtx(), rplTable.getAD_Table_ID());
modelValidationEngine.addModelChange(tableName, this);
}
}
for (X_AD_ReplicationDocument rplDocument : replicationStrategy.getReplicationDocuments()) {
if (X_AD_ReplicationDocument.REPLICATIONTYPE_Merge.equals(rplDocument.getReplicationType()) || X_AD_ReplicationDocument.REPLICATIONTYPE_Reference.equals(rplDocument.getReplicationType())) {
String tableName = MTable.getTableName(replicationStrategy.getCtx(), rplDocument.getAD_Table_ID());
modelValidationEngine.addDocValidate(tableName, this);
}
}
});
}
use of org.adempiere.process.rpl.exp.ExportHelper in project adempiere by adempiere.
the class ExportModelValidator method docValidate.
/**
* Validate Document.
* Called as first step of DocAction.prepareIt
* when you called addDocValidate for the table.
* @param po persistent object
* @param type see TIMING_ constants
* @return error message or null
* @throws Exception
*/
public String docValidate(PO po, int type) {
log.info("Replicate the Document = " + po.get_TableName() + " with Type = " + type);
String result = null;
if (exportHelper != null) {
try {
if (type == TIMING_AFTER_COMPLETE || type == TIMING_AFTER_CLOSE || type == TIMING_AFTER_REVERSECORRECT || type == TIMING_AFTER_VOID || type == TIMING_AFTER_REACTIVATE) //|| type == TIMING_AFTER_PREPARE
{
MReplicationStrategy.getByOrgAndRole(po.getCtx(), orgId, roleId, po.get_TrxName()).stream().forEach(replicationStrategy -> {
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(), replicationStrategy.get_ID(), po.get_Table_ID(), C_DocType_ID);
} else {
replicationDocument = MReplicationStrategy.getReplicationDocument(po.getCtx(), replicationStrategy.get_ID(), po.get_Table_ID());
}
if (replicationDocument != null) {
exportHelper = new ExportHelper(client, replicationStrategy);
try {
exportHelper.exportRecord(po, MReplicationStrategy.REPLICATION_DOCUMENT, replicationDocument.getReplicationType(), type);
} catch (Exception exeption) {
}
}
});
}
} catch (Exception e) {
e.printStackTrace();
result = e.toString();
}
}
return result;
}
Aggregations