/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package services;
import dao.DAO;
import domain.District;
import domain.Lpu;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Required;
import services.utils.DistrictConvertor;
import services.utils.LpuConvertor;
import utils.AddressManager;
/**
*
* @author petr
*/
public class DistrictUpdater {
private DAO dao;
public List<DistrictConvertor> getDistrictList(int lpuId){
ArrayList<DistrictConvertor> districts = new ArrayList<DistrictConvertor>();
districts.add(new DistrictConvertor());
Lpu lpu = getDao().getById(Lpu.class, lpuId);
if (lpu != null){
List<District> districtList = getDao().getDistrictList(lpu);
for (District district : districtList) {
districts.add(new DistrictConvertor(district));
}
}
return districts;
}
public DistrictConvertor getDefaultDistrict(int streetId, String building){
District district = AddressManager.getDefaultDistrict(getDao(), streetId, building);
if (district != null){
Lpu lpu = district.getLpu();
DistrictConvertor dc = new DistrictConvertor(district);
dc.setLpu(new LpuConvertor(lpu));
return dc;
}else{
return null;
}
}
public DAO getDao() {
return dao;
}
@Required
public void setDao(DAO dao) {
this.dao = dao;
}
}