use of org.compiere.model.PO in project adempiere by adempiere.
the class ModelADServiceImpl method updateData.
public StandardResponseDocument updateData(ModelCRUDRequestDocument req) throws XFireFault {
StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
StandardResponse resp = ret.addNewStandardResponse();
ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
String serviceType = modelCRUD.getServiceType();
ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "updateData", serviceType);
if (err != null && err.length() > 0) {
resp.setError(err);
resp.setIsError(true);
return ret;
}
// Validate parameters vs service type
validateCRUD(modelCRUD);
String tableName = modelCRUD.getTableName();
int recordID = modelCRUD.getRecordID();
resp.setRecordID(recordID);
Properties ctx = m_cs.getM_ctx();
// start a trx
String trxName = Trx.createTrxName("ws_modelUpdateData");
Trx trx = Trx.get(trxName, false);
// get the PO for the tablename and record ID
MTable table = MTable.get(ctx, tableName);
if (table == null)
return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
PO po = table.getPO(recordID, trxName);
if (po == null)
return rollbackAndSetError(trx, resp, ret, true, "No Record " + recordID + " in " + tableName);
POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
DataRow dr = modelCRUD.getDataRow();
for (DataField field : dr.getFieldList()) {
// TODO: Implement lookup
if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
int idxcol = po.get_ColumnIndex(field.getColumn());
if (idxcol < 0) {
// The column doesn't exist - it must exist as it's defined in security
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " does not exist");
} else {
try {
setValueAccordingToClass(po, poinfo, field, idxcol);
} catch (XFireFault e) {
log.log(Level.WARNING, "Error setting value", e);
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " value could not be set: " + e.getLocalizedMessage());
}
}
} else {
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed");
}
}
if (!po.save())
return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
// close the trx
if (!trx.commit())
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after delete record " + recordID + " in " + tableName);
trx.close();
return ret;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class ModelADServiceImpl method deleteData.
// getList
public StandardResponseDocument deleteData(ModelCRUDRequestDocument req) throws XFireFault {
StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
StandardResponse resp = ret.addNewStandardResponse();
ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
String serviceType = modelCRUD.getServiceType();
ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "deleteData", serviceType);
if (err != null && err.length() > 0) {
resp.setError(err);
resp.setIsError(true);
return ret;
}
// Validate parameters vs service type
validateCRUD(modelCRUD);
String tableName = modelCRUD.getTableName();
int recordID = modelCRUD.getRecordID();
resp.setRecordID(recordID);
Properties ctx = m_cs.getM_ctx();
// start a trx
String trxName = Trx.createTrxName("ws_modelDeleteData");
Trx trx = Trx.get(trxName, false);
// get the PO for the tablename and record ID
MTable table = MTable.get(ctx, tableName);
if (table == null)
return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
PO po = table.getPO(recordID, trxName);
if (po == null)
return rollbackAndSetError(trx, resp, ret, true, "No Record " + recordID + " in " + tableName);
if (!po.delete(false))
return rollbackAndSetError(trx, resp, ret, true, "Cannot delete record " + recordID + " in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
// close the trx
if (!trx.commit())
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after delete record " + recordID + " in " + tableName);
trx.close();
return ret;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class ModelADServiceImpl method createData.
public StandardResponseDocument createData(ModelCRUDRequestDocument req) throws XFireFault {
StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
StandardResponse resp = ret.addNewStandardResponse();
ModelCRUD modelCRUD = req.getModelCRUDRequest().getModelCRUD();
String serviceType = modelCRUD.getServiceType();
ADLoginRequest reqlogin = req.getModelCRUDRequest().getADLoginRequest();
String err = modelLogin(reqlogin, webServiceName, "createData", serviceType);
if (err != null && err.length() > 0) {
resp.setError(err);
resp.setIsError(true);
return ret;
}
// Validate parameters vs service type
validateCRUD(modelCRUD);
String tableName = modelCRUD.getTableName();
Properties ctx = m_cs.getM_ctx();
// start a trx
String trxName = Trx.createTrxName("ws_modelCreateData");
Trx trx = Trx.get(trxName, false);
// get the PO for the tablename and record ID
MTable table = MTable.get(ctx, tableName);
if (table == null)
return rollbackAndSetError(trx, resp, ret, true, "No table " + tableName);
PO po = table.getPO(0, trxName);
if (po == null)
return rollbackAndSetError(trx, resp, ret, true, "Cannot create PO for " + tableName);
POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
DataRow dr = modelCRUD.getDataRow();
for (DataField field : dr.getFieldList()) {
// TODO: Implement lookup
if (m_webservicetype.isInputColumnNameAllowed(field.getColumn())) {
int idxcol = po.get_ColumnIndex(field.getColumn());
if (idxcol < 0) {
// The column doesn't exist - it must exist as it's defined in security
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " does not exist");
} else {
try {
setValueAccordingToClass(po, poinfo, field, idxcol);
} catch (XFireFault e) {
log.log(Level.WARNING, "Error setting value", e);
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " value could not be set: " + e.getLocalizedMessage());
}
}
} else {
return rollbackAndSetError(trx, resp, ret, true, "Web service type " + m_webservicetype.getValue() + ": input column " + field.getColumn() + " not allowed");
}
}
if (!po.save())
return rollbackAndSetError(trx, resp, ret, true, "Cannot save record in " + tableName + ": " + CLogger.retrieveErrorString("no log message"));
int recordID = po.get_ID();
resp.setRecordID(recordID);
// close the trx
if (!trx.commit())
return rollbackAndSetError(trx, resp, ret, true, "Cannot commit transaction after create record " + recordID + " in " + tableName);
trx.close();
return ret;
}
use of org.compiere.model.PO in project adempiere by adempiere.
the class MigrationCreate method doIt.
/**
*
* Process to create migration from selected records
*
* @author Paul Bowden, Adaxa Pty Ltd
*
*/
@Override
protected String doIt() throws Exception {
MMigration migration = new MMigration(getCtx(), 0, get_TrxName());
MTable table = MTable.get(getCtx(), tableId);
String whereClause;
List<PO> pos;
if (recordId > 0) {
pos = new ArrayList<PO>(1);
pos.add(table.getPO(recordId, get_TrxName()));
} else {
String where = "EntityType = ?";
pos = table.createQuery(where, get_TrxName()).list();
}
for (PO po : pos) {
POInfo info = POInfo.getPOInfo(getCtx(), tableId, get_TrxName());
MMigrationStep step = new MMigrationStep(migration, po, info, MMigrationStep.ACTION_Insert);
}
return "@OK@";
}
use of org.compiere.model.PO 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);
}
}
Aggregations