Skip to content
Snippets Groups Projects
SMPoliciesCollectionApiImpl.cpp 2.73 KiB
Newer Older
Rohan's avatar
Rohan committed
/**
 * Npcf_SMPolicyControl API
 * Session Management Policy Control Service © 2020, 3GPP Organizational
 * Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 1.1.1.alpha-5
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */
Rohan's avatar
Rohan committed

#include "SMPoliciesCollectionApiImpl.h"
#include "sm_policy/pcf_sm_policy_control_errors.hpp"
#include "3gpp_29.500.h"
#include "logger.hpp"
Rohan's avatar
Rohan committed

namespace oai {
namespace pcf {
namespace api {

using namespace oai::pcf::helpers;
using namespace oai::pcf::model;
using namespace oai::pcf::app::sm_policy;
Rohan's avatar
Rohan committed

SMPoliciesCollectionApiImpl::SMPoliciesCollectionApiImpl(
    const std::shared_ptr<Pistache::Rest::Router>& rtr,
    const std::shared_ptr<pcf_smpc> smpc_service, std::string address)
    : SMPoliciesCollectionApi(rtr) {
  this->m_address    = address;
  this->smpc_service = smpc_service;
}
Rohan's avatar
Rohan committed

void SMPoliciesCollectionApiImpl::create_sm_policy(
    const SmPolicyContextData& smPolicyContextData,
    Pistache::Http::ResponseWriter& response) {
  int http_code = 500;
  std::string cause;
  ProblemDetails problem_details;
  SmPolicyDecision decision;
  std::string details_string = "";

  pcf_smpc_error_code res = smpc_service->create_sm_policy_handler(
      smPolicyContextData, decision, details_string);
  nlohmann::json json_data;

  switch (res) {
    case pcf_smpc_error_code::Created:
      http_code = HTTP_STATUS_CODE_201_CREATED;
      break;

    case pcf_smpc_error_code::UserUnknown:
      problem_details.setCause("USER_UNKOWN");
      problem_details.setDetail(details_string);
      http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
      break;

    case pcf_smpc_error_code::InvalidParameters:
      problem_details.setCause("ERROR_INITIAL_PARAMETERS");
      problem_details.setDetail(details_string);
      http_code = HTTP_STATUS_CODE_400_BAD_REQUEST;
      break;

    case pcf_smpc_error_code::ContextDenied:
      problem_details.setCause("POLICY_CONTEXT_DENIED");
      problem_details.setDetail(details_string);
      http_code = HTTP_STATUS_CODE_403_FORBIDDEN;
      break;
    default:
      Logger::pcf_app().error("Unknown error code");
      http_code = HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR;
      problem_details.setCause("INTERNAL_ERROR");
      problem_details.setDetail("Internal Service Error: Unknown return code.");
  }

  if (http_code != HTTP_STATUS_CODE_201_CREATED) {
    to_json(json_data, problem_details);
  } else {
    to_json(json_data, decision);
  }
  response.send(Pistache::Http::Code(http_code), json_data.dump().c_str());
Rohan's avatar
Rohan committed
}

}  // namespace api
}  // namespace pcf
}  // namespace oai