Package com.vst.model

Examples of com.vst.model.Hint


            throws Exception {

        request.setAttribute("questionList", questionManager.getQuestions(null));
        if (!isFormSubmission(request)) {
            String hintId = request.getParameter("hintId");
            Hint hint = null;
            if (!StringUtils.isEmpty(hintId)) {
                hint = hintManager.getHint(hintId);
                hintManager.evict(hint);
            } else {
                hint = new Hint();
            }
            if (request.getParameter("edited") != null) {
                request.setAttribute("addition", "?edited=1");
                hint.setEdited(true);
            }
            hint.setDocLocation(request.getParameter("docLocation"));

            return hint;
        }
        return super.formBackingObject(request);
    }
View Full Code Here


            throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'onSubmit' method...");
        }

        Hint hint = (Hint) command;
        boolean isNew = (hint.getHintId() == null);
        Locale locale = request.getLocale();

        if (request.getParameter("delete") != null) {
            hintManager.removeHint(hint.getHintId().toString());

            saveMessage(request, getText("hint.deleted", locale));
        } else {

            MultipartHttpServletRequest multipartRequest =
                    (MultipartHttpServletRequest) request;
            CommonsMultipartFile file =
                    (CommonsMultipartFile) multipartRequest.getFile("file");
            if (file.getSize() > 0) {
                String fileName = ImageUtil.getUniqueJPEGFile(request);
                FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + fileName);
                fileOutputStream.write(file.getBytes());
                fileOutputStream.close();
                InputStream imageStream = ImageUtil.scaleImage(new FileInputStream(FileHelper.getCurrentPath(request) + fileName), 200, 200);

                fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + fileName);
                byte[] bufer = new byte[62000];
                while (imageStream.read(bufer) != -1) {
                    fileOutputStream.write(bufer);
                }
                fileOutputStream.close();
                hint.setWayToPhoto(fileName);
                hint.setPhotoBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + fileName)));


                InputStream imageSmallStream = ImageUtil.scaleImage(new FileInputStream(FileHelper.getCurrentPath(request) + fileName), 50, 50);

                String fileSmallName = ImageUtil.getUniqueJPEGFile(request);
                fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + fileSmallName);
                bufer = new byte[62000];
                while (imageSmallStream.read(bufer) != -1) {
                    fileOutputStream.write(bufer);
                }
                fileOutputStream.close();
                hint.setWayToSmallPhoto(fileSmallName);
                hint.setPhotoSmallBlob(Hibernate.createBlob(new FileInputStream(FileHelper.getCurrentPath(request) + fileSmallName)));

            } else {
                if (!isNew) {
                    Hint curHint = hintManager.getHint(hint.getHintId().toString());
                    hint.setWayToSmallPhoto(curHint.getWayToSmallPhoto());
                    hint.setPhotoSmallBlob(curHint.getPhotoSmallBlob());
                    hint.setWayToPhoto(curHint.getWayToPhoto());
                    hint.setPhotoBlob(curHint.getPhotoBlob());
                    hintManager.evict(curHint);
                }
            }

            List questionList = hint.getQuestions();
View Full Code Here

    public ModelAndView processFormSubmission(HttpServletRequest request,
                                              HttpServletResponse response,
                                              Object command,
                                              BindException errors)
            throws Exception {
        Hint hint = (Hint) command;
        if (request.getParameter("addQuestion") != null) {
            hint.getQuestions().add(new Question());
            return new ModelAndView("hintForm", "hint", hint);
        }
        if (request.getParameter("deleteQuestion") != null) {
            hint.getQuestions().remove(hint.getQuestionNumber());
            return new ModelAndView("hintForm", "hint", hint);
        }


        return super.processFormSubmission(request,
View Full Code Here

            hints = hintManager.getHints(null);
            request.setAttribute("searchWord", "Укажите текст подсказки");

        } else {
            request.setAttribute("searchWord", request.getParameter("searchWord"));
            Hint hint = new Hint();
            hint.setContents(request.getParameter("searchWord"));
            if (("1".equals(request.getParameter("byFragments")))) {
                hint.setByFragments(true);
                request.setAttribute("byFragments", "true");
            }
            hints = hintManager.findHintsByName(hint);
        }
        //retrieving all smal photoes from the DB blobs to the files on HD
        for (int i = 0; i < hints.size(); i++) {
            Hint curHint = (Hint) hints.get(i);
            if (curHint.getWayToSmallPhoto() != null && !curHint.getWayToSmallPhoto().trim().equals("")) {
                FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + curHint.getWayToSmallPhoto());
                int c;
                InputStream inputStream = curHint.getPhotoSmallBlob().getBinaryStream();

                while ((c = inputStream.read()) != -1) {
                    fileOutputStream.write(c);
                }
                fileOutputStream.close();
View Full Code Here

        request = newGet("/editHint.html");
        request.addParameter("hintId", "1");

        mv = c.handleRequest(request, new MockHttpServletResponse());

        Hint hint = (Hint) mv.getModel().get(c.getCommandName());
        assertNotNull(hint);
        request = newPost("/editHint.html");
        super.objectToRequestParameters(hint, request);

        // update the form's fields and add it back to the request
View Full Code Here

        if (questionId != null) {
            hints = hintManager.getHintByQuestionId(questionId);
        }

        for (int i = 0; i < hints.size(); i++) {
            Hint hint = (Hint) hints.get(i);
            if (hint.getWayToPhoto() != null && !hint.getWayToPhoto().trim().equals("")) {
                File file = new File(FileHelper.getCurrentPath(httpServletRequest) + hint.getWayToPhoto());
                if (file.exists()) {
                    file.delete();
                }
                file.createNewFile();
                FileOutputStream fileOutputStream = new FileOutputStream(FileHelper.getCurrentPath(httpServletRequest) + hint.getWayToPhoto());
                Blob blob = hint.getPhotoBlob();
                byte[] bufer = new byte[62000];
                InputStream inputStream = blob.getBinaryStream();
                while (inputStream.read(bufer) != -1) {
                    fileOutputStream.write(bufer);
                }
View Full Code Here

        hintManager = null;
    }

    public void testGetHints() throws Exception {
        List results = new ArrayList();
        Hint hint = new Hint();
        results.add(hint);

        // set expected behavior on dao
        hintDao.expects(once()).method("getHints")
            .will(returnValue(results));
View Full Code Here

    }

    public void testGetHint() throws Exception {
        // set expected behavior on dao
        hintDao.expects(once()).method("getHint")
            .will(returnValue(new Hint()));
        Hint hint = hintManager.getHint(hintId);
        assertTrue(hint != null);
        hintDao.verify();
    }
View Full Code Here

        assertTrue(hint != null);
        hintDao.verify();
    }

    public void testSaveHint() throws Exception {
        Hint hint = new Hint();

        // set expected behavior on dao
        hintDao.expects(once()).method("saveHint")
            .with(same(hint)).isVoid();
View Full Code Here

        hintManager.saveHint(hint);
        hintDao.verify();
    }

    public void testAddAndRemoveHint() throws Exception {
        Hint hint = new Hint();

        // set required fields

        // set expected behavior on dao
        hintDao.expects(once()).method("saveHint")
            .with(same(hint)).isVoid();
        hintManager.saveHint(hint);
        hintDao.verify();

        // reset expectations
        hintDao.reset();

        hintDao.expects(once()).method("removeHint").with(eq(new Long(hintId)));
        hintManager.removeHint(hintId);
        hintDao.verify();

        // reset expectations
        hintDao.reset();
        // remove
        Exception ex = new ObjectRetrievalFailureException(Hint.class, hint.getHintId());
        hintDao.expects(once()).method("removeHint").isVoid();
        hintDao.expects(once()).method("getHint").will(throwException(ex));
        hintManager.removeHint(hintId);
        try {
            hintManager.getHint(hintId);
View Full Code Here

TOP

Related Classes of com.vst.model.Hint

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.