/** * @see org.openmrs.api.PersonService#retirePersonAttributeType(PersonAttributeType, String) */ @Override public PersonAttributeType retirePersonAttributeType(PersonAttributeType type, String retiredReason) throws APIException { checkIfPersonAttributeTypesAreLocked(); if (retiredReason == null || retiredReason.length() < 1) { throw new APIException("Person.retiring.reason.required", (Object[]) null); } type.setRetired(true); type.setRetiredBy(Context.getAuthenticatedUser()); type.setRetireReason(retiredReason); type.setDateRetired(new Date()); return dao.savePersonAttributeType(type); }
@Override public void unretirePersonAttributeType(PersonAttributeType type) throws APIException { checkIfPersonAttributeTypesAreLocked(); type.setRetired(false); type.setDateRetired(null); type.setRetiredBy(null); type.setRetireReason(null); Context.getPersonService().savePersonAttributeType(type); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { PersonAttributeType type = new PersonAttributeType(); type.setName("name"); type.setFormat("java.lang.String"); type.setRetireReason("retireReason"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see PersonAttributeTypeValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { PersonAttributeType type = new PersonAttributeType(); type .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); type .setFormat("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); type .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(type, "patObj"); new PersonAttributeTypeValidator().validate(type, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("format")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); } }