Search in sources :

Example 1 with ModelSetDocAction

use of org.idempiere.adInterface.x10.ModelSetDocAction in project idempiere by idempiere.

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) {
    Trx trx = null;
    try {
        getCompiereService().connect();
        StandardResponseDocument ret = StandardResponseDocument.Factory.newInstance();
        StandardResponse resp = ret.addNewStandardResponse();
        ModelSetDocAction modelSetDocAction = req.getModelSetDocActionRequest().getModelSetDocAction();
        String serviceType = modelSetDocAction.getServiceType();
        ADLoginRequest reqlogin = req.getModelSetDocActionRequest().getADLoginRequest();
        CompiereService m_cs = getCompiereService();
        String err = login(reqlogin, webServiceName, "setDocAction", serviceType);
        if (err != null && err.length() > 0) {
            resp.setError(err);
            resp.setIsError(true);
            return ret;
        }
        try {
            // Validate parameters
            modelSetDocAction.setTableName(validateParameter("tableName", modelSetDocAction.getTableName()));
            modelSetDocAction.setRecordID(validateParameter("recordID", modelSetDocAction.getRecordID()));
            modelSetDocAction.setDocAction(validateParameter("docAction", modelSetDocAction.getDocAction()));
        } catch (IdempiereServiceFault e) {
            resp.setError(e.getMessage());
            resp.setIsError(true);
            return ret;
        }
        Properties ctx = m_cs.getCtx();
        // start a trx
        String trxName = localTrxName;
        if (trxName == null) {
            trxName = Trx.createTrxName("ws_modelSetDocAction");
            manageTrx = true;
        }
        trx = Trx.get(trxName, true);
        if (manageTrx)
            trx.setDisplayName(getClass().getName() + "_" + webServiceName + "_setDocAction");
        Map<String, Object> requestCtx = getRequestCtx();
        String tableName = modelSetDocAction.getTableName();
        String recordIDVar = modelSetDocAction.getRecordIDVariable();
        int recordID = modelSetDocAction.getRecordID();
        if (recordIDVar != null && recordIDVar.startsWith("@")) {
            Integer retVal = (Integer) parseVariable(recordIDVar, null, null, requestCtx);
            if (retVal == null) {
                return rollbackAndSetError(trx, resp, ret, true, "Cannot resolve variable: " + recordIDVar);
            }
            recordID = retVal;
        }
        String docAction = modelSetDocAction.getDocAction();
        resp.setRecordID(recordID);
        // 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"));
        MWebServiceType m_webservicetype = getWebServiceType();
        // For passing action to validators
        requestCtx.put("DocAction", docAction);
        // Fire Event
        StandardResponseDocument retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_PARSE, po, null, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        // call process it
        try {
            if (!((org.compiere.process.DocAction) po).processIt(docAction))
                return rollbackAndSetError(trx, resp, ret, true, Msg.parseTranslation(ctx, "@FailedProcessingDocument@: " + ((org.compiere.process.DocAction) po).getProcessMsg()));
        } catch (Exception e) {
            return rollbackAndSetError(trx, resp, ret, true, e.toString());
        }
        // Fire Event
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_BEFORE_SAVE, po, null, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        // close the trx
        if (!po.save())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot save after set docAction: " + CLogger.retrieveErrorString("no log message"));
        // Fire Event
        retResp = invokeWSValidator(m_webservicetype, IWSValidator.TIMING_AFTER_SAVE, po, null, trx, requestCtx, resp, ret);
        if (retResp != null)
            return retResp;
        if (manageTrx && !trx.commit())
            return rollbackAndSetError(trx, resp, ret, true, "Cannot commit after docAction");
        // resp.setError("");
        resp.setIsError(false);
        POInfo poinfo = POInfo.getPOInfo(ctx, table.getAD_Table_ID());
        setOuputFields(resp, m_webservicetype, po, poinfo);
        return ret;
    } finally {
        if (manageTrx && trx != null)
            trx.close();
        getCompiereService().disconnect();
    }
}
Also used : ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) MWebServiceType(org.idempiere.webservices.model.MWebServiceType) ModelSetDocAction(org.idempiere.adInterface.x10.ModelSetDocAction) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) IdempiereServiceFault(org.idempiere.webservices.fault.IdempiereServiceFault) Properties(java.util.Properties) ModelSetDocAction(org.idempiere.adInterface.x10.ModelSetDocAction) SQLException(java.sql.SQLException) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) POInfo(org.compiere.model.POInfo) MTable(org.compiere.model.MTable) Trx(org.compiere.util.Trx) PO(org.compiere.model.PO)

Example 2 with ModelSetDocAction

use of org.idempiere.adInterface.x10.ModelSetDocAction in project idempiere by idempiere.

the class CompositeServiceImpl method performOperations.

/**
 * Perform operation
 * @param trx
 * @param ops
 * @param modelADService
 * @param compResp
 * @param respAggregator
 * @param reqlogin
 * @return isError
 */
private boolean performOperations(Trx trx, Operation[] ops, ModelADServiceImpl modelADService, CompositeResponse compResp, ArrayList<StandardResponse> respAggregator, ADLoginRequest reqlogin) {
    for (Operation operation : ops) {
        if (operation.getPreCommit()) {
            if (!commitTrx(trx, compResp, respAggregator, "Cannot commit before Operation", true)) {
                return false;
            }
        }
        modelADService.setManageTrx(false);
        TargetPort.Enum portEnum = operation.getTargetPort();
        StandardResponseDocument respDoc = null;
        if (portEnum == TargetPort.CREATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation createData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.createData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.DELETE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation deleteData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.deleteData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.CREATE_UPDATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation createUpdateData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.createUpdateData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.READ_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                // Do not rollback, Continue with consecutive operations
                respDoc = StandardResponseDocument.Factory.newInstance();
                StandardResponse resp = respDoc.addNewStandardResponse();
                resp.setIsError(false);
                resp.setError("Operation readData must required ModelCRUD");
            } else {
                WindowTabDataDocument dataResponse = modelADService.readData(wrapperDoc);
                if (dataResponse != null) {
                    respDoc = StandardResponseDocument.Factory.newInstance();
                    StandardResponse resp = respDoc.addNewStandardResponse();
                    // Do not fail though read is failed
                    resp.setIsError(false);
                    resp.setWindowTabData(dataResponse.getWindowTabData());
                }
            }
        } else if (portEnum == TargetPort.RUN_PROCESS) {
            if (operation.getModelRunProcess() == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation runProcess must required ModelRunProcess");
                return false;
            }
            ModelRunProcessRequestDocument wrapperDoc = ModelRunProcessRequestDocument.Factory.newInstance();
            ModelRunProcessRequest runProcessReq = wrapperDoc.addNewModelRunProcessRequest();
            runProcessReq.setADLoginRequest(reqlogin);
            runProcessReq.setModelRunProcess(operation.getModelRunProcess());
            RunProcessResponseDocument runResponse = modelADService.runProcess(wrapperDoc);
            if (runResponse != null) {
                respDoc = StandardResponseDocument.Factory.newInstance();
                StandardResponse resp = respDoc.addNewStandardResponse();
                resp.setIsError(runResponse.getRunProcessResponse().getIsError());
                resp.setRunProcessResponse(runResponse.getRunProcessResponse());
            }
        } else if (portEnum == TargetPort.SET_DOC_ACTION) {
            if (operation.getModelSetDocAction() == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation updateData must required ModelSetDocAction");
                return false;
            }
            ModelSetDocActionRequestDocument wrapperDoc = ModelSetDocActionRequestDocument.Factory.newInstance();
            ModelSetDocActionRequest actionReq = wrapperDoc.addNewModelSetDocActionRequest();
            actionReq.setADLoginRequest(reqlogin);
            actionReq.setModelSetDocAction(operation.getModelSetDocAction());
            respDoc = modelADService.setDocAction(wrapperDoc);
        } else if (portEnum == TargetPort.UPDATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation updateData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.updateData(wrapperDoc);
            }
        }
        if (respDoc != null)
            respAggregator.add(respDoc.getStandardResponse());
        if (respDoc != null && respDoc.getStandardResponse().getIsError()) {
            rollbackAndSetError(trx, compResp, respAggregator, null);
            return false;
        }
        if (operation.getPostCommit()) {
            if (!commitTrx(trx, compResp, respAggregator, "Cannot commit after operation", false)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ModelRunProcessRequestDocument(org.idempiere.adInterface.x10.ModelRunProcessRequestDocument) TargetPort(org.idempiere.adInterface.x10.Operation.TargetPort) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) ModelSetDocActionRequest(org.idempiere.adInterface.x10.ModelSetDocActionRequest) ModelSetDocActionRequestDocument(org.idempiere.adInterface.x10.ModelSetDocActionRequestDocument) ModelRunProcessRequest(org.idempiere.adInterface.x10.ModelRunProcessRequest) Operation(org.idempiere.adInterface.x10.Operation) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) RunProcessResponseDocument(org.idempiere.adInterface.x10.RunProcessResponseDocument)

Aggregations

StandardResponse (org.idempiere.adInterface.x10.StandardResponse)2 StandardResponseDocument (org.idempiere.adInterface.x10.StandardResponseDocument)2 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 XmlValueOutOfRangeException (org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException)1 MTable (org.compiere.model.MTable)1 PO (org.compiere.model.PO)1 POInfo (org.compiere.model.POInfo)1 Trx (org.compiere.util.Trx)1 ADLoginRequest (org.idempiere.adInterface.x10.ADLoginRequest)1 ModelCRUDRequestDocument (org.idempiere.adInterface.x10.ModelCRUDRequestDocument)1 ModelRunProcessRequest (org.idempiere.adInterface.x10.ModelRunProcessRequest)1 ModelRunProcessRequestDocument (org.idempiere.adInterface.x10.ModelRunProcessRequestDocument)1 ModelSetDocAction (org.idempiere.adInterface.x10.ModelSetDocAction)1 ModelSetDocActionRequest (org.idempiere.adInterface.x10.ModelSetDocActionRequest)1 ModelSetDocActionRequestDocument (org.idempiere.adInterface.x10.ModelSetDocActionRequestDocument)1 Operation (org.idempiere.adInterface.x10.Operation)1 TargetPort (org.idempiere.adInterface.x10.Operation.TargetPort)1 RunProcessResponseDocument (org.idempiere.adInterface.x10.RunProcessResponseDocument)1 WindowTabDataDocument (org.idempiere.adInterface.x10.WindowTabDataDocument)1