Class CommonUtils


  • public class CommonUtils
    extends Object
    • Constructor Detail

      • CommonUtils

        public CommonUtils()
    • Method Detail

      • getFormattedDate

        public static String getFormattedDate()
      • createGenericResponse

        public static GenericResponse createGenericResponse​(boolean result,
                                                            int responseCode,
                                                            String responseMessage)
      • createGenericResponse

        public static GenericResponse createGenericResponse​(boolean result,
                                                            int responseCode,
                                                            String responseMessage,
                                                            com.fasterxml.jackson.databind.JsonNode node)
      • hasShortCode

        public static boolean hasShortCode​(Map<String,​?> map)
      • hasShortCode

        public static boolean hasShortCode​(String input)
      • jsonStringToMap

        public static Map<String,​Object> jsonStringToMap​(String jsonString)
                                                        throws com.fasterxml.jackson.core.JsonProcessingException
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • mapToJsonString

        public static String mapToJsonString​(Map<String,​Object> mapObj)
                                      throws com.fasterxml.jackson.core.JsonProcessingException
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • isValidJson

        public static boolean isValidJson​(String json)
      • convertIsoToDateString

        public static String convertIsoToDateString​(String isoDateTime)
      • convertStringToLocalDate

        public static LocalDate convertStringToLocalDate​(String dateString)
      • convertLocalDateToString

        public static String convertLocalDateToString​(LocalDate date)
      • toJsonNode

        public static com.fasterxml.jackson.databind.JsonNode toJsonNode​(Object object)
                                                                  throws com.fasterxml.jackson.core.JsonProcessingException
        Converts any Java object into a JsonNode representation.
        Parameters:
        object - the Java object to convert
        Returns:
        JSON representation of the object
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException
      • toPrimitiveOrDefaultFalse

        public static boolean toPrimitiveOrDefaultFalse​(Boolean booleanObject)
        Convert a Boolean reference to its primitive form, using a default value when the input is null.
        Returns:
        `true` if the input is `Boolean.TRUE`, `false` if the input is `Boolean.FALSE` or `null`.
      • addMinutes

        public static Date addMinutes​(Date date,
                                      int minutesToAdd)
        Return a new Date representing the given date plus the specified number of minutes.
        Parameters:
        date - the base date to adjust
        minutesToAdd - the number of minutes to add; may be negative to subtract minutes
        Returns:
        the adjusted Date shifted by minutesToAdd minutes from date
      • getClaims

        public static Map<String,​Object> getClaims​(io.jans.as.model.jwt.Jwt jwtObj)
        Extracts claims from a Jwt into a Map keyed by claim name.

        The returned map contains claim values using appropriate Java types: Strings, Integer, Long, Boolean, List for JSON arrays, or JSONObject for JSON objects.

        Parameters:
        jwtObj - the Jwt to extract claims from; may be null
        Returns:
        a map of claim names to claim values, empty if jwtObj is null
      • toUrlEncodedString

        public static String toUrlEncodedString​(Map<String,​String> params)
        Builds a UTF-8 URL-encoded query string from the provided parameters.
        Parameters:
        params - a map of parameter names to values; entries with a null value are omitted
        Returns:
        a URL-encoded string of `key=value` pairs joined with `&`, encoded using UTF-8