So I am developing a notification service which, for now, only has a Notification and an Email entity, where Email extends Notification.
The Notification entity has a column named type which stores the type of the notification (ie: EMAIL, MESSAGE, PUSH, etc) and I want to know if there is a way to define a default value for the type column for each of the childs of Notification while using lombok.
I see that a common practice is to set the type on the constructor, like this:
public Email() {
setType("EMAIL");
}
But I am using the builder from lombok to instatiate Email, like this:
public static Email fromEmailRequest(final EmailRequest emailRequest) {
if (Objects.isNull(emailRequest)) {
return Email.builder().build();
}
Set<String> set = new LinkedHashSet<>(emailRequest.getRecipients());
return Email.builder()
.content(emailRequest.getContent())
.recipients(Lists.newArrayList(set))
.sender(emailRequest.getSender())
.subject(emailRequest.getSubject())
.type(NotificationTypeEnum.EMAIL)
.build();
}
The approach I am using now sets the type in the request DTO mapper, but I think this logic should be somewhere in the entities.