Skip to content

Commit

Permalink
implmented mission change support and fixed enterprise sync bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
naman108 committed Aug 14, 2023
1 parent a709008 commit 5b13d8e
Show file tree
Hide file tree
Showing 25 changed files with 505 additions and 77 deletions.
1 change: 1 addition & 0 deletions FreeTAKServer/components/core/domain/domain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@
from ._mission_role import MissionRole as MissionRole
from ._mission_subscription import MissionSubscription as MissionSubscription
from ._mission_data import MissionData as MissionData
from ._mission_change_record import MissionChangeRecord as MissionChangeRecord
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from FreeTAKServer.components.core.abstract_component.cot_node import CoTNode
from FreeTAKServer.components.core.abstract_component.cot_property import CoTProperty

class MissionChangeRecord(CoTNode):

def __init__(self, configuration, model, oid=None):
super().__init__(self.__class__.__name__, configuration, model, oid)
self.cot_attributes["type"] = None
self.cot_attributes["contentUid"] = None
self.cot_attributes["missionName"] = None
self.cot_attributes["timestamp"] = None
self.cot_attributes["creatorUid"] = None
self.cot_attributes["serverTime"] = None
self.cot_attributes["contentResource"] = None
self.cot_attributes["detail"] = None

@CoTProperty
def type(self):
return self.cot_attributes.get("type", None)

@type.setter
def type(self, type=None):
self.cot_attributes["type"] = type

@CoTProperty
def contentUid(self):
return self.cot_attributes.get("contentUid", None)

@contentUid.setter
def contentUid(self, contentUid=None):
self.cot_attributes["contentUid"] = contentUid

@CoTProperty
def missionName(self):
return self.cot_attributes.get("missionName", None)

@missionName.setter
def missionName(self, missionName=None):
self.cot_attributes["missionName"] = missionName

@CoTProperty
def timestamp(self):
return self.cot_attributes.get("timestamp", None)

@timestamp.setter
def timestamp(self, timestamp=None):
self.cot_attributes["timestamp"] = timestamp

@CoTProperty
def creatorUid(self):
return self.cot_attributes.get("creatorUid", None)

@creatorUid.setter
def creatorUid(self, creatorUid=None):
self.cot_attributes["creatorUid"] = creatorUid

@CoTProperty
def serverTime(self):
return self.cot_attributes.get("serverTime", None)

@serverTime.setter
def serverTime(self, serverTime=None):
self.cot_attributes["serverTime"] = serverTime

@CoTProperty
def contentResource(self):
return self.cot_attributes.get("contentResource", None)

@contentResource.setter
def contentResource(self, contentResource=None):
self.cot_attributes["contentResource"] = contentResource

@CoTProperty
def detail(self):
return self.cot_attributes.get("detail", None)

@detail.setter
def detail(self, detail=None):
self.cot_attributes["detail"] = detail
24 changes: 24 additions & 0 deletions FreeTAKServer/components/core/domain/domain/_mission_cot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from FreeTAKServer.components.core.abstract_component.cot_node import CoTNode
from FreeTAKServer.components.core.abstract_component.cot_property import CoTProperty

class MissionCOT(CoTNode):
def __init__(self, configuration, model, oid=None):
super().__init__(self.__class__.__name__, configuration, model, oid)
self.cot_attributes["type"] = None
self.cot_attributes["callsign"] = None

@CoTProperty
def type(self):
return self.cot_attributes.get("type", None)

@type.setter
def type(self, type=None):
self.cot_attributes["type"] = type

@CoTProperty
def callsign(self):
return self.cot_attributes.get("callsign", None)

@callsign.setter
def callsign(self, callsign=None):
self.cot_attributes["callsign"] = callsign
10 changes: 7 additions & 3 deletions FreeTAKServer/components/core/domain/domain/_mission_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ._mission_data import MissionData
from ._mission_log import MissionLog
from ._mission_subscription import MissionSubscription
from ._mission_change_record import MissionChangeRecord

class MissionInfo(CoTNode):
def __init__(self, configuration, model, oid=None):
Expand Down Expand Up @@ -39,20 +40,23 @@ def nodeId(self, nodeId=None):

@CoTProperty
def data(self) -> List[MissionData | MissionSubscription | MissionLog | str]:
children: List[MissionData | MissionSubscription | MissionLog] = self.get_children_ex(children_type="MissionData")
children: List[MissionData | MissionSubscription | MissionLog | MissionChangeRecord] = self.get_children_ex(children_type="MissionData")
children.extend(self.get_children_ex(children_type="MissionSubscription"))
children.extend(self.get_children_ex(children_type="MissionLog"))
children.extend(self.get_children_ex(children_type="MissionChangeRecord"))
if len(children) == 0:
return self.cot_attributes.get("data", None)
return children

@data.setter
def data(self, data: MissionData | MissionSubscription | MissionLog | str):
def data(self, data: MissionData | MissionSubscription | MissionLog | MissionChangeRecord | str):
if isinstance(data, MissionData):
self.add_child(data)
elif isinstance(data, MissionSubscription):
self.add_child(data)
elif isinstance(data, MissionLog):
elif isinstance(data, MissionLog):
self.add_child(data)
elif isinstance(data, MissionChangeRecord):
self.add_child(data)
elif isinstance(data, str):
self.cot_attributes["data"].append(data)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

?mission?CreateExternalMissionData = FreeTAKServer.components.extended.mission.mission_facade.Mission.add_mission_external_data

?mission?GetMissionChanges = FreeTAKServer.components.extended.mission.mission_facade.Mission.get_mission_changes

[Mission]
__class = FreeTAKServer.components.extended.mission.mission_facade.Mission

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@

MISSION_EXTERNAL_DATA = "mission_external_data"

MISSION_EXTERNAL_DATA_COLLECTION = "mission_external_data"
MISSION_EXTERNAL_DATA_COLLECTION = "mission_external_data"

MISSION_CHANGE_RECORD = "mission_change_record"

MISSION_CONTENT_DATA = "mission_content_data"
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://iec.ch/TC57/mission_collection#",
"type": "object",
"properties":
{
"mission_change_record":
{
"type": "object",
"anyOf":
[
{ "$ref": "#/definitions/MissionContent" },
{ "$ref": "#/definitions/MissionChangeRecord" }
]
}
},
"definitions":
{
"MissionChangeRecord" :
{
"type": "object",
"description" : "",
"properties":
{
"contentResource":
{
"$ref" : "#/definitions/MissionContentData",
"minItems" : 0,
"maxItems" : 1
}
}
},
"MissionContentData":
{
"type": "object"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
from FreeTAKServer.components.extended.mission.controllers.mission_domain_controller import MissionDomainController
from FreeTAKServer.components.extended.mission.controllers.mission_persistence_controller import MissionPersistenceController
from FreeTAKServer.core.configuration.MainConfig import MainConfig
from FreeTAKServer.core.util.serialization_utils import serialize_to_json
from FreeTAKServer.core.util.time_utils import get_dtg

from digitalpy.core.main.controller import Controller
from digitalpy.core.zmanager.request import Request
from digitalpy.core.zmanager.response import Response
from digitalpy.core.zmanager.action_mapper import ActionMapper
from digitalpy.core.digipy_configuration.configuration import Configuration
from digitalpy.core.parsing.load_configuration import LoadConfiguration

config = MainConfig.instance()

class MissionChangeController(Controller):
"""manage mission change requests"""

def __init__(self, request: Request, response: Response, sync_action_mapper: ActionMapper, configuration: Configuration):
super().__init__(request, response, sync_action_mapper, configuration)
self.domain_controller = MissionDomainController(request, response, sync_action_mapper, configuration)
self.persistence_controller = MissionPersistenceController(request, response, sync_action_mapper, configuration)

def initialize(self, request, response):
"""initialize the controller"""
super().initialize(request, response)
self.domain_controller.initialize(request, response)
self.persistence_controller.initialize(request, response)

def execute(self, method=None):
getattr(self, method)(**self.request.get_values())
return self.response

def create_mission_record(self, mission_uid, creator_uid):
self.persistence_controller.create_mission_change(
type = "CREATE_MISSION",
mission_uid=mission_uid,
creator_uid=creator_uid,
content_uid=None,
cot_detail_uid=None,
content_resource_uid=None
)

def create_mission_content_upload_record(self, mission_content_uid, creator_uid, content_uid):
self.persistence_controller.create_mission_change(
type = "ADD_CONTENT",
mission_uid=mission_content_uid,
creator_uid=creator_uid,
content_uid=None,
cot_detail_uid=None,
content_resource_uid=content_uid
)

def create_mission_cot_record(self, mission_cot_uid, creator_uid, cot_uid):
self.persistence_controller.create_mission_change(
type = "ADD_CONTENT",
mission_uid=mission_cot_uid,
creator_uid=creator_uid,
content_uid=cot_uid,
cot_detail_uid=None,
content_resource_uid=None
)

def get_mission_changes(self, mission_id, config_loader, *args, **kwargs):
change_collection = self.domain_controller.create_mission_collection(config_loader)
change_collection.type = "MissionChange"
change_collection.version = "3"
change_collection.nodeId = config.nodeID

mission_changes = self.persistence_controller.get_mission(mission_id).changes

for change in mission_changes:
change_record = self.domain_controller.create_mission_change_record(config_loader)
change_record.type = change.type
change_record.creatorUid = change.creator_uid
change_record.missionName = change.mission_uid
change_record.serverTime = get_dtg(change.server_time)
change_record.timestamp = get_dtg(change.timestamp)
change_record.contentUid = change.content_uid

if change.content_resource_uid != None:
mission_content = self.domain_controller.create_mission_content_data(config_loader)
self.request.set_value("objectuid", change.content_resource_uid)
self.request.set_value("objecthash", change.content_resource_uid)
enterprise_sync_db: 'EnterpriseSyncDataObject' = self.execute_sub_action("GetEnterpriseSyncMetaData").get_value("objectmetadata")

change_record.contentResource = self.domain_controller.complete_mission_content_data(mission_content, enterprise_sync_db)

change_collection.data = change_record

serialized_change_collections = serialize_to_json(change_collection, self.request, self.execute_sub_action)

self.response.set_value("mission_changes", serialized_change_collections)
return serialized_change_collections
Loading

0 comments on commit 5b13d8e

Please sign in to comment.