Search in sources :

Example 1 with MClient

use of org.compiere.model.MClient in project adempiere by adempiere.

the class ImportHelper method getAD_ClientByValue.

public static MClient getAD_ClientByValue(Properties ctx, String value, String trxName) throws SQLException {
    final String whereClause = I_AD_Client.COLUMNNAME_Value + "= ? ";
    MClient result = new Query(ctx, I_AD_Client.Table_Name, whereClause, trxName).setParameters(value).firstOnly();
    s_log.info("Client_Value =[" + value + "]");
    if (result != null) {
        s_log.info("AD_Client_ID = " + result.getAD_Client_ID());
    }
    return result;
}
Also used : Query(org.compiere.model.Query) MClient(org.compiere.model.MClient)

Example 2 with MClient

use of org.compiere.model.MClient 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 ;");
}
Also used : MEXPFormat(org.compiere.model.MEXPFormat) DocAction(org.compiere.process.DocAction) Element(org.w3c.dom.Element) ExportHelper(org.adempiere.process.rpl.exp.ExportHelper) MReplicationStrategy(org.compiere.model.MReplicationStrategy) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) AdempiereException(org.adempiere.exceptions.AdempiereException) MClient(org.compiere.model.MClient) PO(org.compiere.model.PO)

Example 3 with MClient

use of org.compiere.model.MClient in project adempiere by adempiere.

the class ExportHelper method exportRecord.

/**
	 *
	 * Process - Generate Export Format
 	 * @param po
	 * @param replicationMode
	 * @param replicationType
	 * @param replicationEvent
	 * @return info
     * @throws Exception
     */
public String exportRecord(PO po, Integer replicationMode, String replicationType, Integer replicationEvent) throws Exception {
    MClient client = MClient.get(po.getCtx(), clientId);
    log.info("Client = " + client.toString());
    log.info("po.getAD_Org_ID() = " + po.getAD_Org_ID());
    log.info("po.get_TrxName() = " + po.get_TrxName());
    if (po.get_TrxName() == null || po.get_TrxName().equals("")) {
        po.set_TrxName("exportRecord");
    }
    log.info("Table = " + po.get_TableName());
    if (po.get_KeyColumns().length < 1) {
        //TODO: Create Mesagge.
        throw new Exception(Msg.getMsg(po.getCtx(), "ExportNoneColumnKeyNotSupported"));
    }
    // TODO - get proper Export Format!
    String version = "3.8.2";
    //int EXP_Format_ID = 1000006;
    MEXPFormat exportFormat = null;
    //exportFormat = new MFormat(po.getCtx(), EXP_Format_ID, po.get_TrxName());
    exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), clientId, po.get_Table_ID(), version, po.get_TrxName());
    log.fine("exportFormat = " + exportFormat);
    if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) {
        // Fall back to System Client
        MClient systemClient = MClient.get(po.getCtx(), 0);
        log.info(systemClient.toString());
        exportFormat = MEXPFormat.getFormatByAD_Client_IDAD_Table_IDAndVersion(po.getCtx(), 0, po.get_Table_ID(), version, po.get_TrxName());
        if (exportFormat == null || exportFormat.getEXP_Format_ID() == 0) {
            throw new Exception(Msg.getMsg(po.getCtx(), "EXPFormatNotFound"));
        }
    }
    outDocument = createNewDocument();
    HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
    Element rootElement = outDocument.createElement(exportFormat.getValue());
    if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
        rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
    }
    rootElement.setAttribute("AD_Client_Value", client.getValue());
    rootElement.setAttribute("Version", exportFormat.getVersion());
    rootElement.setAttribute("ReplicationMode", replicationMode.toString());
    rootElement.setAttribute("ReplicationType", replicationType);
    rootElement.setAttribute("ReplicationEvent", replicationEvent.toString());
    outDocument.appendChild(rootElement);
    generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
    MEXPProcessor mExportProcessor = null;
    mExportProcessor = new MEXPProcessor(po.getCtx(), replicationStrategy.getEXP_Processor_ID(), po.get_TrxName());
    log.fine("ExportProcessor = " + mExportProcessor);
    int EXP_ProcessorType_ID = 0;
    EXP_ProcessorType_ID = mExportProcessor.getEXP_Processor_Type_ID();
    MEXPProcessorType expProcessor_Type = new MEXPProcessorType(po.getCtx(), EXP_ProcessorType_ID, po.get_TrxName());
    String javaClass = expProcessor_Type.getJavaClass();
    try {
        Class clazz = Class.forName(javaClass);
        IExportProcessor exportProcessor = (IExportProcessor) clazz.newInstance();
        exportProcessor.process(po.getCtx(), mExportProcessor, outDocument, Trx.get(po.get_TrxName(), false));
    } catch (Exception e) {
        log.severe(e.toString());
        throw e;
    }
    return outDocument.toString();
}
Also used : MEXPFormat(org.compiere.model.MEXPFormat) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) IExportProcessor(org.adempiere.process.rpl.IExportProcessor) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MEXPProcessor(org.compiere.model.MEXPProcessor) MClient(org.compiere.model.MClient) MEXPProcessorType(org.compiere.model.MEXPProcessorType)

Example 4 with MClient

use of org.compiere.model.MClient in project adempiere by adempiere.

the class ExportHelper method exportRecord.

/**
	 * 	 * 	Process - Generate Export Format
	 * @param exportFormat
	 * @param where
	 * @param replicationMode
	 * @param replicationType
	 * @param replicationEvent
	 * @return
     * @throws Exception
     */
public Document exportRecord(MEXPFormat exportFormat, String where, Integer replicationMode, String replicationType, Integer replicationEvent) throws Exception {
    MClient client = MClient.get(exportFormat.getCtx(), clientId);
    MTable table = MTable.get(exportFormat.getCtx(), exportFormat.getAD_Table_ID());
    log.info("Table = " + table);
    Collection<PO> records = new Query(exportFormat.getCtx(), table.getTableName(), exportFormat.getWhereClause(), exportFormat.get_TrxName()).setOnlyActiveRecords(true).list();
    for (PO po : records) {
        log.info("Client = " + client.toString());
        log.finest("po.getAD_Org_ID() = " + po.getAD_Org_ID());
        log.finest("po.get_TrxName() = " + po.get_TrxName());
        if (po.get_TrxName() == null || po.get_TrxName().equals("")) {
            po.set_TrxName("exportRecord");
        }
        if (po.get_KeyColumns().length < 1) {
            //TODO: Create Mesagge.
            throw new Exception(Msg.getMsg(po.getCtx(), "ExportNoneColumnKeyNotSupported"));
        }
        outDocument = createNewDocument();
        HashMap<String, Integer> variableMap = new HashMap<String, Integer>();
        Element rootElement = outDocument.createElement(exportFormat.getValue());
        if (exportFormat.getDescription() != null && !"".equals(exportFormat.getDescription())) {
            rootElement.appendChild(outDocument.createComment(exportFormat.getDescription()));
        }
        rootElement.setAttribute("AD_Client_Value", client.getValue());
        rootElement.setAttribute("Version", exportFormat.getVersion());
        rootElement.setAttribute("ReplicationMode", replicationMode.toString());
        rootElement.setAttribute("ReplicationType", replicationType);
        rootElement.setAttribute("ReplicationEvent", replicationEvent.toString());
        outDocument.appendChild(rootElement);
        generateExportFormat(rootElement, exportFormat, po, po.get_ID(), variableMap);
    }
    // finish record read
    return outDocument;
}
Also used : MTable(org.compiere.model.MTable) Query(org.compiere.model.Query) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) SQLException(java.sql.SQLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MClient(org.compiere.model.MClient) PO(org.compiere.model.PO)

Example 5 with MClient

use of org.compiere.model.MClient in project adempiere by adempiere.

the class EMailTest method doIt.

//	prepare
/**
	 * 	Process - Test EMail
	 *	@return info
	 */
protected String doIt() throws Exception {
    MClient client = MClient.get(getCtx(), p_AD_Client_ID);
    log.info(client.toString());
    //	 Test Client Mail
    String clientTest = client.testEMail();
    addLog(0, null, null, client.getName() + ": " + clientTest);
    //	Test Client DocumentDir
    if (!Ini.isClient()) {
        String documentDir = client.getDocumentDir();
        if (documentDir == null || documentDir.length() == 0)
            documentDir = ".";
        File file = new File(documentDir);
        if (file.exists() && file.isDirectory())
            addLog(0, null, null, "Found Directory: " + client.getDocumentDir());
        else
            addLog(0, null, null, "Not Found Directory: " + client.getDocumentDir());
    }
    MStore[] wstores = MStore.getOfClient(client);
    for (int i = 0; i < wstores.length; i++) {
        MStore store = wstores[i];
        String test = store.testEMail();
        addLog(0, null, null, store.getName() + ": " + test);
    }
    return clientTest;
}
Also used : MStore(org.compiere.model.MStore) File(java.io.File) MClient(org.compiere.model.MClient)

Aggregations

MClient (org.compiere.model.MClient)50 SQLException (java.sql.SQLException)11 ResultSet (java.sql.ResultSet)9 Timestamp (java.sql.Timestamp)9 Properties (java.util.Properties)9 PreparedStatement (java.sql.PreparedStatement)8 File (java.io.File)7 MBPartner (org.compiere.model.MBPartner)7 MUser (org.compiere.model.MUser)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MWarehouse (org.compiere.model.MWarehouse)5 AdempiereUserError (org.compiere.util.AdempiereUserError)5 Enumeration (java.util.Enumeration)4 MInvoice (org.compiere.model.MInvoice)4 MMailText (org.compiere.model.MMailText)4 PO (org.compiere.model.PO)4 Query (org.compiere.model.Query)4 ReportEngine (org.compiere.print.ReportEngine)4 Element (org.w3c.dom.Element)4 BigDecimal (java.math.BigDecimal)3