Class VitamCodeHelper

java.lang.Object
fr.gouv.vitam.common.error.VitamCodeHelper

public class VitamCodeHelper extends Object
Helper to get error message or VitamCode from Service, Domain and item or from error code
  • Method Details

    • isAlphanumericCode

      public static boolean isAlphanumericCode(String code)
      Check if the code is alphanumeric [A-Z0-9]
      Parameters:
      code - the code to check
      Returns:
      true if code is aplhanumeric, false otherwise
    • getFrom

      public static VitamCode getFrom(String code)
      Get VitamCode from code
      Parameters:
      code - the code to get VitamCode
      Returns:
      VitamCode if exists
      Throws:
      IllegalArgumentException - thrown if the code is wrong format or if VitamCode associated to code does not exists
    • getFrom

      public static VitamCode getFrom(ServiceName service, DomainName domain, String item)
      Get VitamCode from Service, Domain and item values
      Parameters:
      service - the service
      domain - the domain
      item - the item
      Returns:
      VitamCode if exists
      Throws:
      IllegalArgumentException - thrown if one argument at least is null or if VitamCode associated to the wanted Service, Domain and item does not exist
    • getMessage

      public static String getMessage(ServiceName service, DomainName domain, String item)
      Get the message from the Service, Domain and item values
      Parameters:
      service - the service
      domain - the domain
      item - the item
      Returns:
      the String message if exists
      Throws:
      IllegalArgumentException - thrown if one argument at least is null or if VitamCode (and the message) associated to the wanted Service, Domain and item does not exist
    • getMessageFromVitamCode

      public static String getMessageFromVitamCode(VitamCode vitamCode)
      Get the message from vitam code
      Parameters:
      vitamCode - the code
      Returns:
      the String message if exists
      Throws:
      IllegalArgumentException - thrown if vitamCode is null or if VitamCode (and the message) associated to the wanted code does not exist
    • getMessage

      public static String getMessage(String vitamCode)
      Get the message from code
      Parameters:
      vitamCode - the code
      Returns:
      the String message if exists
      Throws:
      IllegalArgumentException - thrown if vitamCode is null or if VitamCode (and the message) associated to the wanted code does not exist
    • getParametrizedMessageFromVitamCode

      public static String getParametrizedMessageFromVitamCode(VitamCode vitamCode, Object... params)
      Get parameterized message from code
      Parameters:
      vitamCode - the code
      params - parameters to add to message
      Returns:
      parameterized message
      Throws:
      IllegalArgumentException - thrown if vitamCode or params is null if VitamCode (and the message) associated to the wanted code does not exist
    • getParametrizedMessageFromCode

      public static String getParametrizedMessageFromCode(String vitamCode, Object... params)
      Get parameterized message from code
      Parameters:
      vitamCode - the code
      params - parameters to add to message
      Returns:
      parameterized message
      Throws:
      IllegalArgumentException - thrown if vitamCode or params is null or if VitamCode (and the message) associated to the wanted code does not exist
    • getParametrizedMessage

      public static String getParametrizedMessage(ServiceName service, DomainName domain, String item, Object... params)
      Get parameterized message from Service, Domain and item values
      Parameters:
      service - the service
      domain - the domain
      item - the item
      params - the parameters
      Returns:
      parameterized message
      Throws:
      IllegalArgumentException - thrown if one argument at least is null or if VitamCode (and the message) associated to the wanted code does not exist
    • getFromDomain

      public static List<VitamCode> getFromDomain(DomainName domain)
      Get list of VitamCode from a Domain
      Parameters:
      domain - the domain
      Returns:
      list of VitamCode or empty list
      Throws:
      IllegalArgumentException - thrown if domain is null
    • getFromService

      public static List<VitamCode> getFromService(ServiceName service)
      Get list of VitamCode from a Service
      Parameters:
      service - the service
      Returns:
      list of VitamCode or empty list
      Throws:
      IllegalArgumentException - thrown if service is null
    • getCode

      public static String getCode(VitamCode vitamCode)
      Get the vitam code
      Parameters:
      vitamCode - to get
      Returns:
      the vitam code in String
    • getLogMessage

      public static String getLogMessage(VitamCode vitamCode, Object... params)
      Get formatted message for Logger
      Parameters:
      vitamCode - the Vitam code
      params - parameters for the message
      Returns:
      formatted parameterized message
      Throws:
      IllegalArgumentException - thrown if vitamCode
    • toVitamError

      public static VitamError<com.fasterxml.jackson.databind.JsonNode> toVitamError(VitamCode vitamCode, String description)
      Transform a vitamCode to a VitamError with the given description
      Parameters:
      vitamCode - the vitamCode
      description - the description
      Returns:
      the vitamError
    • toVitamError

      public static <T> VitamError<T> toVitamError(VitamCode vitamCode, String description, Class<T> clasz)
      Transform a vitamCode to a VitamError with the given description
      Parameters:
      vitamCode - the vitamCode
      description - the description
      clasz - the class type
      Returns:
      the vitamError