Package org.apache.ofbiz.service
Class ServiceUtil
java.lang.Object
org.apache.ofbiz.service.ServiceUtil
Generic Service Utility Class
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addErrors
(List<String> targetList, Map<String, Object> targetMap, Map<String, ? extends Object> callResult) Takes the result of an invocation and extracts any error messages and adds them to the targetList or targetMap.genericDateCondition
(DispatchContext dctx, Map<String, ? extends Object> context) static String
getErrorMessage
(Map<String, ? extends Object> result) static Locale
static void
getMessages
(HttpServletRequest request, Map<String, ? extends Object> result, String defaultMessage) static void
getMessages
(HttpServletRequest request, Map<String, ? extends Object> result, String defaultMessage, String msgPrefix, String msgSuffix, String errorPrefix, String errorSuffix, String successPrefix, String successSuffix) static String
getPartyIdCheckSecurity
(GenericValue userLogin, Security security, Map<String, ? extends Object> context, Map<String, Object> result, String secEntity, String secOperation) A small routine used all over to improve code efficiency, get the partyId and does a security check security check: userLogin partyId must equal partyId, or must have [secEntity][secOperation] permissionstatic String
getPartyIdCheckSecurity
(GenericValue userLogin, Security security, Map<String, ? extends Object> context, Map<String, Object> result, String secEntity, String secOperation, String adminSecEntity, String adminSecOperation) static String
static GenericValue
getUserLogin
(DispatchContext dctx, Map<String, ? extends Object> context, String runAsUser) static boolean
A little short-cut method to check to see if a service returned an errorstatic boolean
static boolean
A little short-cut method to check to see if a service was successful (neither error or failed)makeContext
(T... args) static String
makeErrorMessage
(Map<String, ? extends Object> result, String msgPrefix, String msgSuffix, String errorPrefix, String errorSuffix) static String
makeMessageList
(List<? extends Object> msgList, String msgPrefix, String msgSuffix) static String
makeSuccessMessage
(Map<String, ? extends Object> result, String msgPrefix, String msgSuffix, String successPrefix, String successSuffix) returnError
(String errorMessage) A small routine used all over to improve code efficiency, make a result map with the message and the error response codereturnError
(String errorMessage, List<? extends Object> errorMessageList) A small routine used all over to improve code efficiency, make a result map with the message and the error response codereturnError
(String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map<String, ? extends Object> nestedResult) A small routine used all over to improve code efficiency, make a result map with the message and the error response code, also forwards any error messages from the nestedResultreturnError
(List<? extends Object> errorMessageList) A small routine used all over to improve code efficiency, make a result map with the message and the error response codereturnFailure
(String errorMessage) returnFailure
(List<? extends Object> errorMessageList) returnMessage
(String code, String message) A small routine to make a result map with the message and the response code NOTE: This brings out some bad points to our message convention: we should be using a single message or message list and what type of message that is should be determined by the RESPONSE_MESSAGE (and there's another annoyance, it should be RESPONSE_CODE)returnProblem
(String returnType, String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map<String, ? extends Object> nestedResult) A small routine used all over to improve code efficiency, make a result map with the message and the success response codereturnSuccess
(String successMessage) A small routine used all over to improve code efficiency, make a result map with the message and the success response codereturnSuccess
(List<String> successMessageList) A small routine used all over to improve code efficiency, make a result map with the message and the success response codestatic void
setMessages
(HttpServletRequest request, String errorMessage, String eventMessage, String defaultMessage) setServiceFields
(LocalDispatcher dispatcher, String serviceName, Map<String, Object> fromMap, GenericValue userLogin, TimeZone timeZone, Locale locale) Checks all incoming service attributes and look for fields with the same name in the incoming map and copy those onto the outgoing map.
-
Method Details
-
isError
A little short-cut method to check to see if a service returned an error -
isFailure
-
isSuccess
A little short-cut method to check to see if a service was successful (neither error or failed) -
returnError
A small routine used all over to improve code efficiency, make a result map with the message and the error response code -
returnError
public static Map<String,Object> returnError(String errorMessage, List<? extends Object> errorMessageList) A small routine used all over to improve code efficiency, make a result map with the message and the error response code -
returnError
A small routine used all over to improve code efficiency, make a result map with the message and the error response code -
returnFailure
-
returnFailure
-
returnFailure
-
returnError
public static Map<String,Object> returnError(String errorMessage, List<? extends Object> errorMessageList, Map<String, ? extends Object> errorMessageMap, Map<String, ? extends Object> nestedResult) A small routine used all over to improve code efficiency, make a result map with the message and the error response code, also forwards any error messages from the nestedResult -
returnProblem
-
returnSuccess
A small routine used all over to improve code efficiency, make a result map with the message and the success response code -
returnSuccess
A small routine used all over to improve code efficiency, make a result map with the message and the success response code -
returnSuccess
A small routine used all over to improve code efficiency, make a result map with the message and the success response code -
returnMessage
A small routine to make a result map with the message and the response code NOTE: This brings out some bad points to our message convention: we should be using a single message or message list and what type of message that is should be determined by the RESPONSE_MESSAGE (and there's another annoyance, it should be RESPONSE_CODE) -
getPartyIdCheckSecurity
public static String getPartyIdCheckSecurity(GenericValue userLogin, Security security, Map<String, ? extends Object> context, Map<String, Object> result, String secEntity, String secOperation) A small routine used all over to improve code efficiency, get the partyId and does a security check security check: userLogin partyId must equal partyId, or must have [secEntity][secOperation] permission -
getPartyIdCheckSecurity
-
setMessages
public static void setMessages(HttpServletRequest request, String errorMessage, String eventMessage, String defaultMessage) -
getMessages
public static void getMessages(HttpServletRequest request, Map<String, ? extends Object> result, String defaultMessage) -
getMessages
-
getErrorMessage
-
makeErrorMessage
-
makeSuccessMessage
-
makeMessageList
-
addErrors
public static void addErrors(List<String> targetList, Map<String, Object> targetMap, Map<String, ? extends Object> callResult) Takes the result of an invocation and extracts any error messages and adds them to the targetList or targetMap. This will handle both List and String error messags.- Parameters:
targetList
- The List to add the error messages totargetMap
- The Map to add any Map error messages tocallResult
- The result from an invocation
-
genericDateCondition
-
getUserLogin
public static GenericValue getUserLogin(DispatchContext dctx, Map<String, ? extends Object> context, String runAsUser) -
getLocale
-
makeContext
-
setServiceFields
public static Map<String,Object> setServiceFields(LocalDispatcher dispatcher, String serviceName, Map<String, Object> fromMap, GenericValue userLogin, TimeZone timeZone, Locale locale) throws GeneralServiceExceptionChecks all incoming service attributes and look for fields with the same name in the incoming map and copy those onto the outgoing map. Also includes a userLogin if service requires one.- Parameters:
dispatcher
-serviceName
-fromMap
-userLogin
- (optional) - will be added to the map if is requiredtimeZone
-locale
-- Returns:
- filled Map or null on error
- Throws:
GeneralServiceException
-
getResource
-