Search in sources :

Example 51 with AdempiereException

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

the class WMRuleEngine method applyDefinition.

/**
	 * Apply Definition for Warehouse  Strategy
	 * @param inOutBoundLine Order Bound Line
	 * @param warehouseAreaTypeId Area Type Id
	 * @param warehouseSectionTypeId Section Type Id
	 * */
private MWMStrategy applyDefinition(MWMInOutBoundLine inOutBoundLine, int warehouseAreaTypeId, int warehouseSectionTypeId) {
    StringBuffer whereClause = new StringBuffer("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_M_Product_Category_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group1 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Group2 + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IN ('',?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_Classification + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BPartner_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_C_BP_Group_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Area_Type_ID + " IS NULL");
    whereClause.append(") AND ");
    whereClause.append("(");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IN (0,?) OR ");
    whereClause.append(MWMDefinition.COLUMNNAME_WM_Section_Type_ID + " IS NULL");
    whereClause.append(")");
    whereClause.append(" AND EXISTS (SELECT 1 FROM " + MWMStrategy.Table_Name);
    whereClause.append(" WHERE ");
    whereClause.append(MWMStrategy.Table_Name + "." + MWMStrategy.COLUMNNAME_WM_Strategy_ID + "=");
    whereClause.append(MWMDefinition.Table_Name + "." + MWMDefinition.COLUMNNAME_WM_Strategy_ID);
    whereClause.append(" AND ");
    whereClause.append(MWMStrategy.COLUMNNAME_InOutBoundType + "=?");
    whereClause.append(")");
    MProduct product = inOutBoundLine.getMProduct();
    MBPartner partner = inOutBoundLine.getBPartner();
    MWMDefinition definition = new Query(inOutBoundLine.getCtx(), MWMDefinition.Table_Name, whereClause.toString(), inOutBoundLine.get_TrxName()).setClient_ID().setParameters(product.getM_Product_ID(), product.getM_Product_Category_ID(), product.getGroup1(), product.getGroup2(), product.getClassification(), partner.getC_BPartner_ID(), partner.getC_BP_Group_ID(), warehouseAreaTypeId, warehouseSectionTypeId, MWMStrategy.INOUTBOUNDTYPE_OutboundOperation).first();
    if (definition == null) {
        throw new AdempiereException("@WM_Definition_ID@ @NotFound@");
    }
    return definition.getWarehouseStrategy();
}
Also used : MProduct(org.compiere.model.MProduct) Query(org.compiere.model.Query) AdempiereException(org.adempiere.exceptions.AdempiereException) MWMDefinition(org.eevolution.model.MWMDefinition) MBPartner(org.compiere.model.MBPartner)

Example 52 with AdempiereException

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

the class GridTabDataBinder method valueChange.

/**
	 * @param e
	 */
public void valueChange(ValueChangeEvent e) {
    if (//  only active records
    gridTab.isProcessed()) {
        Object source = e.getSource();
        if (source instanceof WEditor) {
            // Elaine 2009/05/06
            WEditor editor = (WEditor) source;
            GridField gridField = editor.getGridField();
            if (gridField != null) {
                if (!gridField.isEditable(true)) {
                    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                    return;
                }
            } else if (!editor.isReadWrite()) {
                logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                return;
            }
        } else {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
        }
    }
    //  processed
    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null && e.getOldValue() != null && //  some editors return "" instead of null
    e.getOldValue().toString().length() > 0)
        //        	  this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui        
        //            mTable.setChanged (true);  
        mTable.setValueAt(e.getNewValue(), row, col);
    else {
        Object newValue = e.getNewValue();
        Integer[] newValues = null;
        if (newValue instanceof Integer[]) {
            newValues = ((Integer[]) newValue);
            newValue = newValues[0];
            if (newValues.length > 1) {
                Integer[] valuesCopy = new Integer[newValues.length - 1];
                System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
                newValues = valuesCopy;
            } else {
                newValues = null;
            }
        } else if (newValue instanceof Object[]) {
            logger.severe("Multiple values can only be processed for IDs (Integer)");
            throw new IllegalArgumentException("Multiple Selection values not available for this field. " + e.getPropertyName());
        }
        mTable.setValueAt(newValue, row, col);
        //  Force Callout
        if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
            GridField mField = gridTab.getField(col);
            if (mField != null && mField.getCallout().length() > 0) {
                //  Dependencies & Callout
                gridTab.processFieldChange(mField);
            }
        }
        if (newValues != null && newValues.length > 0) {
            // Save data, since record need to be used for generating clones.
            if (!gridTab.dataSave(false)) {
                throw new AdempiereException("SaveError");
            }
            // Retrieve the current record ID
            int recordId = gridTab.getKeyID(gridTab.getCurrentRow());
            Trx trx = Trx.get(Trx.createTrxName(), true);
            trx.start();
            try {
                saveMultipleRecords(Env.getCtx(), gridTab.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
                trx.commit();
                gridTab.dataRefreshAll();
            } catch (Exception ex) {
                trx.rollback();
                logger.severe(ex.getMessage());
                throw new AdempiereException("SaveError");
            } finally {
                trx.close();
            }
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) GridTable(org.compiere.model.GridTable) WEditor(org.adempiere.webui.editor.WEditor) GridField(org.compiere.model.GridField) Trx(org.compiere.util.Trx) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 53 with AdempiereException

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

the class ServerPushTemplate method execute.

/**
	 * Execute callback in UI thread
	 * @param callback
	 */
public void execute(IServerPushCallback callback) {
    boolean inUIThread = Executions.getCurrent() != null;
    boolean desktopActivated = false;
    try {
        if (!inUIThread) {
            //10 minutes timeout
            if (Executions.activate(desktop, 10 * 60 * 1000)) {
                desktopActivated = true;
            } else {
                throw new DesktopUnavailableException("Timeout activating desktop.");
            }
        }
        callback.updateUI();
    } catch (DesktopUnavailableException de) {
        throw de;
    } catch (Exception e) {
        throw new AdempiereException("Failed to update client in server push worker thread.", e);
    } finally {
        if (!inUIThread && desktopActivated) {
            Executions.deactivate(desktop);
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) DesktopUnavailableException(org.zkoss.zk.ui.DesktopUnavailableException) AdempiereException(org.adempiere.exceptions.AdempiereException) DesktopUnavailableException(org.zkoss.zk.ui.DesktopUnavailableException)

Example 54 with AdempiereException

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

the class CostingMethodFactory method getCostingMethod.

/**
	 * Get Costing method
	 * @param ce cost element
	 * @param costingMethod costing method. Optional. If null, we get the costing method
	 * 					from cost element
	 * @return costing method class instance
	 */
public ICostingMethod getCostingMethod(String costingMethod) {
    Class<? extends ICostingMethod> cl = s_map.get(costingMethod);
    if (cl == null) {
        throw new AdempiereException("No implementation found for costing method " + costingMethod);
    }
    ICostingMethod cm;
    try {
        cm = cl.newInstance();
    } catch (Exception e) {
        throw new AdempiereException(e);
    }
    return cm;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 55 with AdempiereException

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

the class AbstractCostingMethod method createCostDetails.

protected List<MCostDetail> createCostDetails() {
    final String idColumnName;
    if (model instanceof MMatchPO) {
        idColumnName = I_C_OrderLine.COLUMNNAME_C_OrderLine_ID;
    } else if (model instanceof MMatchInv) {
        idColumnName = I_C_InvoiceLine.COLUMNNAME_C_InvoiceLine_ID;
    } else {
        idColumnName = model.get_TableName() + "_ID";
    }
    List<MCostDetail> list = new ArrayList<MCostDetail>();
    if (model.isSOTrx() == true || model instanceof MInventoryLine || model instanceof MMovementLine) {
        List<CostComponent> costComponents = getCalculatedCosts();
        for (CostComponent costComponent : costComponents) {
            MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costComponent.getAmount(), Env.ZERO, costComponent.getQty(), model.get_TrxName());
            if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, model.get_ID()))
                throw new AdempiereException("Cannot set " + idColumnName);
            StringBuilder description = new StringBuilder();
            if (!Util.isEmpty(model.getDescription(), true))
                description.append(model.getDescription());
            if (model.isSOTrx() != false) {
                description.append(model.isSOTrx() ? "(|->)" : "(|<-)");
            }
            if (// TODO: need evaluate anca
            model.isSOTrx() != false)
                cost.setIsSOTrx(model.isSOTrx());
            else
                cost.setIsSOTrx(model.isSOTrx());
            cost.setM_Transaction_ID(transaction.get_ID());
            cost.setDescription(description.toString());
            cost.saveEx();
            list.add(cost);
        }
    } else // qty and amt is take from documentline
    {
        MCostDetail cost = new MCostDetail(transaction, accountSchema.getC_AcctSchema_ID(), dimension.getM_CostType_ID(), dimension.getM_CostElement_ID(), costThisLevel.multiply(model.getMovementQty()), Env.ZERO, model.getMovementQty(), model.get_TrxName());
        int id;
        if (model instanceof MMatchPO) {
            I_M_InOutLine inOutLine = transaction.getM_InOutLine();
            I_C_OrderLine orderLine = inOutLine.getC_OrderLine();
            id = orderLine.getC_OrderLine_ID();
        } else {
            id = model.get_ID();
        }
        if (!cost.set_ValueOfColumnReturningBoolean(idColumnName, id))
            throw new AdempiereException("Cannot set " + idColumnName);
        if (model.isSOTrx() != false)
            cost.setIsSOTrx(model.isSOTrx());
        else
            cost.setIsSOTrx(model.isSOTrx());
        cost.setM_Transaction_ID(transaction.get_ID());
        cost.saveEx();
        list.add(cost);
    }
    return list;
}
Also used : MMatchPO(org.compiere.model.MMatchPO) MInventoryLine(org.compiere.model.MInventoryLine) I_M_InOutLine(org.compiere.model.I_M_InOutLine) ArrayList(java.util.ArrayList) I_C_OrderLine(org.compiere.model.I_C_OrderLine) AdempiereException(org.adempiere.exceptions.AdempiereException) MMatchInv(org.compiere.model.MMatchInv) MCostDetail(org.compiere.model.MCostDetail) MMovementLine(org.compiere.model.MMovementLine)

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