All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.brihaspathee.zeus.mapper.impl.MemberPhoneMapperImpl Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package com.brihaspathee.zeus.mapper.impl;

import com.brihaspathee.zeus.domain.entity.MemberPhone;
import com.brihaspathee.zeus.dto.account.MemberPhoneDto;
import com.brihaspathee.zeus.mapper.interfaces.MemberPhoneMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

/**
 * Created in Intellij IDEA
 * User: Balaji Varadharajan
 * Date: 30, November 2022
 * Time: 3:34 PM
 * Project: Zeus
 * Package Name: com.brihaspathee.zeus.mapper.impl
 * To change this template use File | Settings | File and Code Template
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MemberPhoneMapperImpl implements MemberPhoneMapper {

    /**
     * Convert Phone entity to phone dto
     * @param phone
     * @return
     */
    @Override
    public MemberPhoneDto phoneToPhoneDto(MemberPhone phone) {
        if(phone == null){
            return null;
        }
        MemberPhoneDto phoneDto = MemberPhoneDto.builder()
                .memberPhoneSK(phone.getMemberAcctPhoneSK())
                .memberPhoneCode(phone.getMemberPhoneCode())
                .phoneTypeCode(phone.getPhoneTypeCode())
                .phoneNumber(phone.getPhoneNumber())
                .ztcn(phone.getZtcn())
                .source(phone.getSource())
                .startDate(phone.getStartDate())
                .endDate(phone.getEndDate())
                .changed(new AtomicBoolean(phone.isChanged()))
                .createdDate(phone.getCreatedDate())
                .updatedDate(phone.getUpdatedDate())
                .build();
        return phoneDto;
    }

    /**
     * Convert phone dto to phone entity
     * @param phoneDto
     * @return
     */
    @Override
    public MemberPhone phoneDtoToPhone(MemberPhoneDto phoneDto) {
        if(phoneDto == null){
            return null;
        }
        MemberPhone phone = MemberPhone.builder()
                .memberPhoneCode(phoneDto.getMemberPhoneCode())
                .phoneTypeCode(phoneDto.getPhoneTypeCode())
                .phoneNumber(phoneDto.getPhoneNumber())
                .ztcn(phoneDto.getZtcn())
                .source(phoneDto.getSource())
                .startDate(phoneDto.getStartDate())
                .endDate(phoneDto.getEndDate())
                .createdDate(phoneDto.getCreatedDate())
                .updatedDate(phoneDto.getUpdatedDate())
                .build();
        if (phoneDto.getChanged() != null){
            phone.setChanged(phoneDto.getChanged().get());
        } else {
            phone.setChanged(false);
        }
        return phone;
    }

    /**
     * Convert phone entities to phone dtos
     * @param phones
     * @return
     */
    @Override
    public List phonesToPhoneDtos(List phones) {
        return phones.stream().map(this::phoneToPhoneDto).collect(Collectors.toList());
    }

    /**
     * Convert phone dtos to phone entities
     * @param phoneDtos
     * @return
     */
    @Override
    public List phoneDtosToPhones(List phoneDtos) {
        return phoneDtos.stream().map(this::phoneDtoToPhone).collect(Collectors.toList());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy