Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set lastUpdatedBy when creating relationships [DHIS2-18226](2.39) #18828

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading