Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package cz.muni.pa165.carparkapp.serviceImpl; import cz.muni.pa165.carparkapp.DAO.BranchDAO; import cz.muni.pa165.carparkapp.Entities.Branch; import cz.muni.pa165.carparkapp.dto.BranchDTO; import cz.muni.pa165.carparkapp.service.BranchService; import java.util.ArrayList; import java.util.List; import org.dozer.DozerBeanMapper; import org.dozer.Mapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * * @author Michal Petko */ @Component("branchService") public class BranchServiceImpl implements BranchService { @Autowired private BranchDAO branchDAO; private final Mapper mapper = new DozerBeanMapper(); public BranchDAO getBranchDAO() { return branchDAO; } public void setBranchDAO(BranchDAO branchDAO) { this.branchDAO = branchDAO; } @Override public BranchDTO addBranch(BranchDTO branchdto) { if (branchdto == null) throw new NullPointerException("Argument cannot be null"); Branch branch = mapper.map(branchdto, Branch.class); branchDAO.createBranch(branch); branchdto.setId(branch.getId()); return branchdto; } @Override public boolean deleteBranch(BranchDTO branchdto) { if (branchdto == null) throw new NullPointerException("Argument cannot be null"); Branch branch = mapper.map(branchdto, Branch.class); boolean result = branchDAO.deleteBranch(branch); return result; } @Override public boolean updateBranch(BranchDTO branchdto) { if (branchdto == null) throw new NullPointerException("Argument cannot be null"); Branch branch = mapper.map(branchdto, Branch.class); return branchDAO.updateBranch(branch); } @Override public BranchDTO findBranch(int id) { if (id < 0) throw new IllegalArgumentException("Argument cannot be negative"); Branch branch = branchDAO.findBranch(id); return mapper.map(branch, BranchDTO.class); } @Override public List<BranchDTO> findAllBranches() { List<BranchDTO> list = new ArrayList<>(); List<Branch> tempList = branchDAO.getAllBranches(); for (Branch b : tempList) list.add(mapper.map(b, BranchDTO.class)); return list; } }