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 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..fcdcb3e0 100644 --- a/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java +++ b/src/integration-test/java/org/openlmis/fulfillment/web/OrderControllerIntegrationTest.java @@ -110,6 +110,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,10 +519,11 @@ public void shouldDeleteMultipleOrders() { given(orderRepository.findByIdInAndStatus(uuids, OrderStatus.CREATING.name())) .willReturn(orders); + IdsDto idsDto = new IdsDto(uuids); restAssured.given() .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE) - .body(uuids) + .body(idsDto) .when() .delete(RESOURCE_URL) .then() @@ -554,10 +556,12 @@ public void shouldNotDeleteMultipleOrdersAsSomeOfTheIdsPointToOrdersWithAnotherS given(orderRepository.findByIdInAndStatus(uuids, OrderStatus.CREATING.name())) .willReturn(orders); + IdsDto idsDto = new IdsDto(uuids); + restAssured.given() .header(HttpHeaders.AUTHORIZATION, getTokenHeader()) .contentType(APPLICATION_JSON_VALUE) - .body(uuids) + .body(idsDto) .when() .delete(RESOURCE_URL) .then() 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..bfb407bc --- /dev/null +++ b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java @@ -0,0 +1,29 @@ +/* + * 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; +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/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..38a8107d 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; @@ -195,12 +196,15 @@ public void shouldDeleteMultipleOrders() { receivingIds.add(order.getReceivingFacilityId()); receivingIds.add(orderTwo.getReceivingFacilityId()); + IdsDto idsDto = new IdsDto(ids); + //when - orderController.deleteMultipleOrders(ids); + 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()); } }