BAEL-7032: Improvement to conditional mapping by using @Condition and added tests
This commit is contained in:
@@ -11,6 +11,8 @@ public class LicenseDto {
|
||||
|
||||
private LocalDateTime endDate;
|
||||
|
||||
private String licenseType;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -35,4 +37,12 @@ public class LicenseDto {
|
||||
this.endDate = endDate;
|
||||
}
|
||||
|
||||
public String getLicenseType() {
|
||||
return licenseType;
|
||||
}
|
||||
|
||||
public void setLicenseType(String licenseType) {
|
||||
this.licenseType = licenseType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.Condition;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
@@ -40,4 +41,13 @@ public interface LicenseMapper {
|
||||
.toDays() <= 14;
|
||||
}
|
||||
|
||||
}
|
||||
@Condition
|
||||
default boolean mapsToExpectedLicenseType(String licenseType) {
|
||||
try {
|
||||
return licenseType != null && License.LicenseType.valueOf(licenseType) != null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@ public class License {
|
||||
|
||||
private boolean renewalRequired;
|
||||
|
||||
private LicenseType licenseType;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -55,4 +57,16 @@ public class License {
|
||||
public void setRenewalRequired(boolean renewalRequired) {
|
||||
this.renewalRequired = renewalRequired;
|
||||
}
|
||||
}
|
||||
|
||||
public enum LicenseType {
|
||||
INDIVIDUAL, FAMILY
|
||||
}
|
||||
|
||||
public LicenseType getLicenseType() {
|
||||
return licenseType;
|
||||
}
|
||||
|
||||
public void setLicenseType(LicenseType licenseType) {
|
||||
this.licenseType = licenseType;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user