Skip to content

Commit

Permalink
fix: Set lastUpdatedBy when creating relationships [DHIS2-18226] (#18828
Browse files Browse the repository at this point in the history
)
  • Loading branch information
enricocolasante authored Oct 15, 2024
1 parent 8368128 commit 0ae2a2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,15 @@ private org.hisp.dhis.relationship.Relationship from(
org.hisp.dhis.relationship.RelationshipItem toItem =
new org.hisp.dhis.relationship.RelationshipItem();

Date now = new Date();
if (toRelationship == null) {
Date now = new Date();

toRelationship = new org.hisp.dhis.relationship.Relationship();
toRelationship.setUid(fromRelationship.getRelationship());
toRelationship.setCreated(now);
toRelationship.setLastUpdated(now);
}
toRelationship.setLastUpdated(now);
toRelationship.setLastUpdatedBy(preheat.getUser());

toRelationship.setRelationshipType(relationshipType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.hisp.dhis.tracker.domain.Relationship;
import org.hisp.dhis.tracker.domain.RelationshipItem;
import org.hisp.dhis.tracker.preheat.TrackerPreheat;
import org.hisp.dhis.user.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -84,10 +85,13 @@ class RelationshipTrackerConverterServiceTest extends DhisConvenienceTest {
private TrackerConverterService<Relationship, org.hisp.dhis.relationship.Relationship>
relationshipConverterService;

private User user;

@Mock public TrackerPreheat preheat;

@BeforeEach
protected void setupTest() {
user = makeUser("A");
OrganisationUnit organisationUnit = createOrganisationUnit('A');
Program program = createProgram('A');
TrackedEntityType teiType = createTrackedEntityType('A');
Expand Down Expand Up @@ -120,6 +124,7 @@ void testConverterFromRelationships() {
when(preheat.getTrackedEntity(TEI)).thenReturn(tei);
when(preheat.getEnrollment(ENROLLMENT)).thenReturn(pi);
when(preheat.getEvent(EVENT)).thenReturn(psi);
when(preheat.getUser()).thenReturn(user);

List<org.hisp.dhis.relationship.Relationship> from =
relationshipConverterService.from(preheat, List.of(relationshipA(), relationshipB()));
Expand All @@ -140,6 +145,7 @@ void testConverterFromRelationships() {
}
assertNotNull(relationship.getFrom());
assertNotNull(relationship.getTo());
assertEquals(user.getUid(), relationship.getLastUpdatedBy().getUid());
});
}

Expand Down

0 comments on commit 0ae2a2d

Please sign in to comment.