Citycom API
This commit is contained in:
@@ -72,7 +72,15 @@
|
||||
</tr><tr>
|
||||
<th>Rimo Operational State</th>
|
||||
<td><?=$address->rimo_op_state?></td>
|
||||
</tr><tr>
|
||||
</tr>
|
||||
<?php if($address->vlan_stag): ?>
|
||||
<tr>
|
||||
<th>VLAN s-tag</th>
|
||||
<td class="text-monospace"><?=$address->vlan_stag?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
|
||||
<tr>
|
||||
<td colspan="2"><h4>Status</h4></td>
|
||||
</tr><tr>
|
||||
<th>Status</th>
|
||||
|
||||
85
application/Api/v1/Modules/Operationaldata/SnoppCitycom.php
Normal file
85
application/Api/v1/Modules/Operationaldata/SnoppCitycom.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace application\Api\v1\Modules\Operationaldata;
|
||||
use application\Api\v1\Modules;
|
||||
|
||||
require_once(APPDIR."/Api/v1/Modules/ApiControllerModule.php");
|
||||
|
||||
/*
|
||||
* API Endpoints for Operationaldata from SNOPP
|
||||
*/
|
||||
class SnoppCitycom extends Modules\ApiControllerModule
|
||||
{
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function orderService($req_id) {
|
||||
if(!$req_id) {
|
||||
return \mfResponse::BadRequest(["message" => "id missing"]);
|
||||
}
|
||||
|
||||
$bb_up = $this->post["bb_up"];
|
||||
$bb_down = $this->post["bb_down"];
|
||||
$execution_date = false;
|
||||
|
||||
if($this->post["execution_date"]) {
|
||||
try {
|
||||
$execution_date = new DateTime($this->post["execution_date"]);
|
||||
} catch(\Exception $e) {
|
||||
return mfResponse::BadRequest(["message" => "Invalid Timestamp format"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!is_numeric($bb_down) || !$bb_down || !is_numeric($bb_up) || !$bb_up || !$bb_down > 10000 || $bb_up > 10000) {
|
||||
return \mfResponse::BadRequest(["message" => "Invalid bandwidth"]);
|
||||
}
|
||||
|
||||
$wohneinheit = false;
|
||||
if(is_numeric($req_id)) {
|
||||
$id = $req_id;
|
||||
$wohneinheit = new \ADBWohneinheit($id);
|
||||
}
|
||||
if(!$wohneinheit || !$wohneinheit->id) {
|
||||
$oaid = $req_id;
|
||||
$wohneinheit = \ADBWohneinheitModel::getFirst(["oaid" => $oaid]);
|
||||
if (!$wohneinheit) {
|
||||
return \mfResponse::NotFound(["message" => "Home not found"]);
|
||||
}
|
||||
}
|
||||
|
||||
$preorder = \PreorderModel::getFirstActive(["adb_wohneinheit_id" => $wohneinheit->id]);
|
||||
if(!$preorder) {
|
||||
return \mfResponse::NotFound(["message" => "Home not found"]);
|
||||
}
|
||||
|
||||
$cc_home_id = \Citycom_OanApiHelper::hausnummerExtrefToCitycomId($wohneinheit->extref);
|
||||
$data["bb_up"] = $bb_up;
|
||||
$data["bb_down"] = $bb_down;
|
||||
$data["product_name"] = false;
|
||||
$data["execution_date"] = ($execution_date) ? $execution_date->format("Y-m-d") : false;
|
||||
$data["services"] = CITYCOM_OAN_API_SERVICES_FOR_ORDER;
|
||||
|
||||
if($preorder->campaign->name == "Citycom - Graz") {
|
||||
$data["product_name"] = "Estmk OAN $bb_down/$bb_up";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$cc_api_client = new \Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS);
|
||||
$cc_api = new \Citycom_OanApiHelper($cc_api_client);
|
||||
|
||||
if(!$cc_api->orderServices($preorder, $cc_home_id, $data)) {
|
||||
return \mfResponse::InternalServerError(["message" => "Error activating service"]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,8 @@ class OperationaldataApicontroller extends mfBaseApicontroller
|
||||
$this->addRoute("/operationaldata/home/:id/connected", [$modules["Snopp"], "setPreorderConnected"], "POST");
|
||||
$this->addRoute("/operationaldata/home/:id/active", [$modules["Snopp"], "setPreorderActive"], "POST");
|
||||
|
||||
$this->addRoute("/operationaldata/preorder/:id/orderService", [$modules["SnoppCitycom"], "orderService"], "POST");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -132,8 +134,12 @@ class OperationaldataApicontroller extends mfBaseApicontroller
|
||||
$name = $network->name;
|
||||
|
||||
if($network->adb_netzgebiet_id) {
|
||||
$cityname = preg_replace('/^Liezen\s+-\s+/', '', $network->adb_netzgebiet->name);
|
||||
$name = "ROC_".$network->adb_netzgebiet->extref."_".$cityname;
|
||||
if($network->adb_netzgebiet->source == "citycom-oan-api") {
|
||||
$name = "OC ".$network->adb_netzgebiet->name;
|
||||
} else {
|
||||
$cityname = preg_replace('/^Liezen\s+-\s+/', '', $network->adb_netzgebiet->name);
|
||||
$name = "ROC_" . $network->adb_netzgebiet->extref . "_" . $cityname;
|
||||
}
|
||||
}
|
||||
|
||||
$net = [];
|
||||
@@ -224,7 +230,13 @@ class OperationaldataApicontroller extends mfBaseApicontroller
|
||||
$woStateNameToId["Cancelled"] = 99;
|
||||
|
||||
|
||||
foreach(PreorderModel::searchActive(["preordercampaign_id" => $campaign_id, "partner_id" => $isp_ids]) as $preorder) {
|
||||
$preorder_search = ["preordercampaign_id" => $campaign_id];
|
||||
if(count($isp_ids)) {
|
||||
$preorder_search["partner_id"] = $isp_ids;
|
||||
}
|
||||
|
||||
|
||||
foreach(PreorderModel::searchActive($preorder_search) as $preorder) {
|
||||
$hausnummer_id = $preorder->adb_hausnummer_id;
|
||||
$wohneinheit_id = $preorder->adb_wohneinheit_id;
|
||||
|
||||
|
||||
31
db/migrations/20250722132925_adb_hausnummer_add_stag.php
Normal file
31
db/migrations/20250722132925_adb_hausnummer_add_stag.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
final class AdbHausnummerAddStag extends AbstractMigration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
$table = $this->table("Hausnummer");
|
||||
$table->addColumn("vlan_stag", "integer", ["null" => true, "default" => null, "after" => "rimo_fcp_name"]);
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if($this->getEnvironment() == "thetool") {
|
||||
|
||||
}
|
||||
|
||||
if($this->getEnvironment() == "addressdb") {
|
||||
$this->table("Hausnummer")->removeColumn("vlan_stag")->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Citycom_OanApi {
|
||||
class Citycom_OanApiClient {
|
||||
private $baseurl;
|
||||
private $username;
|
||||
private $password;
|
||||
@@ -34,7 +34,7 @@ class Citycom_OanApi {
|
||||
]
|
||||
];
|
||||
|
||||
$locations = $this->sendGetRequest($url, $ctx_options);
|
||||
$locations = $this->runApiRequest($url, $ctx_options);
|
||||
return $locations;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class Citycom_OanApi {
|
||||
]
|
||||
];
|
||||
|
||||
$homes = $this->sendGetRequest($url, $ctx_options);
|
||||
$homes = $this->runApiRequest($url, $ctx_options);
|
||||
return $homes;
|
||||
}
|
||||
|
||||
@@ -74,7 +74,23 @@ class Citycom_OanApi {
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
echo $url;
|
||||
echo "$url\n";
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_PRODUCTS;
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
"ignore_errors" => true,
|
||||
"method" => "GET",
|
||||
"header" => [
|
||||
"Accept: application/json",
|
||||
"Authorization: Bearer ".$this->token,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$products = $this->runApiRequest($url, $ctx_options);
|
||||
return $products;
|
||||
|
||||
}
|
||||
|
||||
@@ -86,9 +102,29 @@ class Citycom_OanApi {
|
||||
}
|
||||
}
|
||||
|
||||
if(!array_key_exists("name", $data) || !array_key_exists("bb_down", $data) || !array_key_exists("bb_up", $data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_PRODUCT;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
"ignore_errors" => true,
|
||||
"method" => "POST",
|
||||
"content" => json_encode($data),
|
||||
"header" => [
|
||||
"Accept: application/json",
|
||||
"Content-Type: application/json",
|
||||
"Authorization: Bearer ".$this->token,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$new_product = $this->runApiRequest($url, $ctx_options);
|
||||
return $new_product;
|
||||
|
||||
}
|
||||
|
||||
public function updateProduct($product_id, $data) {
|
||||
@@ -129,6 +165,20 @@ class Citycom_OanApi {
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_GET_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
"ignore_errors" => true,
|
||||
"method" => "GET",
|
||||
"header" => [
|
||||
"Accept: application/json",
|
||||
"Authorization: Bearer ".$this->token,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$services = $this->runApiRequest($url, $ctx_options);
|
||||
return $services;
|
||||
|
||||
}
|
||||
|
||||
public function createService($home_id, $data) {
|
||||
@@ -142,6 +192,20 @@ class Citycom_OanApi {
|
||||
$url = $this->baseurl.CITYCOM_OAN_API_EP_CREATE_SERVICES;
|
||||
echo "$url\n";
|
||||
|
||||
$ctx_options = [
|
||||
"http" => [
|
||||
"ignore_errors" => true,
|
||||
"method" => "POST",
|
||||
"header" => [
|
||||
"Accept: application/json",
|
||||
"Content-type: application/json",
|
||||
"Authorization: Bearer ".$this->token,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$new_service = $this->runApiRequest($url, $ctx_options);
|
||||
return $new_service;
|
||||
}
|
||||
|
||||
public function updateService($service_id, $data) {
|
||||
@@ -248,7 +312,7 @@ class Citycom_OanApi {
|
||||
return true;
|
||||
}
|
||||
|
||||
private function sendGetRequest($url, $ctx_opts, $url_params = [], $page_num = 1) {
|
||||
private function runApiRequest($url, $ctx_opts, $url_params = [], $page_num = 1) {
|
||||
$current_page = $page_num;
|
||||
$return_data = [];
|
||||
|
||||
@@ -273,7 +337,7 @@ class Citycom_OanApi {
|
||||
|
||||
$resp = json_decode($output);
|
||||
//var_dump($resp);
|
||||
if(!is_object($resp) || !property_exists($resp, "success") || !$resp->success) {
|
||||
if(!is_object($resp) || (property_exists($resp, "success") && !$resp->success)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -287,7 +351,7 @@ class Citycom_OanApi {
|
||||
if(property_exists($response, "last_page") && $response->last_page > 1) {
|
||||
if($current_page < $response->last_page) {
|
||||
$next_page = $current_page + 1;
|
||||
$next_data = $this->sendGetRequest($url, $ctx_opts, $url_params, $next_page);
|
||||
$next_data = $this->runApiRequest($url, $ctx_opts, $url_params, $next_page);
|
||||
if(!$next_data) {
|
||||
return $return_data;
|
||||
}
|
||||
@@ -302,6 +366,4 @@ class Citycom_OanApi {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
122
lib/Citycom/OanApiHelper.php
Normal file
122
lib/Citycom/OanApiHelper.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
class Citycom_OanApiHelper {
|
||||
private $log;
|
||||
private $api;
|
||||
|
||||
public function __construct(Citycom_OanApiClient $apiClient) {
|
||||
$this->api = $apiClient;
|
||||
}
|
||||
|
||||
public function findOrCreateProduct($specs = []) {
|
||||
if(!array_key_exists("up", $specs) || !array_key_exists("down", $specs) || !is_numeric($specs["up"]) || !is_numeric($specs["down"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$up = $specs["up"];
|
||||
$down = $specs["down"];
|
||||
|
||||
$search_name = false;
|
||||
if(array_key_exists("name", $specs) && $specs["name"]) {
|
||||
$search_name = $specs["name"];
|
||||
}
|
||||
|
||||
$products = $this->api->getProducts();
|
||||
foreach($products as $product) {
|
||||
if($up == $product->bb_up && $down == $product->bb_down) {
|
||||
if($search_name) {
|
||||
if($product->name == $search_name) {
|
||||
return $product->id;
|
||||
}
|
||||
} else {
|
||||
return $product->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not found, so create new product
|
||||
|
||||
$name = "xinon_tt_{$down}_{$up}";
|
||||
if(array_key_exists("name", $specs)) {
|
||||
$name = $specs["name"];
|
||||
}
|
||||
|
||||
$product_id = $this->api->createProduct([
|
||||
"name" => $name,
|
||||
"bb_down" => $down,
|
||||
"bb_up" => $up
|
||||
]);
|
||||
|
||||
if(!$product_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
public function orderServices($preorder, $sublocation_id, $data) {
|
||||
if(!is_numeric($sublocation_id) || !$sublocation_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!array_key_exists("up", $data) || !array_key_exists("down", $data) || !is_numeric($data["up"]) || !is_numeric($data["down"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!array_key_exists("services", $data) || is_array($data["services"]) || !count($data["services"])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$up = $data["up"];
|
||||
$down = $data["down"];
|
||||
$product_name = $data["product_name"];
|
||||
$execution_date = $data["execution_date"];
|
||||
$services = $data["services"];
|
||||
|
||||
if(!$execution_date) {
|
||||
$execution_date = date("Y-m-d");
|
||||
}
|
||||
|
||||
|
||||
$product_data = [
|
||||
"bb_up" => $up,
|
||||
"bb_down" => $down,
|
||||
"name" => $product_name
|
||||
];
|
||||
|
||||
// find or craete product
|
||||
$product_id = $this->findOrCreateProduct($product_data);
|
||||
if(!$product_id) {
|
||||
$this->log->debug(__METHOD__.": no citycom product for query ".print_r($product_data, true));
|
||||
return false;
|
||||
}
|
||||
|
||||
// order all services and save ctags
|
||||
$cc_service_types = $this->api->getServices();
|
||||
|
||||
$new_services = [];
|
||||
foreach($cc_service_types as $stype) {
|
||||
$service_data = [
|
||||
"service_type" => $stype->id,
|
||||
"product" => $product_id,
|
||||
"billing_date" => $execution_date,
|
||||
"ctag"
|
||||
];
|
||||
$new_service = $this->api->createService($sublocation_id, $service_data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function citycomIdToHausnummerExtref($id) {
|
||||
if(!$id) return false;
|
||||
return "citycom-$id";
|
||||
}
|
||||
|
||||
public static function hausnummerExtrefToCitycomId($extref) {
|
||||
if(!$extref) return false;
|
||||
return str_replace("citycom-", "", $extref);
|
||||
}
|
||||
}
|
||||
@@ -260,6 +260,10 @@ class AddressHelper
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if($hausnummer->vlan_stag != $stag) {
|
||||
$hausnummer->vlan_stag = $stag;
|
||||
$hausnummer->save();
|
||||
}
|
||||
|
||||
return $hausnummer;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class CitycomImporter {
|
||||
// get locations (Hausnummer) + Sublocations (Wohneinheiten)
|
||||
$hausnummer_found_count = 0;
|
||||
|
||||
$ccapi = new \Citycom_OanApi(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS);
|
||||
$ccapi = new \Citycom_OanApiClient(CITYCOM_OAN_API_USER, CITYCOM_OAN_API_PASS);
|
||||
|
||||
$locations = $ccapi->getLocations();
|
||||
if(!is_array($locations)) {
|
||||
|
||||
Reference in New Issue
Block a user