Skip to content

Commit

Permalink
chore: remove ViewMapper interface
Browse files Browse the repository at this point in the history
  • Loading branch information
teleivo committed Nov 4, 2024
1 parent 19187b3 commit ad8f32e
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ RelationshipItem getEnrollmentInRelationshipItem(
UID uid, EnrollmentParams params, boolean includeDeleted) throws NotFoundException;

/** Get all enrollments matching given params. */
@Nonnull
List<Enrollment> getEnrollments(EnrollmentOperationParams params)
throws BadRequestException, ForbiddenException;

/** Get a page of enrollments matching given params. */
@Nonnull
Page<Enrollment> getEnrollments(EnrollmentOperationParams params, PageParams pageParams)
throws BadRequestException, ForbiddenException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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;
Expand Down Expand Up @@ -73,12 +74,14 @@ FileResourceStream getFileResourceImage(UID event, UID dataElement, ImageFileDim
/**
* Get all events matching given params under the privileges of the currently authenticated user.
*/
@Nonnull
List<Event> getEvents(EventOperationParams params) throws BadRequestException, ForbiddenException;

/**
* Get a page of events matching given params under the privileges of the currently authenticated
* user.
*/
@Nonnull
Page<Event> getEvents(EventOperationParams params, PageParams pageParams)
throws BadRequestException, ForbiddenException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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;
Expand Down Expand Up @@ -69,10 +70,12 @@ TrackedEntity getTrackedEntity(UID uid, UID programIdentifier, TrackedEntityPara
throws NotFoundException, ForbiddenException, BadRequestException;

/** Get all tracked entities matching given params. */
@Nonnull
List<TrackedEntity> getTrackedEntities(TrackedEntityOperationParams operationParams)
throws BadRequestException, ForbiddenException, NotFoundException;

/** Get a page of tracked entities matching given params. */
@Nonnull
Page<TrackedEntity> getTrackedEntities(TrackedEntityOperationParams params, PageParams pageParams)
throws BadRequestException, ForbiddenException, NotFoundException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,16 @@
import org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue;
import org.hisp.dhis.webapi.controller.tracker.view.Attribute;
import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(uses = InstantMapper.class)
public interface AttributeMapper extends ViewMapper<TrackedEntityAttributeValue, Attribute> {
public interface AttributeMapper {
@Mapping(target = "attribute", source = "attribute.uid")
@Mapping(target = "code", source = "attribute.code")
@Mapping(target = "displayName", source = "attribute.displayName")
@Mapping(target = "createdAt", source = "created")
@Mapping(target = "updatedAt", source = "lastUpdated")
@Mapping(target = "valueType", source = "attribute.valueType")
@Override
Attribute from(TrackedEntityAttributeValue attribute);
Attribute map(TrackedEntityAttributeValue attribute);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@
import org.hisp.dhis.eventdatavalue.EventDataValue;
import org.hisp.dhis.webapi.controller.tracker.view.DataValue;
import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(uses = {InstantMapper.class, UserMapper.class})
public interface DataValueMapper extends ViewMapper<EventDataValue, DataValue> {

public interface DataValueMapper {
@Mapping(target = "createdAt", source = "created")
@Mapping(target = "updatedAt", source = "lastUpdated")
@Mapping(target = "createdBy", source = "createdByUserInfo")
@Mapping(target = "updatedBy", source = "lastUpdatedByUserInfo")
@Override
DataValue from(EventDataValue dataValue);
DataValue map(EventDataValue dataValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@

import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper;
import org.hisp.dhis.webapi.controller.tracker.view.Note;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(uses = {InstantMapper.class, UserMapper.class})
public interface NoteMapper extends ViewMapper<org.hisp.dhis.note.Note, Note> {
public interface NoteMapper {
@Mapping(target = "note", source = "uid")
@Mapping(target = "storedAt", source = "created")
@Mapping(target = "value", source = "noteText")
@Mapping(target = "createdBy", source = "lastUpdatedBy")
@Mapping(target = "storedBy", source = "creator")
@Override
Note from(org.hisp.dhis.note.Note note);
Note map(org.hisp.dhis.note.Note note);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@

import org.hisp.dhis.trackedentity.TrackedEntityProgramOwner;
import org.hisp.dhis.webapi.controller.tracker.view.ProgramOwner;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper
public interface ProgramOwnerMapper extends ViewMapper<TrackedEntityProgramOwner, ProgramOwner> {
public interface ProgramOwnerMapper {
@Mapping(target = "orgUnit", source = "organisationUnit.uid")
@Mapping(target = "trackedEntity", source = "trackedEntity.uid")
@Mapping(target = "program", source = "program.uid")
@Override
ProgramOwner from(TrackedEntityProgramOwner trackedEntityProgramOwner);
ProgramOwner map(TrackedEntityProgramOwner trackedEntityProgramOwner);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@

import org.hisp.dhis.program.UserInfoSnapshot;
import org.hisp.dhis.webapi.controller.tracker.view.User;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;

@Mapper
public interface UserMapper extends ViewMapper<UserInfoSnapshot, User> {
@Override
User from(UserInfoSnapshot user);
public interface UserMapper {
User map(UserInfoSnapshot user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.hisp.dhis.webapi.controller.tracker.export.event.EventMapper;
import org.hisp.dhis.webapi.controller.tracker.export.relationship.RelationshipMapper;
import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

Expand All @@ -50,9 +49,7 @@
RelationshipMapper.class,
UserMapper.class
})
public interface EnrollmentMapper
extends ViewMapper<Enrollment, org.hisp.dhis.webapi.controller.tracker.view.Enrollment> {

public interface EnrollmentMapper {
/**
* Enrollments can be ordered by given fields which correspond to fields on {@link
* org.hisp.dhis.program.Enrollment}.
Expand Down Expand Up @@ -83,6 +80,5 @@ public interface EnrollmentMapper
@Mapping(target = "relationships", source = "relationshipItems")
@Mapping(target = "attributes", source = "trackedEntity.trackedEntityAttributeValues")
@Mapping(target = "notes", source = "notes")
@Override
org.hisp.dhis.webapi.controller.tracker.view.Enrollment from(Enrollment enrollment);
org.hisp.dhis.webapi.controller.tracker.view.Enrollment map(Enrollment enrollment);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;

import com.fasterxml.jackson.databind.node.ObjectNode;
import java.util.Collection;
import java.util.List;
import org.hisp.dhis.common.DhisApiVersion;
import org.hisp.dhis.common.OpenApi;
Expand Down Expand Up @@ -114,21 +113,22 @@ ResponseEntity<Page<ObjectNode>> getEnrollments(EnrollmentRequestParams requestP

org.hisp.dhis.tracker.export.Page<org.hisp.dhis.program.Enrollment> enrollmentsPage =
enrollmentService.getEnrollments(operationParams, pageParams);
List<Enrollment> enrollments =
enrollmentsPage.getItems().stream().map(ENROLLMENT_MAPPER::map).toList();
List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
ENROLLMENT_MAPPER.fromCollection(enrollmentsPage.getItems()),
requestParams.getFields());
fieldFilterService.toObjectNodes(enrollments, requestParams.getFields());

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(Page.withPager(ENROLLMENTS, enrollmentsPage.withItems(objectNodes)));
}

Collection<org.hisp.dhis.program.Enrollment> enrollments =
enrollmentService.getEnrollments(operationParams);
List<Enrollment> enrollments =
enrollmentService.getEnrollments(operationParams).stream()
.map(ENROLLMENT_MAPPER::map)
.toList();
List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
ENROLLMENT_MAPPER.fromCollection(enrollments), requestParams.getFields());
fieldFilterService.toObjectNodes(enrollments, requestParams.getFields());

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -144,7 +144,7 @@ public ResponseEntity<ObjectNode> getEnrollmentByUid(
throws NotFoundException, ForbiddenException {
EnrollmentParams enrollmentParams = fieldsMapper.map(fields);
Enrollment enrollment =
ENROLLMENT_MAPPER.from(enrollmentService.getEnrollment(uid, enrollmentParams, false));
ENROLLMENT_MAPPER.map(enrollmentService.getEnrollment(uid, enrollmentParams, false));
return ResponseEntity.ok(fieldFilterService.toObjectNode(enrollment, fields));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.hisp.dhis.webapi.controller.tracker.export.UserMapper;
import org.hisp.dhis.webapi.controller.tracker.export.relationship.RelationshipMapper;
import org.hisp.dhis.webapi.controller.tracker.view.InstantMapper;
import org.hisp.dhis.webapi.controller.tracker.view.ViewMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

Expand All @@ -50,8 +49,7 @@
RelationshipMapper.class,
UserMapper.class
})
public interface EventMapper
extends ViewMapper<Event, org.hisp.dhis.webapi.controller.tracker.view.Event> {
public interface EventMapper {

/**
* Events can be ordered by given fields which correspond to fields on {@link
Expand Down Expand Up @@ -115,5 +113,5 @@ public interface EventMapper
@Mapping(target = "dataValues", source = "eventDataValues")
@Mapping(target = "relationships", source = "relationshipItems")
@Mapping(target = "notes", source = "notes")
org.hisp.dhis.webapi.controller.tracker.view.Event from(Event event);
org.hisp.dhis.webapi.controller.tracker.view.Event map(Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,20 @@ ResponseEntity<Page<ObjectNode>> getEvents(EventRequestParams requestParams)

org.hisp.dhis.tracker.export.Page<Event> eventsPage =
eventService.getEvents(eventOperationParams, pageParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventsPage.getItems().stream().map(EVENTS_MAPPER::map).toList();
List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
EVENTS_MAPPER.fromCollection(eventsPage.getItems()), requestParams.getFields());
fieldFilterService.toObjectNodes(events, requestParams.getFields());

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(Page.withPager(EVENTS, eventsPage.withItems(objectNodes)));
}

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();
List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
EVENTS_MAPPER.fromCollection(events), requestParams.getFields());
fieldFilterService.toObjectNodes(events, requestParams.getFields());

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
Expand All @@ -189,15 +190,15 @@ void getEventsAsJsonGzip(EventRequestParams eventRequestParams, HttpServletRespo

EventOperationParams eventOperationParams = eventParamsMapper.map(eventRequestParams);

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();

ResponseHeader.addContentDispositionAttachment(response, EVENT_JSON_FILE + GZIP_EXT);
ResponseHeader.addContentTransferEncodingBinary(response);
response.setContentType(CONTENT_TYPE_JSON_GZIP);

List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
EVENTS_MAPPER.fromCollection(events), eventRequestParams.getFields());
fieldFilterService.toObjectNodes(events, eventRequestParams.getFields());

writeGzip(
response.getOutputStream(), Page.withoutPager(EVENTS, objectNodes), objectMapper.writer());
Expand All @@ -210,15 +211,15 @@ void getEventsAsJsonZip(EventRequestParams eventRequestParams, HttpServletRespon

EventOperationParams eventOperationParams = eventParamsMapper.map(eventRequestParams);

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();

ResponseHeader.addContentDispositionAttachment(response, EVENT_JSON_FILE + ZIP_EXT);
ResponseHeader.addContentTransferEncodingBinary(response);
response.setContentType(CONTENT_TYPE_JSON_ZIP);

List<ObjectNode> objectNodes =
fieldFilterService.toObjectNodes(
EVENTS_MAPPER.fromCollection(events), eventRequestParams.getFields());
fieldFilterService.toObjectNodes(events, eventRequestParams.getFields());

writeZip(
response.getOutputStream(),
Expand All @@ -235,13 +236,13 @@ void getEventsAsCsv(
throws IOException, BadRequestException, ForbiddenException, NotFoundException {
EventOperationParams eventOperationParams = eventParamsMapper.map(eventRequestParams);

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();

ResponseHeader.addContentDispositionAttachment(response, EVENT_CSV_FILE);
response.setContentType(CONTENT_TYPE_CSV);

csvEventService.write(
response.getOutputStream(), EVENTS_MAPPER.fromCollection(events), !skipHeader);
csvEventService.write(response.getOutputStream(), events, !skipHeader);
}

@GetMapping(produces = {CONTENT_TYPE_CSV_GZIP})
Expand All @@ -252,14 +253,14 @@ void getEventsAsCsvGZip(
throws IOException, BadRequestException, ForbiddenException, NotFoundException {
EventOperationParams eventOperationParams = eventParamsMapper.map(eventRequestParams);

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();

ResponseHeader.addContentDispositionAttachment(response, EVENT_CSV_FILE + GZIP_EXT);
ResponseHeader.addContentTransferEncodingBinary(response);
response.setContentType(CONTENT_TYPE_CSV_GZIP);

csvEventService.writeGzip(
response.getOutputStream(), EVENTS_MAPPER.fromCollection(events), !skipHeader);
csvEventService.writeGzip(response.getOutputStream(), events, !skipHeader);
}

@GetMapping(produces = {CONTENT_TYPE_CSV_ZIP})
Expand All @@ -270,17 +271,14 @@ void getEventsAsCsvZip(
throws IOException, BadRequestException, ForbiddenException, NotFoundException {
EventOperationParams eventOperationParams = eventParamsMapper.map(eventRequestParams);

List<Event> events = eventService.getEvents(eventOperationParams);
List<org.hisp.dhis.webapi.controller.tracker.view.Event> events =
eventService.getEvents(eventOperationParams).stream().map(EVENTS_MAPPER::map).toList();

ResponseHeader.addContentDispositionAttachment(response, EVENT_CSV_FILE + ZIP_EXT);
ResponseHeader.addContentTransferEncodingBinary(response);
response.setContentType(CONTENT_TYPE_CSV_ZIP);

csvEventService.writeZip(
response.getOutputStream(),
EVENTS_MAPPER.fromCollection(events),
!skipHeader,
EVENT_CSV_FILE);
csvEventService.writeZip(response.getOutputStream(), events, !skipHeader, EVENT_CSV_FILE);
}

@OpenApi.Response(OpenApi.EntityType.class)
Expand All @@ -292,7 +290,7 @@ ResponseEntity<ObjectNode> getEventByUid(
throws NotFoundException, ForbiddenException {
EventParams eventParams = eventsMapper.map(fields);
org.hisp.dhis.webapi.controller.tracker.view.Event event =
EVENTS_MAPPER.from(eventService.getEvent(uid, eventParams));
EVENTS_MAPPER.map(eventService.getEvent(uid, eventParams));

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

0 comments on commit ad8f32e

Please sign in to comment.