Question
Details on CST Core Jar and how to use it?
Answer
The CST Core Project provides all required base functionality to interact with the Reltio API and serves as the base project to be used for all customer implementations.
Supported Features
- Service methods for performing any REST API call
- Service methods for performing any Reltio REST API call (retry and token generation processes need not to be handled at each project level)
- Generic attribute class (com.reltio.cst.domain.Attribute)
- File I/O operations
- Automatic detection of file encoding format.
How to use the JAR File
Reltio API call usage
The following code block explains how to use the CST core project JAR file to perform the Reltio API call.
import com.reltio.cst.exception.handler.APICallFailureException; import com.reltio.cst.exception.handler.GenericException; import com.reltio.cst.exception.handler.ReltioAPICallFailureException; import com.reltio.cst.service.ReltioAPIService; import com.reltio.cst.service.TokenGeneratorService; /** * * The sample Java class for using the Reltio API service implementation * */publicclassReltioAPISampleServiceImpl { public static void main(String[] args) { //Step1: Create Reltio Token Generator Service TokenGeneratorService tokenGeneratorService = null; try { tokenGeneratorService = new TokenGeneratorServiceImpl( TokenGeneratorServiceImplTest.username, TokenGeneratorServiceImplTest.password, "https://auth.reltio.com/oauth/token"); } catch (APICallFailureException e) { //This Exception is thrown when username/password invalid. Or if Auth server throws any exception//Get the Http error code & error message sent by Reltio API as below System.out.println("Error Code: " + e.getErrorCode() + " >>>> Error Message: " + e.getErrorResponse()); } catch (GenericException e) { //This exception thrown when unexpected error happens like "Auth Server is down"//Get the exception message as below System.out.println(e.getExceptionMessage()); } //If any one exception happens then abort the process as without token, we can't do any Reltio API call.//Step2: Create Reltio API service. Give the tokenGeneratorService as input to the constructor ReltioAPIService reltioAPIService = new SimpleReltioAPIServiceImpl(tokenGeneratorService); //Step3: Now we can do any Reltio API call & n number of times using reltioAPIService and no need to worry about the token generation and retry process String response = null; try { response = reltioAPIService.get("https://dev.reltio.com/reltio/api/R37ggveZezpiECn/entities/_total"); } catch (GenericException e) { //This exception thrown when unexpected error happens like "Reltio Server is down/invalid input details"//Get the exception message as below System.out.println(e.getExceptionMessage()); } catch (ReltioAPICallFailureException e) { //This Exception is thrown when Reltio API throws any exception//Get the Http error code & error message sent by Reltio API as below System.out.println("Error Code: " + e.getErrorCode() + " >>>> Error Message: " + e.getErrorResponse()); } System.out.println(response); //The same way we can do all other API calls } }
List of available method in the ReltioAPIService
package com.reltio.cst.service; import java.util.Map; import com.reltio.cst.domain.HttpMethod; import com.reltio.cst.exception.handler.GenericException; import com.reltio.cst.exception.handler.ReltioAPICallFailureException; /** * * This is interface for accessing the Reltio API service which supports list of * httpmethods mentioned on this enum <code>{@link HttpMethod}</code> * * */ public interface ReltioAPIService { /** * Helps todo the Reltio GET API calls * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestHeaders-Key/Value pair of expected Request Headers. (No need to add Reltio token & content-type headers) * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicStringget(String requestUrl, Map<String, String> requestHeaders) throws GenericException, ReltioAPICallFailureException; /** * * Helps todo the Reltio POST API calls * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestHeaders-Key/Value pair of expected Request Headers. (No need to add Reltio token & content-type headers) * @param requestBody- JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString post(String requestUrl, Map<String, String> requestHeaders, String requestBody) throws GenericException, ReltioAPICallFailureException; /** * * Helps todo the Reltio PUT API calls * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestHeaders-Key/Value pair of expected Request Headers. (No need to add Reltio token & content-type headers) * @param requestBody- JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString put(String requestUrl, Map<String, String> requestHeaders, String requestBody) throws GenericException, ReltioAPICallFailureException; /** * Helps todo the Reltio DELETE API calls * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestHeaders-Key/Value pair of expected Request Headers. (No need to add Reltio token & content-type headers) * @param requestBody- JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString delete(String requestUrl, Map<String, String> requestHeaders, String requestBody) throws GenericException, ReltioAPICallFailureException; /** * Generic Method to any Reltio API call listed in <code>{@link HttpMethod}</code> * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestHeaders-Key/Value pair of expected Request Headers. (No need to add Reltio token & content-type headers) * @param requestBody- JSON Request body ornullifnothing send in the body * @param requestMethod-USE the enum <code>{@link HttpMethod}</code> toselect the required http method * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString doExecute(String requestUrl, Map<String, String> requestHeaders, String requestBody, HttpMethod requestMethod) throws GenericException, ReltioAPICallFailureException; /** * Helps todo the Reltio GET API calls with less method params * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicStringget(String requestUrl) throws GenericException, ReltioAPICallFailureException; /** * Helps todo the Reltio POST API calls with less method params * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestBody- JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString post(String requestUrl, String requestBody) throws GenericException, ReltioAPICallFailureException; /** * * Helps todo the Reltio PUT API calls with less method params * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestBody- JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString put(String requestUrl, String requestBody) throws GenericException, ReltioAPICallFailureException; /** * * Helps todo the Reltio DELETE API calls with less method params * * @param requestUrl-URL of the API callwith all Query parameters (no encoding required) * @param requestBody-JSON Request body ornullifnothing send in the body * @return * @throws GenericException * @throws ReltioAPICallFailureException */ publicString delete(String requestUrl, String requestBody) throws GenericException, ReltioAPICallFailureException; }
File I/O operations
- Supports both read and write implementation for flat file and CSV files.
- Write operations are thread safe.
- This interface includes two implementing classe: flat file reader and CSV file reader.
- The following code demonstates the corresponding class details and how to use the core project for performing the file read:
package com.reltio.file; import java.io.IOException; publicclass SimpleFileReaderTest { public static void main(String[] args) throws IOException { //Step 1: Create Object reference for ReltioFileReader Interface ReltioFileReader reltioFileReader; //Step 2: Create a object based on the File Type.//if CSV then use below option//Step 2.1: Only with File Name using ReltioCSVFileReader reltioFileReader = new ReltioCSVFileReader("<FileName>"); //With File Name & Decoding technique like UTF-8 or any other reltioFileReader = new ReltioCSVFileReader("<FileName>", "UTF-8"); //ELSE if FLAT FILE then use below option//Step 2.1: Only with File Name. Default Delimiter is pipe reltioFileReader = new ReltioFlatFileReader("<FileName>"); //With File Name & Separator like pipe, dollar reltioFileReader = new ReltioFlatFileReader("<FileName>","||"); //With File Name, Separator & Decoding reltioFileReader = new ReltioFlatFileReader("<FileName>","||", "UTF-8"); //Step 3: Read data from the File.//It always returns the parsed data. So no need to any parsing of data. String[] lineValues = reltioFileReader.readLine(); //Step 4: If lineValues is null then it means reached the End of File.while((lineValues = reltioFileReader.readLine()) != null) { //Do required opertaion } //Step 5: Close the stream reltioFileReader.close(); } }
ReltioFileWriter Interface
- Similar to the Reader, this interface also has two implementing classes: CSV writer and flat file writer
- The following code demonstrates the corresponding class details and how to use the core project for writing to a file:
package com.reltio.file; import java.io.IOException; import java.util.ArrayList; import java.util.List; publicclass SimpleFileWriterTest { public static void main(String[] args) throws IOException { //Step 1: Create Reltio File writer Reference ReltioFileWriter reltioFileWriter; //Step 2: Create a object based on the File Type.//if CSV then use below option//Step 2.1: Only with File Name using ReltioCSVFileWriter reltioFileWriter = new ReltioCSVFileWriter("<FileName>"); //With File Name & Encoding technique like UTF-8 or any other reltioFileWriter = new ReltioCSVFileWriter("<FileName>", "UTF-8"); //ELSE if FLAT FILE then use below option//Step 2.1: Only with File Name. Default Delimiter is pipe reltioFileWriter = new ReltioFlatFileWriter("<FileName>"); //With File Name & Separator like pipe, Encoding reltioFileWriter = new ReltioFlatFileWriter("<FileName>","UTF-8"); //With File Name, Separator & Encoding reltioFileWriter = new ReltioFlatFileWriter("<FileName>","UTF-8", "UTF-8"); //Step 3: Write data to the File.//Step 3.1 Write line by line String[] line = null; //only one line reltioFileWriter.writeToFile(line); //Write Bulk of lines to the file List<String[]> lines = new ArrayList<>(); reltioFileWriter.writeToFile(lines); //Write String data to the file (NOTE: only for Reltio Flat File writter) reltioFileWriter.writeToFile("<Flat File>"); //Write Bulk of String line to the file (NOTE: only for Reltio Flat File writter) List<String> linesOfString = new ArrayList<>(); linesOfString.add("<Flat File>"); reltioFileWriter.writeBulkToFile(linesOfString); //Step 4: Close the stream for writting all the lines in the memory reltioFileWriter.close(); } }
References
https://bitbucket.org/reltio-ondemand/reltio-cst-core/src/master/
Comments
Please sign in to leave a comment.