def send_active_emergencys(self, client): """ this function needs to be cleaned up however it's functionality is as follows it query's the DB for active emergency's at which point it iterates over all emergency objects, transforms them into model objects and then xmlStrings finally the object is sent to the client. """ try: from FreeTAKServer.model.SpecificCoT.SendEmergency import SendEmergency from lxml import etree emergencys = self.dbController.query_ActiveEmergency() for emergency in emergencys: emergencyobj = SendEmergency() modelObject = Event.emergecyOn() filledModelObject = SqlAlchemyObjectController( ).convert_sqlalchemy_to_modelobject(emergency.event, modelObject) # emergencyobj.setXmlString(XMLCoTController().serialize_model_to_CoT(filledModelObject)) emergencyobj.setXmlString( etree.tostring((XmlSerializer().from_fts_object_to_format( filledModelObject)))) print(emergencyobj.xmlString) emergencyobj.setModelObject(filledModelObject) SendDataController().sendDataInQueue(None, emergencyobj, [client]) except Exception as e: import traceback self.logger.error(traceback.format_exc()) self.logger.error( 'an exception has been thrown in sending active emergencies ' + str(e))
def from_api_to_fts_object(self, api_json: dict) -> Types.specific_cot: from FreeTAKServer.model.SpecificCoT.SendEmergency import SendEmergency serialized_json = self.serialize_initial_json(api_json) CoTObject = self._create_cot_object(serialized_json, Event.emergecyOn(), SendEmergency()) return CoTObject
def __init__(self, json): if isinstance(json, EmergencyPost): tempObject = event.emergecyOn() elif isinstance(json, EmergencyDelete): tempObject = event.emergecyOff() else: raise Exception( 'unsupported object type passed under json argument') object = SendEmergency() object.setModelObject(tempObject) object.modelObject = self._serializeJsonToModel( object.modelObject, json) object.setXmlString(XMLCoTController().serialize_model_to_CoT( object.modelObject)) self.setCoTObject(object)
pass for relationship in SqlAlchemyObject.__mapper__.relationships: try: y = str(relationship) relationship = '.'.join(str(relationship).split('.', 1)[1::]) relationshipObject = getattr(SqlAlchemyObject, relationship) if relationshipObject != None: modelObjectInstance = getattr(modelObject, relationship) setter = getattr(modelObject, 'set' + relationship) setter( self.convert_sqlalchemy_to_modelobject( relationshipObject, modelObjectInstance)) else: pass except Exception as e: print(str(e)) return modelObject if __name__ == "__main__": from FreeTAKServer.controllers.DatabaseControllers.DatabaseController import DatabaseController contr = DatabaseController().query_ActiveEmergency() x = contr[0] from FreeTAKServer.model.FTSModel.Event import Event modelobj = Event.emergecyOn() y = SqlAlchemyObjectController().convert_sqlalchemy_to_modelobject( x.event, modelobj) 1 == 1