Package com.vst.model

Examples of com.vst.model.ConstructionExample


        Locale locale = request.getLocale();

        if (request.getParameter("delete") != null) {
            Integer exampleId = strength.getExampleId();
            //    strengthManager.removeStrength(strength.getPointId().toString());
            ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(exampleId.toString());
            constructionExample.getStrengthPoints().remove(strength);
//            constructionExampleManager.saveConstructionExample(constructionExample);
            saveMessage(request, getText("strength.deleted", locale));
        } else {
            //adding this point to the list of the construction example
            ConstructionExample constructionExample1 = constructionExampleManager.getConstructionExample(strength.getExampleId().toString());
            if (constructionExample1.getWayToPowerEsckiz() != null) {
                File eskizFile = new File(FileHelper.getCurrentPath(request) + constructionExample1.getWayToPowerEsckiz());
                if (eskizFile.exists()) {
                    constructionExample1.setPowerEsckizBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + constructionExample1.getWayToPowerEsckiz())));
                }
            }
            constructionExampleManager.saveConstructionExample(constructionExample1);
            constructionExampleManager.evict(constructionExample1);
            if (isNew) {
                Integer exampleId = strength.getExampleId();
                ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(exampleId.toString());
//                BuildingObject buildingObject=buildingObjectManager.getBuildingObject(constructionExample.getObjectId().toString());
                constructionExample.getStrengthPoints().add(strength);
                constructionExampleManager.saveConstructionExample(constructionExample);
//                buildingObjectManager.saveBuildingObject(buildingObject);
//                constructionExampleManager.saveConstructionExample(constructionExample);

                ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(constructionExample.getObjectConstructionId().toString());
                String fileName = FileHelper.getCurrentPath(request) + objectConstruction.getWayToDefectMap();
                paintStrength(constructionExample, strength, fileName,"save");


            } else {
                strengthManager.saveStrength(strength);


                Integer exampleId = strength.getExampleId();
                ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(exampleId.toString());
                ObjectConstruction objectConstruction = objectConstructionManager.getObjectConstruction(constructionExample.getObjectConstructionId().toString());
                String fileName = FileHelper.getCurrentPath(request) + objectConstruction.getWayToDefectMap();
                paintStrength(constructionExample, strength, fileName,"update");


            }
View Full Code Here


    public void setNewEskizToAllExamples(ObjectConstruction objectConstruction, HttpServletRequest request) throws IOException, SQLException {

        List constructionExamples = constructionExampleDao.getConstructionExamples(objectConstruction.getTypeId().toString());
        boolean hasEskiz = false;
        for (int i = 0; i < constructionExamples.size(); i++) {
            ConstructionExample constructionExample = (ConstructionExample) constructionExamples.get(i);
            if (constructionExample.getDefectEsckizBlob() != null) {
                hasEskiz = true;
                break;
            }
        }

        if (!hasEskiz) {
            //setting new esckiz blob to all examples
            for (int i = 0; i < constructionExamples.size(); i++) {
                Blob blob=Hibernate.createBlob(new FileInputStream(objectConstruction.getWayToEsckiz()));

                String wayToDefectEskiz = ImageUtil.getUniqueJPEGFile(request);

                File file = new File(wayToDefectEskiz);
                try {
                    file.createNewFile();
                } catch (IOException e) {

                }
                FileOutputStream fileOutputStream = new FileOutputStream(wayToDefectEskiz);
                byte[] bufer = new byte[62000];
                InputStream inputStream = blob.getBinaryStream();
                while (inputStream.read(bufer) != -1) {
                    fileOutputStream.write(bufer);
                }
               inputStream.close();
               fileOutputStream.close();

                String wayToPowerEskiz = ImageUtil.getUniqueJPEGFile(request);
                file = new File(wayToPowerEskiz);
                if (file.exists()) {
                    file.delete();
                }
                file.createNewFile();
                fileOutputStream = new FileOutputStream(wayToPowerEskiz);
                byte[] powerBufer = new byte[62000];
                blob=Hibernate.createBlob(new FileInputStream(objectConstruction.getWayToEsckiz()));

                inputStream = blob.getBinaryStream();
                while (inputStream.read(powerBufer) != -1) {
                    fileOutputStream.write(powerBufer);
                }
             inputStream.close();
               fileOutputStream.close();


                ConstructionExample constructionExample = (ConstructionExample) constructionExamples.get(i);
                constructionExample.setDefectEsckizBlob(Hibernate.createBlob(new FileInputStream(objectConstruction.getWayToEsckiz())));
                constructionExample.setWayToDefectEsckiz(wayToDefectEskiz);
                constructionExample.setWayToPowerEsckiz(wayToPowerEskiz);
                constructionExample.setPowerEsckizBlob(Hibernate.createBlob(new FileInputStream(objectConstruction.getWayToEsckiz())));
                constructionExampleDao.saveConstructionExample(constructionExample);
//                constructionExampleDao.evict(constructionExample);
            }
        }
    }
View Full Code Here

  private void doCopyDefect(HttpServletRequest request,
            HttpServletResponse response) throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException{
    String constructionDefectId = request.getParameter("copy");
        String exId = request.getParameter("exampleId");
        ConstructionExample constructionExample = constructionExampleManager.getConstructionExample(exId);

        if (request.getParameter("type").equals("simple")) {

            ConstructionDefect constructionDefect = constructionDefectManager.getConstructionDefect(constructionDefectId);
            ConstructionDefect newConstructionDefect = (ConstructionDefect) elementCopyManager.getNewObject(constructionDefect);

            constructionExample.getExampleDefects().add(newConstructionDefect);
            constructionDefectManager.saveConstructionDefect(newConstructionDefect);
            constructionExampleManager.saveConstructionExample(constructionExample);

        } else if (request.getParameter("type").equals("zone")) {


            ConstructionDefectZone constructionDefect = constructionDefectManager.getConstructionDefectZone(constructionDefectId);
            ConstructionDefectZone newConstructionDefect = (ConstructionDefectZone) elementCopyManager.getNewObject(constructionDefect);

            constructionExample.getExampleDefectsZone().add(newConstructionDefect);
            constructionDefectManager.saveConstructionDefectZone(newConstructionDefect);
            constructionExampleManager.saveConstructionExample(constructionExample);
        }
  }
View Full Code Here

    public void setConstructionExampleDao(ConstructionExampleDao dao) {
        this.dao = dao;
    }

    public void testAddConstructionExample() throws Exception {
        ConstructionExample constructionExample = new ConstructionExample();

        // set required fields

        dao.saveConstructionExample(constructionExample);

        // verify a primary key was assigned
        assertNotNull(constructionExample.getExampleId());

        // verify set fields are same after save
    }
View Full Code Here

        // verify set fields are same after save
    }

    public void testGetConstructionExample() throws Exception {
        ConstructionExample constructionExample = dao.getConstructionExample(constructionExampleId);
        assertNotNull(constructionExample);
    }
View Full Code Here

        ConstructionExample constructionExample = dao.getConstructionExample(constructionExampleId);
        assertNotNull(constructionExample);
    }

    public void testGetConstructionExamples() throws Exception {
        ConstructionExample constructionExample = new ConstructionExample();
//
//        List results = dao.getConstructionExamples(constructionExample);
//        assertTrue(results.size() > 0);
    }
View Full Code Here

//        List results = dao.getConstructionExamples(constructionExample);
//        assertTrue(results.size() > 0);
    }

    public void testSaveConstructionExample() throws Exception {
        ConstructionExample constructionExample = dao.getConstructionExample(constructionExampleId);

        // update required fields

        dao.saveConstructionExample(constructionExample);
View Full Code Here

        Map<Integer, ConstructionExample> ceMap =
          new HashMap<Integer, ConstructionExample>();
        for (Object n : rowList){
          Object[] cols = (Object[]) n;
          ConstructionExample ce = new ConstructionExample();
          ce.setExampleId((Integer) cols[0]);
          ce.setExampleRelativeNumber((Integer) cols[1]);
          ce.setExampleName((String) cols[2]);
          ce.setDangerCategory((DangerCategory) cols[3]);
          ce.setNoDeffects((Boolean) cols[4]);

          if (ce.getRecommendedDangerCategory() == null){
          DangerCategory dc = new DangerCategory();
          dc.setDangerCategoryId(-1);
          dc.setCategoryName("В");
          ce.setRecommendedDangerCategory(dc);
        }
          ce.setExampleDefects(null);
          ce.setDefectCount(new Integer(0));
          ce.setExampleDefects(new ArrayList<ConstructionDefect>());
          ceMap.put(ce.getExampleId(), ce);
          ceList.add(ce);
        }

        String hql2 =
          "select "+
        " cd.constructionDefectId, "+
        " cd.comment, "+
        " dt.defectTypeId, "+
        " dt.defectTypeName,"+
        " dv.varityId, "+
        " dv.varityName,"+
        " dz.defectZoneId, "+
        " dz.defectZoneName,"+
        " cd.dangerCategory,"+
        " cd.exampleId"+
        " from ConstructionDefectZone as cd left join cd.defectType as dt " +
        "  left join cd.defectZone as dz left join  cd.defectVarity as dv " +
        "  left join cd.dangerCategory";

        if (objectId != null || typeId != null) {
      hql2 = hql2 + "  where cd.exampleId in (select ce.exampleId " +
              " from ConstructionExample as ce where ";
      hql2 = hql2 + buildCondition(objectId, typeId) +")";
    }

        q = getSession().createQuery(hql2);
        presetParams(q, objectId, typeId);
        List res =  q.list();

          for (Object r : res){
            Object[] rescolumns = (Object[]) r;
            ConstructionDefect cd = new ConstructionDefect(
              (Integer) rescolumns[0], (String) rescolumns[1]);
            DefectType dt = new DefectType(
               (Integer) rescolumns[2], (String) rescolumns[3]);
            DefectVarity dv = new DefectVarity(
              (Integer) rescolumns[4], (String) rescolumns[5]);
            DefectZone dz = new DefectZone(
               (Integer) rescolumns[6], (String) rescolumns[7]);

            cd.setDefectType(dt);
            cd.setDefectVarity(dv);
            cd.setDefectZone(dz);
            cd.setDangerCategory((DangerCategory)rescolumns[8]);

            ConstructionExample ce =
              ceMap.get((Integer) rescolumns[9]);
            if (ce != null) {
              if (compareDangerCategory(cd.getDangerCategory(), ce.getRecommendedDangerCategory()) > 0){
                ce.setRecommendedDangerCategory(cd.getDangerCategory());
              }
              ce.getExampleDefects().add(cd);
              System.out.println("EXample defects size:"+ce.getExampleDefects().size());
              ce.setDefectCount(new Integer(ce.getExampleDefects().size()));
            }
          }
       return ceList;
  }
View Full Code Here

    /**
     * @see com.vst.dao.ConstructionExampleDao#getConstructionExample(Integer exampleId)
     */
    public ConstructionExample getConstructionExample(final Integer exampleId) {
        ConstructionExample constructionExample = (ConstructionExample) getHibernateTemplate().get(ConstructionExample.class, exampleId);
        if (constructionExample == null) {
            log.warn("uh oh, constructionExample with exampleId '" + exampleId + "' not found...");
            throw new ObjectRetrievalFailureException(ConstructionExample.class, exampleId);
        }

View Full Code Here

    /**
     * @see com.vst.dao.ConstructionExampleDao#removeConstructionExample(Integer exampleId)
     */
    public void removeConstructionExample(final Integer exampleId) {
        //TODO find out the way for auto-updating position fields after element deleting from collection
        ConstructionExample constructionExample=(ConstructionExample)getConstructionExample(exampleId);
        getHibernateTemplate().delete(constructionExample);
        super.getSession().createQuery("update ConstructionExample set constructionExamplePosition=constructionExamplePosition-1 where objectConstructionId=? AND constructionExamplePosition>?").setString(0, String.valueOf(constructionExample.getObjectConstructionId())).setString(1, String.valueOf(constructionExample.getConstructionExamplePosition())).executeUpdate();
    }
View Full Code Here

TOP

Related Classes of com.vst.model.ConstructionExample

Copyright © 2018 www.massapicom. 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.