Skip to content

Commit

Permalink
OH2-295 Fix Operation Type delete response code
Browse files Browse the repository at this point in the history
  • Loading branch information
mwithi committed Jun 12, 2024
1 parent e23b2b8 commit 65c78b2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/isf/opetype/rest/OperationTypeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class OperationTypeController {

@Autowired
protected OperationTypeBrowserManager opeTypeManager;

@Autowired
protected OperationTypeMapper mapper;

Expand All @@ -68,6 +68,7 @@ public OperationTypeController(OperationTypeBrowserManager opeTypeManager, Opera

/**
* Create a new {@link OperationType}.
*
* @param operationTypeDTO
* @return the newly stored {@link OperationType} object.
* @throws OHServiceException
Expand All @@ -87,21 +88,22 @@ ResponseEntity<OperationTypeDTO> newOperationType(@RequestBody OperationTypeDTO

/**
* Updates the specified {@link OperationType}.
*
* @param operationTypeDTO
* @return the newly updated {@link OperationType} object.
* @throws OHServiceException
*/
@PutMapping(value = "/operationtypes/{code}", produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<OperationTypeDTO> updateOperationTypes(@PathVariable String code, @RequestBody OperationTypeDTO operationTypeDTO)
throws OHServiceException {
throws OHServiceException {
LOGGER.info("Update operationtypes code: {}", operationTypeDTO.getCode());
OperationType opeType = mapper.map2Model(operationTypeDTO);
if (!opeTypeManager.isCodePresent(code)) {
throw new OHAPIException(new OHExceptionMessage("Operation Type not found."));
}
OperationType updatedOperationType;
try {
updatedOperationType = opeTypeManager.updateOperationType(opeType);
updatedOperationType = opeTypeManager.updateOperationType(opeType);
} catch (OHServiceException serviceException) {
throw new OHAPIException(new OHExceptionMessage("Operation Type not updated."));
}
Expand All @@ -110,6 +112,7 @@ ResponseEntity<OperationTypeDTO> updateOperationTypes(@PathVariable String code,

/**
* Get all the available {@link OperationType}s.
*
* @return a {@link List} of {@link OperationType} or NO_CONTENT if there is no data found.
* @throws OHServiceException
*/
Expand All @@ -127,6 +130,7 @@ public ResponseEntity<List<OperationTypeDTO>> getOperationTypes() throws OHServi

/**
* Delete {@link OperationType} with the specified code.
*
* @param code
* @return {@code true} if the {@link OperationType} has been deleted, {@code false} otherwise.
* @throws OHServiceException
Expand All @@ -137,13 +141,13 @@ public ResponseEntity<Boolean> deleteOperationType(@PathVariable("code") String
if (opeTypeManager.isCodePresent(code)) {
List<OperationType> opeTypes = opeTypeManager.getOperationType();
List<OperationType> opeTypeFounds = opeTypes.stream().filter(ad -> ad.getCode().equals(code))
.collect(Collectors.toList());
.collect(Collectors.toList());
if (!opeTypeFounds.isEmpty()) {
try {
opeTypeManager.deleteOperationType(opeTypeFounds.get(0));
} catch (OHServiceException serviceException) {
LOGGER.error("Delete Operation Type code: {} failed.", code);
return ResponseEntity.ok(false);
throw new OHAPIException(new OHExceptionMessage("Operation Type not deleted."));
}
}
} else {
Expand Down

0 comments on commit 65c78b2

Please sign in to comment.