Package com.vst.service.impl

Source Code of com.vst.service.impl.ConstructionExampleManagerImpl

package com.vst.service.impl;

import com.vst.dao.ConstructionExampleDao;
import com.vst.model.ConstructionExample;
import com.vst.model.ConstructionType;
import com.vst.model.DangerCategory;
import com.vst.service.ConstructionExampleManager;
import com.vst.util.BeanUtils;

import java.util.List;
import java.util.Properties;
import java.io.IOException;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class ConstructionExampleManagerImpl extends BaseManager implements ConstructionExampleManager {
    private ConstructionExampleDao dao;

    public ConstructionExample getConstructionExampleForBreadCrump(String exampleId){
        return dao.getConstructionExampleForBreadCrump(exampleId);
    }

    public List fillConstractionExampleData(List constructionExamples , Integer exampleId){
        for (int i = 0; i < constructionExamples.size(); i++) {

            ConstructionExample constructionExample =  (ConstructionExample)constructionExamples.get(i);

            if(constructionExample.getExampleId().equals(exampleId))    {
               constructionExample.setExampleDefects(dao.getExampleDefectsById(exampleId));
               constructionExample.setExampleDefectsZone(dao.getExampleDefectsZoneById(exampleId));
            }
            long size=dao.getExampleDefectCount(constructionExample.getExampleId().toString()).longValue()+dao.getExampleDefectZoneCount(constructionExample.getExampleId().toString()).longValue();
                constructionExample.setDefectCount((int)size);
                constructionExample.setRecommendedDangerCategory(getConstructionRecommendedDangerCategory(constructionExample.getExampleId().toString()));

         }
        return constructionExamples;
    }

   /* public List fillRecomendedDangerCategories(List constructionExamples){
        for (int i = 0; i < constructionExamples.size(); i++) {
            ConstructionExample constructionExample =  (ConstructionExample)constructionExamples.get(i);
            constructionExample.setRecommendedDangerCategory(getConstructionRecommendedDangerCategory(constructionExample.getExampleId().toString()));
         }
        return constructionExamples;
    }
         */
    public DangerCategory getConstructionRecommendedDangerCategory(String exampleId){
        return dao.getConstructionRecommendedDangerCategory(exampleId);
    }


    /**
     * Set the Dao for communication with the data layer.
     * @param dao
     */
    public void setConstructionExampleDao(ConstructionExampleDao dao) {
        this.dao = dao;
    }




    public List getConstructionExamples(final String typeId) {
        return dao.getConstructionExamples(typeId);
    }

    public List getConstructionExamplesLite(final String typeId, String destination) {
        return dao.getConstructionExamplesLite(typeId, destination);
    }


    public List getConstructionExamplesForObject(String objectId){
        return dao.getConstructionExamplesForObject(objectId);
    }

    public List getConstructionExamplesForTable(Integer objectId, Integer typeId){
      return dao.getConstructionExamplesForTable(objectId, typeId);
    }

    public void makeNotNull(ConstructionExample constructionExample){
        if(constructionExample.getConstructionType()==null){
            constructionExample.setConstructionType(new ConstructionType());
        }
        if(constructionExample.getDangerCategory()==null){
            constructionExample.setDangerCategory(new DangerCategory());
        }
        if(constructionExample.getRecommendedDangerCategory()==null){
            constructionExample.setRecommendedDangerCategory(new DangerCategory());
        }



    }

    public Integer getMaxId(){
        return dao.getMaxId();
    }

    /**
     * @see com.vst.service.ConstructionExampleManager#getConstructionExample(String exampleId)
     */
    public ConstructionExample getConstructionExample(final String exampleId) {
        return dao.getConstructionExample(new Integer(exampleId));
    }

    /**
     * @see com.vst.service.ConstructionExampleManager#saveConstructionExample(ConstructionExample constructionExample)
     */
    public void saveConstructionExample(ConstructionExample constructionExample) {
        dao.saveConstructionExample(constructionExample);
    }

    /**
     * @see com.vst.service.ConstructionExampleManager#removeConstructionExample(String exampleId)
     */
    public boolean removeConstructionExample(final String exampleId) {
        dao.removeConstructionExample(new Integer(exampleId));
        return true;
    }

     public boolean isInspectionSpent(Integer buildingId, String currentPath) throws IOException, SQLException {
        BasicDataSource basicDataSource = (BasicDataSource) BeanUtils.getBean("dataSource", currentPath);
        Properties props = new Properties();
        props.setProperty("driver.url", "jdbc:mysql://localhost/vstbase");
        props.setProperty("driver.class", basicDataSource.getDriverClassName());
        props.setProperty("user", basicDataSource.getUsername());
        props.setProperty("password", basicDataSource.getPassword());

        List list = dao.getExamplesWithNoDefects(buildingId, props);
        System.out.println("LIST SIZEEEEEE ==== "+list.size());

        for (int i = 0; i < list.size(); i++) {
            System.out.println("EXAMPLE == "+list.get(i).toString()+"  SIZE === "+(dao.getExampleDefectCount(list.get(i).toString()).longValue()+dao.getExampleDefectZoneCount(list.get(i).toString()).longValue()));
            if ((dao.getExampleDefectCount(list.get(i).toString()).longValue()+dao.getExampleDefectZoneCount(list.get(i).toString()).longValue())==0){

                System.out.println("False!!!!!");
                return false;
            }
        }


        return true;
    }


    public Integer getExampleNumberByConstructionObjectId(Integer objectConstructionId){
        return dao.getExampleNumberByConstructionObjectId(objectConstructionId);
    }

  public void copyExample(Integer srcExampleId, int copyNumber) {
    dao.copyExample(srcExampleId, copyNumber);
  }

}
TOP

Related Classes of com.vst.service.impl.ConstructionExampleManagerImpl

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.