Package com.vst.webapp.action

Source Code of com.vst.webapp.action.MenuController

package com.vst.webapp.action;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.vst.service.BuildingObjectManager;
import com.vst.dto.BuildingObjectTypeDTO;
import com.vst.model.BuildingObject;
import com.vst.model.ObjectConstruction;

import java.util.List;
import java.util.ArrayList;
import java.io.File;

/**
* Created by IntelliJ IDEA.
* User: ALEXEI
* Date: 06.07.2008
* Time: 11:50:43
* To change this template use File | Settings | File Templates.
*/
public class MenuController implements Controller {

    private BuildingObjectManager buildingObjectManager = null;

    public void setBuildingObjectManager(BuildingObjectManager buildingObjectManager) {
        this.buildingObjectManager = buildingObjectManager;
    }

    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        List buildingObjects = buildingObjectManager.getBuildingObjects(null);
        List buildingObjectTypes = new ArrayList();
        String currentRegion = "";
        BuildingObjectTypeDTO buildingObjectTypeDTO = new BuildingObjectTypeDTO();

        for (int i = 0; i < buildingObjects.size(); i++) {
            BuildingObject buildingObject = (BuildingObject) buildingObjects.get(i);

            List objectConstructionList = buildingObject.getConstructionTypes();
            for (int j = 0; j < objectConstructionList.size(); j++) {
                ObjectConstruction objectConstruction = (ObjectConstruction) objectConstructionList.get(j);
                if (objectConstruction.getDescription() != null) {
                    objectConstruction.setBriefDescription(objectConstruction.getDescription().length() > 10 ? objectConstruction.getDescription().substring(0, 9) + "..." : objectConstruction.getDescription());
                }
            }
        }


        for (int i = 0; i < buildingObjects.size(); i++) {
            BuildingObject buildingObject = (BuildingObject) buildingObjects.get(i);
            if (i == 0 || (!currentRegion.equals(buildingObject.getRegion()) && !(currentRegion == null) && !currentRegion.trim().equals(""))) {
                if (i != 0) {
                    buildingObjectTypes.add(buildingObjectTypeDTO);
                }
                buildingObjectTypeDTO = new BuildingObjectTypeDTO();
                currentRegion = buildingObject.getRegion();
                buildingObjectTypeDTO.setObjectType(currentRegion);
            }
            buildingObjectTypeDTO.getBuildingObjects().add(buildingObject);


        }
        buildingObjectTypeDTO.setObjectType(currentRegion);
        buildingObjectTypes.add(buildingObjectTypeDTO);

        httpServletRequest.setAttribute("buildingObjectTypes", buildingObjectTypes);


        return new ModelAndView("test");
    }
}
TOP

Related Classes of com.vst.webapp.action.MenuController

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.