Package org.apache.ofbiz.service
Class ServiceUtil
- java.lang.Object
-
- org.apache.ofbiz.service.ServiceUtil
-
public final class ServiceUtil extends java.lang.Object
Generic Service Utility Class
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
module
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addErrors(java.util.List<java.lang.String> targetList, java.util.Map<java.lang.String,java.lang.Object> targetMap, java.util.Map<java.lang.String,? extends java.lang.Object> callResult)
Takes the result of an invocation and extracts any error messages and adds them to the targetList or targetMap.static java.util.Map<java.lang.String,java.lang.Object>
cancelJob(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
static java.util.Map<java.lang.String,java.lang.Object>
cancelJobRetries(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
static java.util.Map<java.lang.String,java.lang.Object>
genericDateCondition(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
static java.lang.String
getErrorMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result)
static void
getMessages(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String defaultMessage)
static void
getMessages(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String defaultMessage, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String errorPrefix, java.lang.String errorSuffix, java.lang.String successPrefix, java.lang.String successSuffix)
static java.lang.String
getPartyIdCheckSecurity(GenericValue userLogin, Security security, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Object> result, java.lang.String secEntity, java.lang.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 java.lang.String
getPartyIdCheckSecurity(GenericValue userLogin, Security security, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Object> result, java.lang.String secEntity, java.lang.String secOperation, java.lang.String adminSecEntity, java.lang.String adminSecOperation)
static java.lang.String
getResource()
static GenericValue
getUserLogin(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.lang.String runAsUser)
static boolean
isError(java.util.Map<java.lang.String,? extends java.lang.Object> results)
A little short-cut method to check to see if a service returned an errorstatic boolean
isFailure(java.util.Map<java.lang.String,? extends java.lang.Object> results)
static boolean
isSuccess(java.util.Map<java.lang.String,? extends java.lang.Object> results)
A little short-cut method to check to see if a service was successful (neither error or failed)static <T> java.util.Map<java.lang.String,java.lang.Object>
makeContext(T... args)
static java.lang.String
makeErrorMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String errorPrefix, java.lang.String errorSuffix)
static java.lang.String
makeMessageList(java.util.List<? extends java.lang.Object> msgList, java.lang.String msgPrefix, java.lang.String msgSuffix)
static java.lang.String
makeSuccessMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String successPrefix, java.lang.String successSuffix)
static java.util.Map<java.lang.String,java.lang.Object>
purgeOldJobs(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
static java.util.Map<java.lang.String,java.lang.Object>
resetJob(DispatchContext dctx, java.util.Map<java.lang.String,java.lang.Object> context)
static java.util.Map<java.lang.String,java.lang.Object>
returnError(java.lang.String errorMessage)
A small routine used all over to improve code efficiency, make a result map with the message and the error response codestatic java.util.Map<java.lang.String,java.lang.Object>
returnError(java.lang.String errorMessage, java.util.List<? extends java.lang.Object> errorMessageList)
A small routine used all over to improve code efficiency, make a result map with the message and the error response codestatic java.util.Map<java.lang.String,java.lang.Object>
returnError(java.lang.String errorMessage, java.util.List<? extends java.lang.Object> errorMessageList, java.util.Map<java.lang.String,? extends java.lang.Object> errorMessageMap, java.util.Map<java.lang.String,? extends java.lang.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 nestedResultstatic java.util.Map<java.lang.String,java.lang.Object>
returnError(java.util.List<? extends java.lang.Object> errorMessageList)
A small routine used all over to improve code efficiency, make a result map with the message and the error response codestatic java.util.Map<java.lang.String,java.lang.Object>
returnFailure()
static java.util.Map<java.lang.String,java.lang.Object>
returnFailure(java.lang.String errorMessage)
static java.util.Map<java.lang.String,java.lang.Object>
returnFailure(java.util.List<? extends java.lang.Object> errorMessageList)
static java.util.Map<java.lang.String,java.lang.Object>
returnMessage(java.lang.String code, java.lang.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)static java.util.Map<java.lang.String,java.lang.Object>
returnProblem(java.lang.String returnType, java.lang.String errorMessage, java.util.List<? extends java.lang.Object> errorMessageList, java.util.Map<java.lang.String,? extends java.lang.Object> errorMessageMap, java.util.Map<java.lang.String,? extends java.lang.Object> nestedResult)
static java.util.Map<java.lang.String,java.lang.Object>
returnSuccess()
A small routine used all over to improve code efficiency, make a result map with the message and the success response codestatic java.util.Map<java.lang.String,java.lang.Object>
returnSuccess(java.lang.String successMessage)
A small routine used all over to improve code efficiency, make a result map with the message and the success response codestatic java.util.Map<java.lang.String,java.lang.Object>
returnSuccess(java.util.List<java.lang.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(javax.servlet.http.HttpServletRequest request, java.lang.String errorMessage, java.lang.String eventMessage, java.lang.String defaultMessage)
static java.util.Map<java.lang.String,java.lang.Object>
setServiceFields(LocalDispatcher dispatcher, java.lang.String serviceName, java.util.Map<java.lang.String,java.lang.Object> fromMap, GenericValue userLogin, java.util.TimeZone timeZone, java.util.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 Detail
-
isError
public static boolean isError(java.util.Map<java.lang.String,? extends java.lang.Object> results)
A little short-cut method to check to see if a service returned an error
-
isFailure
public static boolean isFailure(java.util.Map<java.lang.String,? extends java.lang.Object> results)
-
isSuccess
public static boolean isSuccess(java.util.Map<java.lang.String,? extends java.lang.Object> results)
A little short-cut method to check to see if a service was successful (neither error or failed)
-
returnError
public static java.util.Map<java.lang.String,java.lang.Object> returnError(java.lang.String errorMessage)
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 java.util.Map<java.lang.String,java.lang.Object> returnError(java.lang.String errorMessage, java.util.List<? extends java.lang.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
public static java.util.Map<java.lang.String,java.lang.Object> returnError(java.util.List<? extends java.lang.Object> errorMessageList)
A small routine used all over to improve code efficiency, make a result map with the message and the error response code
-
returnFailure
public static java.util.Map<java.lang.String,java.lang.Object> returnFailure(java.lang.String errorMessage)
-
returnFailure
public static java.util.Map<java.lang.String,java.lang.Object> returnFailure(java.util.List<? extends java.lang.Object> errorMessageList)
-
returnFailure
public static java.util.Map<java.lang.String,java.lang.Object> returnFailure()
-
returnError
public static java.util.Map<java.lang.String,java.lang.Object> returnError(java.lang.String errorMessage, java.util.List<? extends java.lang.Object> errorMessageList, java.util.Map<java.lang.String,? extends java.lang.Object> errorMessageMap, java.util.Map<java.lang.String,? extends java.lang.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
public static java.util.Map<java.lang.String,java.lang.Object> returnProblem(java.lang.String returnType, java.lang.String errorMessage, java.util.List<? extends java.lang.Object> errorMessageList, java.util.Map<java.lang.String,? extends java.lang.Object> errorMessageMap, java.util.Map<java.lang.String,? extends java.lang.Object> nestedResult)
-
returnSuccess
public static java.util.Map<java.lang.String,java.lang.Object> returnSuccess(java.lang.String successMessage)
A small routine used all over to improve code efficiency, make a result map with the message and the success response code
-
returnSuccess
public static java.util.Map<java.lang.String,java.lang.Object> returnSuccess()
A small routine used all over to improve code efficiency, make a result map with the message and the success response code
-
returnSuccess
public static java.util.Map<java.lang.String,java.lang.Object> returnSuccess(java.util.List<java.lang.String> successMessageList)
A small routine used all over to improve code efficiency, make a result map with the message and the success response code
-
returnMessage
public static java.util.Map<java.lang.String,java.lang.Object> returnMessage(java.lang.String code, java.lang.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)
-
getPartyIdCheckSecurity
public static java.lang.String getPartyIdCheckSecurity(GenericValue userLogin, Security security, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Object> result, java.lang.String secEntity, java.lang.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
public static java.lang.String getPartyIdCheckSecurity(GenericValue userLogin, Security security, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.util.Map<java.lang.String,java.lang.Object> result, java.lang.String secEntity, java.lang.String secOperation, java.lang.String adminSecEntity, java.lang.String adminSecOperation)
-
setMessages
public static void setMessages(javax.servlet.http.HttpServletRequest request, java.lang.String errorMessage, java.lang.String eventMessage, java.lang.String defaultMessage)
-
getMessages
public static void getMessages(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String defaultMessage)
-
getMessages
public static void getMessages(javax.servlet.http.HttpServletRequest request, java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String defaultMessage, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String errorPrefix, java.lang.String errorSuffix, java.lang.String successPrefix, java.lang.String successSuffix)
-
getErrorMessage
public static java.lang.String getErrorMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result)
-
makeErrorMessage
public static java.lang.String makeErrorMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String errorPrefix, java.lang.String errorSuffix)
-
makeSuccessMessage
public static java.lang.String makeSuccessMessage(java.util.Map<java.lang.String,? extends java.lang.Object> result, java.lang.String msgPrefix, java.lang.String msgSuffix, java.lang.String successPrefix, java.lang.String successSuffix)
-
makeMessageList
public static java.lang.String makeMessageList(java.util.List<? extends java.lang.Object> msgList, java.lang.String msgPrefix, java.lang.String msgSuffix)
-
addErrors
public static void addErrors(java.util.List<java.lang.String> targetList, java.util.Map<java.lang.String,java.lang.Object> targetMap, java.util.Map<java.lang.String,? extends java.lang.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
-
purgeOldJobs
public static java.util.Map<java.lang.String,java.lang.Object> purgeOldJobs(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
-
cancelJob
public static java.util.Map<java.lang.String,java.lang.Object> cancelJob(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
-
cancelJobRetries
public static java.util.Map<java.lang.String,java.lang.Object> cancelJobRetries(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
-
genericDateCondition
public static java.util.Map<java.lang.String,java.lang.Object> genericDateCondition(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context)
-
getUserLogin
public static GenericValue getUserLogin(DispatchContext dctx, java.util.Map<java.lang.String,? extends java.lang.Object> context, java.lang.String runAsUser)
-
makeContext
@SafeVarargs public static <T> java.util.Map<java.lang.String,java.lang.Object> makeContext(T... args)
-
resetJob
public static java.util.Map<java.lang.String,java.lang.Object> resetJob(DispatchContext dctx, java.util.Map<java.lang.String,java.lang.Object> context)
-
setServiceFields
public static java.util.Map<java.lang.String,java.lang.Object> setServiceFields(LocalDispatcher dispatcher, java.lang.String serviceName, java.util.Map<java.lang.String,java.lang.Object> fromMap, GenericValue userLogin, java.util.TimeZone timeZone, java.util.Locale locale) throws GeneralServiceException
Checks 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
public static java.lang.String getResource()
-
-