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.ics.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.ics.controllers.VoidResponse;
38 import org.oransc.ics.controllers.a1e.A1eConsts;
39 import org.oransc.ics.controllers.a1e.A1eEiJobStatus;
40 import org.oransc.ics.controllers.r1consumer.ConsumerConsts;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.http.HttpStatus;
44 import org.springframework.http.MediaType;
45 import org.springframework.http.ResponseEntity;
46 import org.springframework.web.bind.annotation.PathVariable;
47 import org.springframework.web.bind.annotation.PostMapping;
48 import org.springframework.web.bind.annotation.RequestBody;
49 import org.springframework.web.bind.annotation.RestController;
51 @RestController("A1eCallbacksSimulatorController")
52 @Tag(name = A1eConsts.CONSUMER_API_CALLBACKS_NAME, description = A1eConsts.CONSUMER_API_CALLBACKS_DESCRIPTION)
53 public class A1eCallbacksSimulatorController {
55 private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
57 public static class TestResults {
59 public List<A1eEiJobStatus> eiJobStatusCallbacks =
60 Collections.synchronizedList(new ArrayList<A1eEiJobStatus>());
63 eiJobStatusCallbacks.clear();
68 private TestResults testResults = new TestResults();
70 public static String getJobStatusUrl(String infoJobId) {
71 return "/example-dataconsumer/info-jobs/" + infoJobId + "/status";
75 path = "/example-dataconsumer/info-jobs/{infoJobId}/status",
76 produces = MediaType.APPLICATION_JSON_VALUE)
78 summary = "Callback for changed Information Job status",
79 description = "The primitive is implemented by the data consumer and is invoked when a Information Job status has been changed.")
84 description = "OK", //
85 content = @Content(schema = @Schema(implementation = VoidResponse.class))) //
87 public ResponseEntity<Object> jobStatusCallback( //
88 @PathVariable(ConsumerConsts.INFO_JOB_ID_PATH) String infoJobId, //
89 @RequestBody A1eEiJobStatus status) {
90 logger.info("Job status callback status: {} infoJobId: {}", status.state, infoJobId);
91 this.testResults.eiJobStatusCallbacks.add(status);
92 return new ResponseEntity<>(HttpStatus.OK);