Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. *
  6. * Software distributed under the License is distributed on an "AS IS"
  7. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  8. * License for the specific language governing rights and limitations
  9. * under the License.
  10. *
  11. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  12. */
  13. package org.openmrs.validator;
  14.  
  15. import org.apache.commons.logging.Log;
  16. import org.apache.commons.logging.LogFactory;
  17. import org.openmrs.RelationshipType;
  18. import org.openmrs.annotation.Handler;
  19. import org.springframework.validation.Errors;
  20. import org.springframework.validation.ValidationUtils;
  21. import org.springframework.validation.Validator;
  22.  
  23. /**
  24. * Validates attributes on the {@link RelationshipType} object.
  25. *
  26. * @since 1.10
  27. */
  28. @Handler(supports = { RelationshipType.class }, order = 50)
  29. public class RelationshipTypeValidator implements Validator {
  30.  
  31. /** Log for this class and subclasses */
  32. protected final Log log = LogFactory.getLog(getClass());
  33.  
  34. /**
  35. * Determines if the command object being submitted is a valid type
  36. *
  37. * @see org.springframework.validation.Validator#supports(java.lang.Class)
  38. */
  39. @SuppressWarnings("unchecked")
  40. public boolean supports(Class c) {
  41. return c.equals(RelationshipType.class);
  42. }
  43.  
  44. /**
  45. * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
  46. * @should fail validation if aIsToB(or A is To B) is null or empty or whitespace
  47. * @should fail validation if bIsToA(or B is To A) is null or empty or whitespace
  48. * @should fail validation if Description is null or empty or whitespace
  49. * @should pass validation if all required fields are set
  50. */
  51. public void validate(Object obj, Errors errors) {
  52. RelationshipType relationshipType = (RelationshipType) obj;
  53. if (relationshipType == null) {
  54. errors.rejectValue("relationshipType", "error.general");
  55.  
  56. }
  57. else {
  58.  
  59. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "aIsToB", "RelationshipType.aIsToB.required");
  60. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "bIsToA", "RelationshipType.bIsToA.required");
  61. ValidationUtils.rejectIfEmptyOrWhitespace(errors, "Description", "error.description");
  62.  
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement