Package web

Source Code of web.AddressController

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web;

import domain.District;
import domain.Lpu;
import domain.address.AddressObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import utils.AddressManager;
import web.generic.CH;
import web.generic.GenericSFController;

/**
*
* @author petr
*/
public class AddressController extends GenericSFController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
        String addressParentId = hsr.getParameter("address");
        String lpuId = hsr.getParameter("lpu");
        String streetId = hsr.getParameter("street");
        String building = hsr.getParameter("building");
        String values = "";
        if (addressParentId != null){
            AddressObject ao = null;
            try{
                ao = CH.getOptional(getDao(), AddressObject.class, addressParentId);
            }catch(Exception ex){
            }
            if (ao != null) {
                List<AddressObject> childs = getDao().getChildList(ao);

                values += ao.getType().getLevel();
                for (int level = 3; level <= 5; level++) {
                    values += "=0;не выбран";
                    for (Iterator<AddressObject> it = childs.iterator(); it.hasNext();) {
                        AddressObject child = it.next();
                        if (child.getType().getLevel() == level) {
                            values += ";" + child.getId() + ";" + child.getSpecTitle();
                            it.remove();
                        }
                    }
                }

    //        values = values.length() > 0 ? values.substring(1) : "";
            }else{
                values += "=0;не выбран=0;не выбран=0;не выбран=0";
            }
        }else if (lpuId != null) {
            Lpu lpu = CH.getOptional(getDao(), Lpu.class, lpuId);
            List<District> districtList = getDao().getDistrictList(lpu);
            values +="0;не указан";
            for (District district : districtList) {
                values += ";" + district.getId() + ";" + district;
            }
        }else if (streetId != null && building != null && !building.isEmpty()) {
            AddressObject ao = CH.getOptional(getDao(), AddressObject.class, streetId);
            if (ao != null){
                District defaultDistrict = AddressManager.getDefaultDistrict(getDao(), ao.getId(), building);
//            values += defaultDistrict.getId() + ";" + defaultDistrict + "=";
//            values += defaultDistrict.getLpu().getId() + ";" + defaultDistrict.getLpu() + "=";
//            List<District> districts = getDao().getDistrictList(defaultDistrict.getLpu());
//            for (District district : districts) {
                if (defaultDistrict != null){
                    values += defaultDistrict.getId() + ";" +
                             defaultDistrict.getLpu().getId() + ";" +
                             defaultDistrict.getLpu() + " участок: " + defaultDistrict;
                }
            }
//            }
        }

        Map m = new HashMap();
        m.put("values", values);
        return new ModelAndView("address", m);
    }

    public int getValue(){
        return 1;
    }

}
TOP

Related Classes of web.AddressController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.