Package com.vst.webapp.action

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

package com.vst.webapp.action;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;

import com.vst.Constants;
import com.vst.model.ConstructionExample;
import com.vst.model.ObjectConstruction;
import com.vst.service.ObjectConstructionManager;
import com.vst.util.FileHelper;

public class AllExamplesEskizController extends AbstractVstController {
  protected static final Log log = LogFactory.getLog(AllExamplesEskizController.class);
    private ObjectConstructionManager objectConstructionManager = null;

    public void setObjectConstructionManager(ObjectConstructionManager objectConstructionManager) {
        this.objectConstructionManager = objectConstructionManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'handleRequest' method...");
        }

        String objectConstructionId = request.getParameter("objectConstructionId");
        List waysToEskiz = new ArrayList();
        Map wayMap;
        boolean noPhoto = true;
        if (objectConstructionId != null) {
            ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(objectConstructionId);
            List constructionExampleList = objectConstruction.getConstructionExamples();
            for (int i = 0; i < constructionExampleList.size(); i++) {
                ConstructionExample constructionExample = (ConstructionExample) constructionExampleList.get(i);
                if (constructionExample.getWayToDefectEsckiz() != null && !"".equals(constructionExample.getWayToDefectEsckiz()) && constructionExample.getDefectEsckizBlob() != null) {
                    noPhoto = false;
                    File file = new File(FileHelper.getCurrentPath(request) + constructionExample.getWayToDefectEsckiz());
                    if (file.exists()) {
                        file.delete();
                    }
                    file.createNewFile();
                    FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + constructionExample.getWayToDefectEsckiz());
                    Blob blob = constructionExample.getDefectEsckizBlob();
                    byte[] bufer = new byte[62000];
                    InputStream inputStream = blob.getBinaryStream();
                    while (inputStream.read(bufer) != -1) {
                        fileOutputStream.write(bufer);
                    }
                    inputStream.close();
                    fileOutputStream.close();
                }
                wayMap = new HashMap();
                wayMap.put("way", constructionExample.getWayToDefectEsckiz());
                wayMap.put("comment", constructionExample.getExampleName() == null ? String.valueOf(constructionExample.getExampleRelativeNumber()) : constructionExample.getExampleName());
                waysToEskiz.add(wayMap);
            }
            request.setAttribute("noPhoto", new Boolean(noPhoto));
            return new ModelAndView("allExamplesEskiz", Constants.EXAMPLE_ESKIZ_WAYS, waysToEskiz);

        } else {
            request.setAttribute("noObjectConstruction", "true");
        }
        return new ModelAndView("allExamplesEskiz");


    }
}
TOP

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

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.