Class ServiceUtil

java.lang.Object
org.apache.ofbiz.service.ServiceUtil

public final class ServiceUtil extends Object
Generic Service Utility Class
  • Method Details

    • isError

      public static boolean isError(Map<String,? extends Object> results)
      A little short-cut method to check to see if a service returned an error
    • isFailure

      public static boolean isFailure(Map<String,? extends Object> results)
    • isSuccess

      public static boolean isSuccess(Map<String,? extends Object> results)
      A little short-cut method to check to see if a service was successful (neither error or failed)
    • returnError

      public static Map<String,Object> returnError(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 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

      public static Map<String,Object> returnError(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
    • returnFailure

      public static Map<String,Object> returnFailure(String errorMessage)
    • returnFailure

      public static Map<String,Object> returnFailure(List<? extends Object> errorMessageList)
    • returnFailure

      public static Map<String,Object> 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

      public static Map<String,Object> returnProblem(String returnType, String errorMessage, List<? extends Object> errorMessageList, Map<String,? extends Object> errorMessageMap, Map<String,? extends Object> nestedResult)
    • returnSuccess

      public static Map<String,Object> returnSuccess(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 Map<String,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 Map<String,Object> returnSuccess(List<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 Map<String,Object> 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)
    • 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

      public static String getPartyIdCheckSecurity(GenericValue userLogin, Security security, Map<String,? extends Object> context, Map<String,Object> result, String secEntity, String secOperation, String adminSecEntity, String adminSecOperation)
    • 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

      public static void getMessages(HttpServletRequest request, Map<String,? extends Object> result, String defaultMessage, String msgPrefix, String msgSuffix, String errorPrefix, String errorSuffix, String successPrefix, String successSuffix)
    • getErrorMessage

      public static String getErrorMessage(Map<String,? extends Object> result)
    • makeErrorMessage

      public static String makeErrorMessage(Map<String,? extends Object> result, String msgPrefix, String msgSuffix, String errorPrefix, String errorSuffix)
    • makeSuccessMessage

      public static String makeSuccessMessage(Map<String,? extends Object> result, String msgPrefix, String msgSuffix, String successPrefix, String successSuffix)
    • makeMessageList

      public static String makeMessageList(List<? extends Object> msgList, String msgPrefix, String msgSuffix)
    • 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 to
      targetMap - The Map to add any Map error messages to
      callResult - The result from an invocation
    • genericDateCondition

      public static Map<String,Object> genericDateCondition(DispatchContext dctx, Map<String,? extends Object> context)
    • getUserLogin

      public static GenericValue getUserLogin(DispatchContext dctx, Map<String,? extends Object> context, String runAsUser)
    • getLocale

      public static Locale getLocale(Map<String,? extends Object> context)
    • makeContext

      @SafeVarargs public static <T> Map<String,Object> makeContext(T... args)
    • setServiceFields

      public static Map<String,Object> setServiceFields(LocalDispatcher dispatcher, String serviceName, Map<String,Object> fromMap, GenericValue userLogin, TimeZone timeZone, 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 required
      timeZone -
      locale -
      Returns:
      filled Map or null on error
      Throws:
      GeneralServiceException
    • getResource

      public static String getResource()