Example usage for javax.persistence NoResultException toString

List of usage examples for javax.persistence NoResultException toString

Introduction

In this page you can find the example usage for javax.persistence NoResultException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:net.fenyo.mail4hotspot.web.WebController.java

@RequestMapping(value = "/mobile-get-user", method = RequestMethod.POST)
public ModelAndView mobileGetUserPost(@RequestParam(value = "username", required = false) final String username,
        @RequestParam(value = "password", required = false) final String password,
        @RequestParam(value = "info", required = false) final String info, final ModelMap model) {
    log.info("TRACE: mobile-get-user;post;" + username + ";" + password + ";" + info + ";");

    ModelAndView mav = new ModelAndView();
    mav.setViewName("mobile-action-getuser");

    mav.addObject("provider", "");
    mav.addObject("email", "");
    mav.addObject("login", "");
    mav.addObject("uuid", "");
    try {/*from   ww  w  . j  av  a 2 s  .co m*/
        final User user = generalServices.getUser(username);
        if (user.getPassword().equals(password) == false) {
            log.info("TRACE: mobile-get-user;invalid password;" + username + ";" + password + ";" + info + ";");
            mav.addObject("statusCode", 1);
            mav.addObject("statusString", "invalid password");
            mav.addObject("uuid", "");
            final Account account = generalServices.getFirstAccount(username);

            generalServices.sendInternalMailByAccount(account, "Warning message from VPN-over-DNS",
                    "Dear customer,\n\nThis is to inform you that there was an attempt to log on your VPN-over-DNS account with an invalid password.\n\n-- The VPN-over-DNS support team.");
        } else {
            log.info("TRACE: mobile-get-user;password checked;" + username + ";" + password + ";" + info + ";");
            final Account account = generalServices.getFirstAccount(username);
            if (account != null && account.getProvider() != Provider.NOT_INITIALIZED) {
                mav.addObject("provider", account.getProvider());
                mav.addObject("email", URLEncoder.encode(account.getEmail(), "UTF-8"));
                mav.addObject("login", URLEncoder.encode(account.getUsername(), "UTF-8"));
            }
            mav.addObject("statusCode", 0);
            mav.addObject("statusString", "OK");
            mav.addObject("uuid", user.getUuid());

            // fenyoa is used to check the service every minute, so no new mail every minute for him
            if (!user.getUsername().equals("fenyoa"))
                generalServices.sendInternalMailByAccount(account, "Welcome back at VPN-over-DNS !",
                        "Dear customer,\n\nThis is to confirm that you have successfully logged on your VPN-over-DNS account.\n\n-- The VPN-over-DNS support team.");
        }
    } catch (final NoResultException ex) {
        log.info("TRACE: mobile-get-user;no such user;" + username + ";" + password + ";" + info + ";");
        log.warn(ex);
        mav.addObject("statusCode", 2);
        mav.addObject("statusString", "no such user");
        mav.addObject("uuid", "");
    } catch (final Exception ex) {
        log.info("TRACE: mobile-get-user;exception;" + username + ";" + password + ";" + info + ";");
        log.warn(ex);
        mav.addObject("statusCode", 3);
        mav.addObject("statusString", ex.toString());
        mav.addObject("uuid", "");
    }

    return mav;
}

From source file:net.fenyo.mail4hotspot.web.WebController.java

@RequestMapping(value = "/mobile-set-user", method = RequestMethod.POST)
public ModelAndView mobileSetUserPost(@RequestParam(value = "username", required = false) final String username,
        @RequestParam(value = "password", required = false) final String password,
        @RequestParam(value = "provider", required = false) final String provider_string,
        @RequestParam(value = "provider_email", required = false) final String provider_email,
        @RequestParam(value = "provider_login", required = false) final String provider_login,
        @RequestParam(value = "provider_password", required = false) final String provider_password,
        @RequestParam(value = "info", required = false) final String info, final ModelMap model) {
    log.info("TRACE: mobile-set-user;post;" + username + ";" + password + ";" + info + ";" + provider_string
            + ";" + provider_email + ";" + provider_login + ";" + provider_password + ";");

    ModelAndView mav = new ModelAndView();
    mav.setViewName("mobile-action-createuser");

    try {//w w w . j av  a 2s .  co m
        Account.Provider provider = null;
        if (provider_string.equals("GMAIL"))
            provider = Provider.GMAIL;
        if (provider_string.equals("HOTMAIL"))
            provider = Provider.HOTMAIL;
        if (provider_string.equals("OPERAMAIL"))
            provider = Provider.OPERAMAIL;
        if (provider_string.equals("YAHOO"))
            provider = Provider.YAHOO;
        if (provider_string.equals("TESTIMAPLOCALHOST"))
            provider = Provider.TESTIMAPLOCALHOST;
        if (provider_string.equals("TESTIMAPRSI"))
            provider = Provider.TESTIMAPRSI;
        if (provider_string.equals("TESTPOPLOCALHOST"))
            provider = Provider.TESTPOPLOCALHOST;
        if (provider_string.equals("TESTPOPRSI"))
            provider = Provider.TESTPOPRSI;
        if (provider == null) {
            log.info("TRACE: mobile-set-user;bad provider;" + username + ";" + password + ";" + info + ";"
                    + provider_string + ";" + provider_email + ";" + provider_login + ";" + provider_password
                    + ";");
            mav.addObject("statusCode", 253);
            mav.addObject("statusString", "bad provider");
        } else {
            final int statusCode = generalServices.setUser(username, password, provider, provider_email,
                    provider_login, provider_password);
            mav.addObject("statusCode", statusCode);
            switch (statusCode) {
            case 0:
                log.info("TRACE: mobile-set-user;done;" + username + ";" + password + ";" + info + ";"
                        + provider_string + ";" + provider_email + ";" + provider_login + ";"
                        + provider_password + ";");
                mav.addObject("statusString", "OK");
                break;

            case 1:
                log.info("TRACE: mobile-set-user;invalid password;" + username + ";" + password + ";" + info
                        + ";" + provider_string + ";" + provider_email + ";" + provider_login + ";"
                        + provider_password + ";");
                mav.addObject("statusString", "invalid password");
                break;

            default:
                log.info("TRACE: mobile-set-user;invalid status code;" + username + ";" + password + ";" + info
                        + ";" + provider_string + ";" + provider_email + ";" + provider_login + ";"
                        + provider_password + ";");
                mav.addObject("statusString", "should not be there");
                break;
            }
        }
    } catch (final NoResultException ex) {
        log.info("TRACE: mobile-set-user;no such user;" + username + ";" + password + ";" + info + ";"
                + provider_string + ";" + provider_email + ";" + provider_login + ";" + provider_password
                + ";");
        log.warn(ex);
        mav.addObject("statusCode", 254);
        mav.addObject("statusString", "no such user");
    } catch (final Exception ex) {
        log.info("TRACE: mobile-set-user;exception;" + username + ";" + password + ";" + info + ";"
                + provider_string + ";" + provider_email + ";" + provider_login + ";" + provider_password
                + ";");
        log.warn(ex);
        mav.addObject("statusCode", 255);
        mav.addObject("statusString", ex.toString());
    }

    return mav;
}