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

OAM-200: Added container for request body due to problems with array … #33

Merged
merged 5 commits into from
Jun 20, 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
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
--source-file src/main/resources/messages_en.properties

# Run Gradle build
gradle clean build
gradle clean build integrationTest
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -511,12 +512,13 @@ public ResultDto<Boolean> 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<UUID> ids) {
public void deleteMultipleOrders(@RequestBody IdsDto idsDto) {

List<UUID> ids = idsDto.getIds();
if (CollectionUtils.isEmpty(ids)) {
XLOGGER.info("Nothing to delete");
throw new ValidationException("no ids given");
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java
Original file line number Diff line number Diff line change
@@ -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 [email protected].
*/

package org.openlmis.fulfillment.web.util;
tsznaj marked this conversation as resolved.
Show resolved Hide resolved

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<UUID> ids;
}
6 changes: 3 additions & 3 deletions src/main/resources/api-definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/schemas/idsDto.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
Loading