diff --git a/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/batch/config/CredentialItemTasklet.java b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/batch/config/CredentialItemTasklet.java index a18e42d13..a1f149e67 100644 --- a/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/batch/config/CredentialItemTasklet.java +++ b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/batch/config/CredentialItemTasklet.java @@ -7,10 +7,12 @@ import io.mosip.credential.request.generator.entity.CredentialEntity; import io.mosip.credential.request.generator.exception.ApiNotAccessibleException; import io.mosip.credential.request.generator.util.RestUtil; +import io.mosip.credential.request.generator.util.TrimExceptionMessage; import io.mosip.idrepository.core.dto.CredentialIssueRequestDto; import io.mosip.idrepository.core.dto.CredentialServiceRequestDto; import io.mosip.idrepository.core.dto.CredentialServiceResponse; import io.mosip.idrepository.core.dto.CredentialServiceResponseDto; +import io.mosip.idrepository.core.dto.ErrorDTO; import io.mosip.idrepository.core.logger.IdRepoLogger; import io.mosip.idrepository.core.security.IdRepoSecurityManager; import io.mosip.kernel.core.exception.ExceptionUtils; @@ -91,6 +93,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon try { forkJoinPool.submit(() -> credentialEntities.parallelStream().forEach(credential -> { + TrimExceptionMessage trimMessage = new TrimExceptionMessage(); try { LOGGER.info(IdRepoSecurityManager.getUser(), CREDENTIAL_ITEM_PROCESSOR, "batchid = " + batchId, "started processing item : " + credential.getRequestId()); @@ -122,8 +125,9 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon responseObject.getErrors() != null && !responseObject.getErrors().isEmpty()) { LOGGER.debug(IdRepoSecurityManager.getUser(), CREDENTIAL_ITEM_PROCESSOR, "batchid = " + batchId, responseObject.toString()); - + ErrorDTO error = responseObject.getErrors().get(0); credential.setStatusCode(CredentialStatusCode.FAILED.name()); + credential.setStatusComment(error.getMessage()); } else { CredentialServiceResponse credentialServiceResponse = responseObject.getResponse(); @@ -132,6 +136,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon credential.setIssuanceDate(credentialServiceResponse.getIssuanceDate()); credential.setStatusCode(credentialServiceResponse.getStatus()); credential.setSignature(credentialServiceResponse.getSignature()); + credential.setStatusComment("credentials issued to partner"); } credential.setUpdatedBy(CREDENTIAL_USER); @@ -143,6 +148,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon LOGGER.error(IdRepoSecurityManager.getUser(), CREDENTIAL_ITEM_PROCESSOR, "batchid = " + batchId, ExceptionUtils.getStackTrace(e)); credential.setStatusCode("FAILED"); + credential.setStatusComment(trimMessage.trimExceptionMessage(e.getMessage())); credential.setUpdateDateTime(DateUtils.getUTCCurrentDateTime()); credential.setUpdatedBy(CREDENTIAL_USER); } catch (IOException e) { @@ -150,6 +156,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon LOGGER.error(IdRepoSecurityManager.getUser(), CREDENTIAL_ITEM_PROCESSOR, "batchid = " + batchId, ExceptionUtils.getStackTrace(e)); credential.setStatusCode("FAILED"); + credential.setStatusComment(trimMessage.trimExceptionMessage(e.getMessage())); credential.setUpdateDateTime(DateUtils.getUTCCurrentDateTime()); credential.setUpdatedBy(CREDENTIAL_USER); } catch (Exception e) { @@ -157,6 +164,7 @@ public RepeatStatus execute(StepContribution contribution, ChunkContext chunkCon LOGGER.error(IdRepoSecurityManager.getUser(), CREDENTIAL_ITEM_PROCESSOR, "batchid = " + batchId, ExceptionUtils.getStackTrace(e)); credential.setStatusCode("FAILED"); + credential.setStatusComment(trimMessage.trimExceptionMessage(e.getMessage())); credential.setUpdateDateTime(DateUtils.getUTCCurrentDateTime()); credential.setUpdatedBy(CREDENTIAL_USER); } diff --git a/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/entity/CredentialEntity.java b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/entity/CredentialEntity.java index 1ac632145..4febc4e1f 100644 --- a/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/entity/CredentialEntity.java +++ b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/entity/CredentialEntity.java @@ -74,6 +74,9 @@ public class CredentialEntity { /** The deleted date time. */ @Column(name = "del_dtimes") private LocalDateTime deletedDateTime; + + @Column(name = "status_comment") + private String statusComment; /** * Gets the request id. @@ -291,4 +294,12 @@ public void setSignature(String signature) { this.signature = signature; } + public String getStatusComment() { + return statusComment; + } + + public void setStatusComment(String statusComment) { + this.statusComment = statusComment; + } + } diff --git a/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/util/TrimExceptionMessage.java b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/util/TrimExceptionMessage.java new file mode 100644 index 000000000..01777d0da --- /dev/null +++ b/id-repository/credential-request-generator/src/main/java/io/mosip/credential/request/generator/util/TrimExceptionMessage.java @@ -0,0 +1,18 @@ +package io.mosip.credential.request.generator.util; + +/** + * The Class TrimExceptionMessage. + * + * @author Neha + */ + +public class TrimExceptionMessage { + + private static final int MESSAGE_LENGTH = 400; + + public String trimExceptionMessage(String exceptionMessage) { + return exceptionMessage.substring(0, Math.min(exceptionMessage.length(), MESSAGE_LENGTH)); + + } + +}