-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update scan and file Rest endpoints to return proper error codes (#123)
- Loading branch information
Showing
8 changed files
with
114 additions
and
65 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...om/solace/maas/ep/event/management/agent/scanManager/mapper/DataCollectionFileMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager.mapper; | ||
|
||
import com.solace.maas.ep.event.management.agent.scanManager.model.DataCollectionFileBO; | ||
import com.solace.maas.ep.event.management.agent.scanManager.model.DataCollectionFileDTO; | ||
import org.mapstruct.CollectionMappingStrategy; | ||
import org.mapstruct.Mapper; | ||
|
||
@Mapper(componentModel = "spring", collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED) | ||
public interface DataCollectionFileMapper { | ||
DataCollectionFileBO map(DataCollectionFileDTO dto); | ||
|
||
DataCollectionFileDTO map(DataCollectionFileBO bo); | ||
} |
14 changes: 14 additions & 0 deletions
14
...va/com/solace/maas/ep/event/management/agent/scanManager/model/DataCollectionFileDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class DataCollectionFileDTO { | ||
private String id; | ||
|
||
private String path; | ||
|
||
private boolean purged; | ||
} |
24 changes: 24 additions & 0 deletions
24
.../solace/maas/ep/event/management/agent/scanManager/rest/DataCollectionFileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager.rest; | ||
|
||
import com.solace.maas.ep.event.management.agent.scanManager.model.DataCollectionFileDTO; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
public interface DataCollectionFileController { | ||
|
||
@Operation( | ||
summary = "Retrieves the details about scan files", | ||
description = "Use this API to retrieve the details about the files generated by a scan request.", | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "Details about the scan files have been retrieved successfully." | ||
) | ||
} | ||
) | ||
ResponseEntity<Page<DataCollectionFileDTO>> list(@RequestParam("scanId") String scanId, Pageable pageable); | ||
} |
21 changes: 13 additions & 8 deletions
21
...ace/maas/ep/event/management/agent/scanManager/rest/DataCollectionFileControllerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager.rest; | ||
|
||
import com.solace.maas.ep.event.management.agent.constants.RestEndpoint; | ||
import com.solace.maas.ep.event.management.agent.scanManager.model.DataCollectionFileBO; | ||
import com.solace.maas.ep.event.management.agent.scanManager.mapper.DataCollectionFileMapper; | ||
import com.solace.maas.ep.event.management.agent.scanManager.model.DataCollectionFileDTO; | ||
import com.solace.maas.ep.event.management.agent.service.DataCollectionFileService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
|
||
@Slf4j | ||
@Validated | ||
@CrossOrigin | ||
@RestController | ||
@RequestMapping(RestEndpoint.DATA_COLLECTION_FILE_URL) | ||
public class DataCollectionFileControllerImpl { | ||
private final DataCollectionFileService dataCollectionFileService; | ||
public class DataCollectionFileControllerImpl implements DataCollectionFileController { | ||
private final DataCollectionFileService dataCollectionFileService; | ||
private final DataCollectionFileMapper dataCollectionFileMapper; | ||
|
||
public DataCollectionFileControllerImpl(DataCollectionFileService dataCollectionFileService) { | ||
public DataCollectionFileControllerImpl(DataCollectionFileService dataCollectionFileService, | ||
DataCollectionFileMapper dataCollectionFileMapper) { | ||
this.dataCollectionFileService = dataCollectionFileService; | ||
this.dataCollectionFileMapper = dataCollectionFileMapper; | ||
} | ||
|
||
@Override | ||
@GetMapping("/query") | ||
public ResponseEntity<Page<DataCollectionFileBO>> list(@RequestParam("scanId") String scanId, | ||
Pageable pageable) { | ||
return ResponseEntity.ok().body(dataCollectionFileService.findByScanId(scanId, pageable)); | ||
public ResponseEntity<Page<DataCollectionFileDTO>> list(@RequestParam("scanId") String scanId, Pageable pageable) { | ||
return ResponseEntity.ok().body(dataCollectionFileService.findByScanId(scanId, pageable) | ||
.map(dataCollectionFileMapper::map)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 16 additions & 12 deletions
28
...ain/java/com/solace/maas/ep/event/management/agent/scanManager/rest/RestErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,33 @@ | ||
package com.solace.maas.ep.event.management.agent.scanManager.rest; | ||
|
||
import com.solace.maas.ep.common.model.EventErrorDTO; | ||
import com.solace.maas.ep.event.management.agent.plugin.route.exceptions.ClientException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.data.mapping.PropertyReferenceException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@Order(Ordered.HIGHEST_PRECEDENCE) | ||
@RestControllerAdvice | ||
public class RestErrorHandler { | ||
|
||
@ExceptionHandler({RestException.class}) | ||
@ExceptionHandler(ClientException.class) | ||
@ResponseBody | ||
public ResponseEntity<EventErrorDTO> handleRestException(RestException restException) { | ||
public ResponseEntity<EventErrorDTO> handleRestException(ClientException restException) { | ||
EventErrorDTO eventErrorDTO = new EventErrorDTO(restException.getMessage()); | ||
return new ResponseEntity<>(eventErrorDTO, HttpStatus.BAD_REQUEST); | ||
} | ||
|
||
@ResponseStatus(value = HttpStatus.BAD_REQUEST) | ||
public static class RestException extends RuntimeException { | ||
public RestException(String message) { | ||
super(message); | ||
} | ||
|
||
public RestException(String message, Exception cause) { | ||
super(message, cause); | ||
} | ||
@ExceptionHandler(PropertyReferenceException.class) | ||
@ResponseBody | ||
public ResponseEntity<EventErrorDTO> handlePropertyReferenceException(PropertyReferenceException exception) { | ||
EventErrorDTO eventErrorDTO = new EventErrorDTO(exception.getMessage()); | ||
return new ResponseEntity<>(eventErrorDTO, HttpStatus.BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters