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();
}
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();
}
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations