[PANC-156] created credit to loan account worker#9
[PANC-156] created credit to loan account worker#9kaibalya-fynarfin wants to merge 5 commits intofynarfin:developfrom
Conversation
2397fca to
1b784bd
Compare
| public String disburseLoan(String fineractTenantId, LoanDisbursementRequestDto loanDisbursementRequestDto, String channelRequest, | ||
| String basicAuthHeader) { | ||
| HttpHeaders headers = new HttpHeaders(); | ||
| headers.add("Content-Type", "application/json"); |
There was a problem hiding this comment.
Use string constant for headers
| channelRequestDTO = objectMapper.readValue(channelRequest, TransactionChannelRequestDTO.class); | ||
| } catch (Exception ex) { | ||
| logger.info(ex.getMessage()); | ||
| return null; |
There was a problem hiding this comment.
Don't return null it might cause a NPE
There was a problem hiding this comment.
I am required to return null because that would help me to know wheather an exception has been caused, i will set the zeebe variables accordingly.
| requestBody = objectMapper.writeValueAsString(loanDisbursementRequestDto); | ||
| channelRequestDTO = objectMapper.readValue(channelRequest, TransactionChannelRequestDTO.class); | ||
| } catch (Exception ex) { | ||
| logger.info(ex.getMessage()); |
There was a problem hiding this comment.
Properly log the error with an message and use logger.error
| logger.info("Response: {} status: {}", exchange.getBody().toString(), exchange.getStatusCode()); | ||
| return exchange.getBody(); | ||
| } catch (Exception ex) { | ||
| logger.error(ex.getMessage()); |
There was a problem hiding this comment.
log the error with proper message
| RestTemplateUtil restTemplateUtil = new RestTemplateUtil(); | ||
| ResponseEntity<String> exchange = restTemplateUtil.exchange(url, HttpMethod.POST, headers, requestBody); | ||
| logger.info(exchange.toString()); | ||
| logger.info("Response: {} status: {}", exchange.getBody().toString(), exchange.getStatusCode()); |
There was a problem hiding this comment.
Don't log the response body as it might contain sensitive info
| if (isAmsLocalEnabled) { | ||
| Map<String, Object> variables = job.getVariablesAsMap(); | ||
| logger.info(variables.toString()); | ||
| String fineractTenantId = variables.get("tenantId").toString(); |
There was a problem hiding this comment.
Use Zeebe variables here instead of hardcoding "tenantId" do this for all the variables
There was a problem hiding this comment.
done for all the variables.
|
|
||
| public class LoanDisbursementRequestDtoHelper { | ||
|
|
||
| public LoanDisbursementRequestDto createLoanDisbursementRequestDto(String originDate) { |
There was a problem hiding this comment.
Add proper exception handling to deal with potential parsing errors
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(RestTemplateUtil.class); | ||
|
|
||
| private String keystorePath = "keystore.jks"; |
There was a problem hiding this comment.
Don't hardcode the path and password as these are sensitive info
| return new RestTemplate(factory); | ||
| } catch (Exception e) { | ||
|
|
||
| throw new RuntimeException("Error creating RestTemplate with custom SSL context", e); |
There was a problem hiding this comment.
Include more descriptive logging before throwing the exception. Additionally, consider creating a custom exception to encapsulate the specific error scenario
| private RestTemplate createCustomRestTemplate() { | ||
| try { | ||
| KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); | ||
| keyStore.load(new FileInputStream(new File(keystorePath)), keystorePassword.toCharArray()); |
There was a problem hiding this comment.
Use a try-with-resources block to ensure that the FileInputStream is closed properly, if not closed properly it might cause resource leak
created credit to loan account worker for the loan disbursement bpmn.