def _serializeJsonToModel(self, object: event, json):
     try:
         point = object.point
         end = object.detail.getlink()
         if json.getaddress():
             locator = Nominatim(user_agent="myGeocoder")
             location = locator.geocode(json.getaddress())
             end.setpoint(f"{location.latitude}, {location.longitude}")
             # point.setlat(location.latitude)
         else:
             end.setpoint(
                 f"{json.getlatitudeDest()}, {json.getlongitudeDest()}")
         end.setcallsign(json.getendName())
         object.detail.setlink(end)
         object.detail.contact.setcallsign(json.getrouteName())
         object.detail.link_attr.setmethod(json.getmethod)
         start = object.detail.getlink()
         start.setpoint(f"{json.getlatitude()}, {json.getlongitude()}")
         start.setcallsign(json.getstartName())
         object.detail.setlink(start)
         if json.gettimeout() != '':
             object.setstale(staletime=int(json.gettimeout()))
         else:
             object.setstale(
                 staletime=RestAPIVariables.defaultGeoObjectTimeout)
         return object
     except AttributeError as e:
         raise Exception(
             'a parameter has been passed which is not recognized with error: '
             + str(e))
Ejemplo n.º 2
0
 def test_xml_serialization(self):
     """
     test new serialization in contrast with legacy serializer to ensure compatibility
     """
     from FreeTAKServer.model.FTSModel.Event import Event
     xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
     fts_obj = XmlSerializer().from_format_to_fts_object(
         xmlstring, Event.GeoChat())
     obj = XmlSerializer().from_fts_object_to_format(fts_obj)
     print(etree.tostring(obj).decode())
     legacyftsobj = XMLCoTController().serialize_CoT_to_model(
         Event.GeoChat(), etree.fromstring(xmlstring))
     legacy_string = XMLCoTController().serialize_model_to_CoT(legacyftsobj)
     self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def __init__(self, json):
     tempObject = event.Presence()
     object = SendPresence()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(object.modelObject, json)
     object.setXmlString(XMLCoTController().serialize_model_to_CoT(object.modelObject))
     self.setCoTObject(object)
Ejemplo n.º 6
0
    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))
Ejemplo n.º 7
0
 def test_to_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     xmlstring = '<event version="2.0" uid="ANDROID-R5CN70EYKQH" type="a-f-G-U-C" how="h-e" start="2020-12-24T18:16:22.325Z" time="2020-12-24T18:16:22.325Z" stale="2020-12-24T18:22:37.325Z"><detail><__group name="Teal" role="Team Member"/><status battery="76"/><takv version="4.2.0.4 (47e136dd).1607456856-CIV" platform="ATAK-CIV" device="SAMSUNG SM-N986U" os="29"/><track course="159.1462509079387" speed="0.0"/><contact callsign="SPAC3SLOTH" endpoint="*:-1:stcp" /><uid Droid="SPAC3SLOTH"/><precisionlocation altsrc="GPS" geopointsrc="GPS"/></detail><point le="9999999.0" ce="11.0" hae="178.84407323983876" lon="-76.675505" lat="39.664392"/></event>'
     fts_obj = XmlSerializer().from_format_to_fts_object(
         xmlstring, Event.Connection())
     y = ProtobufSerializer().from_fts_object_to_format(fts_obj)
     1 == 1
Ejemplo n.º 8
0
 def __init__(self, json):
     tempObject = event.SimpleCoT()
     object = SendSimpleCoT()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(object.modelObject, json)
     DatabaseController().create_CoT(object.modelObject)
     object.setXmlString(XMLCoTController().serialize_model_to_CoT(object.modelObject))
     self.setCoTObject(object)
Ejemplo n.º 9
0
 def __init__(self, json):
     tempObject = event.SimpleCoT()
     object = SendSimpleCoT()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(object.modelObject, json)
     DatabaseController().create_CoT(object.modelObject)
     object.setXmlString(etree.tostring(XmlSerializer().from_fts_object_to_format(object.modelObject)))
     self.setCoTObject(object)
Ejemplo n.º 10
0
 def point_controller(self, Json):
     JsonFull = self.pointJsonFull
     simpleModelObject = Event.dropPoint(etree.fromstring(JsonFull[1]))
     JsonProcessed = self.serialize_simplified_json_to_comprehensive(
         Json, JsonFull[0])
     processedModelObject = self.serializeJsonToModel(
         simpleModelObject, JsonProcessed)
     return processedModelObject
Ejemplo n.º 11
0
    def main(self):
        from lxml import etree
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    pass
            else:
                pass
            try:
                data = self.receive_data_from_federate(1)
            except ssl.SSLWantReadError:
                data = None
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    # event = etree.Element('event')
                    # SpecificCoTObj = XMLCoTController().categorize_type(protobuf_object.type)
                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
 def __init__(self, json):
     tempObject = event.Route()
     # tempObject.detail.setlink(None)
     # tempObject.detail.setlink(None)
     object = SendRoute()
     object.setModelObject(tempObject)
     object.modelObject = self._serializeJsonToModel(
         object.modelObject, json)
     object.setXmlString(
         tostring(XmlSerializer().from_fts_object_to_format(
             object.modelObject)))
     self.setCoTObject(object)
Ejemplo n.º 13
0
 def test_from_protobuf_serialization(self):
     from FreeTAKServer.model.FTSModel.Event import Event
     from FreeTAKServer.model.protobufModel.fig_pb2 import FederatedEvent
     import lxml
     protobufString = b'\n\x83\x04\x08\xbe\xb9\xfb\x85\xeb.\x10\xbe\xb9\xfb\x85\xeb.\x18\x96\xab\x92\x86\xeb.!\xaf\xf6b\x88\\d<@) {Mcr\x1aG\xc01\x00\x00\x00\xe0\xcf\x12cA9\x00\x00\x00\xe0\xcf\x12cAA\x00\x00\x00\xe0\xcf\x12cAJ.S-1-5-21-2720623347-3037847324-4167270909-1002R\x0ba-f-G-U-C-IZ\x03h-eb\xfa\x02<detail><takv version="4.0.0.117" platform="WinTAK-CIV" os="Microsoft Windows 10 Home" device="Micro-Star International Co., Ltd MS-7C02"/><contact callsign="FEATHER" endpoint="*:-1:stcp"/><uid Droid="FEATHER"/><__group name="Cyan" role="Team Member"/><_flow-tags_ TAK-Server-c0581fed97ff4cb89eb8666a8794670cc9f77ddb-badf-48da-abe7-84545ecda69d="2020-12-29T23:04:27Z"/></detail>hd'
     # protobufString2 = b'"\x00\x00\x00="\x12;\x08\x01\x12.S-1-5-21-2720623347-3037847324-4167270909-1002\x1a\x07FEATHER'
     protobufObj = FederatedEvent()
     protobufObj.ParseFromString(protobufString)
     # protobufObj.ParseFromString(protobufString2)
     #y = [name.name for name in protobufObj.event.DESCRIPTOR.fields]
     fts_obj = ProtobufSerializer().from_format_to_fts_object(protobufObj, Event.Connection())
     z = lxml.etree.tostring(XmlSerializer().from_fts_object_to_format(fts_obj))
     1 == 1
    def main(self):
        from defusedxml import ElementTree as etree
        import time
        while True:
            time.sleep(0.1)
            command = self.receive_command_data(self.pipe)
            if command:
                try:
                    self.m_SendConnectionHandler.Handle(self, command)
                except Exception as e:
                    logger.debug("exception in command chain " + str(e))
            else:
                pass

            data = self.receive_data_from_federate(1)
            if data:
                for protobuf_object in data:
                    # TODO: clean all of this up as it's just a PoC

                    try:
                        detail = etree.fromstring(protobuf_object.event.other)
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer(
                        ).from_format_to_fts_object(protobuf_object,
                                                    Event.FederatedCoT())
                        specific_obj = SendOther()
                        event = XmlSerializer().from_fts_object_to_format(
                            fts_obj)
                        xmlstring = event
                        xmlstring.find('detail').remove(
                            xmlstring.find('detail').find('remarks'))
                        xmlstring.find('detail').extend(
                            [child for child in detail])
                        # specific_obj.xmlString = etree.tostring(xmlstring)
                        print(etree.tostring(xmlstring))
                        specific_obj.xmlString = etree.tostring(xmlstring)
                        self.pipe.send(specific_obj)
                    except Exception as e:
                        pass
                    """if isinstance(SpecificCoTObj, SendOtherController):
                        detail = protobuf_object.event.other
                        protobuf_object.event.other = ''
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, Event.Other())
                        protobuf_object.event.other = detail
                        SpecificCoTObj.object = fts_obj
                        SpecificCoTObj.Object =
                    else:
                        fts_obj = ProtobufSerializer().from_format_to_fts_object(protobuf_object, SpecificCoTObj().object)
                        self.pipe.send(data)"""
            else:
                pass
Ejemplo n.º 15
0
def test(json):
    modelObject = Event.dropPoint()
    out = XMLCoTController().serialize_CoT_to_model(modelObject,
                                                    etree.fromstring(json))
    xml = XMLCoTController().serialize_model_to_CoT(out, 'event')
    from FreeTAKServer.controllers.SpecificCoTControllers.SendDropPointController import SendDropPointController
    rawcot = RawCoT()
    rawcot.xmlString = xml
    rawcot.clientInformation = None
    object = SendDropPointController(rawcot)
    print(
        etree.tostring(object.sendDropPoint.xmlString,
                       pretty_print=True).decode())
    '''EventObject = json
Ejemplo n.º 16
0
 def test_xml_serialization(self):
     """
     test new serialization in contrast with legacy serializer to ensure compatibility
     """
     from FreeTAKServer.model.FTSModel.Event import Event
     # xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
     xmlstring = '<event version="2.0" uid="115e1a1a-9947-4531-801c-40215fa4888c" type="b-m-r" time="2021-03-17T21:53:08.07Z" start="2021-03-17T21:53:08.07Z" stale="2021-03-24T21:53:08.07Z" how="h-e"><point lat="0" lon="0" hae="0" ce="9999999" le="9999999" /><detail><contact callsign="Eliopoli/BOP" /><link uid="4eaf4026-8db6-48ef-83c2-063dd0120339" type="b-m-p-w" point="44.1644630, -65.7995800,85.84967474" callsign="Eliopoli/BOP SP" relation="c" remarks="" /><link uid="42882562-9dc6-481b-9c89-9a5ba96fbf57" type="b-m-p-w" point="43.9676310, -66.1266740,16.80836837" callsign="Eliopoli" relation="c" remarks="" /><link_attr color="-1" type="b-m-r" method="Driving" direction="Infil" routetype="Primary" order="Ascending Check Points" /></detail></event>'
     # fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.GeoChat())
     fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.Route())
     obj = XmlSerializer().from_fts_object_to_format(fts_obj)
     print(etree.tostring(obj).decode())
     # legacyftsobj = XMLCoTController().serialize_CoT_to_model(Event.GeoChat(), etree.fromstring(xmlstring))
     legacy_string = XMLCoTController().serialize_model_to_CoT(fts_obj)
     self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
Ejemplo n.º 17
0
def SendGeoChat():
    try:
        json = request.json
        modelObject = Event.GeoChat()
        out = ApplyFullJsonController().serializeJsonToModel(modelObject, json)
        xml = XMLCoTController().serialize_model_to_CoT(out, 'event')
        from FreeTAKServer.controllers.SpecificCoTControllers.SendGeoChatController import SendGeoChatController
        rawcot = RawCoT()
        rawcot.xmlString = xml
        rawcot.clientInformation = None
        object = SendGeoChatController(rawcot)
        APIPipe.send(object.getObject())
        return '200', 200
    except Exception as e:
        print(e)
Ejemplo n.º 18
0
    def test_xml_serialization(self):
        """
        test new serialization in contrast with legacy serializer to ensure compatibility
        """
        from FreeTAKServer.model.FTSModel.Event import Event
        # xmlstring = '<event version="2.0" uid="GeoChat.ANDROID-359975090666199.FEATHER.27d8ef23-8578-4cb4-8f53-02f5dc150cd2" type="b-t-f" how="h-g-i-g-o" start="2021-01-03T19:01:35.472Z" time="2021-01-03T19:01:35.472Z" stale="2021-01-04T19:01:35.472Z"><detail><__chat id="S-1-5-21-2720623347-3037847324-4167270909-1002" parent="RootContactGroup" chatroom="FEATHER" groupOwner="false"><chatgrp uid0="ANDROID-359975090666199" uid1="S-1-5-21-2720623347-3037847324-4167270909-1002" id="S-1-5-21-2720623347-3037847324-4167270909-1002"/></__chat><link uid="ANDROID-359975090666199" relation="p-p" type="a-f-G-E-V-A"/><remarks time="2021-01-03T19:01:35.472Z" source="BAO.F.ATAK.ANDROID-359975090666199" to="S-1-5-21-2720623347-3037847324-4167270909-1002">at VDO</remarks><__serverdestination destinations="192.168.2.66:4242:tcp:ANDROID-359975090666199"/><marti><dest callsign = "WOLF"/><dest callsign="GALLOP"/><dest callsign="FEATHER"/></marti></detail><point le="9999999.0" ce="3.2" hae="22.958679722315807" lon="-66.10803" lat="43.855711"/></event>'
        xmlstring = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><event version="2.0" uid="03Z0170972" type="a-f-A-M-H-Q" time="2021-06-17T19:08:19.699Z" start="2021-06-17T19:08:19.699Z" stale="2021-06-18T19:08:23.199Z" how="m-g"><point lat="43.85566678637877" lon="-66.10800161079035" hae="0.11165844181401496" ce="0.0" le="0.0" /><detail> <contact callsign="UAS-NOVA" /><sensor elevation="0.0" vfov="66.0" north="226.70000076293945" roll="0.0" range="300" azimuth="46.0" model="Phantom 3 Advanced Camera" fov="81.0" type="r-e" version="0.6" /></detail></event>'

        # fts_obj = XmlSerializer().from_format_to_fts_object(xmlstring, Event.GeoChat())
        fts_obj = XmlSerializer().from_format_to_fts_object(
            xmlstring, Event.DroneSensor())
        obj = XmlSerializer().from_fts_object_to_format(fts_obj)
        print(etree.tostring(obj).decode())
        # legacyftsobj = XMLCoTController().serialize_CoT_to_model(Event.GeoChat(), etree.fromstring(xmlstring))
        legacy_string = XMLCoTController().serialize_model_to_CoT(fts_obj)
        self.assertEqual(legacy_string.decode(), etree.tostring(obj).decode())
Ejemplo n.º 19
0
 def intstantiateClientInformationModelFromConnection(
         self, rawClientInformation, queue):
     try:
         tempObject = Event.Connection()
         self.clientInformation = ClientInformation()
         argument = "initialConnection"
         self.clientInformation.dataQueue = queue
         self.clientInformation.socket = rawClientInformation.socket
         self.clientInformation.IP = rawClientInformation.ip
         self.clientInformation.idData = rawClientInformation.xmlString
         self.clientInformation.alive = 1
         self.clientInformation.ID = uuid.uuid1().int
         self.clientInformation.modelObject = XmlSerializer(
         ).from_format_to_fts_object(
             rawClientInformation.xmlString.encode(), tempObject)
         return self.clientInformation
     except Exception as e:
         logger.debug('error in client information controller ' + str(e))
         return -1
    def receive_data_from_federates(self):
        # returns data received from federate
        # the following logic receives data from the federate and processes the protobuf
        # up to 100 CoT's
        dataCount = 0
        dataArray = []
        # 100 is the limit of data which can be received from a federate in one iteration
        while dataCount < 100:
            dataCount += 1
            try:
                try:
                    self.connection.settimeout(0.01)
                    data = self.connection.recv(self.buffer)
                    self.connection.settimeout(0)
                except TimeoutError:
                    break

                except Exception as e:
                    self.disconnect()
                    self.killSwitch = True
                    return 0
                if data != [b'']:
                    header = data[0]
                    content = self.connection.recv(
                        self.get_header_length(header))
                    EmptyFTSObject = Event.FederatedCoT()
                    protoObject = FederatedEvent().FromString(content)
                    print(protoObject)
                    FTSObject = FederatedCoTController(
                    ).serialize_main_contentv1(protoObject, EmptyFTSObject)
                    print('received data from Federate')
                    print(content)
                else:
                    self.killSwitch = True

                dataArray.append(FTSObject)

            except Exception as e:
                pass
Ejemplo n.º 21
0
    def from_api_to_fts_object(self, api_json: dict) -> Types.specific_cot:

        serialized_json = self.serialize_initial_json(api_json)
        CoTObject = self.create_cot_object(serialized_json, Event.SimpleCoT(),
                                           SendSimpleCoT())
        return CoTObject
Ejemplo n.º 22
0
                ftssetter(nestedObject)

            else:
                #get setter for associated fts object attribute
                FTSSetter = getattr(ftsobject, 'set'+field.name)

                # get the protobuf objects nested message
                protoObjectValue = getattr(protoobject, field.name)

                # call the fts setter with the object value
                FTSSetter(protoObjectValue)

        return ftsobject

if __name__ == "__main__":
    ftsobj = Event.FederatedCoT()

    msga = fig_pb2.FederatedEvent()
    geo = msga.event
    geo.sendTime = 1
    geo.startTime = 2
    geo.staleTime = 3
    geo.lat = 4
    geo.lon = 5
    geo.hae = 6
    geo.ce = 7
    geo.le = 8
    geo.uid = '9'
    geo.type = '10'
    geo.coordSource = '11'
    geo.other = '<detail/>'
                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
Ejemplo n.º 24
0
def updatetemplate(checklistid, taskid):
    from flask import request
    from defusedxml import ElementTree as etree
    from FreeTAKServer.controllers.SpecificCoTControllers.SendExcheckUpdateController import SendExcheckUpdateController
    from FreeTAKServer.controllers.XMLCoTController import XMLCoTController
    from FreeTAKServer.model.FTSModel.Event import Event
    from FreeTAKServer.model.RawCoT import RawCoT
    import uuid
    import hashlib

    data = request.data

    xml = etree.parse(
        str(
            PurePath(Path(MainConfig.ExCheckChecklistFilePath),
                     Path(checklistid + '.xml')))).getroot()
    updatedTask = etree.fromstring(data)
    tasks = xml.find('checklistTasks')
    for task in tasks:
        uid = task.find('uid')
        if uid.text == taskid:
            tasks.replace(task, updatedTask)
        else:
            pass
    with open(
            str(
                PurePath(Path(MainConfig.ExCheckChecklistFilePath),
                         Path(checklistid + '.xml'))), 'w+') as file:
        file.write(etree.tostring(xml).decode())
        file.close()

    # Create Object to send to client
    object = Event.ExcheckUpdate()
    object.setuid(str(uuid.uuid4()))
    object.setversion('2.0')
    object.detail.mission.settype("CHANGE")
    object.detail.mission.settool("ExCheck")
    object.detail.mission.setname(checklistid)
    object.detail.mission.setauthorUid(request.args.get("clientUid"))
    object.detail.mission.MissionChanges.MissionChange.creatorUid.setINTAG(
        request.args.get("clientUid"))
    object.detail.mission.MissionChanges.MissionChange.missionName.setINTAG(
        checklistid)
    object.detail.mission.MissionChanges.MissionChange.type.setINTAG(
        "ADD_CONTENT")
    object.detail.mission.MissionChanges.MissionChange.contentResource.filename.setINTAG(
        taskid + '.xml')
    object.detail.mission.MissionChanges.MissionChange.contentResource.hash.setINTAG(
        str(
            hashlib.sha256(
                str(
                    open(
                        MainConfig.ExCheckChecklistFilePath + '/' +
                        checklistid + '.xml', 'r')).encode()).hexdigest()))
    object.detail.mission.MissionChanges.MissionChange.contentResource.keywords.setINTAG(
        'Task')
    object.detail.mission.MissionChanges.MissionChange.contentResource.name.setINTAG(
        taskid)
    object.detail.mission.MissionChanges.MissionChange.contentResource.size.setINTAG(
        str(len(data)))
    #TODO: change this value
    object.detail.mission.MissionChanges.MissionChange.contentResource.submitter.setINTAG(
        'atak')
    object.detail.mission.MissionChanges.MissionChange.contentResource.uid.setINTAG(
        taskid)
    '''object = etree.fromstring(templateex)
    object.uid = uuid.uuid4()
    object.find('detail').find('mission').type= "CHANGE"
    object.find('detail').find('mission').name = taskid
    object.find('detail').find('mission').Uid = request.args.get("clientUid")
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('creatorUid').text = request.args.get("clientUid")
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('missionName').text = taskid
    object.find('detail').find('mission').find('MissionChanges').find('MissionChange').find('filename').text = checklistid+'.xml'
    object.detail.mission.MissionChanges.MissionChange.contentResource.hash.setINTAG(str(hashlib.sha256(str(data).encode()).hexdigest()))
    object.detail.mission.MissionChanges.MissionChange.contentResource.keywords.setINTAG('Task')
    object.detail.mission.MissionChanges.MissionChange.contentResource.name.setINTAG(checklistid)
    object.detail.mission.MissionChanges.MissionChange.contentResource.size.setINTAG(str(len(data)))
    #TODO: change this value
    object.detail.mission.MissionChanges.MissionChange.contentResource.submitter.setINTAG('test')
    object.detail.mission.MissionChanges.MissionChange.contentResource.uid.setINTAG(checklistid)'''
    rawcot = RawCoT()
    xml = XMLCoTController().serialize_model_to_CoT(object)
    rawcot.xmlString = xml

    PIPE.put(rawcot)
    #PIPE.send()

    return '', 200
Ejemplo n.º 25
0
        if len(method_list) == 1:
            return method_list[0]

        elif len(method_list) == 0:
            raise AttributeError(expected_class_name +
                                 ' does not have specified attribute')

        elif len(method_list) > 1 and expected_class_name is not None:
            for method in method_list:
                if method.__self__.__class__.__name__.lower(
                ) == expected_class_name.lower():
                    return method
                else:
                    pass
            raise AttributeError('invalid json')

        else:
            raise AttributeError('invalid json')

    def from_fts_object_to_format(self, FTSObject: Event) -> dict:
        for key, value in object.items():
            getters = self._get_fts_object_var_getter(FTSObject, key)
            getter = self._get_method_in_method_list(getters, key)
            value = getter()
        return object_body


if __name__ == "__main__":
    getter = JsonSerializer().get_fts_object_var_getter(
        Event.Presence(), 'uid')
    print(getter())