Example usage for org.springframework.validation ObjectError toString

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.openmrs.module.hospitalcore.web.controller.concept.DiagnosisImporterController.java

@RequestMapping(method = RequestMethod.POST)
public String create(UploadFile uploadFile, BindingResult result, Model model) {
    if (result.hasErrors()) {
        //ghanshyam 25/06/2012 tag BC_IMPOSSIBLE_CAST code Error error = (Error) obj

        for (ObjectError obj : result.getAllErrors()) {
            ObjectError error = (ObjectError) obj;
            System.err.println("Error: " + error.toString());
        }/*w w  w.  ja  va 2s .c  om*/
        return "/module/hospitalcore/concept/uploadForm";
    }

    System.out.println("Begin importing");
    Integer diagnosisNo = 0;
    try {
        HospitalCoreService hcs = (HospitalCoreService) Context.getService(HospitalCoreService.class);
        diagnosisNo = hcs.importConcepts(uploadFile.getDiagnosisFile().getInputStream(),
                uploadFile.getMappingFile().getInputStream(), uploadFile.getSynonymFile().getInputStream());
        model.addAttribute("diagnosisNo", diagnosisNo);
        System.out.println("Diagnosis imported " + diagnosisNo);
    } catch (Exception e) {
        e.printStackTrace();
        model.addAttribute("fail", true);
        model.addAttribute("error", e.toString());
    }

    return "/module/hospitalcore/concept/uploadForm";
}

From source file:com.pw.ism.controllers.MessageController.java

@RequestMapping(value = "sendmail", method = RequestMethod.POST, headers = { "Content-type=application/json" })
public ResponseEntity<String> sendMail(@Valid @RequestBody MailMessage mail, BindingResult result) {
    if (result.hasErrors()) {
        for (ObjectError error : result.getAllErrors()) {
            LOGGER.info("not valid: " + error.toString());
        }//from   ww w . ja  va  2 s.  c  o m
        return new ResponseEntity<>("NOK!", HttpStatus.BAD_REQUEST);
    } else {
        return new ResponseEntity<>("OK!", HttpStatus.OK);
    }
}

From source file:org.oncoblocks.centromere.core.test.DataImportTests.java

@Test
public void validationTest() throws Exception {
    EntrezGene gene = new EntrezGene();
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(gene, gene.getClass().getName());
    validator.validate(gene, bindingResult);
    if (bindingResult.hasErrors()) {
        for (ObjectError error : bindingResult.getAllErrors()) {
            System.out.println(error.toString());
        }/*from ww w . j a  va  2 s  .c o m*/
    } else {
        fail("Validation did not catch missing field.");
    }
}

From source file:org.sakaiproject.metaobj.shared.control.EditStructuredArtifactDefinitionController.java

protected void save(StructuredArtifactDefinitionBean sad, Errors errors) {
    //check to see if you have edit permissions
    boolean isAllowed = isAllowed(SharedFunctionConstants.EDIT_ARTIFACT_DEF);
    Agent currentAgent = getAuthManager().getAgent();

    //TODO verify user is system admin, if editting global SAD

    if (isAllowed || currentAgent.getId().getValue().equals(sad.getOwner().getId().getValue())) {
        // todo this should all be done on the server
        // check only if new xsd has been submitted
        if (sad.getSchemaFile() != null) {

            String type = sad.getType().getId().getValue();

            getSecurityService().pushAdvisor(new SecurityAdvisor() {
                public SecurityAdvice isAllowed(String userId, String function, String reference) {
                    return SecurityAdvice.ALLOWED;
                }// www  .  jav  a 2  s . c o  m
            });

            try {
                Collection artifacts = artifactFinder.findByType(type);
                StructuredArtifactValidator validator = new StructuredArtifactValidator();

                // validate every artifact against new xsd to determine
                // whether or not an xsl conversion file is necessary
                for (Iterator i = artifacts.iterator(); i.hasNext();) {
                    Object obj = i.next();
                    if (obj instanceof StructuredArtifact) {
                        StructuredArtifact artifact = (StructuredArtifact) obj;
                        artifact.setHome(getStructuredArtifactDefinitionManager().convertToHome(sad));
                        Errors artifactErrors = new BindException(artifact, "bean");
                        validator.validate(artifact, artifactErrors);
                        if (artifactErrors.getErrorCount() > 0) {
                            if (sad.getXslConversionFileId() == null
                                    || sad.getXslConversionFileId().getValue().length() == 0) {

                                errors.rejectValue("schemaFile", "invalid_schema_file_edit",
                                        "key missing:  invalid_schema_file_edit");

                                for (Iterator x = artifactErrors.getAllErrors().iterator(); x.hasNext();) {
                                    ObjectError error = (ObjectError) x.next();
                                    logger.warn(error.toString());
                                }

                                return;

                            } else {
                                sad.setRequiresXslFile(true);
                                break;
                            }
                        }
                    }
                }
            } finally {
                getSecurityService().popAdvisor();
            }
        }

        try {
            getStructuredArtifactDefinitionManager().save(sad);
        } catch (PersistenceException e) {
            errors.rejectValue(e.getField(), e.getErrorCode(), e.getErrorInfo(), e.getDefaultMessage());
        }
    } else {
        errors.rejectValue("id", "not_allowed", new Object[] {}, "Not allowed to delete");
    }
}

From source file:mx.com.quadrum.contratos.controller.crud.ContactoController.java

@ResponseBody
@RequestMapping(value = "agregarContacto", method = RequestMethod.POST)
public String agregarContacto(@Valid @ModelAttribute("contacto") Contacto contacto, BindingResult bindingResult,
        HttpSession session) {//  w w w .  j a va  2  s  .c o  m
    if (session.getAttribute("usuario") == null) {
        return SESION_CADUCA;
    }
    if (bindingResult.hasErrors()) {
        for (ObjectError e : bindingResult.getAllErrors()) {
            System.out.println(e.getCode());
            System.out.println(e.getDefaultMessage());
            System.out.println(e.getObjectName());
            System.out.println(e.toString());
        }
        return ERROR_DATOS;
    }
    if (contactoService.existeCorreo(contacto.getMail())) {
        return "Error...#Ya existe un usuario con el correo que quiere ingresar.";
    }
    return contactoService.agregar(contacto);
}

From source file:org.apereo.openlrs.controllers.xapi.XAPIExceptionHandlerAdvice.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody//from   w  w w .ja va  2  s  .c  om
public XAPIErrorInfo handleMethodArgumentNotValidException(final HttpServletRequest request,
        MethodArgumentNotValidException e) {
    final List<String> errorMessages = new ArrayList<String>();
    for (ObjectError oe : e.getBindingResult().getAllErrors()) {
        if (oe instanceof FieldError) {
            final FieldError fe = (FieldError) oe;
            final String msg = String.format("Field error in object '%s' on field '%s': rejected value [%s].",
                    fe.getObjectName(), fe.getField(), fe.getRejectedValue());
            errorMessages.add(msg);
        } else {
            errorMessages.add(oe.toString());
        }
    }
    final XAPIErrorInfo result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, errorMessages);
    this.logException(e);
    this.logError(result);
    return result;
}

From source file:org.apache.rave.portal.web.validator.NewAccountValidator.java

protected void writeResultToLog(Errors errors) {
    if (errors.hasErrors()) {
        if (logger.isInfoEnabled()) {
            for (ObjectError error : errors.getAllErrors()) {
                logger.info("Validation error: {}", error.toString());
            }/*  w w  w  . jav a 2s. c om*/
        }
    } else {
        logger.debug("Validation successful");
    }
}

From source file:org.apache.rave.portal.web.validator.UserProfileValidator.java

private void writeResultToLog(Errors errors) {
    if (errors.hasErrors()) {
        if (logger.isInfoEnabled()) {
            for (ObjectError error : errors.getAllErrors()) {
                logger.info("Validation error: {}", error.toString());
            }/* w w w.j a  v  a 2  s. c  o  m*/
        }
    } else {
        logger.debug("Validation successful");
    }
}