PromoCustomerJobAssembler.java 2.36 KB
Newer Older
akbar fauzi's avatar
akbar fauzi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
package com.eksad.masterdata.domain.assembler;

import com.eksad.ddms.common.dto.CreationalSpecificationDTO;
import com.eksad.ddms.common.util.object.IObjectAssembler;
import com.eksad.ddms.common.util.status.DataStatus;
import com.eksad.masterdata.common.dto.PromoCustomerJobDTO;
import com.eksad.masterdata.domain.CreationalSpecification;
import com.eksad.masterdata.domain.PromoCustomerJob;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class PromoCustomerJobAssembler implements IObjectAssembler<PromoCustomerJob, PromoCustomerJobDTO> {

    @Override
    public PromoCustomerJobDTO toDTO(PromoCustomerJob x) {
        return new PromoCustomerJobDTO(
                x.getPromoCustJobID(),
                x.getPromoID(),
                x.getCustJobID(),
                x.getCustJobName(),
                x.getPromoCustJobStatus(),
                x.getPromoCustJobCreational() == null ? new CreationalSpecificationDTO() : new CreationalSpecificationDTOAssembler().toDTO(x.getPromoCustJobCreational()));
    }

    @Override
    public PromoCustomerJob toDomain(PromoCustomerJobDTO y) {
        return new PromoCustomerJob(
                y.getPromoCustJobID(),
                y.getPromoID(),
                y.getCustJobID(),
                y.getCustJobName(),
                y.getPromoCustJobStatus(),
                y.getPromoCustJobCreationalDTO() == null ? new CreationalSpecification() : new CreationalSpecificationDTOAssembler().toDomain(y.getPromoCustJobCreationalDTO()));
    }

    public List<PromoCustomerJobDTO> toDTOs(Set<PromoCustomerJob> arg0) {
        List<PromoCustomerJobDTO> res = new ArrayList<>();
        arg0.stream().filter(o -> DataStatus.ACTIVE.equals(o.getPromoCustJobStatus())).forEach((o) -> {
            res.add(toDTO(o));
        });
        return res;
    }

    public List<PromoCustomerJobDTO> toDTOs(List<PromoCustomerJob> arg0) {
        List<PromoCustomerJobDTO> res = new ArrayList<>();
        arg0.stream().filter(o -> DataStatus.ACTIVE.equals(o.getPromoCustJobStatus())).forEach((o) -> {
            res.add(toDTO(o));
        });
        return res;
    }

    public Set<PromoCustomerJob> toDomains(List<PromoCustomerJobDTO> arg0) {
        Set<PromoCustomerJob> res = new HashSet<>();
        arg0.stream().forEach((o) -> {
            res.add(toDomain(o));
        });
        return res;
    }
}