Answer the question
In order to leave comments, you need to log in
How to replace bulky code with lambdas or make it more beautiful?
I have a mapper that converts real entities from a base to a DTO. The problem is that the tables are nested.
To be precise, I have 5 tables that are interconnected like this:
And that's exactly what I eventually need to map entity A to DTO. To do this, I wrote a very cumbersome mapper:
public AssuranceAccessLineDto mapperToAssuranceAccessLineDto(AccessLine accessLine) {
return modelMapper.map(accessLine, AssuranceAccessLineDto.class)
.setId(accessLine.getId())
.setTechnology(accessLine.getTechnology().name())
.setStatus(accessLine.getStatus().name())
.setLineId(accessLine.getLineId())
.setPortId(accessLine.getPort().getId())
.setAssuranceNeProfileDto(
accessLine.getDefaultNeProfile() == null ?
null : mapperToAssuranceDefaultNeProfileDto(accessLine.getDefaultNeProfile())
)
.setAssuranceSubscriberNeProfileDto(
(accessLine.getDefaultNeProfile() == null || accessLine.getDefaultNeProfile().getSubscriberNeProfile() == null) ?
null : mapperToAssuranceSubscriberNeProfileDto(
accessLine.getDefaultNeProfile().getSubscriberNeProfile()
)
)
.setAssuranceDefaultNetworkLineProfileDto(
accessLine.getDefaultNetworkLineProfile() == null ?
null : mapperToAssuranceDefaultNetworkLineProfileDto(
accessLine.getDefaultNetworkLineProfile()
)
)
.setAssuranceSubscriberNetworkLineProfileDto(
(accessLine.getDefaultNetworkLineProfile() == null || accessLine.getDefaultNetworkLineProfile().getSubscriberNetworkLineProfile() == null) ?
null : mapperToAssuranceSubscriberNetworkLineProfileDto(
accessLine.getDefaultNetworkLineProfile().getSubscriberNetworkLineProfile()
)
);
}
Answer the question
In order to leave comments, you need to log in
No, lambdas are not for that.
Advice - this (and similar) garbage
accessLine.getDefaultNeProfile() == null || accessLine.getDefaultNeProfile().getSubscriberNeProfile() == null) ?
null : mapperToAssuranceSubscriberNeProfileDto(
accessLine.getDefaultNeProfile().getSubscriberNeProfile()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question