/** * @see org.openmrs.api.PersonService#unvoidRelationship(org.openmrs.Relationship) */ @Override public Relationship unvoidRelationship(Relationship relationship) throws APIException { relationship.setVoided(false); relationship.setVoidedBy(null); relationship.setDateVoided(null); relationship.setVoidReason(null); return Context.getPersonService().saveRelationship(relationship); }
/** * @see org.openmrs.api.PersonService#voidRelationship(org.openmrs.Relationship, * java.lang.String) */ @Override public Relationship voidRelationship(Relationship relationship, String voidReason) throws APIException { if (relationship.getVoided()) { return relationship; } relationship.setVoided(true); if (relationship.getVoidedBy() == null) { relationship.setVoidedBy(Context.getAuthenticatedUser()); } if (voidReason != null) { relationship.setVoidReason(voidReason); } relationship.setDateVoided(new Date()); return Context.getPersonService().saveRelationship(relationship); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { Relationship relationship = new Relationship(1); relationship.setVoidReason("voidReason"); Map<String, String> map = new HashMap<>(); MapBindingResult errors = new MapBindingResult(map, Relationship.class.getName()); new RelationshipValidator().validate(relationship, errors); Assert.assertFalse(errors.hasErrors()); }
/** * @see RelationshipValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { Relationship relationship = new Relationship(1); relationship .setVoidReason("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(relationship, "relationship"); new RelationshipValidator().validate(relationship, errors); Assert.assertEquals(true, errors.hasFieldErrors("voidReason")); }
/** * The purpose of this method is to allow subclasses of Relationship to delegate a portion of * their copy() method back to the superclass, in case the base class implementation changes. * * @param target a Relationship that will have the state of <code>this</code> copied into it * @return the Relationship that was passed in, with state copied into it */ protected Relationship copyHelper(Relationship target) { target.personA = getPersonA(); target.relationshipType = getRelationshipType(); target.personB = getPersonB(); target.setCreator(getCreator()); target.setDateCreated(getDateCreated()); target.setVoided(getVoided()); target.setVoidedBy(getVoidedBy()); target.setDateVoided(getDateVoided()); target.setVoidReason(getVoidReason()); return target; }