2 * ============LICENSE_START=======================================================
3 * Modifications Copyright (C) 2025 OpenInfra Foundation Europe
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.oran.smo.teiv.adapters.focom_to_teiv_adapter;
22 import com.fasterxml.jackson.core.JsonProcessingException;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import io.cloudevents.CloudEvent;
25 import lombok.RequiredArgsConstructor;
26 import lombok.extern.slf4j.Slf4j;
27 import org.oran.smo.teiv.adapters.focom_to_teiv_adapter.service.FocomToTeivModelBuilder;
28 import org.springframework.scheduling.annotation.Scheduled;
29 import org.springframework.stereotype.Component;
31 import java.io.IOException;
36 @RequiredArgsConstructor
37 public class FocomToTeivIngestion {
39 private static final ObjectMapper objectMapper = new ObjectMapper();
40 private final KafkaEventProducer kafkaEventProducer;
41 private final FocomToTeivModelBuilder jsonBuilder;
43 @Scheduled(fixedRateString = "${polling.interval}")
44 public void pollExternalApi() throws IOException {
45 Map<String, Object> json = jsonBuilder.getFocomtoTeivJson();
46 log.debug("Retrieved JSON for FOCOM_PROVISION_REQUEST_NAME: {}", json);
48 sendCloudEvent(json, "merge");
49 } catch (IOException e) {
50 log.error("Failed to poll external API or send CloudEvent", e);
54 private void sendCloudEvent(Map<String, Object> json, String eventType) throws JsonProcessingException {
55 String payload = objectMapper.writeValueAsString(json);
56 CloudEvent event = CloudEventFactory.createEvent(payload, eventType);
57 log.info("Sending CloudEvent with payload: {}", payload);
58 kafkaEventProducer.sendCloudEvent(event);