labs4capella / python4capella

Python for Capella
Eclipse Public License 2.0
52 stars 10 forks source link

PVMT.get_p_v_value() doesn't work with EnumerationPropertyValue and Team for Capella #122

Closed ylussaud closed 2 years ago

ylussaud commented 2 years ago

It returns EnumerationPropertyLiteral[TRANSIENT] or similar, corresponding to the .toString() on a CDOObject.

This can be fixed with the following code:

    def get_p_v_value(elem, PVName):
        """
        status: OK
        """
        for group in elem.get_java_object().getOwnedPropertyValueGroups():
            for pv in group.getOwnedPropertyValues():
                if PVName == pv.getName():
                    if pv.eClass().getName() == "BooleanPropertyValue":
                        return str(pv.isValue())
                    elif pv.eClass().getName() == "EnumerationPropertyValue":
                        if pv.getValue() is not None:
                            return pv.getValue().getName()
                        else:
                            return None
                    else:
                        return str(pv.getValue())
        return None
ylussaud commented 2 years ago

We probably need to check other uses of the str() constructor that implicitly calls toString(). The behavior is not the same between EMF and CDO.