Example usage for org.springframework.ui ModelMap ModelMap

List of usage examples for org.springframework.ui ModelMap ModelMap

Introduction

In this page you can find the example usage for org.springframework.ui ModelMap ModelMap.

Prototype

public ModelMap(String attributeName, @Nullable Object attributeValue) 

Source Link

Document

Construct a new ModelMap containing the supplied attribute under the supplied name.

Usage

From source file:org.agatom.springatom.cmp.wizards.data.result.WizardResult.java

public WizardResult addDebugData(final String attr, final Object value) {
    if (this.debugData == null) {
        this.debugData = new ModelMap(attr, value);
    } else {/*  www .j a v a 2  s.  c  om*/
        this.debugData.addAttribute(attr, value);
    }
    return this;
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/register", method = RequestMethod.POST)
@Timed//from  w w w  .j  a v  a 2s.com
@ExceptionMetered
public ModelMap register(@RequestBody MultiValueMap<String, String> params, HttpSession session,
        HttpServletResponse resp) {
    // Check thirdParty Pin
    String thirdParty = params.getFirst("tpPin");
    if (thirdParty == null) {
        invalidCredentials(resp);
        return null;
    }
    thirdParty = thirdParties.getProperty(thirdParty);
    if (thirdParty == null) {
        invalidCredentials(resp);
        return null;
    }

    // Check email
    String email = params.getFirst("email");
    if (email == null) {
        invalidCredentials(resp);
        return null;
    }
    email = EmailUtils.normalizeEmail(email);

    // Check googlePassword
    String googlePassword = params.getFirst("googlePassword");
    if (googlePassword == null) {
        googlePassword = params.getFirst("password");
    }
    if (googlePassword == null) {
        invalidCredentials(resp);
        return null;
    }

    User user = service.getUser(email);
    if (user == null) {
        user = new User(email);
        user.setPassword(params.getFirst("password"));
        user.setGvPassword(Boolean.parseBoolean(params.getFirst("gvPassword")));
    }
    if (user.getPassword() == null) {
        invalidCredentials(resp);
        return null;
    }

    // Monitors
    if (params.getFirst("monitorSMS") != null) {
        user.setMonitorSMS(Boolean.parseBoolean(params.getFirst("monitorSMS")));
    }
    if (params.getFirst("monitorVM") != null) {
        user.setMonitorVM(Boolean.parseBoolean(params.getFirst("monitorVM")));
    }
    if (params.getFirst("monitorMC") != null) {
        user.setMonitorMC(Boolean.parseBoolean(params.getFirst("monitorMC")));
    }

    // Notifiers
    extractUserFromForm(user, params);

    try {
        RegistrationInfo info = service.register(user, googlePassword);
        if (info.isRegistered()) {
            String message = "You are receiving this email because " + thirdParty
                    + " has registered your account with GVMax\n"
                    + "GVMax is a service used to monitor GoogleVoice and provide notifications for incoming SMS and Voicemail\n"
                    + "GVMax also provides other services such as sending Group SMS's and integration with GoogleTalk, Twitter etc...\n"
                    + "You can view your account at https://www.gvmax.com\n" + "username: " + user.getEmail()
                    + "\n";
            if (info.isAlreadyRegistered()) {
                message = "You are receiving this email because " + thirdParty
                        + " has modified your account at GVMax\n"
                        + "You can view your account at https://www.gvmax.com\n" + "username: "
                        + user.getEmail() + "\n";
            }
            if (user.isGvPassword()) {
                message += "password: your google voice password\n";
            } else {
                message += "password: " + user.getPassword() + "\n";
            }

            try {
                relay.sendEmail(relay.getEmailSender(), relay.getEmailSender(), user.getEmail(),
                        "Welcome to GVMax", message);
            } catch (Exception e) {
                logger.warn("Unable to send email: " + e.getMessage());
            }
        }
        return new ModelMap("info", info);
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/unregister", method = RequestMethod.POST)
@Timed//w  w  w.  jav  a2 s .  c om
@ExceptionMetered
public ModelMap unregister(@RequestParam(value = "pin", required = false) String pin, HttpSession session,
        HttpServletResponse resp) {
    try {
        User user = getUser(service, session, pin);
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }
        service.unregister(user.getEmail());
        logout(session);
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
    }
    return null;
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/monitors", method = RequestMethod.POST)
@Timed/*w w  w.j a v a 2s .com*/
@ExceptionMetered
public ModelMap monitors(@RequestBody MultiValueMap<String, String> params, HttpSession session,
        HttpServletResponse resp) {
    try {
        String pin = params.getFirst("pin");
        User user = getUser(service, session, pin);
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }
        boolean monitorSMS = Boolean.parseBoolean(params.getFirst("monitorSMS"));
        boolean monitorVM = Boolean.parseBoolean(params.getFirst("monitorVM"));
        boolean monitorMC = Boolean.parseBoolean(params.getFirst("monitorMC"));
        service.setMonitors(user.getEmail(), monitorSMS, monitorVM, monitorMC);
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/notifiers", method = RequestMethod.POST)
@Timed/*from  w w w  .  j av a 2s.c  om*/
@ExceptionMetered
public ModelMap notifiers(@RequestBody MultiValueMap<String, String> params, HttpSession session,
        HttpServletResponse resp) {
    try {
        User user = getUser(service, session, params.getFirst("pin"));
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }

        extractUserFromForm(user, params);

        try {
            service.setNotifiers(user);
            return new ModelMap("result", "ok");
        } catch (IOException e) {
            sendError(400, e.getMessage(), resp);
            return null;
        }
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/enableGV", method = RequestMethod.POST)
@Timed//from  ww w.j av a 2 s .c  om
@ExceptionMetered
public ModelMap enableGV(@RequestParam(value = "password") String password,
        @RequestParam(value = "pin", required = false) String pin, HttpSession session,
        HttpServletResponse resp) {
    try {
        User user = getUser(service, session, pin);
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }
        service.changePassword(user.getEmail(), password, true);
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    } catch (IOException e) {
        sendError(400, e.getMessage(), resp);
        return null;
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/forgotPassword", method = RequestMethod.POST)
@Timed//from   www. j a  v a  2s  . co m
@ExceptionMetered
public ModelMap forgotPassword(@RequestParam(value = "email") String email, HttpServletResponse resp) {
    try {
        service.forgotPassword(email);
        return new ModelMap("response", "ok");
    } catch (Exception e) {
        logger.warn(e);
        internalError(e, resp);
        return null;
    }
}

From source file:com.gvmax.web.api.WebAppAPI.java

@RequestMapping(value = "/changePassword", method = RequestMethod.POST)
@Timed//w ww.  ja  v a  2  s  . com
@ExceptionMetered
public ModelMap changePassword(@RequestParam(value = "pin", required = false) String pin,
        @RequestParam(value = "old_password", required = false) String oldPassword,
        @RequestParam(value = "new_password") String newPassword, HttpSession session,
        HttpServletResponse resp) {
    try {
        User user = getUser(service, session, pin);
        if (user == null) {
            invalidCredentials(resp);
            return null;
        }
        if (user.isGvPassword()) {
            sendError(400, "user is using google voice password. Cannot change password via api.", resp);
            return null;
        }
        if (!user.getPassword().equals(oldPassword)) {
            invalidCredentials(resp);
            return null;
        }
        if (StringUtils.isBlank(newPassword)) {
            invalidCredentials(resp);
            return null;
        }
        service.changePassword(user.getEmail(), newPassword, false);
        return new ModelMap("result", "ok");
    } catch (DataAccessException e) {
        internalError(e, resp);
        return null;
    } catch (IOException e) {
        sendError(400, e.getMessage(), resp);
        return null;
    }
}

From source file:org.esupportail.portlet.filemanager.portlet.PortletControllerAjax.java

private ModelAndView upload(String dir, String filename, InputStream inputStream, Locale locale,
        UploadActionType uploadOption) {
    boolean success = true;
    String text = "";
    try {//from   w w w  .j  av a 2 s .  co m
        if (this.serverAccess.putFile(dir, filename, inputStream, userParameters, uploadOption)) {
            String msg = context.getMessage("ajax.upload.ok", null, locale);
            text = "{'success':'true', 'msg':'".concat(msg).concat("'}");
            log.info("upload file " + filename + " in " + dir + " ok");
        } else {
            success = false;
        }
    } catch (Exception e) {
        log.error("error uploading file " + filename + " in " + dir, e);
        success = false;
    }
    if (!success) {
        log.info("Error uploading file " + filename + " in " + dir);
        String msg = context.getMessage("ajax.upload.failed", null, locale);
        text = "{'success':'false', 'msg':'".concat(msg).concat("'}");
    }
    ModelMap model = new ModelMap("text", text);
    return new ModelAndView("text", model);
}