2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oransc.enrichment.controller;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.media.Content;
25 import io.swagger.v3.oas.annotations.media.Schema;
26 import io.swagger.v3.oas.annotations.responses.ApiResponse;
27 import io.swagger.v3.oas.annotations.responses.ApiResponses;
28 import io.swagger.v3.oas.annotations.tags.Tag;
30 import java.lang.invoke.MethodHandles;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.List;
37 import org.oransc.enrichment.controllers.VoidResponse;
38 import org.oransc.enrichment.controllers.consumer.ConsumerConsts;
39 import org.oransc.enrichment.controllers.consumer.ConsumerEiJobStatus;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.http.HttpStatus;
43 import org.springframework.http.MediaType;
44 import org.springframework.http.ResponseEntity;
45 import org.springframework.web.bind.annotation.PathVariable;
46 import org.springframework.web.bind.annotation.PostMapping;
47 import org.springframework.web.bind.annotation.RequestBody;
48 import org.springframework.web.bind.annotation.RestController;
50 @RestController("ConsumerSimulatorController")
51 @Tag(name = ConsumerConsts.CONSUMER_API_CALLBACKS_NAME)
52 public class ConsumerSimulatorController {
54 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
56 public static class TestResults {
58 public List<ConsumerEiJobStatus> status = Collections.synchronizedList(new ArrayList<ConsumerEiJobStatus>());
66 private TestResults testResults = new TestResults();
68 public static String getJobStatusUrl(String eiJobId) {
69 return "/example_dataconsumer/eijobs/" + eiJobId + "/status";
72 @PostMapping(path = "/example_dataconsumer/eijobs/{eiJobId}/status", produces = MediaType.APPLICATION_JSON_VALUE)
74 summary = "Callback for changed EI job status",
75 description = "The primitive is implemented by the data consumer and is invoked when a EI job status has been changed.")
80 description = "OK", //
81 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
83 public ResponseEntity<Object> jobStatusCallback( //
84 @PathVariable("eiJobId") String eiJobId, //
85 @RequestBody ConsumerEiJobStatus status) {
86 logger.info("Job status callback status: {} eiJobId: {}", status.state, eiJobId);
87 this.testResults.status.add(status);
88 return new ResponseEntity<>(HttpStatus.OK);