PromoPosAssembler.java 2.26 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 63 64 65 66
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.PromoPosDTO;
import com.eksad.masterdata.domain.CreationalSpecification;
import com.eksad.masterdata.domain.PromoPos;

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

public class PromoPosAssembler implements IObjectAssembler<PromoPos, PromoPosDTO> {

    @Override
    public PromoPosDTO toDTO(PromoPos x) {
        return new PromoPosDTO(
                x.getPosServiceID(),
                x.getPosServiceName(),
                x.getPromoPosID(),
                x.getPromoPosStatus(),
                x.getPromoID(),
                x.getAhassID(),
                x.getPromoPosCreational() == null ? new CreationalSpecificationDTO() : new CreationalSpecificationDTOAssembler().toDTO(x.getPromoPosCreational())
        );
    }

    @Override
    public PromoPos toDomain(PromoPosDTO y) {
        return new PromoPos(
                y.getPosServiceID(),
                y.getPosServiceName(),
                y.getPromoPosID(),
                y.getPromoPosStatus(),
                y.getPromoID(),
                y.getAhassID(),
                y.getPromoPosCreationalDTO() == null ? new CreationalSpecification() : new CreationalSpecificationDTOAssembler().toDomain(y.getPromoPosCreationalDTO())
        );
    }

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

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

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