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

OLMIS-7906: Added GET /api/bottomUpQuantifications/forFinalApprovalWithGroupCosts endpoint #59

Merged
merged 2 commits into from
Apr 8, 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 @@ -59,6 +59,7 @@
import org.openlmis.buq.builder.BottomUpQuantificationDataBuilder;
import org.openlmis.buq.builder.ProgramDtoDataBuilder;
import org.openlmis.buq.domain.buq.BottomUpQuantification;
import org.openlmis.buq.dto.BottomUpQuantificationGroupCostsData;
import org.openlmis.buq.dto.buq.BottomUpQuantificationDto;
import org.openlmis.buq.dto.referencedata.ProgramDto;
import org.openlmis.buq.i18n.MessageKeys;
Expand Down Expand Up @@ -595,14 +596,14 @@ public void shouldReturnUnauthorizedForAuditLogEndpointIfUserIsNotAuthorized() {
}

@Test
public void shouldReturnBottomUpQuantificationsForFinalApproval() {
public void shouldReturnBottomUpQuantificationsForFinalApprovalWithGroupCosts() {
mockUserHasAtLeastOneOfFollowingRights(PermissionService.MOH_PORALG_RIGHTS);
given(bottomUpQuantificationService.getBottomUpQuantificationsForFinalApproval(
given(bottomUpQuantificationService.getBottomUpQuantificationsForFinalApprovalWithGroupCosts(
any(UUID.class),
any(UUID.class),
any(UUID.class),
any(Pageable.class)))
.willReturn(new PageImpl<>(Collections.singletonList(bottomUpQuantification)));
.willReturn(Collections.singletonList(new BottomUpQuantificationGroupCostsData()));

restAssured.given()
.header(HttpHeaders.AUTHORIZATION, getTokenHeader())
Expand All @@ -613,9 +614,7 @@ public void shouldReturnBottomUpQuantificationsForFinalApproval() {
.get(FOR_FINAL_APPROVAL_URL)
.then()
.statusCode(HttpStatus.SC_OK)
.body("content", Matchers.hasSize(1))
.body("content[0].id", Matchers.is(bottomUpQuantification.getId().toString()))
.body("content[0].status", Matchers.is(bottomUpQuantification.getStatus().toString()));
.body("content", Matchers.hasSize(1));

assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected].
*/

package org.openlmis.buq.dto;

import java.util.Map;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.openlmis.buq.dto.buq.BottomUpQuantificationDto;

@Getter
@Setter
@NoArgsConstructor
public class BottomUpQuantificationGroupCostsData {

private BottomUpQuantificationDto bottomUpQuantification;
private Map<String, String> calculatedGroupsCosts;

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.openlmis.buq.domain.buq.Rejection;
import org.openlmis.buq.domain.productgroup.ProductGroup;
import org.openlmis.buq.domain.sourceoffund.SourceOfFund;
import org.openlmis.buq.dto.BottomUpQuantificationGroupCostsData;
import org.openlmis.buq.dto.ResultDto;
import org.openlmis.buq.dto.buq.BottomUpQuantificationDto;
import org.openlmis.buq.dto.buq.BottomUpQuantificationLineItemDto;
Expand Down Expand Up @@ -753,6 +754,48 @@ public Page<BottomUpQuantification> getBottomUpQuantificationsForFinalApproval(
pageable);
}

/**
* Retrieves bottom-up quantifications that are ready for final approval
* based on the specified processing period, program, geographic zone,
* and user permissions, along with group costs data.
*
* @param programId The UUID of the program for which quantifications are retrieved.
* @param processingPeriodId The UUID of the processing period.
* @param geographicZoneId The UUID of the geographic zone.
* @param pageable object used to encapsulate the pagination related values: page,
* size and sort.
* @return A page of {@link BottomUpQuantification} objects representing quantifications ready
* for final approval.
*/
public List<BottomUpQuantificationGroupCostsData>
getBottomUpQuantificationsForFinalApprovalWithGroupCosts(
UUID programId,
UUID processingPeriodId,
UUID geographicZoneId,
Pageable pageable) {
Page<BottomUpQuantification> bottomUpQuantifications =
getBottomUpQuantificationsForFinalApproval(programId, processingPeriodId,
geographicZoneId, pageable);
List<ProductGroup> productGroups = productGroupRepository.findAll();

return bottomUpQuantifications.stream()
.map(buq -> buildBottomUpQuantificationGroupCostsData(buq, productGroups))
.collect(Collectors.toList());
}

private BottomUpQuantificationGroupCostsData buildBottomUpQuantificationGroupCostsData(
BottomUpQuantification bottomUpQuantification, List<ProductGroup> productGroups) {
BottomUpQuantificationGroupCostsData bottomUpQuantificationGroupCostsData =
new BottomUpQuantificationGroupCostsData();
bottomUpQuantificationGroupCostsData.setBottomUpQuantification(
bottomUpQuantificationDtoBuilder.buildDto(bottomUpQuantification));
bottomUpQuantificationGroupCostsData.setCalculatedGroupsCosts(
calculateProductGroupsCost(Collections.singletonList(bottomUpQuantification),
productGroups)
);
return bottomUpQuantificationGroupCostsData;
}

private boolean isZoneInHierarchy(UUID targetZoneId, GeographicZoneDto zone) {
if (zone == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openlmis.buq.ApproveFacilityForecastingStats;
import org.openlmis.buq.domain.buq.BottomUpQuantification;
import org.openlmis.buq.domain.buq.Rejection;
import org.openlmis.buq.dto.BottomUpQuantificationGroupCostsData;
import org.openlmis.buq.dto.buq.BottomUpQuantificationDto;
import org.openlmis.buq.dto.buq.RejectionDto;
import org.openlmis.buq.dto.productgroup.ProductGroupsCostData;
Expand Down Expand Up @@ -319,31 +320,26 @@ public Page<BottomUpQuantificationDto> getForApproval(Pageable pageable,
}

/**
* Get bottom-up quantifications to approve for right supervisor.
* Get bottom-up quantifications along with group costs data to approve for right supervisor.
*
* @param pageable object used to encapsulate the pagination related values: page, size and sort.
* @return List of bottom-up quantifications to approve.
* @return List of bottom-up quantifications to approve along with group costs data.
*/
@GetMapping(value = "/forFinalApproval")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Page<BottomUpQuantificationDto> getForFinalApproval(Pageable pageable,
public Page<BottomUpQuantificationGroupCostsData> getForFinalApprovalWithGroupCostsData(
Pageable pageable,
@RequestParam(value = PROGRAM_ID) UUID programId,
@RequestParam(value = PROCESSING_PERIOD_ID) UUID processingPeriodId,
@RequestParam(value = GEOGRAPHIC_ZONE_ID) UUID geographicZoneId) {
permissionService.hasAtLeastOnePermission(PermissionService.MOH_PORALG_RIGHTS);
Page<BottomUpQuantification> bottomUpQuantificationsForFinalApproval =
bottomUpQuantificationService.getBottomUpQuantificationsForFinalApproval(programId,
processingPeriodId, geographicZoneId, pageable);

List<BottomUpQuantificationDto> content = bottomUpQuantificationsForFinalApproval
.getContent()
.stream()
.map(buq -> bottomUpQuantificationDtoBuilder.buildDto(buq))
.collect(Collectors.toList());
List<BottomUpQuantificationGroupCostsData> content =
bottomUpQuantificationService.getBottomUpQuantificationsForFinalApprovalWithGroupCosts(
programId, processingPeriodId, geographicZoneId, pageable);

return Pagination.getPage(content, pageable,
bottomUpQuantificationsForFinalApproval.getTotalElements());
content.size());
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/api-definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ schemas:

- bottomUpQuantification: !include schemas/bottomUpQuantification.json
- bottomUpQuantificationPage: !include schemas/bottomUpQuantificationPage.json
- bottomUpQuantificationGroupCostsData: !include schemas/bottomUpQuantificationGroupCostsData.json
- bottomUpQuantificationGroupCostsDataPage: !include schemas/bottomUpQuantificationGroupCostsDataPage.json
- sourceOfFund: !include schemas/sourceOfFund.json
- sourceOfFundPage: !include schemas/sourceOfFundPage.json
- remark: !include schemas/remark.json
Expand Down Expand Up @@ -695,7 +697,7 @@ resourceTypes:
Keep-Alive:
body:
application/json:
schema: bottomUpQuantificationPage
schema: bottomUpQuantificationGroupCostsData
400:
body:
application/json:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema",
"title": "BottomUpQuantificationGroupCostsData",
"description": "Single bottom up quantification group costs data instance",
"properties": {
"calculatedGroupsCosts": {
"type": [
"object",
"null"
],
"title": "calculatedGroupsCosts"
},
"bottomUpQuantification": {
"type": [
"object",
"null"
],
"$ref": "bottomUpQuantification.json",
"title": "bottomUpQuantification"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema",
"title": "Collection",
"description": "Paginated collection",
"properties": {
"content": {
"type": "array",
"items": {
"type": "array",
"$ref": "bottomUpQuantificationGroupCostsData.json"
}
},
"totalPages": {
"type": "integer",
"title": "totalPages"
},
"totalElements": {
"type": "integer",
"title": "totalElements"
},
"size": {
"type": "integer",
"title": "size"
},
"number": {
"type": "integer",
"title": "number"
},
"numberOfElements": {
"type": "integer",
"title": "numberOfElements"
},
"last": {
"type": "boolean",
"title": "last"
},
"first": {
"type": "boolean",
"title": "first"
},
"sort?": {
"title": "sort",
"type": "array",
"items": {
"type": "object"
}
}
},
"required": [
"content",
"totalPages",
"totalElements",
"size",
"number",
"numberOfElements",
"first",
"last"
]
}
Loading