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