Example usage for org.springframework.validation ObjectError ObjectError

List of usage examples for org.springframework.validation ObjectError ObjectError

Introduction

In this page you can find the example usage for org.springframework.validation ObjectError ObjectError.

Prototype

public ObjectError(String objectName, String defaultMessage) 

Source Link

Document

Create a new instance of the ObjectError class.

Usage

From source file:com.asual.summer.core.spring.ExtendedServletRequestDataBinder.java

public BindingResult getBindingResult() {
    BindingResult result = super.getInternalBindingResult();
    if ((RequestUtils.getRequest() != null && RequestUtils.isValidation()) && !result.hasErrors()) {
        result.addError(new ObjectError("validation", "success"));
    }//from   w w  w . j a v  a 2  s. c  o  m
    return result;
}

From source file:com.sjsu.bikelet.web.TenantLicensePolicyController.java

@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid TenantLicensePolicy tenantLicensePolicy, BindingResult bindingResult, Model uiModel,
        HttpServletRequest httpServletRequest) {
    validateDate(bindingResult, tenantLicensePolicy);

    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, tenantLicensePolicy);
        return "tenantlicensepolicys/create";
    }//from w  w  w .j  a va 2s  . c  o  m
    uiModel.asMap().clear();

    try {
        tenantLicensePolicyService.saveTenantLicensePolicy(tenantLicensePolicy);
    } catch (BikeletValidationException e) {
        bindingResult.addError(new ObjectError("tenantLicensePolicy", e.getMessage()));
        if (bindingResult.hasErrors()) {
            populateEditForm(uiModel, tenantLicensePolicy);
            return "tenantlicensepolicys/create";
        }
    }

    return "redirect:/tenantlicensepolicys/"
            + encodeUrlPathSegment(tenantLicensePolicy.getId().toString(), httpServletRequest);
}

From source file:io.onedecision.engine.decisions.model.dmn.validators.DmnValidationErrors.java

@Override
public void reject(String errorCode, Object[] errorArgs, String defaultMessage) {
    globalErrors.add(new ObjectError(getObjectName(), defaultMessage));
}

From source file:org.smigo.user.authentication.RestAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    response.setStatus(HttpStatus.FORBIDDEN.value());
    List<ObjectError> errors = new ArrayList<ObjectError>();
    if (exception instanceof BadCredentialsException) {
        errors.add(new ObjectError("bad-credentials", "msg.badcredentials"));
    } else {/*from w  w  w.j a va2 s. c o m*/
        errors.add(new ObjectError("username", "msg.unknownerror"));
    }
    String responseBody = objectMapper.writeValueAsString(errors);
    response.getWriter().append(responseBody);

    final String username = Arrays.toString(request.getParameterMap().get("username"));
    final String note = "Authentication Failure:" + username + System.lineSeparator() + exception;
    log.info(note);
    mailHandler.sendAdminNotification("authentication failure", note);
}

From source file:org.smigo.config.RestExceptionResolver.java

@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) {//  www  . j  a va 2  s  .  com
    if (ex instanceof AccessDeniedException) {
        return getModelAndView(response, HttpStatus.FORBIDDEN,
                new Object[] { new ObjectError("AccessDenied", "msg.needtobeloggedin") });
    }

    final String uri = (String) request.getAttribute("javax.servlet.error.request_uri");
    if (request.getRequestURI().startsWith("/rest/") || uri != null && uri.startsWith("/rest/")) {
        return getModelAndView(response, HttpStatus.INTERNAL_SERVER_ERROR,
                new Object[] { new ObjectError("unknown-error", "msg.unknownerror") });
    }

    if (handler == null) {
        return null;
    }

    try {
        final HandlerMethod handlerMethod = (HandlerMethod) handler;
        final boolean annotatedWithRestController = handlerMethod.getBeanType()
                .isAnnotationPresent(RestController.class);
        final boolean annotatedWithResponseBody = handlerMethod.getMethodAnnotation(ResponseBody.class) != null;
        if (annotatedWithResponseBody || annotatedWithRestController) {
            return getModelAndView(response, HttpStatus.INTERNAL_SERVER_ERROR,
                    new Object[] { new ObjectError("unknown-error", "msg.unknownerror") });
        }
    } catch (Exception e) {
        log.error("Failed to return object error. Handler:" + handler, ex);
    }
    return null;
}

From source file:com.sjsu.bikelet.web.TenantLicensePolicyController.java

private void validateDate(BindingResult bindingResult, TenantLicensePolicy tenantLicensePolicy) {

    if (tenantLicensePolicy.getLicenseEndDate() == null
            || !tenantLicensePolicy.getLicenseEndDate().after(tenantLicensePolicy.getLicenseStartDate())) {
        bindingResult.addError(/*  w  w w  . j  a  v  a2 s . com*/
                new ObjectError("tenantLicensePolicy", "License Start Date must be before license End Date"));
    } else if (!CollectionUtils
            .isEmpty(tenantLicensePolicyService.verifyLicensePolicyDates(tenantLicensePolicy))) {
        bindingResult.addError(new ObjectError("tenantLicensePolicy",
                "New license start date and end date must supersede existing ones"));
    }

}

From source file:org.energyos.espi.datacustodian.web.custodian.UploadController.java

@RequestMapping(value = Routes.DATA_CUSTODIAN_UPLOAD, method = RequestMethod.POST)
public String uploadPost(@ModelAttribute UploadForm uploadForm, BindingResult result)
        throws IOException, JAXBException {

    try {/*w  ww  .  ja v a2 s.  c o  m*/

        importService.importData(uploadForm.getFile().getInputStream(), null);
        return "redirect:/custodian/retailcustomers";

    } catch (SAXException e) {

        result.addError(new ObjectError("uploadForm", e.getMessage()));
        return "/custodian/upload";

    } catch (Exception e) {

        result.addError(new ObjectError("uploadForm", "Unable to process file"));
        return "/custodian/upload";
    }
}

From source file:org.energyos.espi.datacustodian.web.custodian.UploadControllerTests.java

@Test
@Ignore/*from   www  .  j  av a 2s  .  c  om*/
public void uploadPost_givenInvalidFile_displaysUploadViewWithErrors() throws Exception {
    Mockito.doThrow(new SAXException("Unable to process file")).when(importService)
            .importData(any(InputStream.class), null);

    String view = controller.uploadPost(form, result);

    assertEquals("/custodian/upload", view);
    verify(result).addError(new ObjectError("uploadForm", "Unable to process file"));
}

From source file:com.create.validation.PropertyValidationErrorsProviderTest.java

private ObjectError getObjectError() {
    return new ObjectError(OBJECT_NAME, ERROR_MESSAGE);
}

From source file:org.kew.rmf.matchconf.web.CustomWireController.java

@RequestMapping(value = "/{configType}_configs/{configName}/wires", method = RequestMethod.POST, produces = "text/html")
public String create(@PathVariable("configType") String configType,
        @PathVariable("configName") String configName, @Valid Wire wire, BindingResult bindingResult,
        Model uiModel, HttpServletRequest httpServletRequest) {
    // assert unique_together:config&name
    if (Configuration.findConfigurationsByNameEquals(configName).getSingleResult()
            .getWireForName(wire.getName()) != null) {
        bindingResult.addError(new ObjectError("wire.name",
                "There is already a Wire set up for this configuration with this name."));
    }//from  w  w w . j a v  a 2  s .com
    this.customValidation(configName, wire, bindingResult);
    if (bindingResult.hasErrors()) {
        populateEditForm(uiModel, configName, wire);
        return String.format("%s_config_wires/create", configType);
    }
    uiModel.asMap().clear();
    Configuration config = Configuration.findConfigurationsByNameEquals(configName).getSingleResult();
    wire.setConfiguration(config);
    wire.persist();
    config.getWiring().add(wire);
    config.merge();
    return String.format("redirect:/%s_configs/", configType)
            + encodeUrlPathSegment(configName, httpServletRequest) + "/wires/"
            + encodeUrlPathSegment(wire.getName(), httpServletRequest);
}