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

chore: Use UID in relationship exporter [DHIS2-17790] #18912

Merged
merged 2 commits into from
Oct 25, 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 @@ -272,7 +272,7 @@ public String getUserAccessErrors(
}

List<RelationshipType> relationshipTypes =
relationshipService.getRelationships(mergeObject.getRelationships()).stream()
relationshipService.getRelationships(UID.of(mergeObject.getRelationships())).stream()
.map(Relationship::getRelationshipType)
.distinct()
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Set;
import javax.annotation.Nonnull;
import lombok.RequiredArgsConstructor;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.feedback.BadRequestException;
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.feedback.NotFoundException;
Expand Down Expand Up @@ -76,9 +77,9 @@ public Page<Relationship> getRelationships(
}

@Override
public Relationship getRelationship(@Nonnull String uid)
public Relationship getRelationship(@Nonnull UID uid)
throws ForbiddenException, NotFoundException {
Relationship relationship = relationshipStore.getByUid(uid);
Relationship relationship = relationshipStore.getByUid(uid.getValue());

if (relationship == null) {
throw new NotFoundException(Relationship.class, uid);
Expand All @@ -94,10 +95,10 @@ public Relationship getRelationship(@Nonnull String uid)
}

@Override
public List<Relationship> getRelationships(@Nonnull List<String> uids)
public List<Relationship> getRelationships(@Nonnull Set<UID> uids)
throws ForbiddenException, NotFoundException {
List<Relationship> relationships = new ArrayList<>();
for (String uid : uids) {
for (UID uid : uids) {
relationships.add(getRelationship(uid));
}
return relationships;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.feedback.BadRequestException;
import org.hisp.dhis.feedback.ForbiddenException;
import org.hisp.dhis.feedback.NotFoundException;
Expand All @@ -47,13 +48,13 @@ List<Relationship> getRelationships(RelationshipOperationParams params)
Page<Relationship> getRelationships(RelationshipOperationParams params, PageParams pageParams)
throws ForbiddenException, NotFoundException, BadRequestException;

Relationship getRelationship(String uid) throws ForbiddenException, NotFoundException;
Relationship getRelationship(UID uid) throws ForbiddenException, NotFoundException;

/**
* Get relationships matching given {@code UID}s under the privileges of the currently
* authenticated user.
*/
List<Relationship> getRelationships(@Nonnull List<String> uids)
List<Relationship> getRelationships(@Nonnull Set<UID> uids)
throws ForbiddenException, NotFoundException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ class DeduplicationHelperTest extends TestBase {

@BeforeEach
public void setUp() throws ForbiddenException, NotFoundException {
List<String> relationshipUids =
List.of(CodeGenerator.generateUid(), CodeGenerator.generateUid());
Set<UID> relationshipUids = UID.of(CodeGenerator.generateUid(), CodeGenerator.generateUid());
List<String> attributeUids = List.of(CodeGenerator.generateUid(), CodeGenerator.generateUid());
Set<UID> enrollmentUids = UID.of(CodeGenerator.generateUid(), CodeGenerator.generateUid());

Expand All @@ -124,7 +123,7 @@ public void setUp() throws ForbiddenException, NotFoundException {
enrollment = createEnrollment(createProgram('A'), getTrackedEntityA(), organisationUnitA);
mergeObject =
MergeObject.builder()
.relationships(relationshipUids)
.relationships(UID.toValueList(relationshipUids))
.trackedEntityAttributes(attributeUids)
.enrollments(UID.toValueList(enrollmentUids))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.hisp.dhis.category.CategoryService;
import org.hisp.dhis.common.CodeGenerator;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.http.HttpStatus;
Expand Down Expand Up @@ -197,7 +198,7 @@ void shouldCreateRelationship() throws SmsCompressionException {
() -> assertEquals(originator, sms.getOriginator()),
() -> assertEquals(user, sms.getCreatedBy()),
() -> {
Relationship relationship = relationshipService.getRelationship(relationshipUid);
Relationship relationship = relationshipService.getRelationship(UID.of(relationshipUid));
assertAll(
() -> assertEquals(relationshipUid, relationship.getUid()),
() -> assertEquals(event1, relationship.getFrom().getEvent()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ ResponseEntity<ObjectNode> getRelationshipByUid(
@OpenApi.Param(value = String[].class) @RequestParam(defaultValue = DEFAULT_FIELDS_PARAM)
List<FieldPath> fields)
throws NotFoundException, ForbiddenException {
Relationship relationship =
RELATIONSHIP_MAPPER.from(relationshipService.getRelationship(uid.getValue()));
Relationship relationship = RELATIONSHIP_MAPPER.from(relationshipService.getRelationship(uid));

return ResponseEntity.ok(fieldFilterService.toObjectNode(relationship, fields));
}
Expand Down
Loading