I am trying check 2 of the below fields apr and aprType int he return statement , if they are non empty

21 Views Asked by At

I am trying check 2 of the below fields apr and aprType , if they are non empty. Below is the method:

> public WfccApplicationEntity constructApplicationEntity(
UpdateWfccApplicationDecisionRequest request,
WfccApplicationEntity entity) {
return entity.toBuilder()
>         .statusCode(request.getStatusCode())
>         .caseNumber(request.getCaseNumber())
>         .updatedBy(request.getUpdatedBy())
>         .apr(request.getApr())
>         .aprType(request.getAprType())
>         .statusCodeUpdatedDate(now())
>         .customerId(request.getCustomerId())
>         .statusCodeUpdatedDate(now())
>         .build();
>   }

I want to use org.apache.commons.lang3.StringUtils.isNotBlank() to check the fields

I am not able to use if statement in the return statement

1

There are 1 best solutions below

0
Md. Faisal Habib On

Include Apache Commons Lang library (org.apache.commons.lang3.StringUtils) in your build configuration.

If you are using Gradle, you can add the Apache Commons Lang dependency to your project's build.gradle file as follows:

dependencies {
    implementation 'org.apache.commons:commons-lang3:3.12.0'
}

Save the build.gradle file after adding the dependency. Gradle will automatically download the Apache Commons Lang library and include it in your project. Sync your project with the latest gradle file.

Then you can try to use StringUtils.isNotBlank() method.

Here's a sample code:

import org.apache.commons.lang3.StringUtils;

public WfccApplicationEntity constructApplicationEntity(UpdateWfccApplicationDecisionRequest request, WfccApplicationEntity entity) {
    return entity.toBuilder()
            .statusCode(request.getStatusCode())
            .caseNumber(request.getCaseNumber())
            .updatedBy(request.getUpdatedBy())
            .apr(StringUtils.isNotBlank(request.getApr()) ? request.getApr() : entity.getApr())
            .aprType(StringUtils.isNotBlank(request.getAprType()) ? request.getAprType() : entity.getAprType())
            .statusCodeUpdatedDate(now())
            .customerId(request.getCustomerId())
            .statusCodeUpdatedDate(now())
            .build();
}