Package com.moesif.api
Class APIHelper
- java.lang.Object
-
- com.moesif.api.APIHelper
-
public class APIHelper extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static com.fasterxml.jackson.databind.ObjectMappermapper
-
Constructor Summary
Constructors Constructor Description APIHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidappendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String,Object> parameters)Appends the given set of parameters to the given query stringstatic voidappendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String,Object> parameters)Replaces template parameters in the given urlstatic StringcleanUrl(StringBuilder url)Validates and processes the given Urlstatic StringdateToString(Date date)Convert a date to an ISO8601 formatted stringstatic LinkedHashMap<String,Object>deserialize(String json)JSON Deserialization of the given json string.static <T> Tdeserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)JSON Deserialization of the given json string.static <T> Tdeserialize(String json, Class<T> typeReference)JSON Deserialization of the given json string.static ExecutorServicegetScheduler()Singleton access to the threadpool schedulerstatic StringgetVersion()Get the current version of the moesifapi-java artifactstatic booleanisNullOrWhiteSpace(String s)Validates if the string is null, empty or whitespacestatic DateparseDate(String date)Parse a date from its string representationstatic voidpopulate(String json, APIException obj)Populates an object of an APIException subclass with the required properties.static Map<String,Object>prepareFormFields(Object value)Prepares Array style form fields from a given array of valuesstatic voidremoveNullValues(Map<String,?> map)Removes null values from the given mapstatic voidreplaceAll(StringBuilder stringBuilder, String toReplace, String replaceWith)Replaces all occurrences of the given string in the string builderstatic Stringserialize(Object obj)JSON Serialization of a given object.static voidshutdown()Shutdown all the threads
-
-
-
Method Detail
-
getScheduler
public static ExecutorService getScheduler()
Singleton access to the threadpool scheduler- Returns:
- ExecutorService instance
-
shutdown
public static void shutdown()
Shutdown all the threads
-
parseDate
public static Date parseDate(String date) throws ParseException
Parse a date from its string representation- Parameters:
date- ISO8601 encodede date string- Returns:
- Parsed Date object
- Throws:
ParseException
-
dateToString
public static String dateToString(Date date)
Convert a date to an ISO8601 formatted string- Parameters:
date- Date object to format- Returns:
- ISO8601 formatted date string
-
serialize
public static String serialize(Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
JSON Serialization of a given object.- Parameters:
obj- The object to serialize into JSON- Returns:
- The serialized Json string representation of the given object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- if error serializing JSON obj
-
deserialize
public static <T> T deserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws IOException
JSON Deserialization of the given json string.- Type Parameters:
T- The type of the object to deserialize into- Parameters:
json- The json string to deserializetypeReference- The TypeReference of the object to deserialize into- Returns:
- The deserialized object
- Throws:
IOException- if error deserializing
-
deserialize
public static <T> T deserialize(String json, Class<T> typeReference) throws IOException
JSON Deserialization of the given json string.- Type Parameters:
T- The type of the object to deserialize into- Parameters:
json- The json string to deserializetypeReference- The Class of the object to deserialize into- Returns:
- The deserialized object
- Throws:
IOException- if error deserializing
-
populate
public static void populate(String json, APIException obj) throws IOException
Populates an object of an APIException subclass with the required properties.- Parameters:
json- The json string to deserializeobj- The object to populate- Throws:
IOException- if error deserializing
-
deserialize
public static LinkedHashMap<String,Object> deserialize(String json) throws IOException
JSON Deserialization of the given json string.- Parameters:
json- The json string to deserialize- Returns:
- The deserialized json as a Map
- Throws:
IOException- if error deserializing
-
appendUrlWithTemplateParameters
public static void appendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String,Object> parameters)
Replaces template parameters in the given url- Parameters:
queryBuilder- The query string builder to replace the template parametersparameters- The parameters to replace in the url
-
appendUrlWithQueryParameters
public static void appendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String,Object> parameters)
Appends the given set of parameters to the given query string- Parameters:
queryBuilder- The query url string to append the parametersparameters- The parameters to append
-
isNullOrWhiteSpace
public static boolean isNullOrWhiteSpace(String s)
Validates if the string is null, empty or whitespace- Parameters:
s- The string to validate- Returns:
- The result of validation
-
replaceAll
public static void replaceAll(StringBuilder stringBuilder, String toReplace, String replaceWith)
Replaces all occurrences of the given string in the string builder- Parameters:
stringBuilder- The string builder to update with replaced stringstoReplace- The string to replace in the string builderreplaceWith- The string to replace with
-
removeNullValues
public static void removeNullValues(Map<String,?> map)
Removes null values from the given map- Parameters:
map- the input map
-
cleanUrl
public static String cleanUrl(StringBuilder url)
Validates and processes the given Url- Parameters:
url- The given Url to process- Returns:
- Pre-process Url as string
-
prepareFormFields
public static Map<String,Object> prepareFormFields(Object value)
Prepares Array style form fields from a given array of values- Parameters:
value- Value for the form fields- Returns:
- Dictionary of form fields created from array elements
-
getVersion
public static String getVersion()
Get the current version of the moesifapi-java artifact- Returns:
- Version string
-
-