Search in sources :

Example 1 with X_AD_ReplicationDocument

use of org.compiere.model.X_AD_ReplicationDocument 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);
            }
        }
    });
}
Also used : CLogger(org.compiere.util.CLogger) Properties(java.util.Properties) MClient(org.compiere.model.MClient) X_AD_ReplicationTable(org.compiere.model.X_AD_ReplicationTable) ExportHelper(org.adempiere.process.rpl.exp.ExportHelper) Env(org.compiere.util.Env) X_AD_ReplicationDocument(org.compiere.model.X_AD_ReplicationDocument) MReplicationStrategy(org.compiere.model.MReplicationStrategy) ModelValidator(org.compiere.model.ModelValidator) MReplicationTable(org.compiere.model.MReplicationTable) MTable(org.compiere.model.MTable) PO(org.compiere.model.PO) ModelValidationEngine(org.compiere.model.ModelValidationEngine) X_AD_ReplicationTable(org.compiere.model.X_AD_ReplicationTable) MClient(org.compiere.model.MClient) X_AD_ReplicationDocument(org.compiere.model.X_AD_ReplicationDocument)

Example 2 with X_AD_ReplicationDocument

use of org.compiere.model.X_AD_ReplicationDocument 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;
}
Also used : ExportHelper(org.adempiere.process.rpl.exp.ExportHelper) X_AD_ReplicationDocument(org.compiere.model.X_AD_ReplicationDocument)

Aggregations

ExportHelper (org.adempiere.process.rpl.exp.ExportHelper)2 X_AD_ReplicationDocument (org.compiere.model.X_AD_ReplicationDocument)2 Properties (java.util.Properties)1 MClient (org.compiere.model.MClient)1 MReplicationStrategy (org.compiere.model.MReplicationStrategy)1 MReplicationTable (org.compiere.model.MReplicationTable)1 MTable (org.compiere.model.MTable)1 ModelValidationEngine (org.compiere.model.ModelValidationEngine)1 ModelValidator (org.compiere.model.ModelValidator)1 PO (org.compiere.model.PO)1 X_AD_ReplicationTable (org.compiere.model.X_AD_ReplicationTable)1 CLogger (org.compiere.util.CLogger)1 Env (org.compiere.util.Env)1