Search in sources :

Example 41 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project head by mifos.

the class DefineProductCategoryPreviewController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @RequestParam(value = EDIT_PARAM, required = false) String edit, @ModelAttribute("formBean") ProductCategoryFormBean bean, BindingResult result) {
    ModelAndView modelAndView = new ModelAndView("defineNewCategory");
    if (StringUtils.isNotBlank(cancel)) {
        modelAndView.setViewName(REDIRECT_TO_ADMIN);
    } else if (StringUtils.isNotBlank(edit)) {
        modelAndView.setViewName("defineNewCategory");
        modelAndView.addObject("formBean", bean);
        modelAndView.addObject("typeList", this.getProductCategoryTypes());
    } else if (result.hasErrors()) {
        modelAndView.setViewName("newProductCategoryPreview");
        modelAndView.addObject("formBean", bean);
    } else {
        CreateOrUpdateProductCategory productCategory = new CreateOrUpdateProductCategory(Short.parseShort(bean.getProductTypeId()), bean.getProductCategoryName(), bean.getProductCategoryDesc(), Short.parseShort(bean.getProductCategoryStatusId()), bean.getGlobalPrdCategoryNum());
        try {
            this.adminServiceFacade.createProductCategory(productCategory);
            modelAndView.setViewName(REDIRECT_TO_ADMIN);
        } catch (BusinessRuleException e) {
            ObjectError error = new ObjectError("formBean", new String[] { e.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            modelAndView.setViewName("newProductCategoryPreview");
            modelAndView.addObject("formBean", bean);
        }
    }
    return modelAndView;
}
Also used : CreateOrUpdateProductCategory(org.mifos.dto.domain.CreateOrUpdateProductCategory) BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project head by mifos.

the class DefineProductCategoryPreviewController method showPopulatedForm.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView showPopulatedForm(ProductCategoryFormBean formBean) {
    ModelAndView modelAndView = new ModelAndView("defineNewCategory");
    modelAndView.addObject("formbean", formBean);
    modelAndView.addObject("typeList", this.getProductCategoryTypes());
    return modelAndView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 43 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project head by mifos.

the class DefineProductMixController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String canceBtn, @RequestParam(value = PREVIEW_PARAM, required = false) String previewBtn, @ModelAttribute("formBean") ProductMixFormBean formBean, BindingResult result, SessionStatus status) {
    ModelAndView mav = new ModelAndView("defineProductMix");
    ProductMixFormValidator formValidator = new ProductMixFormValidator();
    if (StringUtils.isNotBlank(canceBtn)) {
        mav = new ModelAndView(REDIRECT_TO_ADMIN_SCREEN);
        status.setComplete();
    }
    if (StringUtils.isBlank(formBean.getProductTypeId())) {
        List<ProductTypeDto> productTypes = this.adminServiceFacade.retrieveProductTypesApplicableToProductMix();
        mav.addObject("formBean", productMixAssembler.createFormBean(productTypes));
        validateForPreview(formValidator, formBean, result, previewBtn);
    } else if (StringUtils.isNotBlank(formBean.getProductTypeId()) && StringUtils.isBlank(formBean.getProductId())) {
        populateProductNameOptions(formBean);
        validateForPreview(formValidator, formBean, result, previewBtn);
    } else if (StringUtils.isNotBlank(formBean.getProductTypeId()) && StringUtils.isNotBlank(formBean.getProductId()) && (formBean.getAllowed() == null && formBean.getNotAllowed() == null)) {
        populateAllowedNotAllowedOptions(formBean);
        validateForPreview(formValidator, formBean, result, previewBtn);
    } else {
        checkAndFixFormStringArrys(formBean);
        validateForPreview(formValidator, formBean, result, previewBtn);
        ProductMixPreviewDto preview = this.productMixAssembler.createProductMixPreview(formBean);
        mav = new ModelAndView("previewProductMix");
        mav.addObject("ref", preview);
        mav.addObject("formView", "defineProductMix");
    }
    return mav;
}
Also used : ProductTypeDto(org.mifos.dto.domain.ProductTypeDto) ProductMixPreviewDto(org.mifos.dto.screen.ProductMixPreviewDto) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 44 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project head by mifos.

the class DeleteCoaController method processFormSubmit.

@RequestMapping(method = RequestMethod.POST)
public ModelAndView processFormSubmit(@RequestParam(value = CANCEL_PARAM, required = false) String cancel, @Valid @ModelAttribute("formBean") CoaFormBean formBean, BindingResult result, SessionStatus status) {
    ModelAndView mav = new ModelAndView(REDIRECT_TO_COA_ADMIN_SCREEN);
    if (StringUtils.isNotBlank(cancel)) {
        status.setComplete();
    } else {
        try {
            coaServiceFacade.delete(formBean.getAccountId());
            status.setComplete();
        } catch (BusinessRuleException ex) {
            ObjectError error = new ObjectError("formBean", new String[] { ex.getMessageKey() }, new Object[] {}, "default: ");
            result.addError(error);
            mav.setViewName(DELETE_COA);
            mav.addObject("formBean", formBean);
        }
    }
    return mav;
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) ObjectError(org.springframework.validation.ObjectError) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with ModelAndView

use of org.springframework.web.servlet.ModelAndView in project head by mifos.

the class DateTimeUpdateController method handleRequestInternal.

@Override
@RequestMapping("/dateTimeUpdate.ftl")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView returnValue = new ModelAndView("pageNotFound");
    if (TestMode.MAIN == getTestingService().getTestMode()) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {
        String dateTimeString = request.getParameter("dateTime");
        String result = null;
        if (null == dateTimeString) {
            result = "Missing 'dateTime' parameter!";
        } else if ("system".equals(dateTimeString)) {
            getDateTimeService().resetToCurrentSystemDateTime();
            result = getDateTimeService().getCurrentDateTime().toString();
        } else {
            DateTimeFormatter formatter = ISODateTimeFormat.basicDateTimeNoMillis();
            DateTime dateTime = formatter.parseDateTime(dateTimeString);
            getDateTimeService().setCurrentDateTime(dateTime);
            result = dateTime.toString();
        }
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("updateResult", result);
        model.put("request", request);
        Map<String, Object> status = new HashMap<String, Object>();
        List<String> errorMessages = new ArrayList<String>();
        status.put("errorMessages", errorMessages);
        ModelAndView modelAndView = new ModelAndView("dateTimeUpdate", "model", model);
        modelAndView.addObject("status", status);
        returnValue = modelAndView;
    }
    return returnValue;
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelAndView (org.springframework.web.servlet.ModelAndView)1573 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)668 Test (org.junit.jupiter.api.Test)195 Test (org.junit.Test)188 HashMap (java.util.HashMap)165 ArrayList (java.util.ArrayList)139 RedirectView (org.springframework.web.servlet.view.RedirectView)90 Map (java.util.Map)84 List (java.util.List)69 IOException (java.io.IOException)60 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)60 Date (java.util.Date)57 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)49 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)49 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)47 GetMapping (org.springframework.web.bind.annotation.GetMapping)45 HandlerMethod (org.springframework.web.method.HandlerMethod)45 IPerson (org.apereo.portal.security.IPerson)43 JSONView (com.intel.mountwilson.util.JSONView)34