Search in sources :

Example 1 with ModelSetDocAction

use of pl.x3E.adInterface.ModelSetDocAction in project adempiere by adempiere.

the class ModelADServiceImpl method setDocAction.

/*
	 * Model oriented web service to change DocAction for documents, i.e. Complete a Material Receipt
	 * WARNING!!! This web service complete documents not via workflow, so it jump over any approval step considered in document workflow
	 *   To complete documents using workflow it's better to use the runProcess web service
	 */
public StandardResponseDocument setDocAction(ModelSetDocActionRequestDocument req) throws XFireFault {
    StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
    StandardResponse resp = ret.addNewStandardResponse();
    ModelSetDocAction modelSetDocAction = req.getModelSetDocActionRequest().getModelSetDocAction();
    String serviceType = modelSetDocAction.getServiceType();
    ADLoginRequest reqlogin = req.getModelSetDocActionRequest().getADLoginRequest();
    String err = modelLogin(reqlogin, webServiceName, "setDocAction", serviceType);
    if (err != null && err.length() > 0) {
        resp.setError(err);
        resp.setIsError(true);
        return ret;
    }
    Properties ctx = m_cs.getM_ctx();
    // Validate parameters
    modelSetDocAction.setTableName(validateParameter("tableName", modelSetDocAction.getTableName()));
    modelSetDocAction.setRecordID(validateParameter("recordID", modelSetDocAction.getRecordID()));
    modelSetDocAction.setDocAction(validateParameter("docAction", modelSetDocAction.getDocAction()));
    String tableName = modelSetDocAction.getTableName();
    int recordID = modelSetDocAction.getRecordID();
    String docAction = modelSetDocAction.getDocAction();
    resp.setRecordID(recordID);
    // start a trx
    String trxName = Trx.createTrxName("ws_modelSetDocAction");
    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);
    // set explicitly the column DocAction to avoid automatic process of default option
    po.set_ValueOfColumn("DocAction", docAction);
    if (!po.save())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot save before set docAction: " + CLogger.retrieveErrorString("no log message"));
    // call process it
    try {
        if (!((org.compiere.process.DocAction) po).processIt(docAction))
            return rollbackAndSetError(trx, resp, ret, true, "Couldn't set docAction: " + ((org.compiere.process.DocAction) po).getProcessMsg());
    } catch (Exception e) {
        return rollbackAndSetError(trx, resp, ret, true, e.toString());
    }
    // close the trx
    if (!po.save())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot save after set docAction: " + CLogger.retrieveErrorString("no log message"));
    if (!trx.commit())
        return rollbackAndSetError(trx, resp, ret, true, "Cannot commit after docAction");
    trx.close();
    // resp.setError("");
    resp.setIsError(false);
    return ret;
}
Also used : ADLoginRequest(pl.x3E.adInterface.ADLoginRequest) StandardResponse(pl.x3E.adInterface.StandardResponse) Properties(java.util.Properties) ModelSetDocAction(pl.x3E.adInterface.ModelSetDocAction) SQLException(java.sql.SQLException) StandardResponseDocument(pl.x3E.adInterface.StandardResponseDocument) MTable(org.compiere.model.MTable) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Aggregations

SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MTable (org.compiere.model.MTable)1 PO (org.compiere.model.PO)1 Trx (org.compiere.util.Trx)1 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)1 ModelSetDocAction (pl.x3E.adInterface.ModelSetDocAction)1 StandardResponse (pl.x3E.adInterface.StandardResponse)1 StandardResponseDocument (pl.x3E.adInterface.StandardResponseDocument)1