diff --git a/build b/build index bd753cc..90be1cd 100644 --- a/build +++ b/build @@ -1 +1 @@ -94 \ No newline at end of file +95 \ No newline at end of file diff --git a/openapi/owprov.yaml b/openapi/owprov.yaml index 656acf1..926de74 100644 --- a/openapi/owprov.yaml +++ b/openapi/owprov.yaml @@ -585,12 +585,6 @@ components: type: array items: type: string - operatorId: - type: string - format: uuid - subscriberDeviceId: - type: string - format: uuid geoCode: type: string @@ -754,12 +748,6 @@ components: type: string accessPIN: type: string - operatorId: - type: string - format: uuid - subscriberDeviceId: - type: string - format: uuid DeviceConfigurationElement: type: object diff --git a/src/RESTAPI/RESTAPI_sub_devices_handler.cpp b/src/RESTAPI/RESTAPI_sub_devices_handler.cpp index 47e0a9e..7b8555b 100644 --- a/src/RESTAPI/RESTAPI_sub_devices_handler.cpp +++ b/src/RESTAPI/RESTAPI_sub_devices_handler.cpp @@ -47,8 +47,6 @@ namespace OpenWifi { } if( !ValidDbId(NewObject.managementPolicy, StorageService()->PolicyDB(), true , RESTAPI::Errors::UnknownManagementPolicyUUID, *this) || - !ValidDbId(NewObject.contact, StorageService()->OpContactDB(), true, RESTAPI::Errors::InvalidContactId, *this) || - !ValidDbId(NewObject.location, StorageService()->OpLocationDB(), true, RESTAPI::Errors::InvalidLocationId, *this) || !ValidDbId(NewObject.operatorId, StorageService()->OperatorDB(), true, RESTAPI::Errors::InvalidOperatorId, *this) || !ValidDbId(NewObject.serviceClass, StorageService()->ServiceClassDB(), true, RESTAPI::Errors::InvalidServiceClassId, *this) || !ValidSubscriberId(NewObject.subscriberId, true, *this) || @@ -77,8 +75,6 @@ namespace OpenWifi { } if( !ValidDbId(UpdateObj.managementPolicy, StorageService()->PolicyDB(), true , RESTAPI::Errors::UnknownManagementPolicyUUID, *this) || - !ValidDbId(UpdateObj.contact, StorageService()->OpContactDB(), true, RESTAPI::Errors::InvalidContactId, *this) || - !ValidDbId(UpdateObj.location, StorageService()->OpLocationDB(), true, RESTAPI::Errors::InvalidLocationId, *this) || !ValidDbId(UpdateObj.operatorId, StorageService()->OperatorDB(), true, RESTAPI::Errors::InvalidOperatorId, *this) || !ValidDbId(UpdateObj.serviceClass, StorageService()->ServiceClassDB(), true, RESTAPI::Errors::InvalidServiceClassId, *this) || !ValidSubscriberId(UpdateObj.subscriberId, true, *this) || @@ -91,8 +87,6 @@ namespace OpenWifi { ProvObjects::UpdateObjectInfo(RawObject,UserInfo_.userinfo,Existing.info); AssignIfPresent(RawObject, "deviceType", Existing.deviceType); AssignIfPresent(RawObject, "subscriberId", Existing.subscriberId); - AssignIfPresent(RawObject, "location", Existing.location); - AssignIfPresent(RawObject, "contact", Existing.contact); AssignIfPresent(RawObject, "managementPolicy", Existing.managementPolicy); AssignIfPresent(RawObject, "serviceClass", Existing.serviceClass); AssignIfPresent(RawObject, "qrCode", Existing.qrCode); @@ -102,6 +96,8 @@ namespace OpenWifi { AssignIfPresent(RawObject, "locale", Existing.locale); AssignIfPresent(RawObject, "billingCode", Existing.billingCode); AssignIfPresent(RawObject, "realMacAddress", Existing.realMacAddress); + AssignIfPresent(RawObject, "contact", UpdateObj.contact, Existing.contact); + AssignIfPresent(RawObject, "location", UpdateObj.location, Existing.location); if(RawObject->has("configuration")) { Existing.configuration = UpdateObj.configuration; diff --git a/src/RESTObjects/RESTAPI_ProvObjects.cpp b/src/RESTObjects/RESTAPI_ProvObjects.cpp index fccf444..8969b03 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.cpp +++ b/src/RESTObjects/RESTAPI_ProvObjects.cpp @@ -398,6 +398,38 @@ namespace OpenWifi::ProvObjects { return false; } + void SubLocation::to_json(Poco::JSON::Object &Obj) const { + field_to_json( Obj,"type",type); + field_to_json( Obj,"buildingName",buildingName); + field_to_json( Obj,"addressLines",addressLines); + field_to_json( Obj,"city",city); + field_to_json( Obj,"state",state); + field_to_json( Obj,"postal",postal); + field_to_json( Obj,"country",country); + field_to_json( Obj,"phones",phones); + field_to_json( Obj,"mobiles",mobiles); + field_to_json( Obj,"geoCode",geoCode); + } + + bool SubLocation::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json( Obj,"type", type); + field_from_json( Obj,"buildingName",buildingName); + field_from_json( Obj,"addressLines",addressLines); + field_from_json( Obj,"city",city); + field_from_json( Obj,"state",state); + field_from_json( Obj,"postal",postal); + field_from_json( Obj,"country",country); + field_from_json( Obj,"phones",phones); + field_from_json( Obj,"mobiles",mobiles); + field_from_json( Obj,"geoCode",geoCode); + return true; + } catch (...) { + + } + return false; + } + void OperatorLocationList::to_json(Poco::JSON::Object &Obj) const { field_to_json( Obj, "locations", locations); } @@ -502,6 +534,42 @@ namespace OpenWifi::ProvObjects { return false; } + void SubContact::to_json(Poco::JSON::Object &Obj) const { + field_to_json( Obj,"type", type); + field_to_json( Obj,"title",title); + field_to_json( Obj,"salutation",salutation); + field_to_json( Obj,"firstname",firstname); + field_to_json( Obj,"lastname",lastname); + field_to_json( Obj,"initials",initials); + field_to_json( Obj,"visual",visual); + field_to_json( Obj,"mobiles",mobiles); + field_to_json( Obj,"phones",phones); + field_to_json( Obj,"primaryEmail",primaryEmail); + field_to_json( Obj,"secondaryEmail",secondaryEmail); + field_to_json( Obj,"accessPIN",accessPIN); + } + + bool SubContact::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + field_from_json( Obj,"type", type); + field_from_json( Obj,"title",title); + field_from_json( Obj,"salutation",salutation); + field_from_json( Obj,"firstname",firstname); + field_from_json( Obj,"lastname",lastname); + field_from_json( Obj,"initials",initials); + field_from_json( Obj,"visual",visual); + field_from_json( Obj,"mobiles",mobiles); + field_from_json( Obj,"phones",phones); + field_from_json( Obj,"primaryEmail",primaryEmail); + field_from_json( Obj,"secondaryEmail",secondaryEmail); + field_from_json( Obj,"accessPIN",accessPIN); + return true; + } catch (...) { + + } + return false; + } + void OperatorContactList::to_json(Poco::JSON::Object &Obj) const { field_to_json( Obj, "contacts", contacts); } diff --git a/src/RESTObjects/RESTAPI_ProvObjects.h b/src/RESTObjects/RESTAPI_ProvObjects.h index 3362d51..18711d1 100644 --- a/src/RESTObjects/RESTAPI_ProvObjects.h +++ b/src/RESTObjects/RESTAPI_ProvObjects.h @@ -221,6 +221,22 @@ namespace OpenWifi::ProvObjects { }; typedef std::vector LocationVec; + struct SubLocation { + std::string type; + std::string buildingName; + Types::StringVec addressLines; + std::string city; + std::string state; + std::string postal; + std::string country; + Types::StringVec phones; + Types::StringVec mobiles; + std::string geoCode; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + struct OperatorLocationList { std::vector locations; @@ -314,6 +330,24 @@ namespace OpenWifi::ProvObjects { bool from_json(const Poco::JSON::Object::Ptr &Obj); }; + struct SubContact { + std::string type; + std::string title; + std::string salutation; + std::string firstname; + std::string lastname; + std::string initials; + std::string visual; + Types::StringVec mobiles; + Types::StringVec phones; + std::string primaryEmail; + std::string secondaryEmail; + std::string accessPIN; + + void to_json(Poco::JSON::Object &Obj) const; + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + struct OperatorContactList { std::vector contacts; @@ -602,8 +636,8 @@ namespace OpenWifi::ProvObjects { std::string deviceType; Types::UUID_t operatorId; Types::UUID_t subscriberId; - Types::UUID_t location; - Types::UUID_t contact; + SubLocation location; + SubContact contact; Types::UUID_t managementPolicy; Types::UUID_t serviceClass; std::string qrCode; diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 928f9d9..a543a83 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -1994,6 +1994,14 @@ namespace OpenWifi { return false; } + template bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, const T &value, T & assignee) { + if(O->has(Field)) { + assignee = value; + return true; + } + return false; + } + inline void AddCORS() { auto Origin = Request->find("Origin"); if (Origin != Request->end()) { diff --git a/src/storage/storage_sub_devices.cpp b/src/storage/storage_sub_devices.cpp index 52f4ded..63da406 100644 --- a/src/storage/storage_sub_devices.cpp +++ b/src/storage/storage_sub_devices.cpp @@ -38,16 +38,16 @@ namespace OpenWifi { }; static ORM::IndexVec SubscriberDeviceDB_Indexes{ - { std::string("subscriber_device_name_index"), + { std::string("subscriber_device_name_index2"), ORM::IndexEntryVec{ {std::string("name"), ORM::Indextype::ASC} } }, - { std::string("subscriber_device_serialNumber_index"), + { std::string("subscriber_device_serialNumber_index2"), ORM::IndexEntryVec{ {std::string("serialNumber"), ORM::Indextype::ASC} } } , - { std::string("subscriber_device_realMacAddress_index"), + { std::string("subscriber_device_realMacAddress_index2"), ORM::IndexEntryVec{ {std::string("realMacAddress"), ORM::Indextype::ASC} } } }; SubscriberDeviceDB::SubscriberDeviceDB( OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L) : - DB(T, "sub_devices", SubscriberDeviceDB_Fields, SubscriberDeviceDB_Indexes, P, L, "sdv") { + DB(T, "sub_devices2", SubscriberDeviceDB_Fields, SubscriberDeviceDB_Indexes, P, L, "sdv") { } bool SubscriberDeviceDB::Upgrade([[maybe_unused]] uint32_t from, uint32_t &to) { @@ -70,8 +70,8 @@ template<> void ORM::DB< OpenWifi::SubDeviceDBRecordType, OpenWifi::ProvObjec Out.deviceType = In.get<7>(); Out.operatorId = In.get<8>(); Out.subscriberId = In.get<9>(); - Out.location = In.get<10>(); - Out.contact = In.get<11>(); + Out.location = OpenWifi::RESTAPI_utils::to_object(In.get<10>()); + Out.contact = OpenWifi::RESTAPI_utils::to_object(In.get<11>()); Out.managementPolicy = In.get<12>(); Out.serviceClass = In.get<13>(); Out.qrCode = In.get<14>(); @@ -96,8 +96,8 @@ template<> void ORM::DB< OpenWifi::SubDeviceDBRecordType, OpenWifi::ProvObjec Out.set<7>(In.deviceType); Out.set<8>(In.operatorId); Out.set<9>(In.subscriberId); - Out.set<10>(In.location); - Out.set<11>(In.contact); + Out.set<10>(OpenWifi::RESTAPI_utils::to_string(In.location)); + Out.set<11>(OpenWifi::RESTAPI_utils::to_string(In.contact)); Out.set<12>(In.managementPolicy); Out.set<13>(In.serviceClass); Out.set<14>(In.qrCode); @@ -110,12 +110,3 @@ template<> void ORM::DB< OpenWifi::SubDeviceDBRecordType, OpenWifi::ProvObjec Out.set<21>(In.suspended); Out.set<22>(In.realMacAddress); } - - -/* - -$ cmake3 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DLibCrypto_INCLUDE_DIR=/usr/include -DLibCrypto_LIBRARY=/usr/lib64/libcrypto.so .. - - - - */ \ No newline at end of file