Example usage for org.springframework.ui Model asMap

List of usage examples for org.springframework.ui Model asMap

Introduction

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

Prototype

Map<String, Object> asMap();

Source Link

Document

Return the current set of model attributes as a Map.

Usage

From source file:org.asqatasun.webapp.controller.ForgottenOrChangePasswordController.java

/**
 * /*  www  . ja va  2  s  . co m*/
 * @param email
 * @param token
 * @param model
 * @param request
 * @return 
 */
private String displayChangePasswordView(String id, String token, Model model, HttpServletRequest request) {
    Long userId;
    try {
        userId = Long.valueOf(id);
    } catch (NumberFormatException nfe) {
        throw new ForbiddenUserException();
    }
    if (StringUtils.isBlank(token)) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME;
    }
    User currentUser = getCurrentUser();
    User user;
    // if the change password request comes from an authentied user or from
    // an admin
    if (token.equalsIgnoreCase(TgolKeyStore.AUTHENTICATED_KEY)) {
        if (currentUser == null
                || (!currentUser.getId().equals(userId)
                        && !currentUser.getRole().getRoleName().equals(TgolKeyStore.ROLE_ADMIN_NAME_KEY))
                || forbiddenUserList.contains(currentUser.getEmail1())) {
            return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME;
        } else {
            if (!currentUser.getId().equals(userId)) {
                user = getUserDataService().read(userId);
            } else {
                user = currentUser;
            }
        }
        // the request is submitted through an unauthentified user and the token
        // has to be checked.
    } else {
        user = getUserDataService().read(userId);
        try {
            // if the token is invalid
            if (!tokenManager.checkUserToken(user.getEmail1(), token)) {
                model.addAttribute(TgolKeyStore.INVALID_CHANGE_PASSWORD_URL_KEY, true);
                return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME;
            } else {
                // if the token is valid but the request comes from the 
                // form submission with success
                Object passwordModified = model.asMap().get(TgolKeyStore.PASSWORD_MODIFIED_KEY);
                if (passwordModified instanceof Boolean && (Boolean) passwordModified) {
                    tokenManager.setTokenUsed(token);
                    return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME;
                }
            }
        } catch (ArrayIndexOutOfBoundsException aioobe) {
            model.addAttribute(TgolKeyStore.INVALID_CHANGE_PASSWORD_URL_KEY, true);
            return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME;
        }
    }
    if (user == null) {
        return TgolKeyStore.ACCESS_DENIED_VIEW_REDIRECT_NAME;
    }
    ChangePasswordCommand cpc = new ChangePasswordCommand();
    model.addAttribute(TgolKeyStore.CHANGE_PASSWORD_COMMAND_KEY, cpc);
    model.addAttribute(TgolKeyStore.USER_NAME_KEY, user.getEmail1());
    request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, user.getId());
    return TgolKeyStore.CHANGE_PASSWORD_VIEW_NAME;
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of setUpSignUpPage method, of class SignUpController.
 *///from  ww w. java2  s  .  c  o  m
public void testSetUpSignUpPage() {
    System.out.println("setUpSignUpPage");

    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    String result = instance.setUpSignUpPage(model);
    // the returned view is the sign-up view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of submitForm method, of class SignUpController.
 * @throws java.lang.Exception//ww w .jav  a 2 s .  co m
 */
public void testSubmitForm() throws Exception {
    System.out.println("submitForm");

    setUpMockRoleDataService();
    setUpUserDataService();
    setUpMockExposablePropertyPlaceholderConfigurer();
    setUpValidatorAndBindingResult();
    setUpMockEmailSender();

    // Set up instance dependences
    Model model = new ExtendedModelMap();

    // the returned UserSignUpCommand is seen as valid regarding the validator
    // the CONFIRMATION sign-up page is displayed
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_REDIRECT_NAME;
    String result = instance.submitSignUpForm(mockValidCreateUserCommand, mockValidBindingResult, model);
    assertEquals(expResult, result);

    // the returned UserSignUpCommand is seen as invalid regarding the validator
    // the sign-up form is displayed again

    expResult = TgolKeyStore.SIGN_UP_VIEW_NAME;
    result = instance.submitSignUpForm(mockInvalidCreateUserCommand, mockInvalidBindingResult, model);
    assertEquals(expResult, result);
    assertSame(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY), mockInvalidCreateUserCommand);
}

From source file:org.asqatasun.webapp.controller.SignUpControllerTest.java

/**
 * Test of setUpSignUpConfirmationPage method, of class SignUpController.
 *///from ww  w .  j  a  v  a  2  s  .  c  om
public void testSetUpSignUpConfirmationPage() {
    System.out.println("setUpSignUpConfirmationPage");
    Model model = new ExtendedModelMap();
    String expResult = TgolKeyStore.SIGN_UP_CONFIRMATION_VIEW_NAME;
    String result = instance.setUpSignUpConfirmationPage(model);
    // the returned view is the sign-up confirmation view name
    assertEquals(expResult, result);
    // the model contains a UserSignUpCommand instance to maps the data of
    // the form of the view
    assertTrue(model.asMap().get(TgolKeyStore.CREATE_USER_COMMAND_KEY) instanceof CreateUserCommand);
}

From source file:org.broadleafcommerce.admin.web.controller.entity.AdminOrderController.java

@Override
protected String showViewUpdateCollection(HttpServletRequest request, Model model, Map<String, String> pathVars,
        String id, String collectionField, String collectionItemId, String modalHeaderType)
        throws ServiceException {
    String returnPath = super.showViewUpdateCollection(request, model, pathVars, id, collectionField,
            collectionItemId, modalHeaderType);

    if ("orderItems".equals(collectionField)) {
        EntityForm ef = (EntityForm) model.asMap().get("entityForm");

        ListGrid adjustmentsGrid = ef.findListGrid("orderItemAdjustments");
        if (adjustmentsGrid != null && CollectionUtils.isEmpty(adjustmentsGrid.getRecords())) {
            ef.removeListGrid("orderItemAdjustments");
        }/* ww  w .  j a  va  2 s  .  c  om*/

        ListGrid priceDetailsGrid = ef.findListGrid("orderItemPriceDetails");
        if (priceDetailsGrid != null && CollectionUtils.isEmpty(priceDetailsGrid.getRecords())) {
            ef.removeListGrid("orderItemPriceDetails");
        }
    }

    return returnPath;
}

From source file:org.broadleafcommerce.admin.web.controller.entity.AdminProductController.java

@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model,
        @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id) throws Exception {
    String view = super.viewEntityForm(request, response, model, pathVars, id);

    //Skus have a specific toolbar action to generate Skus based on permutations
    EntityForm form = (EntityForm) model.asMap().get("entityForm");
    ListGridAction generateSkusAction = new ListGridAction(ListGridAction.GEN_SKUS)
            .withDisplayText("Generate_Skus").withIconClass("icon-fighter-jet").withButtonClass("generate-skus")
            .withUrlPostfix("/generate-skus");

    ListGrid skusGrid = form.findListGrid("additionalSkus");
    if (skusGrid != null) {
        skusGrid.addToolbarAction(generateSkusAction);
        skusGrid.setCanFilterAndSort(false);
    }//from   w w w.j  av  a2  s.co  m

    // When we're dealing with product bundles, we don't want to render the product options and additional skus
    // list grids. Remove them from the form.
    if (ProductBundle.class.isAssignableFrom(Class.forName(form.getEntityType()))) {
        form.removeListGrid("additionalSkus");
        form.removeListGrid("productOptions");
    }

    form.removeListGrid("defaultSku.skuAttributes");

    return view;
}

From source file:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java

/**
 * Shows the appropriate modal dialog to view the selected collection item. This will display the modal as readonly
 *
 * @param request//from  w w  w . j a v a  2  s . c  o  m
 * @param response
 * @param model
 * @param pathVars
 * @param id
 * @param collectionField
 * @param collectionItemId
 * @return the return view path
 * @throws Exception
 */
@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/{alternateId}/view", method = RequestMethod.GET)
public String showViewCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model,
        @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id,
        @PathVariable(value = "collectionField") String collectionField,
        @PathVariable(value = "collectionItemId") String collectionItemId,
        @PathVariable(value = "alternateId") String alternateId) throws Exception {
    String returnPath = showViewUpdateCollection(request, model, pathVars, id, collectionField, alternateId,
            collectionItemId, "viewCollectionItem");

    // Since this is a read-only view, actions don't make sense in this context
    EntityForm ef = (EntityForm) model.asMap().get("entityForm");
    ef.removeAllActions();

    return returnPath;
}

From source file:org.broadleafcommerce.openadmin.web.controller.entity.AdminBasicEntityController.java

@RequestMapping(value = "/{id}/{collectionField:.*}/{collectionItemId}/view", method = RequestMethod.GET)
public String showViewCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model,
        @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id,
        @PathVariable(value = "collectionField") String collectionField,
        @PathVariable(value = "collectionItemId") String collectionItemId) throws Exception {
    String returnPath = showViewUpdateCollection(request, model, pathVars, id, collectionField,
            collectionItemId, null, "viewCollectionItem");

    // Since this is a read-only view, actions don't make sense in this context
    EntityForm ef = (EntityForm) model.asMap().get("entityForm");
    ef.removeAllActions();/*from   www  .  ja v  a  2 s  .  c  o m*/

    return returnPath;
}

From source file:org.emonocot.portal.controller.SearchController.java

@RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<Page> searchAPI(@RequestParam(value = "query", required = false) String query,
        @RequestParam(value = "limit", required = false, defaultValue = "24") Integer limit,
        @RequestParam(value = "start", required = false, defaultValue = "0") Integer start,
        @RequestParam(value = "facet", required = false) @FacetRequestFormat List<FacetRequest> facets,
        @RequestParam(value = "x1", required = false) Double x1,
        @RequestParam(value = "y1", required = false) Double y1,
        @RequestParam(value = "x2", required = false) Double x2,
        @RequestParam(value = "y2", required = false) Double y2,
        @RequestParam(value = "sort", required = false) String sort, Model model) throws SolrServerException {

    spatial(query, x1, y1, x2, y2, null, limit, start, facets, sort, null, model);
    return new ResponseEntity<Page>((Page) model.asMap().get("result"), HttpStatus.OK);
}

From source file:org.emonocot.portal.controller.SearchController.java

@RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/javascript")
public ResponseEntity<JSONPObject> searchAPIJSONP(@RequestParam(value = "query", required = false) String query,
        @RequestParam(value = "limit", required = false, defaultValue = "24") Integer limit,
        @RequestParam(value = "start", required = false, defaultValue = "0") Integer start,
        @RequestParam(value = "facet", required = false) @FacetRequestFormat List<FacetRequest> facets,
        @RequestParam(value = "x1", required = false) Double x1,
        @RequestParam(value = "y1", required = false) Double y1,
        @RequestParam(value = "x2", required = false) Double x2,
        @RequestParam(value = "y2", required = false) Double y2,
        @RequestParam(value = "sort", required = false) String sort,
        @RequestParam(value = "callback", required = true) String callback, Model model)
        throws SolrServerException {

    spatial(query, x1, y1, x2, y2, null, limit, start, facets, sort, null, model);
    return new ResponseEntity<JSONPObject>(new JSONPObject(callback, (Page) model.asMap().get("result")),
            HttpStatus.OK);/* ww  w  . ja v a  2s.  c o  m*/
}