Search in sources :

Example 66 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class MigrationFromXML method loadFile.

private void loadFile(File file) throws SAXException, IOException {
    if (!file.exists())
        return;
    if (!file.getName().endsWith(".xml"))
        return;
    if (file.getName().equals("build.xml"))
        return;
    log.log(Level.CONFIG, "Loading file: " + file);
    Document doc = builder.parse(file);
    NodeList migrations = doc.getDocumentElement().getElementsByTagName("Migration");
    for (int i = 0; i < migrations.getLength(); i++) {
        Element element = (Element) migrations.item(i);
        // Top level - create a new transaction for every migration and commit
        Trx.run(trxName -> {
            Properties ctx = Env.getCtx();
            MMigration migration;
            try {
                migration = MMigration.fromXmlNode(ctx, element, trxName);
                if (migration == null) {
                    log.log(Level.CONFIG, "XML file not a Migration. Skipping.");
                    return;
                }
                if (isApply()) {
                    if (MMigration.STATUSCODE_Applied.equals(migration.getStatusCode())) {
                        log.log(Level.CONFIG, migration.toString() + " ---> Migration already applied - skipping.");
                        return;
                    }
                    if (MMigration.STATUSCODE_Failed.equals(migration.getStatusCode()) || MMigration.STATUSCODE_PartiallyApplied.equals(migration.getStatusCode())) {
                        log.log(Level.CONFIG, migration.toString() + " ---> Migration exists but has to be rolled back.");
                        applyMigration(migration.getCtx(), migration.getAD_Migration_ID(), trxName);
                    }
                    applyMigration(migration.getCtx(), migration.getAD_Migration_ID(), trxName);
                }
            } catch (AdempiereException | SQLException e) {
                if (!isForce()) {
                    throw new AdempiereException("Loading migration from " + file.toString() + " failed.", e);
                }
            }
        });
    }
}
Also used : SQLException(java.sql.SQLException) AdempiereException(org.adempiere.exceptions.AdempiereException) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Properties(java.util.Properties) MMigration(org.compiere.model.MMigration)

Example 67 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class InvoiceCreateInOut method doIt.

//	prepare
/**
	 * 	Create Shipment
	 *	@return info
	 *	@throws Exception
	 */
protected String doIt() throws Exception {
    log.info("C_Invoice_ID=" + p_C_Invoice_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID);
    if (p_C_Invoice_ID <= 0)
        throw new FillMandatoryException("C_Invoice_ID");
    if (p_M_Warehouse_ID == 0)
        throw new FillMandatoryException(PARAM_M_Warehouse_ID);
    //
    MInvoice invoice = new MInvoice(getCtx(), p_C_Invoice_ID, null);
    if (invoice.get_ID() <= 0)
        throw new AdempiereException("@NotFound@ @C_Invoice_ID@");
    if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus()))
        throw new AdempiereException("@InvoiceCreateDocNotCompleted@");
    //
    for (MInvoiceLine invoiceLine : invoice.getLines(false)) {
        createLine(invoice, invoiceLine);
    }
    if (m_inout == null)
        throw new InvoiceFullyMatchedException();
    //
    return m_inout.getDocumentNo();
}
Also used : InvoiceFullyMatchedException(org.adempiere.exceptions.InvoiceFullyMatchedException) AdempiereException(org.adempiere.exceptions.AdempiereException) MInvoiceLine(org.compiere.model.MInvoiceLine) MInvoice(org.compiere.model.MInvoice) FillMandatoryException(org.adempiere.exceptions.FillMandatoryException)

Example 68 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class ScanBar method loadData.

protected void loadData() {
    data = new LinkedHashMap<String, Vector>();
    for (PO po : getDocumentLines()) {
        MProduct product = null;
        MAttributeSetInstance asi = null;
        String lotNo = null;
        String serNo = null;
        Integer referenceId = null;
        BigDecimal qty = null;
        boolean reset = false;
        int M_Product_ID = po.get_ValueAsInt(MProduct.COLUMNNAME_M_Product_ID);
        int M_AttributeSetInstance_ID = po.get_ValueAsInt(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID);
        if (M_Product_ID > 0)
            product = MProduct.get(Env.getCtx(), M_Product_ID);
        else
            continue;
        if (M_AttributeSetInstance_ID > 0) {
            asi = new MAttributeSetInstance(Env.getCtx(), M_AttributeSetInstance_ID, null);
            lotNo = asi.getLot();
            serNo = asi.getSerNo();
        } else {
            M_AttributeSetInstance_ID = 0;
            reset = true;
            lotNo = null;
            serNo = null;
        }
        if (po instanceof MInOutLine) {
            MInOutLine ioLine = (MInOutLine) po;
            referenceId = ioLine.getC_OrderLine_ID();
            qty = ioLine.getMovementQty();
        }
        if (po instanceof MInventoryLine) {
            MInventoryLine invenotryLine = (MInventoryLine) po;
            qty = invenotryLine.getQtyCount();
        }
        if (getSource() != null && source.size() > 0) {
            ArrayList<Object> values = checkProduct(product, qty, reset);
            if (values == null)
                throw new AdempiereException("@M_Product_ID@ ; " + product.getName() + " @InValid@");
        }
        String key = product.getValue();
        if (lotNo != null && lotNo.length() > 0)
            key = key + lotNo;
        if (serNo != null && serNo.length() > 0)
            key = key + serNo;
        Vector<Object> line = new Vector<Object>(6);
        // 0
        line.add(product.getValue());
        // 1
        line.add(product.getName());
        // 2
        line.add(lotNo);
        // 3
        line.add(serNo);
        // 4
        line.add(qty);
        // 5
        line.add(po.get_ID());
        // 6
        line.add(referenceId != null ? referenceId.intValue() : 0);
        data.put(key, line);
    }
}
Also used : MProduct(org.compiere.model.MProduct) MInOutLine(org.compiere.model.MInOutLine) MInventoryLine(org.compiere.model.MInventoryLine) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) BigDecimal(java.math.BigDecimal) AdempiereException(org.adempiere.exceptions.AdempiereException) Vector(java.util.Vector) PO(org.compiere.model.PO)

Example 69 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class ProcessBuilder method process.

/**
     * Define process based on process search key
     * @param value
     * @return
     */
public ProcessBuilder process(final String value) {
    if (value == null || value.length() == 0)
        throw new AdempiereException("@AD_Process_ID@ @NotFound@");
    this.process = MProcess.get(context, MProcess.getProcess_ID(value, null));
    if (this.process == null)
        throw new AdempiereException("@AD_Process_ID@ @NotFound@");
    this.processId = process.getAD_Process_ID();
    return this;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 70 with AdempiereException

use of org.adempiere.exceptions.AdempiereException in project adempiere by adempiere.

the class ProcessBuilder method execute.

/**
     * Execute ths process with new transaction
     * @return
     */
public ProcessInfo execute() throws AdempiereException {
    try {
        Trx.run(trxName -> {
            generateProcessInfo(trxName);
            processBuilder.run(trxName);
            if (processInfo.isError())
                throw new AdempiereException("@ProcessRunError@ @Error@ " + processInfo.getSummary());
        });
    } catch (AdempiereException e) {
        if (processInfo.isError())
            throw new AdempiereException(e.getMessage());
        else {
            processInfo.setError(true);
            throw new AdempiereException("@ProcessRunError@ @Error@ " + e.getMessage());
        }
    }
    return processInfo;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException)

Aggregations

AdempiereException (org.adempiere.exceptions.AdempiereException)326 BigDecimal (java.math.BigDecimal)79 SQLException (java.sql.SQLException)46 ArrayList (java.util.ArrayList)36 ResultSet (java.sql.ResultSet)33 PreparedStatement (java.sql.PreparedStatement)31 Timestamp (java.sql.Timestamp)31 MProduct (org.compiere.model.MProduct)28 List (java.util.List)25 Query (org.compiere.model.Query)20 File (java.io.File)17 Properties (java.util.Properties)16 PO (org.compiere.model.PO)16 Env (org.compiere.util.Env)15 MBPartner (org.compiere.model.MBPartner)14 ImmutableList (com.google.common.collect.ImmutableList)12 I_M_HU (de.metas.handlingunits.model.I_M_HU)12 FillMandatoryException (org.adempiere.exceptions.FillMandatoryException)12 ProcessInfo (org.compiere.process.ProcessInfo)12 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)11