From 8a306392346b26c2974eaa53b98a335e0ecea6a2 Mon Sep 17 00:00:00 2001 From: tsznaj Date: Wed, 19 Jun 2024 14:59:34 +0200 Subject: [PATCH 1/5] OAM-200: Added container for request body due to problems with array in body. --- .../fulfillment/web/OrderController.java | 6 ++++-- .../openlmis/fulfillment/web/util/IdsDto.java | 12 ++++++++++++ src/main/resources/api-definition.yaml | 6 +++--- src/main/resources/schemas/idsDto.json | 16 ++++++++++++++++ .../fulfillment/web/OrderControllerTest.java | 5 ++++- 5 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java create mode 100644 src/main/resources/schemas/idsDto.json diff --git a/src/main/java/org/openlmis/fulfillment/web/OrderController.java b/src/main/java/org/openlmis/fulfillment/web/OrderController.java index 31d3c9c6..b4b2b24d 100644 --- a/src/main/java/org/openlmis/fulfillment/web/OrderController.java +++ b/src/main/java/org/openlmis/fulfillment/web/OrderController.java @@ -59,6 +59,7 @@ import org.openlmis.fulfillment.util.FacilityTypeHelper; import org.openlmis.fulfillment.web.util.BasicOrderDto; import org.openlmis.fulfillment.web.util.BasicOrderDtoBuilder; +import org.openlmis.fulfillment.web.util.IdsDto; import org.openlmis.fulfillment.web.util.OrderDto; import org.openlmis.fulfillment.web.util.OrderDtoBuilder; import org.openlmis.fulfillment.web.util.OrderReportDto; @@ -511,12 +512,13 @@ public ResultDto retryOrderTransfer(@PathVariable("id") UUID id) { /** * Delete multiple orders with status CREATING. * - * @param ids ids of orders to be deleted, should not be empty + * @param idsDto ids of orders to be deleted, should not be empty */ @RequestMapping(value = "/orders", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) - public void deleteMultipleOrders(@RequestBody List ids) { + public void deleteMultipleOrders(@RequestBody IdsDto idsDto) { + List ids = idsDto.getIds(); if (CollectionUtils.isEmpty(ids)) { XLOGGER.info("Nothing to delete"); throw new ValidationException("no ids given"); diff --git a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java new file mode 100644 index 00000000..18b1122e --- /dev/null +++ b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java @@ -0,0 +1,12 @@ +package org.openlmis.fulfillment.web.util; + +import java.util.List; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class IdsDto { + private List ids; +} diff --git a/src/main/resources/api-definition.yaml b/src/main/resources/api-definition.yaml index dd7db83f..42ca9415 100644 --- a/src/main/resources/api-definition.yaml +++ b/src/main/resources/api-definition.yaml @@ -100,7 +100,7 @@ schemas: "items": { "type": "object", "$ref": "schemas/auditLogEntry.json" } } - orderStatsData: !include schemas/orderStatsData.json - + - idsDto: !include schemas/idsDto.json traits: - secured: queryParameters: @@ -369,10 +369,10 @@ resourceTypes: schema: localizedMessage delete: is: [ secured ] - description: Removes many orders by id. This endpoint requires ORDERE_DELETE right. + description: Removes many orders by id. This endpoint requires ORDERS_DELETE right. body: application/json: - schema: uuidArray + schema: idsDto responses: "204": headers: diff --git a/src/main/resources/schemas/idsDto.json b/src/main/resources/schemas/idsDto.json new file mode 100644 index 00000000..1b010d58 --- /dev/null +++ b/src/main/resources/schemas/idsDto.json @@ -0,0 +1,16 @@ +{ + "type": "object", + "$schema": "http://json-schema.org/draft-04/schema", + "title": "IdsDto", + "description": "uuids container dto", + "properties": { + "ids": { + "title": "ids", + "type": "array", + "items": { + "type": "string", + "title": "id" + } + } + } +} diff --git a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java index 0b44761f..bfddddbb 100644 --- a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java +++ b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java @@ -56,6 +56,7 @@ import org.openlmis.fulfillment.testutils.UpdateDetailsDataBuilder; import org.openlmis.fulfillment.util.AuthenticationHelper; import org.openlmis.fulfillment.util.FacilityTypeHelper; +import org.openlmis.fulfillment.web.util.IdsDto; import org.openlmis.fulfillment.web.util.OrderDto; import org.openlmis.fulfillment.web.util.OrderDtoBuilder; import org.openlmis.fulfillment.web.validator.OrderValidator; @@ -186,6 +187,8 @@ public void shouldDeleteMultipleOrders() { ids.add(order.getId()); ids.add(orderTwo.getId()); + IdsDto idsDto = new IdsDto(ids); + List orders = new ArrayList(); orders.add(order); orders.add(orderTwo); @@ -196,7 +199,7 @@ public void shouldDeleteMultipleOrders() { receivingIds.add(orderTwo.getReceivingFacilityId()); //when - orderController.deleteMultipleOrders(ids); + orderController.deleteMultipleOrders(idsDto); //then verify(orderRepository).findByIdInAndStatus(ids, OrderStatus.CREATING.name()); From 26fb247035ec409acf9c6b1972cd9dbc2936623d Mon Sep 17 00:00:00 2001 From: tsznaj Date: Wed, 19 Jun 2024 16:30:18 +0200 Subject: [PATCH 2/5] OAM-200: Added copyrights. --- .../org/openlmis/fulfillment/web/util/IdsDto.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java index 18b1122e..3c635cd4 100644 --- a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java +++ b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java @@ -1,3 +1,18 @@ +/* + * 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 info@OpenLMIS.org. + */ + package org.openlmis.fulfillment.web.util; import java.util.List; From 2738d4d7774e4b73bf10cbc0d8327e0078975e65 Mon Sep 17 00:00:00 2001 From: tsznaj Date: Thu, 20 Jun 2024 11:34:33 +0200 Subject: [PATCH 3/5] OAM-200: Added fixed. --- .../web/OrderControllerIntegrationTest.java | 37 +++++++++++++------ .../openlmis/fulfillment/web/util/IdsDto.java | 2 + .../fulfillment/web/OrderControllerTest.java | 5 ++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java b/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java index 69eb7484..a5ff5e3b 100644 --- a/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java +++ b/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java @@ -50,6 +50,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; +import com.jayway.restassured.response.ValidatableResponse; import guru.nidi.ramltester.junit.RamlMatchers; import java.math.BigDecimal; import java.time.LocalDate; @@ -110,6 +111,7 @@ import org.openlmis.fulfillment.util.DateHelper; import org.openlmis.fulfillment.util.FacilityTypeHelper; import org.openlmis.fulfillment.web.util.BasicOrderDto; +import org.openlmis.fulfillment.web.util.IdsDto; import org.openlmis.fulfillment.web.util.OrderDto; import org.openlmis.fulfillment.web.util.StatusChangeDto; import org.springframework.beans.factory.annotation.Autowired; @@ -518,14 +520,16 @@ public void shouldDeleteMultipleOrders() { given(orderRepository.findByIdInAndStatus(uuids, OrderStatus.CREATING.name())) .willReturn(orders); - restAssured.given() + IdsDto idsDto = new IdsDto(uuids); + + ValidatableResponse response = restAssured.given() .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE) - .body(uuids) + .body(idsDto) .when() .delete(RESOURCE_URL) - .then() - .statusCode(204); + .then(); +// .statusCode(204); verify(orderRepository).findByIdInAndStatus(uuids, OrderStatus.CREATING.name()); @@ -554,15 +558,24 @@ public void shouldNotDeleteMultipleOrdersAsSomeOfTheIdsPointToOrdersWithAnotherS given(orderRepository.findByIdInAndStatus(uuids, OrderStatus.CREATING.name())) .willReturn(orders); - restAssured.given() - .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) - .contentType(APPLICATION_JSON_VALUE) - .body(uuids) - .when() - .delete(RESOURCE_URL) - .then() - .statusCode(404); + IdsDto idsDto = new IdsDto(uuids); + + ValidatableResponse response = null; + try { + response = restAssured.given() + .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) + .contentType(APPLICATION_JSON_VALUE) + .body(idsDto) + .when() + .delete(RESOURCE_URL) + .then(); +// .statusCode(404); + } catch (Exception e) { + e.printStackTrace(); + + + } verify(orderRepository).findByIdInAndStatus(uuids, OrderStatus.CREATING.name()); verify(orderRepository, times(0)).deleteById(any(UUID.class)); diff --git a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java index 3c635cd4..bfb407bc 100644 --- a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java +++ b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java @@ -19,9 +19,11 @@ import java.util.UUID; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data @AllArgsConstructor +@NoArgsConstructor public class IdsDto { private List ids; } diff --git a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java index bfddddbb..38a8107d 100644 --- a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java +++ b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java @@ -187,8 +187,6 @@ public void shouldDeleteMultipleOrders() { ids.add(order.getId()); ids.add(orderTwo.getId()); - IdsDto idsDto = new IdsDto(ids); - List orders = new ArrayList(); orders.add(order); orders.add(orderTwo); @@ -198,12 +196,15 @@ public void shouldDeleteMultipleOrders() { receivingIds.add(order.getReceivingFacilityId()); receivingIds.add(orderTwo.getReceivingFacilityId()); + IdsDto idsDto = new IdsDto(ids); + //when orderController.deleteMultipleOrders(idsDto); //then verify(orderRepository).findByIdInAndStatus(ids, OrderStatus.CREATING.name()); verify(permissionService).canDeleteOrders(receivingIds); + verify(orderRepository).deleteById(order.getId()); verify(orderRepository).deleteById(orderTwo.getId()); } } From 70a8bbd8602fc08d602e7fc9660686a93a988fc8 Mon Sep 17 00:00:00 2001 From: tsznaj Date: Thu, 20 Jun 2024 12:12:34 +0200 Subject: [PATCH 4/5] OAM-200: Clean up. --- .../web/OrderControllerIntegrationTest.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java b/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java index a5ff5e3b..fcdcb3e0 100644 --- a/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java +++ b/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java @@ -50,7 +50,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import com.jayway.restassured.response.ValidatableResponse; import guru.nidi.ramltester.junit.RamlMatchers; import java.math.BigDecimal; import java.time.LocalDate; @@ -521,15 +520,14 @@ public void shouldDeleteMultipleOrders() { .willReturn(orders); IdsDto idsDto = new IdsDto(uuids); - - ValidatableResponse response = restAssured.given() + restAssured.given() .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE) .body(idsDto) .when() .delete(RESOURCE_URL) - .then(); -// .statusCode(204); + .then() + .statusCode(204); verify(orderRepository).findByIdInAndStatus(uuids, OrderStatus.CREATING.name()); @@ -560,22 +558,15 @@ public void shouldNotDeleteMultipleOrdersAsSomeOfTheIdsPointToOrdersWithAnotherS IdsDto idsDto = new IdsDto(uuids); - ValidatableResponse response = null; - try { - response = restAssured.given() - .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) - .contentType(APPLICATION_JSON_VALUE) - .body(idsDto) - .when() - .delete(RESOURCE_URL) - .then(); -// .statusCode(404); - } catch (Exception e) { - - e.printStackTrace(); - + restAssured.given() + .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) + .contentType(APPLICATION_JSON_VALUE) + .body(idsDto) + .when() + .delete(RESOURCE_URL) + .then() + .statusCode(404); - } verify(orderRepository).findByIdInAndStatus(uuids, OrderStatus.CREATING.name()); verify(orderRepository, times(0)).deleteById(any(UUID.class)); From 20cdfd97a1d75b17f8abf4258b698d33b28d7e45 Mon Sep 17 00:00:00 2001 From: tsznaj Date: Thu, 20 Jun 2024 12:12:50 +0200 Subject: [PATCH 5/5] OAM-200: Added integrationTest for build. --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index d55b7a21..d59ffa06 100755 --- a/build.sh +++ b/build.sh @@ -7,4 +7,4 @@ --source-file src/main/resources/messages_en.properties # Run Gradle build -gradle clean build +gradle clean build integrationTest