Skip to content

Commit

Permalink
Merge pull request eclipse-tractusx#514 from FraunhoferISST/fix/deman…
Browse files Browse the repository at this point in the history
…dandcapacitynotification_swaggerui

fix: demandandcapacitynotification_swaggerui
  • Loading branch information
tom-rm-meyer-ISST authored Jul 23, 2024
2 parents a7c7e04 + 663812e commit 260c08e
Showing 1 changed file with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
*/
package org.eclipse.tractusx.puris.backend.demandandcapacitynotification.controller;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -50,24 +53,26 @@ public class DemandAndCapacityNotificationRequestApiController {

@Operation(summary = "This endpoint receives the DemandAndCapacityNotification 2.0.0 requests")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Ok"),
@ApiResponse(responseCode = "400", description = "Bad Request"),
@ApiResponse(responseCode = "500", description = "Internal Server Error")
@ApiResponse(responseCode = "200", description = "Ok", content = @Content),
@ApiResponse(responseCode = "400", description = "Bad Request", content = @Content),
@ApiResponse(responseCode = "500", description = "Internal Server Error", content = @Content)
})
@PostMapping("request")
public ResponseEntity<DemandAndCapacityNotificationSamm> postDemandAndCapacityNotification(
public ResponseEntity<?> postDemandAndCapacityNotification(
@RequestHeader("edc-bpn") String bpnl,
@RequestBody String body)
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {@Content(examples = {
@ExampleObject(sample)
})})
@RequestBody JsonNode body)
{
if (!bpnlPattern.matcher(bpnl).matches()) {
log.warn("Rejecting request at DemandAndCapacityNotification request 2.0.0 endpoint. Invalid BPNL");
return ResponseEntity.badRequest().build();
}
try {
var data = objectMapper.readTree(body);
log.info("Received POST request for DemandAndCapacityNotification 2.0.0 with BPNL: " + bpnl);
var notification = objectMapper.readValue(
data.get("content").get("demandAndCapacityNotification").toString(),
body.get("content").get("demandAndCapacityNotification").toString(),
DemandAndCapacityNotificationSamm.class);
demandAndCapacityNotificationRequestApiService.handleIncomingNotification(bpnl, notification);
} catch (Exception e) {
Expand All @@ -76,4 +81,44 @@ public ResponseEntity<DemandAndCapacityNotificationSamm> postDemandAndCapacityNo
}
return ResponseEntity.ok(null);
}

final static String sample = "{\n" +
" \"header\": {\n" +
" \"senderBpn\": \"BPNL7588787849VQ\",\n" +
" \"context\": \"CX-DemandAndCapacityNotification:2.0\",\n" +
" \"messageId\": \"3b4edc05-e214-47a1-b0c2-1d831cdd9ba9\",\n" +
" \"receiverBpn\": \"BPNL6666787765VQ\",\n" +
" \"sentDateTime\": \"2023-06-19T21:24:00+07:00\",\n" +
" \"version\": \"3.0.0\"\n" +
" },\n" +
" \"content\": {\n" +
" \"demandAndCapacityNotification\": {\n" +
" \"affectedSitesSender\": [\n" +
" \"BPNS7588787849VQ\"\n" +
" ],\n" +
" \"affectedSitesRecipient\": [\n" +
" \"BPNS6666787765VQ\"\n" +
" ],\n" +
" \"materialNumberSupplier\": [\n" +
" \"MNR-8101-ID146955.001\"\n" +
" ],\n" +
" \"contentChangedAt\": \"2023-12-13T15:00:00+01:00\",\n" +
" \"startDateOfEffect\": \"2023-12-13T15:00:00+01:00\",\n" +
" \"relatedNotificationId\": \"urn:uuid:d05cef4a-b692-45bf-87cc-eda2d84e4c04\",\n" +
" \"materialNumberCustomer\": [\n" +
" \"MNR-7307-AU340474.002\"\n" +
" ],\n" +
" \"leadingRootCause\": \"strike\",\n" +
" \"materialGlobalAssetId\": [\n" +
" \"urn:uuid:48878d48-6f1d-47f5-8ded-a441d0d879df\"\n" +
" ],\n" +
" \"effect\": \"demand-reduction\",\n" +
" \"notificationId\": \"urn:uuid:d9452f24-3bf3-4134-b3eb-68858f1b2362\",\n" +
" \"text\": \"Capacity reduction due to ongoing strike.\",\n" +
" \"expectedEndDateOfEffect\": \"2023-12-17T08:00:00+01:00\",\n" +
" \"sourceNotificationId\": \"urn:uuid:c69cb3e4-16ad-43c3-82b9-0deac75ecf9e\",\n" +
" \"status\": \"resolved\"\n" +
" }\n" +
" }\n" +
"}";
}

0 comments on commit 260c08e

Please sign in to comment.