BaseApi (Basic APIs)
asJSONPrettyString
Convert a map object to a json formatted string.
BaseApi.asJSONPrettyString(Object obj)Parameters
obj: the object (can be a hashmap)Sample Code
Map<String, Object> product = new HashMap<>();
product.put("productId", "11");
String strJson = BaseApi.asJSONPrettyString(product);Returns
the formatted stringasJSONString
Convert map object to a json string without formatting.
BaseApi.asJSONString(Object obj)Parameters
obj: objectSample Code
Map<String, Object> product = new HashMap<>();
product.put("productId", "11");
String strJson = BaseApi.asJSONString(product);Returns
the json stringfromJSONString
Convert a json string to a map object.
BaseApi.fromJSONString(String json)Parameters
json: string representation of jsonSample Code
String jsonString = "{\n" +
" \"productId\": \"abc\"\n" +
"}";
Map<String, Object> map = BaseApi.fromJSONString(jsonString);Returns
constructed hashmapfromJSONStringAsArray
Convert a json string as a linked hashmap. The map can be interpreted later on.
BaseApi.fromJSONStringAsArray(String json)Parameters
json: string representation of jsonSample Code
String jsonString = "[\n" +
" {\n" +
" \"product\": \"abc\"\n" +
" }\n" +
"]";
List<Map<String, Object>> mapList = BaseApi.fromJSONStringAsArray(jsonString);Returns
the array of json objectsreadJSON
Read the JSON from a file name located in a specific directory. It is converted into an map object.
BaseApi.readJSON(String dir, String fileName)Parameters
dir: the directory
fileName: name of the fileSample Code
Map<String, Object> map = BaseApi.readJSON("/tmp/folder1", "file.json");Returns
json document objectwriteJSON
Write a map object into a file located on a specific directory.
BaseApi.writeJSON(String dir, String fileName, Object obj)Parameters
dir: directory
fileName: name of the file
obj: json document object Sample Code
String jsonString = "[\n" +
" {\n" +
" \"product\": \"abc\"\n" +
" }\n" +
"]";
BaseApi.writeJSON("/tmp/folder1", "file.json", jsonString);Returns
result of the operationwritePrettyJSON
Write a map object into a file located on a specific directory. The JSON information is a formatted inside the file.
BaseApi.writePrettyJSON(String dir, String fileName, Object obj)Parameters
dir: directory
fileName: name of the file
obj: json formatted documentSample Code
String jsonString = "[\n" +
" {\n" +
" \"product\": \"abc\"\n" +
" }\n" +
"]";
BaseApi.writePrettyJSON("/tmp/folder1", "file.json", jsonString);Returns
result of the operationsuccessResult
Build and return a successful result map object.
BaseApi.successResult()
or
BaseApi.successResult(String msg)
or
BaseApi.successResult(String msg, Object data)Parameters
msg message to be sent
data Sample Code
BaseApi.successResult("Successfully added records");Returns
result of the operationerrorResult
Build and return an error result map object.
BaseApi.errorResult(String msg)
or
BaseApi.errorResult(String msg, int code)Parameters
msg: message to be sent
code: return codeSample Code
BaseApi.errorResult("Failed to process records");Returns
the result of the operationextractMessage
Extract the message from the result object. The result object has a detailed message in it therefore it will be returned.
BaseApi.extractMessage(Object obj)Parameters
obj: object as a hashmapReturns
message stringisResult
Checking whether the object is a result object.
BaseApi.isResult(Object obj)Parameters
obj: the object as a hashmapSample Code
Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResult(res);Returns
status of the resultisResultOrNull
Checking if result object is a valid one or a just a NuLL
BaseApi.isResultOrNull(Object obj)Parameters
obj: the object as a hashmapSample Code
Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResultOrNull(res);Returns
the status of the resultUUID
Generate a UUID sequence.
BaseApi.UUID()Parameters
noneSample Code
String uuid = BaseApi.UUID();Returns
the uuiduidToClassName
Extract class name from an input string.
BaseApi.uidToClassName(String uid)Parameters
uid: the className idReturns
the class nameuidToId
Extract an long id number from a string UID.
BaseApi.uidToId(String uid)Parameters
uid: Returns
gives iduidToIdStr
Retrieves the ID as a string from uid.
BaseApi.uidToIdStr(String uid) Parameters
uid: Returns
gives id in strwaitForMillis
Wait for certain MS given as a long number. It is a blocking function call.
BaseApi.waitForMillis(long tm) Parameters
tm: Sample Code
Result res = BaseApi.waitForMillis(10);Returns
waits for given timeremoteCall
// Basic Description //
BaseApi.remoteCall(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameSample Code
Object res = remoteCall("DSApi", "get", "shared.common.product", "12);Returns
execute the callremoteCallAsResult
// Description //
BaseApi.remoteCallAsResult(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameSample Code
Result res = remoteCallAsResult("BigQueryApi", "executeQuery", "SELECT ID FROM product_tbl");Returns
// Some coderemoteCallAsMap
// Description //
BaseApi.remoteCallAsMap(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameSample Code
Map<String, Object> res = remoteCallAsMap("UMApi", "getCurrentUser");Returns
// Some coderemoteCallAsString
// Description //
BaseApi.remoteCallAsString(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameSample Code
String res = remoteCallAsString("GCPRestApi", "getProjectId");Returns
// Some coderemoteCallAsList
// Description //
BaseApi.remoteCallAsList(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameReturns
// Some coderemoteCallAsListOfMaps
// Description //
BaseApi.remoteCallAsListOfMaps(String javaClassName, String javaMethodName, Object... args)Parameters
javaClassName
javaMethodNameReturns
// Some codeLast updated
Was this helpful?