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 string​

asJSONString

Convert map object to a json string​ without formatting.

BaseApi.asJSONString(Object obj)

Parameters

obj:  object

Sample Code

Map<String, Object> product = new HashMap<>();
product.put("productId", "11");
String strJson = BaseApi.asJSONString(product);

Returns

the json string​

fromJSONString

Convert a json string​ to a map object.

BaseApi.fromJSONString(String json)

Parameters

json:     string representation of json

Sample Code

String jsonString = "{\n" +
      "    \"productId\": \"abc\"\n" +
      "}";
Map<String, Object> map = BaseApi.fromJSONString(jsonString);

Returns

constructed hashmap​

fromJSONStringAsArray

Convert a json string​ as a linked hashmap. The map can be interpreted later on.

BaseApi.fromJSONStringAsArray(String json)

Parameters

json:    string representation of json

Sample Code

String jsonString = "[\n" +
      "    {\n" +
      "    \"product\": \"abc\"\n" +
      "    }\n" +
      "]";
List<Map<String, Object>> mapList = BaseApi.fromJSONStringAsArray(jsonString);

Returns

the array of json objects

readJSON

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 file

Sample Code

Map<String, Object> map = BaseApi.readJSON("/tmp/folder1", "file.json");

Returns

json document object​

writeJSON

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 operation​

writePrettyJSON

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 document

Sample Code

    String jsonString = "[\n" +
      "    {\n" +
      "    \"product\": \"abc\"\n" +
      "    }\n" +
      "]";
    BaseApi.writePrettyJSON("/tmp/folder1", "file.json", jsonString);

Returns

result of the operation​

successResult

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 operation​

errorResult

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 code

Sample Code

BaseApi.errorResult("Failed to process records");

Returns

the result of the operation​

extractMessage

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 hashmap

Returns

message string​

isResult

Checking whether the object is a result object​.

BaseApi.isResult(Object obj)

Parameters

obj:    the object as a hashmap

Sample Code

Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResult(res);

Returns

status of the result​

isResultOrNull

Checking if result object is a valid one or a just a NuLL

BaseApi.isResultOrNull(Object obj)

Parameters

obj:    the object as a hashmap

Sample Code

Result res = Result.getSuccessResult("success");
boolean isResult = BaseApi.isResultOrNull(res);

Returns

the status of the result​

UUID

Generate a UUID sequence.

BaseApi.UUID()

Parameters

none​

Sample Code

String uuid = BaseApi.UUID();

Returns

the uuid​

uidToClassName

Extract class name​ from an input string.

BaseApi.uidToClassName(String uid)

Parameters

uid:    the className id

Returns

the class name​

uidToId

Extract an long id number from a string UID.

BaseApi.uidToId(String uid)

Parameters

uid: 

Returns

gives id

uidToIdStr

Retrieves​ the ID as a string from uid.

BaseApi.uidToIdStr(String uid) 

Parameters

uid: 

Returns

gives id in str

waitForMillis

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 time

remoteCall

// Basic Description //

BaseApi.remoteCall(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Sample Code

Object res = remoteCall("DSApi", "get", "shared.common.product", "12);

Returns

execute the call

remoteCallAsResult

// Description //

BaseApi.remoteCallAsResult(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Sample Code

Result res = remoteCallAsResult("BigQueryApi", "executeQuery", "SELECT ID FROM product_tbl");

Returns

// Some code

remoteCallAsMap

// Description //

BaseApi.remoteCallAsMap(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Sample Code

Map<String, Object> res =  remoteCallAsMap("UMApi", "getCurrentUser");

Returns

// Some code

remoteCallAsString

// Description //

BaseApi.remoteCallAsString(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Sample Code

String res = remoteCallAsString("GCPRestApi", "getProjectId");

Returns

// Some code

remoteCallAsList

// Description //

BaseApi.remoteCallAsList(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Returns

// Some code

remoteCallAsListOfMaps

// Description //

BaseApi.remoteCallAsListOfMaps(String javaClassName, String javaMethodName, Object... args)

Parameters

javaClassName
javaMethodName

Returns

// Some code

Last updated