mirror of
https://github.com/Telecominfraproject/wlan-cloud-owprov.git
synced 2025-10-29 17:52:28 +00:00
Adding device type registry
This commit is contained in:
@@ -376,8 +376,6 @@ namespace OpenWifi{
|
||||
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
__DBG__
|
||||
|
||||
std::string Claimer;
|
||||
if(HasParameter("claimer",Claimer) && !Claimer.empty()) {
|
||||
uint64_t ErrorCode;
|
||||
@@ -387,41 +385,31 @@ namespace OpenWifi{
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
|
||||
__DBG__
|
||||
|
||||
ProvObjects::InventoryTag Existing;
|
||||
if(SerialNumber.empty() || !DB_.GetRecord(RESTAPI::Protocol::SERIALNUMBER,SerialNumber,Existing)) {
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
__DBG__
|
||||
auto RawObject = ParseStream();
|
||||
ProvObjects::InventoryTag NewObject;
|
||||
if(!NewObject.from_json(RawObject)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
}
|
||||
__DBG__
|
||||
|
||||
std::cout << "Devclass: '" << NewObject.devClass << "'" << std::endl;
|
||||
if(!NewObject.devClass.empty() && !Provisioning::DeviceClass::Validate(NewObject.devClass.c_str())) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidDeviceClass);
|
||||
}
|
||||
|
||||
__DBG__
|
||||
|
||||
|
||||
|
||||
if(!NewObject.deviceType.empty()) {
|
||||
if(!DeviceTypeCache()->IsAcceptableDeviceType(NewObject.deviceType)) {
|
||||
return BadRequest(RESTAPI::Errors::InvalidDeviceTypes);
|
||||
}
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(!UpdateObjectInfo(RawObject, UserInfo_.userinfo, Existing.info)) {
|
||||
return BadRequest(RESTAPI::Errors::NameMustBeSet);
|
||||
}
|
||||
__DBG__
|
||||
|
||||
std::string NewVenue, NewEntity, NewLocation, NewContact, NewConfiguration, NewPolicy;
|
||||
bool MovingVenue=false,
|
||||
@@ -431,7 +419,6 @@ namespace OpenWifi{
|
||||
MovingConfiguration=false,
|
||||
MovingPolicy=false;
|
||||
|
||||
__DBG__
|
||||
AssignIfPresent(RawObject, "rrm",Existing.rrm);
|
||||
|
||||
if(AssignIfPresent(RawObject, "venue",NewVenue)) {
|
||||
@@ -441,19 +428,16 @@ namespace OpenWifi{
|
||||
MovingVenue = Existing.venue != NewVenue;
|
||||
}
|
||||
|
||||
__DBG__
|
||||
if(AssignIfPresent(RawObject, "entity",NewEntity)) {
|
||||
if(!NewEntity.empty() && !StorageService()->EntityDB().Exists("id",NewEntity)) {
|
||||
return BadRequest(RESTAPI::Errors::EntityMustExist);
|
||||
}
|
||||
MovingEntity = Existing.entity != NewEntity;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(!NewEntity.empty() && !NewVenue.empty()) {
|
||||
return BadRequest(RESTAPI::Errors::NotBoth);
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(AssignIfPresent(RawObject, "location",NewLocation)) {
|
||||
if(!NewLocation.empty() && !StorageService()->LocationDB().Exists("id",NewLocation)) {
|
||||
@@ -461,7 +445,6 @@ namespace OpenWifi{
|
||||
}
|
||||
MovingLocation = Existing.location != NewLocation;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(AssignIfPresent(RawObject, "contact",NewContact)) {
|
||||
if(!NewContact.empty() && !StorageService()->ContactDB().Exists("id",NewContact)) {
|
||||
@@ -469,7 +452,6 @@ namespace OpenWifi{
|
||||
}
|
||||
MovingContact = Existing.contact != NewContact;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(AssignIfPresent(RawObject, "deviceConfiguration",NewConfiguration)) {
|
||||
if(!NewConfiguration.empty() && !StorageService()->ConfigurationDB().Exists("id",NewConfiguration)) {
|
||||
@@ -477,7 +459,6 @@ namespace OpenWifi{
|
||||
}
|
||||
MovingConfiguration = Existing.deviceConfiguration != NewConfiguration;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if(AssignIfPresent(RawObject, "managementPolicy",NewPolicy)) {
|
||||
if(!NewPolicy.empty() && !StorageService()->PolicyDB().Exists("id",NewPolicy)) {
|
||||
@@ -485,7 +466,6 @@ namespace OpenWifi{
|
||||
}
|
||||
MovingPolicy = Existing.managementPolicy != NewPolicy;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
std::string NewSubScriber;
|
||||
if(AssignIfPresent(RawObject, "subscriber", NewSubScriber)) {
|
||||
@@ -502,18 +482,15 @@ namespace OpenWifi{
|
||||
Existing.subscriber = "";
|
||||
}
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if( RawObject->has("devClass") && NewObject.devClass!= Existing.devClass) {
|
||||
Existing.devClass = NewObject.devClass;
|
||||
}
|
||||
__DBG__
|
||||
|
||||
if( RawObject->has("state") && NewObject.state!= Existing.state) {
|
||||
Existing.state = NewObject.state;
|
||||
}
|
||||
|
||||
__DBG__
|
||||
std::string Arg;
|
||||
bool UnAssign=false;
|
||||
if(HasParameter("unassign", Arg) && Arg=="true") {
|
||||
@@ -539,11 +516,8 @@ namespace OpenWifi{
|
||||
Existing.managementPolicy.clear();
|
||||
}
|
||||
|
||||
__DBG__
|
||||
|
||||
std::cout << "Updating: " << Existing.info.id << " " << Existing.serialNumber << std::endl;
|
||||
if(StorageService()->InventoryDB().UpdateRecord("id", Existing.info.id, Existing)) {
|
||||
__DBG__
|
||||
if(!UnAssign) {
|
||||
if(MovingEntity) {
|
||||
if(!Existing.entity.empty())
|
||||
@@ -588,15 +562,13 @@ namespace OpenWifi{
|
||||
Existing.managementPolicy = NewPolicy;
|
||||
}
|
||||
}
|
||||
__DBG__
|
||||
|
||||
DB_.UpdateRecord("id", Existing.info.id, Existing);
|
||||
__DBG__
|
||||
|
||||
ProvObjects::InventoryTag NewObjectCreated;
|
||||
DB_.GetRecord("id", Existing.info.id, NewObjectCreated);
|
||||
Poco::JSON::Object Answer;
|
||||
NewObject.to_json(Answer);
|
||||
__DBG__
|
||||
return ReturnObject(Answer);
|
||||
}
|
||||
InternalError(RESTAPI::Errors::RecordNotUpdated);
|
||||
|
||||
Reference in New Issue
Block a user