def buildings_post(): """ method to post a new building """ #body = request.get_data() #body = json.loads(body.decode("utf-8")) newid = str(uuid.uuid4()) newobj = Building(id=newid) #if body["ownerId"]: # newobj.ownerId = body["ownerId"] newobj.save() return newobj.attribute_values
def buildings_building_id_delete(buildingId) -> str: try: building = Building.get(buildingId) building.delete() except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) return 'Successfully deleted buildingId=%s.' % (buildingId)
def buildings_building_id_delete(buildingId) -> str: try: building = Building.get(buildingId) building.delete() except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) return 'Successfully deleted buildingId=%s.' % (buildingId)
def buildings_building_id_get(buildingId) -> str: try: building = Building.get(buildingId) except Exception as e: print(e) return 'Building with id=%s does not exist.' % (buildingId) return building.attribute_values
def buildings_building_id_get(buildingId) -> str: try: building = Building.get(buildingId) except Exception as e: print(e) return 'Building with id=%s does not exist.' % (buildingId) return building.attribute_values
def buildings_building_id_get(buildingId): """ method to get building using building id """ try: building = Building.get(buildingId) except Exception: return 'Building with id=%s does not exist.' % (buildingId) return building.attribute_values
def users_user_id_put(userId, newUser): user = get_users_by_id(userId) if (user == 404): return 'User with the provided ID does not exist', 404 # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newUser: try: building = Building.get(newUser['buildingId']) except Exception as e: return 'Building with specified ID does not exist' # Check that if email is changed, it is not the same as another user's if 'email' in newUser: newemail = newUser['email'] u = get_users_by_email(newemail) if len(u) != 0 and newemail != user.attribute_values['email']: return 'A user with the given email id already exists', 400 attributes = user.attribute_values.keys() for key in newUser.keys(): if key in attributes and key != 'id': user.update_item(key, value=newUser[key], action='PUT') return 'User updated successfully'
def robots_robot_id_put(robotId, newRobot): """ method to update a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId),404 # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newRobot: try: building = Building.get(newRobot['buildingId']) except Exception as e: return 'Building with specified ID does not exist',412 # Do the same for sensor ID if 'sensorId' in newRobot: for val in newRobot['sensorId']: try: #print(val) sensor = Sensor.get(val) except Exception as e: return 'Sensor with specified ID does not exist',412 attributes = robot.attribute_values.keys() for key in newRobot.keys(): if key in attributes and key!= "id": # print(key) robot.update_item(key, value=newRobot[key], action='PUT') return 'Robot with id=%s updated successfully.' % (robotId),200
def db_put(id,type,newSensor): if type not in types: return 1 if type == 'sensor': try: sensor = Sensor.get(id) except Exception: return 2 # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 2 attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key != 'id': if newSensor[key] == '': sensor.update_item(key, value=' ', action='PUT') else: sensor.update_item(key, value=newSensor[key], action='PUT') return 0
def robots_robot_id_put(robotId, newRobot): """ method to update a robot using robot id """ try: robot = Robot.get(robotId) except Exception: return 'Robot with id=%s does not exist.' % (robotId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newRobot: try: building = Building.get(newRobot['buildingId']) except Exception as e: return 'Building with specified ID does not exist' # Do the same for sensor ID if 'sensorId' in newRobot: try: sensor = Sensor.get(newRobot['sensorId']) except Exception as e: return 'Sensor with specified ID does not exist' attributes = robot.attribute_values.keys() for key in newRobot.keys(): if key in attributes and key is not 'id': robot.update_item(key, value=newRobot[key], action='PUT') return 'Robot with id=%s updated successfully.' % (robotId)
def buildings_building_id_get(buildingId): """ method to get building using building id """ try: building = Building.get(buildingId) except Exception: return 'Building with id=%s does not exist.' % (buildingId) return building.attribute_values
def buildings_post(): """ method to post a new building """ body = request.get_data() body = json.loads(body.decode("utf-8")) # Check that the owner exists # try: # owner = User.get(body["ownerId"]) # except Excpetion as e: # return 'The owner specified does not exist' newid = str(uuid.uuid4()) newobj = Building(id=newid) if "ownerId" in body: newobj.ownerId = body["ownerId"] newobj.save() return newobj.attribute_values
def buildings_building_id_delete(buildingId): """ method to delete building using building id """ try: building = Building.get(buildingId) building.delete() except Exception: return 'Building with id=%s does not exist.' % (buildingId) return 'Successfully deleted buildingId=%s.' % (buildingId)
def buildings_building_id_delete(buildingId): """ method to delete building using building id """ try: building = Building.get(buildingId) building.delete() except Exception: return 'Building with id=%s does not exist.' % (buildingId) return 'Successfully deleted buildingId=%s.' % (buildingId)
def buildings_post(): """ method to post a new building """ body = request.get_data() body = json.loads(body.decode("utf-8")) # Check that the owner exists # try: # owner = User.get(body["ownerId"]) # except Excpetion as e: # return 'The owner specified does not exist' newid = str(uuid.uuid4()) newobj = Building(id=newid) if "ownerId" in body: newobj.ownerId = body["ownerId"] newobj.save() return newobj.attribute_values
def buildings_building_id_sensors_post(buildingId) -> str: try: building = Building.get(buildingId) except Exception as e: print(e) return 'Building with id=%s does not exist.' % (buildingId) newID = str(uuid.uuid4()) newObj = Sensor(id=newID, buildingId=buildingId) newObj.save() return newObj.attribute_values
def buildings_building_id_robots_post(buildingId): """ method to post robot under a building """ try: building = Building.get(buildingId) except Exception: return 'Building with id %s does not exist.' % (buildingId) newid = str(uuid.uuid4()) newobj = Robot(id=newid, buildingId=buildingId) newobj.save() return newobj.attribute_values
def buildings_building_id_sensors_post(buildingId): """ method to post a sensor using sensor id """ try: building = Building.get(buildingId) except Exception: return 'Building with id=%s does not exist.' % (buildingId) newid = str(uuid.uuid4()) newobj = Sensor(id=newid, buildingId=buildingId) newobj.save() return newobj.attribute_values
def buildings_building_id_robots_post(buildingId): """ method to post robot under a building """ try: building = Building.get(buildingId) except Exception: return 'Building with id %s does not exist.' % (buildingId) newid = str(uuid.uuid4()) newobj = Robot(id=newid, buildingId=buildingId) newobj.save() return newobj.attribute_values
def buildings_building_id_put(buildingId, newBuilding) -> str: try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) attributes = building.attribute_values.keys() for key in newBuilding.keys(): if key in attributes and key is not 'id': building.update_item(key, value=newBuilding[key], action='PUT') return 'Building with id=%s updated successfully.' % (buildingId)
def buildings_building_id_put(buildingId, newBuilding) -> str: try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) attributes = building.attribute_values.keys() for key in newBuilding.keys(): if key in attributes and key is not 'id': building.update_item(key, value=newBuilding[key], action='PUT') return 'Building with id=%s updated successfully.' % (buildingId)
def buildings_building_id_sensors_post(buildingId) -> str: try: building = Building.get(buildingId) except Exception as e: print(e) return 'Building with id=%s does not exist.' % (buildingId) newID = str(uuid.uuid4()) newObj = Sensor(id=newID, buildingId=buildingId) newObj.save() return newObj.attribute_values
def buildings_building_id_sensors_post(buildingId): """ method to post a sensor using sensor id """ try: building = Building.get(buildingId) except Exception: return 'Building with id=%s does not exist.' % (buildingId) newid = str(uuid.uuid4()) newobj = Sensor(id=newid, buildingId=buildingId) newobj.save() return newobj.attribute_values
def buildings_building_id_robots_get(buildingId, capability = None): resultList = [] try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) if capability is not None and capability != '': for item in Robot.scan(buildingId__eq=buildingId, capabilities__contains=capability, conditional_operator='AND'): resultList.append(item.attribute_values) else: for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return resultList
def users_user_id_get(userId): """ method to retrieve user using user id """ try: user = User.get(userId) buildings = Building.scan(ownerId__eq=userId) #add ownedBuildings to the user object without having it reflect in the model user.__dict__["attribute_values"].update({"ownedBuildings": []}) #look at all the builings the user owns for building in buildings: #add the builings to the ownedBuildings list user.__dict__["attribute_values"]["ownedBuildings"].append(building.attribute_values["id"]) except Exception as inst: print(inst.args) return 'User with id=%s does not exist.' % (userId) return user.attribute_values
def buildings_building_id_robots_get(buildingId, capability=None): resultList = [] try: building = Building.get(buildingId) except Exception as e: return 'Building with id=%s does not exist.' % (buildingId) if capability is not None and capability != '': for item in Robot.scan(buildingId__eq=buildingId, capabilities__contains=capability, conditional_operator='AND'): resultList.append(item.attribute_values) else: for item in Robot.scan(buildingId__eq=buildingId): resultList.append(item.attribute_values) return resultList
def users_user_id_get(userId): """ method to retrieve user using user id """ try: user = User.get(userId) buildings = Building.scan(ownerId__eq=userId) #add ownedBuildings to the user object without having it reflect in the model user.__dict__["attribute_values"].update({"ownedBuildings": []}) #look at all the builings the user owns for building in buildings: #add the builings to the ownedBuildings list user.__dict__["attribute_values"]["ownedBuildings"].append( building.attribute_values["id"]) except Exception as inst: print(inst.args) return 'User with id=%s does not exist.' % (userId) return user.attribute_values
def sensors_sensor_id_put(sensorId, newSensor): """ method to update sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def users_user_id_put(userId, newUser): """ method to update a user using user id """ try: user = User.get(userId) except Exception: return 'User with id=%s does not exist.' % (userId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newuser: try: building = Building.get(newuser['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = user.attribute_values.keys() for key in newUser.keys(): if key in attributes and key is not 'id': user.update_item(key, value=newUser[key], action='PUT') return 'User with id=%s updated successfully.' % (userId)
def users_user_id_put(userId, newUser): """ method to update a user using user id """ try: user = User.get(userId) except Exception: return 'User with id=%s does not exist.' % (userId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newuser: try: building = Building.get(newuser['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = user.attribute_values.keys() for key in newUser.keys(): if key in attributes and key is not 'id': user.update_item(key, value=newUser[key], action='PUT') return 'User with id=%s updated successfully.' % (userId)
def sensors_sensor_id_put(sensorId, newSensor): """ method to update sensor using sensor id """ try: sensor = Sensor.get(sensorId) except Exception: return 'Sensor with id=%s does not exist.' % (sensorId) # Need to check that if building ID is changed, the new Building exists if 'buildingId' in newSensor: try: building = Building.get(newSensor['buildingId']) except Exception as e: return 'Building with specified ID does not exist' attributes = sensor.attribute_values.keys() for key in newSensor.keys(): if key in attributes and key is not 'id': sensor.update_item(key, value=newSensor[key], action='PUT') return 'Sensor with id=%s updated successfully.' % (sensorId)
def buildings_get() -> str: resultList = [] for item in Building.scan(): resultList.append(item.attribute_values) return resultList
from storageModels import Sensor, Building mySens = Sensor(sensorId = 'yet another id', sensorType='type', buildingId = 'theHASH', roomId = 'another hash', data=['data', 'moredata']) mySens.save() newBuilding = Building(id = 'one other id something', buildingId = '1', building='Franks shop', rooms = ['a', 'b'], owner = 1, users = ['a', 'b'], sensors = ['a', 'b'], robots = ['a', 'b']) newBuilding.save()
from storageModels import Sensor, Building, Robot, User Sensor.create_table(read_capacity_units=1, write_capacity_units=1) Building.create_table(read_capacity_units=1, write_capacity_units=1) Robot.create_table(read_capacity_units=1, write_capacity_units=1) User.create_table(read_capacity_units=1, write_capacity_units=1)
def buildings_post() -> str: newID = str(uuid.uuid4()) newObj = Building(id=newID) newObj.save() return newObj.attribute_values
def buildings_get() -> str: resultList = [] for item in Building.scan(): resultList.append(item.attribute_values) return resultList
def buildings_post() -> str: newID = str(uuid.uuid4()) newObj = Building(id=newID) newObj.save() return newObj.attribute_values
def buildings_delete(): """ method to delete all buildings """ temp = [] for item in Building.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)
def buildings_delete() -> str: temp = [] for item in Building.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)
def buildings_get(): """ method to get all buildings """ resultlist = [] for item in Building.scan(): resultlist.append(item.attribute_values) return resultlist
from storageModels import Sensor, Building mySens = Sensor(sensorId='yet another id', sensorType='type', buildingId='theHASH', roomId='another hash', data=['data', 'moredata']) mySens.save() newBuilding = Building(id='one other id something', buildingId='1', building='Franks shop', rooms=['a', 'b'], owner=1, users=['a', 'b'], sensors=['a', 'b'], robots=['a', 'b']) newBuilding.save()
def buildings_delete() -> str: temp = [] for item in Building.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)
def buildings_get(): """ method to get all buildings """ resultlist = [] for item in Building.scan(): resultlist.append(item.attribute_values) return resultlist
def buildings_delete(): """ method to delete all buildings """ temp = [] for item in Building.scan(): temp.append(item.delete()) return "%s items deleted." % len(temp)