📄 servicemultieventhandler.java
字号:
String curSuffix = UtilHttp.MULTI_ROW_DELIMITER + i; boolean rowSelected = request.getParameter(UtilHttp.ROW_SUBMIT_PREFIX + i) == null ? false : "Y".equalsIgnoreCase(request.getParameter(UtilHttp.ROW_SUBMIT_PREFIX + i)); // make sure we are to process this row if (useRowSubmit && !rowSelected) { continue; } // build the context Map serviceContext = FastMap.newInstance(); List modelParmInList = modelService.getInModelParamList(); Iterator modelParmInIter = modelParmInList.iterator(); while (modelParmInIter.hasNext()) { ModelParam modelParam = (ModelParam) modelParmInIter.next(); String paramName = (String) modelParam.name; // Debug.logInfo("In ServiceMultiEventHandler processing input parameter [" + modelParam.name + (modelParam.optional?"(optional):":"(required):") + modelParam.mode + "] for service [" + serviceName + "]", module); // don't include userLogin, that's taken care of below if ("userLogin".equals(paramName)) continue; // don't include locale, that is also taken care of below if ("locale".equals(paramName)) continue; Object value = null; if (modelParam.stringMapPrefix != null && modelParam.stringMapPrefix.length() > 0) { Map paramMap = UtilHttp.makeParamMapWithPrefix(request, modelParam.stringMapPrefix, curSuffix); value = paramMap; } else if (modelParam.stringListSuffix != null && modelParam.stringListSuffix.length() > 0) { List paramList = UtilHttp.makeParamListWithSuffix(request, modelParam.stringListSuffix, null); value = paramList; } else { // first check for request parameters String[] paramArr = request.getParameterValues(paramName + curSuffix); if (paramArr != null) { if (paramArr.length > 1) { value = Arrays.asList(paramArr); } else { value = paramArr[0]; } } // if the parameter wasn't passed and no other value found, don't pass on the null if (value == null) { value = request.getAttribute(paramName + curSuffix); } if (value == null) { value = session.getAttribute(paramName + curSuffix); } // now check global scope if (value == null) { if (checkGlobalScope) { String[] gParamArr = request.getParameterValues(paramName); if (gParamArr != null) { if (gParamArr.length > 1) { value = Arrays.asList(gParamArr); } else { value = gParamArr[0]; } } if (value == null) { value = request.getAttribute(paramName); } if (value == null) { value = session.getAttribute(paramName); } } } if (value == null) { // still null, give up for this one continue; } if (value instanceof String && ((String) value).length() == 0) { // interpreting empty fields as null values for each in back end handling... value = null; } } // set even if null so that values will get nulled in the db later on serviceContext.put(paramName, value); // Debug.logInfo("In ServiceMultiEventHandler got value [" + value + "] for input parameter [" + paramName + "] for service [" + serviceName + "]", module); } // get only the parameters for this service - converted to proper type serviceContext = modelService.makeValid(serviceContext, ModelService.IN_PARAM, true, null, locale); // include the UserLogin value object if (userLogin != null) { serviceContext.put("userLogin", userLogin); } // include the Locale object if (locale != null) { serviceContext.put("locale", locale); } // Debug.logInfo("ready to call " + serviceName + " with context " + serviceContext, module); // invoke the service Map result = null; try { result = dispatcher.runSync(serviceName, serviceContext); } catch (ServiceAuthException e) { // not logging since the service engine already did errorMessages.add(messagePrefixStr + "Service invocation error on row (" + i +"): " + e.getNonNestedMessage()); } catch (ServiceValidationException e) { // not logging since the service engine already did request.setAttribute("serviceValidationException", e); List errors = e.getMessageList(); if (errors != null) { Iterator erri = errors.iterator(); while (erri.hasNext()) { errorMessages.add("Service invocation error on row (" + i + "): " + erri.next()); } } else { errorMessages.add(messagePrefixStr + "Service invocation error on row (" + i +"): " + e.getNonNestedMessage()); } } catch (GenericServiceException e) { Debug.logError(e, "Service invocation error", module); errorMessages.add(messagePrefixStr + "Service invocation error on row (" + i +"): " + e.getNested() + messageSuffixStr); } // check for an error message String errorMessage = ServiceUtil.makeErrorMessage(result, messagePrefixStr, messageSuffixStr, "", ""); if (UtilValidate.isNotEmpty(errorMessage)) { errorMessages.add(errorMessage); } // set the results in the request if ((result != null) && (result.entrySet() != null)) { Iterator rmei = result.entrySet().iterator(); while (rmei.hasNext()) { Map.Entry rme = (Map.Entry) rmei.next(); String resultKey = (String) rme.getKey(); Object resultValue = rme.getValue(); if (resultKey != null && !ModelService.RESPONSE_MESSAGE.equals(resultKey) && !ModelService.ERROR_MESSAGE.equals(resultKey) && !ModelService.ERROR_MESSAGE_LIST.equals(resultKey) && !ModelService.ERROR_MESSAGE_MAP.equals(resultKey) && !ModelService.SUCCESS_MESSAGE.equals(resultKey) && !ModelService.SUCCESS_MESSAGE_LIST.equals(resultKey)) { request.setAttribute(resultKey, resultValue); } } } } } finally { if (errorMessages.size() > 0) { // rollback the transaction try { TransactionUtil.rollback(beganTrans, "Error in multi-service event handling: " + errorMessages.toString(), null); } catch (GenericTransactionException e) { Debug.logError(e, "Could not rollback transaction", module); } errorMessages.add(0, errorPrefixStr); errorMessages.add(errorSuffixStr); StringBuffer errorBuf = new StringBuffer(); Iterator ei = errorMessages.iterator(); while (ei.hasNext()) { String em = (String) ei.next(); errorBuf.append(em + "\n"); } request.setAttribute("_ERROR_MESSAGE_", errorBuf.toString()); returnString = "error"; } else { // commit the transaction try { TransactionUtil.commit(beganTrans); } catch (GenericTransactionException e) { Debug.logError(e, "Could not commit transaction", module); throw new EventHandlerException("Commit transaction failed"); } returnString = "success"; } } return returnString; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -