Search in sources :

Example 1 with ModelRunProcessRequestDocument

use of org.idempiere.adInterface.x10.ModelRunProcessRequestDocument 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)

Example 2 with ModelRunProcessRequestDocument

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

the class ModelADServiceImpl method runProcess.

public RunProcessResponseDocument runProcess(ModelRunProcessRequestDocument req) {
    try {
        getCompiereService().connect();
        RunProcessResponseDocument resbadlogin = RunProcessResponseDocument.Factory.newInstance();
        RunProcessResponse rbadlogin = resbadlogin.addNewRunProcessResponse();
        ModelRunProcess modelRunProcess = req.getModelRunProcessRequest().getModelRunProcess();
        String serviceType = modelRunProcess.getServiceType();
        ADLoginRequest reqlogin = req.getModelRunProcessRequest().getADLoginRequest();
        String err = login(reqlogin, webServiceName, "runProcess", serviceType);
        if (err != null && err.length() > 0) {
            rbadlogin.setError(err);
            rbadlogin.setIsError(true);
            return resbadlogin;
        }
        // Validate parameters
        try {
            modelRunProcess.setADMenuID(validateParameter("AD_Menu_ID", modelRunProcess.getADMenuID()));
        } catch (XmlValueOutOfRangeException e) {
            // Catch the exception when the Menu ID is not an Integer
            String menuUU = getUUIDValue(modelRunProcess.xgetADMenuID());
            if (menuUU == null) {
                throw e;
            }
            modelRunProcess.setADMenuID(validateParameter("AD_Menu_ID", 0, menuUU));
        }
        try {
            modelRunProcess.setADProcessID(validateParameter("AD_Process_ID", modelRunProcess.getADProcessID()));
        } catch (XmlValueOutOfRangeException e) {
            // Catch the exception when the Process ID is not an Integer
            String processUU = getUUIDValue(modelRunProcess.xgetADProcessID());
            if (processUU == null) {
                throw e;
            }
            modelRunProcess.setADProcessID(validateParameter("AD_Process_ID", 0, processUU));
        }
        modelRunProcess.setADRecordID(validateParameter("AD_Record_ID", modelRunProcess.getADRecordID()));
        modelRunProcess.setDocAction(validateParameter("DocAction", modelRunProcess.getDocAction()));
        RunProcessDocument docprocess = RunProcessDocument.Factory.newInstance();
        RunProcess reqprocess = docprocess.addNewRunProcess();
        reqprocess.setParamValues(modelRunProcess.getParamValues());
        reqprocess.setADProcessID(modelRunProcess.getADProcessID());
        reqprocess.setADMenuID(modelRunProcess.getADMenuID());
        reqprocess.setADRecordID(modelRunProcess.getADRecordID());
        reqprocess.setDocAction(modelRunProcess.getDocAction());
        RunProcessResponseDocument response = Process.runProcess(getCompiereService(), docprocess, getRequestCtx(), localTrxName);
        if (response != null && response.getRunProcessResponse() != null && response.getRunProcessResponse().getIsError())
            log.warning("Error running webservice " + serviceType + " -> " + response.getRunProcessResponse().getError());
        Map<String, Object> requestCtx = getRequestCtx();
        requestCtx.put(serviceType + "_Summary", response.getRunProcessResponse().getSummary());
        return response;
    } finally {
        getCompiereService().disconnect();
    }
}
Also used : ModelRunProcess(org.idempiere.adInterface.x10.ModelRunProcess) RunProcessDocument(org.idempiere.adInterface.x10.RunProcessDocument) ADLoginRequest(org.idempiere.adInterface.x10.ADLoginRequest) ModelRunProcess(org.idempiere.adInterface.x10.ModelRunProcess) RunProcess(org.idempiere.adInterface.x10.RunProcess) RunProcessResponse(org.idempiere.adInterface.x10.RunProcessResponse) XmlValueOutOfRangeException(org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException) RunProcessResponseDocument(org.idempiere.adInterface.x10.RunProcessResponseDocument)

Aggregations

RunProcessResponseDocument (org.idempiere.adInterface.x10.RunProcessResponseDocument)2 XmlValueOutOfRangeException (org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException)1 ADLoginRequest (org.idempiere.adInterface.x10.ADLoginRequest)1 ModelCRUDRequestDocument (org.idempiere.adInterface.x10.ModelCRUDRequestDocument)1 ModelRunProcess (org.idempiere.adInterface.x10.ModelRunProcess)1 ModelRunProcessRequest (org.idempiere.adInterface.x10.ModelRunProcessRequest)1 ModelRunProcessRequestDocument (org.idempiere.adInterface.x10.ModelRunProcessRequestDocument)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 RunProcess (org.idempiere.adInterface.x10.RunProcess)1 RunProcessDocument (org.idempiere.adInterface.x10.RunProcessDocument)1 RunProcessResponse (org.idempiere.adInterface.x10.RunProcessResponse)1 StandardResponse (org.idempiere.adInterface.x10.StandardResponse)1 StandardResponseDocument (org.idempiere.adInterface.x10.StandardResponseDocument)1 WindowTabDataDocument (org.idempiere.adInterface.x10.WindowTabDataDocument)1