/** * @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); }
/** * 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; }
@Test public void voidRelationship_shouldVoidRelationshipAndSetVoidedByToGivenUserIfGivenRelationshipIsNotVoided() { Relationship relationship = personService.getRelationship(1); assertFalse("We need an unvoided relationship to test the method", relationship.getVoided()); String voidReason = "Something"; User user = Context.getUserService().getUser(501); assertNotNull("need a user to void", user); relationship.setVoidedBy(user); // TODO - voiding is done by the BaseVoidHandler called via AOP before voidRelationship // is executed. Coverage of voidRelationship is low because relationship.getVoided() is true // when entering voidRelationship // Documented at TRUNK-5151 personService.voidRelationship(relationship, voidReason); Relationship voidedRelationship = personService.getRelationship(1); assertTrue(voidedRelationship.getVoided()); assertThat(voidedRelationship.getVoidReason(), is(voidReason)); assertNotNull(voidedRelationship.getDateVoided()); assertEquals(voidedRelationship.getVoidedBy(), user); }