in src/pydolphinscheduler/models/meta.py [0:0]
def j2p(mcs, cm: classmethod, name: str, attrs: Dict, params=None):
"""Convert JavaObject to Python object according attribute in the ``__init__`` method.
``py4j.java_gateway.JavaObject`` return the Java object from the DolphinScheduler server, we can
access the Java object attribute by ``getAttrName`` method. This method try to assign the Java object
attribute to the Python object attribute according the attribute in python ``__init__`` method.
For example, If the method return value is ``py4j.java_gateway.JavaObject`` we temporary call it
``JObject``, and we create a ``PObject`` object in Python, the ``__init__`` method is:
.. code-block:: python
def __init__(
self,
name: str,
description: str
):
self.name = name
self.description = description
Because the ``name`` and ``description`` is the attribute in the ``__init__`` method, so this method
will try to call method ``getName`` and ``getDescription`` from the ``JObject`` and assign the return
value to the ``PObject`` attribute. Just like this:
.. code-block:: python
return PObject(name=JObject.getName(), description=JObject.getDescription())
"""
@wraps(cm)
def wrapper(*args, **kwargs):
class_ = type(name, (), attrs)
method_result = cm.__func__(class_, *args, **kwargs)
# skip convert if method result is not JavaObject, they maybe some property method
if not isinstance(method_result, JavaObject):
return method_result
obj_init_params = []
for param in params:
java_func_name = mcs.py4j_attr_func_name(param)
java_func = getattr(method_result, java_func_name)
obj_init_params.append(java_func())
return class_(*obj_init_params)
return wrapper