def post(self): args = device_category_parser.parse_args() # Get DeviceCategory arguments if DeviceCategoryValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_device_category(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if DeviceCategoryValidator.is_data_type_valid(args["data_type"]): data_type = args["data_type"] else: return Response.error(FIELD_NOT_VALID) device_category = DeviceCategory(name=name, data_type=data_type) result = self.repository.add_device_category(device_category) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def put(self, device_category_name): args = device_category_parser.parse_args() response = self.repository.get_device_category( device_category_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get DeviceCategory arguments if DeviceCategoryValidator.is_name_valid(args["name"]): name = args["name"] else: return Response.error(FIELD_NOT_VALID) if DeviceCategoryValidator.is_data_type_valid(args["data_type"]): data_type = args["data_type"] else: return Response.error(FIELD_NOT_VALID) device = {"name": name, "data_type": data_type} response = self.repository.update_device_category( device_category_name, device) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def post(self): args = business_rule_parser.parse_args() # Get BusinessRule arguments if BusinessRuleValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_business_rule(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_query_valid(args["query"]): query = args["query"] else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_executing_valid(args["executing"]): executing = args["executing"] else: executing = True business_rule = BusinessRule(name=name, query=query, executing=executing) result = self.repository.add_business_rule(business_rule) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def post(self): args = location_parser.parse_args() # Get Location arguments if LocationValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_location(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if LocationValidator.is_latlng_valid(args["latlng"]): latlng = args["latlng"] else: latlng = None location = Location(name=name, latlng=latlng) result = self.repository.add_location(location) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def put(self, device_name): args = device_parser.parse_args() response = self.repository.get_device(device_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get Device arguments if DeviceValidator.is_name_valid(args["name"]): name = args["name"] else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_category_valid(args["category"]): category = args["category"] else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_location_valid(args["location"]): location = args["location"] else: return Response.error(FIELD_NOT_VALID) device = {"name": name, "category": category, "location": location} response = self.repository.update_device(device_name, device) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def put(self, entry_id=None): args = entry_parser.parse_args() response = self.api_repository.get_entry(entry_id) if not response: return Response.error(NOT_EXISTS_ID) # Get Entry arguments if validator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if validator.is_date_valid(args["date"]): date = args["date"] else: return Response.error(FIELD_NOT_VALID) entry = { "value": value, "date": date } response = self.api_repository.update_entry(entry_id, entry) if response: return Response.success({"internal_id": response}) return Response.error(GENERIC)
def put(self, location_name): args = location_parser.parse_args() # Get Location arguments if LocationValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_location(name) if response is None: return Response.error(NOT_EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if LocationValidator.is_latlng_valid(args["latlng"]): latlng = args["latlng"] else: latlng = None location = { "name": name, "latlng": latlng, } response = self.repository.update_location(location_name, location) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def delete(self, business_rule_name): response = self.repository.get_business_rule(business_rule_name) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_business_rule(business_rule_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def delete(self, location_name): response = self.repository.get_location(location_name) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_location(location_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def delete(self, event_id): response = self.repository.get_event(event_id) if response is None: return Response.error(NOT_EXISTS_ID) result = self.repository.delete_event(event_id) if result: return Response.success({"id": result}) return Response.error(GENERIC)
def post(self): args = event_parser.parse_args() # Get Event arguments if EventValidator.is_device_name_valid(args["device_name"]): device_name = args["device_name"] device = self.repository.get_device(device_name) if not device: return Response.error(NOT_EXISTS_DEVICE) else: return Response.error(FIELD_NOT_VALID) if EventValidator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if EventValidator.is_date_valid(args["datetime"]): datetime = args["datetime"] else: return Response.error(FIELD_NOT_VALID) device_category_name = device.category if device_category_name is None: return Response.error(NOT_DEVICE_CATEGORY) device_category = self.repository.get_device_category( device_category_name) if device_category is None: return Response.error(NOT_DEVICE_CATEGORY) device_category_data_type = device_category.data_type if device_category_data_type is None: return Response.error(NOT_DEVICE_CATEGORY) event = None if device_category_data_type == DataTypeEnum.EventA: event = EventA(device_name=device_name, value=value, datetime=datetime) elif device_category_data_type == DataTypeEnum.EventB: event = EventB(device_name=device_name, value=value, datetime=datetime) if event is None: return Response.error(GENERIC) result = self.repository.add_event(event) if result: return Response.success({"id": result}) return Response.error(GENERIC)
def get(self, data_type_name): response = self.repository.get_data_type(data_type_name) if response: return Response.success(response) return Response.error(NOT_EXISTS_ID)
def get(self, location_name): response = self.repository.get_location(location_name) if response: return Response.success( translator.location_translator(response)) return Response.error(NOT_EXISTS_ID)
def get(self, business_rule_name): response = self.repository.get_business_rule(business_rule_name) if response: return Response.success( translator.business_rule_translator(response)) return Response.error(NOT_EXISTS_ID)
def get(self, wifi_name): response = self.geo_repository.get_info_from_wifi(wifi_name) print(response) if response: return Response.success(response) return Response.error(GENERIC)
def get(self, ip): response = self.geo_repository.get_info_from_ip(ip) print(response) if response: return Response.success(response.json()) return Response.error(GENERIC)
def delete(self, device_category_name): response = self.repository.get_device_category( device_category_name) if response is None: return Response.error(NOT_EXISTS_ID) response = self.repository.get_devices_with_device_category( device_category_name) if response: return Response.error(DEVICE_CATEGORY_HAS_DEVICE) result = self.repository.delete_device_category( device_category_name) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def delete(self, entry_id=None): response = self.api_repository.get_entry(entry_id) if response: result = self.api_repository.delete_entry(entry_id) if result: return Response.success({"internal_id": result}) return Response.error(NOT_EXISTS_ID)
def post(self): args = object_parser.parse_args() try: self.repository.execute_response(args["data"]) return Response.success(args["data"]) except (AttributeError, ValueError) as err: logger.error(err) return Response.error()
def get(self, device_category_name): response = self.repository.get_device_category( device_category_name) if response: return Response.success( translator.device_category_translator(response)) return Response.error(NOT_EXISTS_ID)
def get(self, device_name): response = self.repository.get_device(device_name) if response is None: return Response.error(NOT_EXISTS_ID) response = self.repository.get_events_for_device(device_name) return Response.success( [translator.event_translator(event) for event in response])
def post(self): args = entry_parser.parse_args() # Get Entry arguments if validator.is_value_valid(args["value"]): value = args["value"] else: return Response.error(FIELD_NOT_VALID) if validator.is_date_valid(args["date"]): date = args["date"] else: return Response.error(FIELD_NOT_VALID) entry = Entry(value=value, date=date) result = self.api_repository.add_entry(entry) if result: return Response.success({"internal_id": result}) return Response.error(GENERIC)
def put(self, business_rule_name): args = business_rule_parser.parse_args() response = self.repository.get_business_rule(business_rule_name) if response is None: return Response.error(NOT_EXISTS_ID) # Get BusinessRule arguments if BusinessRuleValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_business_rule(name) if response is None: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_query_valid(args["query"]): query = args["query"] else: return Response.error(FIELD_NOT_VALID) if BusinessRuleValidator.is_executing_valid(args["executing"]): executing = args["executing"] else: executing = True business_rule = { "name": name, "query": query, "executing": executing } response = self.repository.update_business_rule( business_rule_name, business_rule) if response: return Response.success({"name": response}) return Response.error(GENERIC)
def post(self): args = device_parser.parse_args() # Get Device arguments if DeviceValidator.is_name_valid(args["name"]): name = args["name"] response = self.repository.get_device(name) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_category_valid(args["category"]): category = args["category"] response = self.repository.get_device_category(category) if response is None: return Response.error(NOT_DEVICE_CATEGORY) else: return Response.error(FIELD_NOT_VALID) if DeviceValidator.is_location_valid(args["location"]): location = args["location"] response = self.repository.get_location(location) if response is None: return Response.error(NOT_EXISTS_LOCATION) else: location = None device = Device(name=name, category=category, location=location) result = self.repository.add_device(device) if result: return Response.success({"name": result}) return Response.error(GENERIC)
def get(self, response_id): response = self.repository.get_response(response_id) if response: return Response.success(translator.responseplan_translator(response)) return Response.error(NOT_EXISTS_ID)
def post(self): args = response_plan_parser.parse_args() # Get response_plan arguments if validator.is_response_plan_id_valid(args["response_plan_id"]): response_plan_id = args["response_plan_id"] response = self.repository.get_response_external_id(response_plan_id) if response: return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if validator.is_message_status_valid(args["message_status"]): message_status = args["message_status"] else: return Response.error(FIELD_NOT_VALID) if validator.is_alert_category_valid(args["alert_category"]): category = args["alert_category"] else: return Response.error(FIELD_NOT_VALID) if validator.is_alert_severity_valid(args["alert_severity"]): severity = args["alert_severity"] else: severity = str(enums.AlertSeverityEnum.NORMAL.value) if validator.is_actions_valid(args["actions"]): actions = str(args["actions"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_parameters_valid(args["action_parameters"]): parameters = str(args["action_parameters"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_formats_valid(args["action_format"]): format = str(args["action_format"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_descriptions_valid(args["action_description"]): description = str(args["action_description"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_bodys_valid(args["action_body"]): body = str(args["action_body"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_triggers_valid(args["action_trigger"]): trigger = str(args["action_trigger"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_accessibility_valid(args["accessibility"]): accessibility = args["accessibility"] else: accessibility = str(enums.AccessibilityEnum.ADMINISTRATOR.value) if validator.is_area_valid(args["area"]): area = args["area"] else: area = "" if validator.is_geolocation_valid(args["geolocation"]): geolocation = args["geolocation"] else: return Response.error(FIELD_NOT_VALID) response_plan = ResponsePlan(response_plan_id=response_plan_id, message_status=message_status, alert_category=category, alert_severity=severity, actions=actions, action_parameters=parameters, action_format=format, action_description=description, action_body=body, action_trigger=trigger, accessibility=accessibility, area=area, geolocation=geolocation) result = self.repository.add_response(response_plan) if result: return Response.success({"internal_id": result}) return Response.error(GENERIC)
def get(self, entry_id): response = self.api_repository.get_entry(entry_id) if response: return Response.success(translator.entry_translator(response)) return Response.error(NOT_EXISTS_ID)
def put(self, response_id=None): args = response_plan_parser.parse_args() response = self.repository.get_response(response_id) if not response: return Response.error(NOT_EXISTS_ID) # Get response_plan arguments if validator.is_response_plan_id_valid(args["response_plan_id"]): response_plan_id = args["response_plan_id"] response = self.repository.get_response_external_id(response_plan_id) if response and response.internal_id != int(response_id): return Response.error(EXISTS_ID) else: return Response.error(FIELD_NOT_VALID) if validator.is_message_status_valid(args["message_status"]): message_status = args["message_status"] else: return Response.error(FIELD_NOT_VALID) if validator.is_alert_category_valid(args["alert_category"]): category = args["alert_category"] else: return Response.error(FIELD_NOT_VALID) if validator.is_alert_severity_valid(args["alert_severity"]): severity = args["alert_severity"] else: severity = str(enums.AlertSeverityEnum.NORMAL.value) if validator.is_actions_valid(args["actions"]): actions = str(args["actions"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_parameters_valid(args["action_parameters"]): parameters = str(args["action_parameters"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_formats_valid(args["action_format"]): format = str(args["action_format"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_descriptions_valid(args["action_description"]): description = str(args["action_description"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_bodys_valid(args["action_body"]): body = str(args["action_body"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_action_triggers_valid(args["action_trigger"]): trigger = str(args["action_trigger"]) else: return Response.error(FIELD_NOT_VALID) if validator.is_accessibility_valid(args["accessibility"]): accessibility = args["accessibility"] else: accessibility = str(enums.AccessibilityEnum.ADMINISTRATOR.value) if validator.is_area_valid(args["area"]): area = args["area"] else: area = "" if validator.is_geolocation_valid(args["geolocation"]): geolocation = args["geolocation"] else: return Response.error(FIELD_NOT_VALID) response_plan = { "response_plan_id": response_plan_id, "message_status": message_status, "alert_category": category, "alert_severity": severity, "actions": actions, "action_parameters": parameters, "action_format": format, "action_description": description, "action_body": body, "action_trigger": trigger, "accessibility": accessibility, "area": area, "geolocation": geolocation } result = self.repository.modify_response(response_id, response_plan) if result: return Response.success({"internal_id": result}) return Response.error(GENERIC)
def get(self, event_id): response = self.repository.get_event(event_id) if response: return Response.success(translator.event_translator(response)) return Response.error(NOT_EXISTS_ID)