Esempio n. 1
0
    def delete(self, _id, messagetype):
        try:
            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)
            logging.info(project.value)

            #delete board ID
            message = project.remove_message(messagetype)

            logging.info('remove message: {}'.format(message))

            write_result = yield dbapi.update_by_id('projects', _id, {
                "messages": project.value["messages"],
                "fwcode": project.value["fwcode"],
            })
            logging.info(write_result)

            self.set_status(200)
            self.write(json.dumps(project.value, default=json_util.default))
            self.set_header("Content-Type", "application/json")

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Esempio n. 2
0
    def put(self, _id, messagetype):
        try:

            logging.info('message definition request')
            message = ujson.loads(self.request.body.decode('utf-8'))
            logging.info(message)

            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)

            project.remove_message(message['metadata']['type'])
            message = project.add_message(message)
            
            write_result = yield dbapi.update_by_id('projects', _id, {
                "messages": project.value["messages"],
                "fwcode": project.value["fwcode"],
            })
            logging.info(write_result)

            self.set_status(200)
            self.write(json.dumps(project.value, default=json_util.default))
            self.set_header("Content-Type", "application/json")

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")            
Esempio n. 3
0
    def put(self, _id):
        logging.info(_id)

        try:
            update = ujson.loads(self.request.body.decode('utf-8'))
            
            if not "filter" in update.keys():
                update.update({"filter": {}})

            write_result = yield dbapi.update_by_id('projects', _id, update["document"], update["filter"])
            logging.info(write_result)
            project = yield dbapi.find_one_by_id("projects", _id)
            #TODO: schema validation after update is bad ...
            project = projectmanager.Project(project)

            self.set_status(200)
            self.write(json.dumps(project.value, default=json_util.default))
            self.set_header("Content-Type", "application/json")


        except Exception as e:
            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Esempio n. 4
0
    def post(self, _id):
        logging.info(_id)

        try:
            project = ujson.loads(self.request.body.decode('utf-8'))
            project = projectmanager.Project(project)

            #store project on db to get an _id:
            write_result = yield dbapi.insert('projects', project.value)
            logging.info(write_result)

            #add computed data and store them again ... FIX THIS
            project.set_project_params([cmd.to_ui_command_def() for cmd in ibcommands.commands if cmd.show])
            

            write_result = yield dbapi.update_by_id('projects', project.value["_id"], project.value)
            logging.info(write_result)

            self.set_status(200)
            self.write(json.dumps(project.value, default=json_util.default))
            self.set_header("Content-Type", "application/json")

        except Exception as e:
            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Esempio n. 5
0
    def get(self, _id, macaddress):
        try:
            dispatch_board = {'registration': {'new': False}}

            logging.info('device registration request for mac {}'.format(macaddress))

            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)

            #get board ID
            board = project.get_board_by_mac(macaddress)

            if not board:
                #create board ID
                logging.info('New board')

                board = project.add_board(macaddress)
                
                apiresult = yield brokerapi.create_user(board["ID"], board["password"], settings.XMPP_USER)

                write_result = yield dbapi.update_by_id('projects', _id, {"boards": project.value["boards"]})
                logging.info(write_result)

                dispatch_board.update({'registration': {'new': True}})

            logging.info(board)

            #allways return board ID in case the board has been re-installed but was already registered
            device_params = {

                "IOTTLY_XMPP_DEVICE_PASSWORD": board["password"],
                "IOTTLY_XMPP_DEVICE_USER": board["jid"],
                "IOTTLY_XMPP_SERVER_HOST": settings.PUBLIC_XMPP_HOST,
                "IOTTLY_XMPP_SERVER_PORT": settings.PUBLIC_XMPP_PORT,
                "IOTTLY_XMPP_SERVER_USER": settings.XMPP_USER,
                "IOTTLY_PROJECT_ID": _id,
                "IOTTLY_SECRET_SALT": project.value["secretsalt"]
            }
            logging.info(device_params)
            self.write(json.dumps(device_params, default=json_util.default))
            self.set_header("Content-Type", "application/json")

            del board['password']
            dispatch_board['registration'].update({'board': board})
            self._broadcast(dispatch_board)

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")
Esempio n. 6
0
    def delete(self, _id, macaddress):
        try:
            project = yield dbapi.find_one_by_id("projects", _id)
            project = projectmanager.Project(project)
            logging.info(project.value)

            #delete board ID
            board = project.remove_board(macaddress)

            logging.info('remove board: {}'.format(board))

            apiresult = yield brokerapi.delete_user(board["ID"])

            write_result = yield dbapi.update_by_id('projects', _id, {"boards": project.value["boards"]})
            logging.info(write_result)

        except Exception as e:

            logging.error(e)
            self.set_status(500)
            error = {'error': '{}'.format(e)}
            self.write(json.dumps(error, default=json_util.default))
            self.set_header("Content-Type", "application/json")