Commit 8eb85789 authored by Jiahang Chen's avatar Jiahang Chen
Browse files

complete the acceptFellingJob functionality

parent 4a4524dd
......@@ -15,10 +15,17 @@ def acceptJob(self, job: FellingJob) -> bool:
return self.add_to_job_list(job)
def queryJobStatus(self, identifier):
pass
for job in self.job_list:
if job.get("id") == identifier:
return {"identifier": identifier, "status": job.get("status")}
return {"identifier": identifier, "status": "NOT FOUND"}
def removeJob(self, identifier):
pass
for job in self.job_list:
if job.get("id") == identifier:
self.job_list.remove(job)
return True
return False
def from_json(self, json_obj):
super().from_json(json_obj)
......
......@@ -3,8 +3,10 @@ class ID(object):
Define primitive variable type ID
"""
def __init__(self, identifier):
# TODO validate identifier
self.__identifier = identifier
@property
def ID(self):
return self.__identifier
......
from ml.managed_actor import ManagedActor
from ml.identifier import ID
import types
import uuid
class Feature(ManagedActor):
......@@ -8,7 +8,7 @@ def __init__(self, name, ref_managing_actor):
super(Feature, self).__init__(name, ref_managing_actor)
self.__name = name
self.__class_name = ""
self.__identifier = ID
self.__identifier = ID(identifier="s3i:{}".format(uuid.uuid4())).ID
self.__subfeatures = []
@property
......@@ -19,6 +19,10 @@ def type_name(self):
def name(self):
return self.__name
@name.setter
def name(self, value):
self.__name = value
@property
def subfeatures(self):
return self.__subfeatures
......@@ -27,7 +31,17 @@ def subfeatures(self):
def identifier(self):
return self.__identifier
@identifier.setter
def identifier(self, value):
self.__identifier = value
def to_json(self):
return {
"class": self.name,
"id": self.identifier,
}
def from_json(self, json_obj):
self.__name = json_obj.get("name", "")
self.__class_name = json_obj.get("class", "")
self.__identifier(json_obj.get("identifier", ""))
self.__identifier = json_obj.get("identifier", "")
from ml.ml40.features.feature import Feature
class Property(Feature):
def __init__(self, name, ref_managing_actor):
super(Property, self).__init__(name=name, ref_managing_actor=ref_managing_actor)
......@@ -3,6 +3,25 @@
class Job(Document):
def __init__(self, name, ref_managing_actor, status=JobStatus.Pending):
def __init__(self, name, ref_managing_actor):
super(Job, self).__init__(name=name,
ref_managing_actor=ref_managing_actor)
self.__status = JobStatus(0)
@property
def status(self):
return self.__status
@status.setter
def status(self, value):
self.__status = value
def to_json(self):
temp_dict = super().to_json()
if self.status:
_dict = temp_dict.copy()
_dict.update({
"status": self.status.name
})
return _dict
return temp_dict
from ml.ml40.features.properties.property import Property
import copy
class Value(Property):
def __init__(self, name, ref_managing_actor):
......@@ -20,3 +20,15 @@ def valid_from(self):
def set_valid_from(self, valid_from):
self._valid_from = valid_from
def to_json(self):
temp_dict = super().to_json()
if self.valid_from and self.valid_to:
_dict = temp_dict.copy()
_dict.update({
"value_to": self.valid_to,
"value_from": self.valid_from
})
return _dict
return temp_dict
......@@ -66,11 +66,12 @@ def __init__(
self.__name = ""
self.__class_name = ""
self.__type_name = ""
self.roles = []
self.__roles = []
self.__features = {}
if attributes:
self.__name = attributes.get("name", "")
self.__roles = attributes.get("roles", "")
self.__class_name = attributes.get("class", "")
self.__type_name = attributes.get("type", "")
......@@ -287,6 +288,7 @@ def on_get_value_request(self, msg):
def on_service_request(self, body_json):
service_type = body_json.get("serviceType")
parameters = body_json.get("parameters")
service_functionality = service_type.split('/')[0]
service_functionality_obj = self.features.get(service_functionality, None)
if service_functionality_obj is None:
......@@ -299,7 +301,12 @@ def on_service_request(self, body_json):
# TODO: Call right functionality.
func_proxy = service_functionality_obj.proxy()
method = getattr(func_proxy, service_type.split('/')[1])
result = {"ok": method("test_job").get()}
result = method(**parameters).get()
if isinstance(result, bool):
results = {"ok": result}
else:
results = result
service_reply = ServiceReply()
service_reply.fillServiceReply(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment