Class ResultMapParser

java.lang.Object
com.perforce.p4java.impl.mapbased.server.cmd.ResultMapParser

public abstract class ResultMapParser extends Object
Utility to parse a result map and test for info/error messages etc.
  • Field Details

    • CORE_AUTH_FAIL_STRING_1

      protected static final String CORE_AUTH_FAIL_STRING_1
      Signals access (login) needed.
      See Also:
    • CORE_AUTH_FAIL_STRING_2

      protected static final String CORE_AUTH_FAIL_STRING_2
      Signals access (login) needed.
      See Also:
    • CORE_AUTH_FAIL_STRING_3

      protected static final String CORE_AUTH_FAIL_STRING_3
      Signals ticket has expired.
      See Also:
    • CORE_AUTH_FAIL_STRING_4

      protected static final String CORE_AUTH_FAIL_STRING_4
      Signals ticket has expired.
      See Also:
  • Constructor Details

    • ResultMapParser

      public ResultMapParser()
  • Method Details

    • parseCommandResultMapIfIsInfoMessageAsString

      public static String parseCommandResultMapIfIsInfoMessageAsString(@Nonnull List<Map<String,Object>> resultMaps) throws AccessException, RequestException
      Parses the command result map to return a String of info messages. The messages are expected to be info and if they are not (i.e. they are error messages) an exception is thrown.
      Parameters:
      resultMaps - the result maps
      Returns:
      the string
      Throws:
      AccessException - the access exception
      RequestException - the request exception
    • isInfoMessage

      public static boolean isInfoMessage(Map<String,Object> map)
      Checks for a info message.
      Parameters:
      map - the map
      Returns:
      true, if info message
    • isWarningMessage

      public static boolean isWarningMessage(Map<String,Object> map)
      Checks for a warning message.
      Parameters:
      map - the map
      Returns:
      true, if warning message
    • handleErrorStr

      public static boolean handleErrorStr(Map<String,Object> map) throws RequestException, AccessException
      Tests the map for errors and throws an exception if found.
      Parameters:
      map - the map
      Returns:
      true, if successful
      Throws:
      RequestException - the request exception
      AccessException - the access exception
    • handleWarningStr

      public static boolean handleWarningStr(Map<String,Object> map) throws RequestException, AccessException
      Tests the map for warnings and throws an exception if found.
      Parameters:
      map - the map
      Returns:
      true, if successful
      Throws:
      RequestException - the request exception
      AccessException - the access exception
    • getErrorStr

      public static String getErrorStr(Map<String,Object> map)
      RPC impl errors come across the wire as a map in the form usually like this:
      
       fmt0=Access for user '%user%' has not been enabled by 'p4 protect'.,
       func=client-Message, user=nouser, code0=822483067
       
      With tags being used for non-error payloads, we can just basically pick up the presence of the code0 entry; if it's there, use fmt0 as the format and the other args as appropriate...

      FIXME: work with multiple code/fmt sets... -- HR.

      Parameters:
      map - the map
      Returns:
      the error string if found.
    • getWarningStr

      public static String getWarningStr(Map<String,Object> map)
    • isAuthFail

      public static boolean isAuthFail(String errStr)
      Checks to see if an error String is as a result of an auth fail.
      Parameters:
      errStr - the err str
      Returns:
      true, if is auth fail
    • getInfoStr

      public static String getInfoStr(Map<String,Object> map)
      Gets the info message from the passed-in Perforce command results map. If no info message found in the results map it returns null.

      Note that the severity code is MessageSeverityCode.E_INFO. Therefore, only message with severity code = MessageSeverityCode.E_INFO will be returned.

      RPC impl errors come across the wire as a map in the form usually like this:

      
       fmt0=Access for user '%user%' has not been enabled by 'p4 protect'.,
       func=client-Message, user=nouser, code0=822483067
       
      Note that the code0 entry will be used to get the severity level; the fmt0 entry contains the message.

      Parameters:
      map - Perforce command results map
      Returns:
      possibly-null info string
      Since:
      2011.2
    • getErrorOrInfoStr

      public static String getErrorOrInfoStr(Map<String,Object> map)
      Gets the info/warning/error/fatal message from the passed-in Perforce command results map. If no info/warning/error/fatal message found in the results map it returns null.

      Note that the minimum severity code is MessageSeverityCode.E_INFO. Therefore, only message with severity code >= MessageSeverityCode.E_INFO will be returned.

      RPC impl errors come across the wire as a map in the form usually like this:

      
       fmt0=Access for user '%user%' has not been enabled by 'p4 protect'.,
       func=client-Message, user=nouser, code0=822483067
       
      Note that the code0 entry will be used to get the severity level; the fmt0 entry contains the message.

      Parameters:
      map - Perforce command results map
      Returns:
      possibly-null info/warning/error/fatal string
      Since:
      2011.2
    • throwRequestExceptionIfErrorMessageFound

      public static void throwRequestExceptionIfErrorMessageFound(Map<String,Object> map) throws RequestException
      Throw request exception if error message found.
      Parameters:
      map - the map
      Throws:
      RequestException - the request exception
    • handleErrorOrInfoStr

      public static boolean handleErrorOrInfoStr(Map<String,Object> map) throws RequestException, AccessException
      Handle error or info str.
      Parameters:
      map - the map
      Returns:
      true, if successful
      Throws:
      RequestException - the request exception
      AccessException - the access exception
    • parseCommandResultMapAsString

      public static String parseCommandResultMapAsString(@Nonnull List<Map<String,Object>> resultMaps) throws AccessException, RequestException
      Parses the command result map as string.
      Parameters:
      resultMaps - the result maps
      Returns:
      the string
      Throws:
      AccessException - the access exception
      RequestException - the request exception
    • parseCommandResultMapAsFileSpecs

      public static List<IFileSpec> parseCommandResultMapAsFileSpecs(int id, IServer server, List<Map<String,Object>> resultMaps)
      Parses the command result map as file specs.
      Parameters:
      id - the id
      server - the server
      resultMaps - the result maps
      Returns:
      the list
    • parseCommandResultMapAsExtendedFileSpecs

      public static List<IExtendedFileSpec> parseCommandResultMapAsExtendedFileSpecs(int id, IServer server, List<Map<String,Object>> resultMaps)
      Parses the command result map as file specs.
      Parameters:
      id - the id
      server - the server
      resultMaps - the result maps
      Returns:
      the list
    • parseGraphCommandResultMapAsFileSpecs

      public static List<IFileSpec> parseGraphCommandResultMapAsFileSpecs(IServer server, List<Map<String,Object>> resultMaps)
      Parses the graph command result map as file specs.
      Parameters:
      server - the server
      resultMaps - the result maps
      Returns:
      the list
    • handleFileErrorStr

      public static String handleFileErrorStr(Map<String,Object> map) throws ConnectionException, AccessException
      Handle file error str.
      Parameters:
      map - the map
      Returns:
      the string
      Throws:
      ConnectionException - the connection exception
      AccessException - the access exception
    • isExistClientOrLabelOrUser

      public static boolean isExistClientOrLabelOrUser(Map<String,Object> map)
      Unfortunately, the p4 command version returns a valid map for non-existent clients/labels/users; the only way we can detect that the client/label/user doesn't exist is to see if the Update or Access map entries exist -- if they do, the client/label/user is (most likely) a valid client/label/user on this server. This seems less than optimal to me... -- HR.
      Parameters:
      map - the map
      Returns:
      true, if is exist client or label or user
    • isNonExistClientOrLabelOrUser

      public static boolean isNonExistClientOrLabelOrUser(Map<String,Object> map)
      Unfortunately, the p4 command version returns a valid map for non-existent clients/labels/users; the only way we can detect that the client/label/user doesn't exist is to see if the Update or Access map entries exist -- if they do, the client/label/user is (most likely) a valid client/label/user on this server. This seems less than optimal to me... -- HR.
      Parameters:
      map - the map
      Returns:
      true, if is non exist client or label or user