SubscriptionsCollectionApiImpl.cpp 3.59 KB
Newer Older
1
/**
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * Nsmf_EventExposure
 * Session Management Event Exposure Service. © 2019, 3GPP Organizational
 * Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 1.1.0.alpha-1
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */

/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
34
35
36

#include "SubscriptionsCollectionApiImpl.h"

37
38
39
40
41
#include "logger.hpp"
#include "smf_msg.hpp"
#include "3gpp_29.508.h"
#include "itti_msg_sbi.hpp"
#include "smf_config.hpp"
42
#include "3gpp_conversions.hpp"
43
44
45

extern smf::smf_config smf_cfg;

46
47
48
49
50
51
52
namespace oai {
namespace smf_server {
namespace api {

using namespace oai::smf_server::model;

SubscriptionsCollectionApiImpl::SubscriptionsCollectionApiImpl(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
53
    std::shared_ptr<Pistache::Rest::Router> rtr, smf::smf_app* smf_app_inst,
54
    std::string address)
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
55
56
57
    : SubscriptionsCollectionApi(rtr),
      m_smf_app(smf_app_inst),
      m_address(address) {}
58

59
void SubscriptionsCollectionApiImpl::create_individual_subcription(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
60
61
    const NsmfEventExposure& nsmfEventExposure,
    Pistache::Http::ResponseWriter& response) {
62
63
64
  Logger::smf_api_server().info(
      "SubscriptionsCollectionApiImpl::create_individual_subcription...");

65
  // Create a  message and store the necessary information
66
67
  Logger::smf_api_server().debug(
      "Create a Event Exposure message and store the necessary information");
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
68
  smf::event_exposure_msg event_exposure = {};
69

70
71
72
  // Convert from NsmfEventExposure to event_exposure_msg
  xgpp_conv::smf_event_exposure_notification_from_openapi(
      nsmfEventExposure, event_exposure);
73

74
  // Handle the message in smf_app
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
75
76
  std::shared_ptr<itti_sbi_event_exposure_request> itti_msg =
      std::make_shared<itti_sbi_event_exposure_request>(
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
77
          TASK_SMF_SBI, TASK_SMF_APP);
78
  itti_msg->event_exposure = event_exposure;
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
79
  itti_msg->http_version   = 1;
80
81
82

  evsub_id_t sub_id = m_smf_app->handle_event_exposure_subscription(itti_msg);

83
  // Send response
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
84
  nlohmann::json json_data = {};
85
86
87
88
  to_json(json_data, nsmfEventExposure);

  if (sub_id != -1) {
    json_data["subId"] = std::to_string(sub_id);
Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
89
90
91
    response.headers().add<Pistache::Http::Header::Location>(
        m_address + base + smf_cfg.sbi_api_version + "/nsmf_event-exposure/" +
        std::to_string(sub_id));  // Location header
92
93
  }

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
94
95
  response.headers().add<Pistache::Http::Header::ContentType>(
      Pistache::Http::Mime::MediaType("application/json"));
96
  response.send(Pistache::Http::Code(201), json_data.dump().c_str());
97
98
}

Tien-Thinh Nguyen's avatar
Tien-Thinh Nguyen committed
99
100
101
}  // namespace api
}  // namespace smf_server
}  // namespace oai