def instance_parse(package, source_element, root): ins = UMLInstance(package, source_element.get('name'), source_element.get('{%s}id' % ns['xmi'])) # Detail is sparx specific # TODO: Put modelling tool in settings and use tool specific parser here detail = root.xpath("//element[@xmi:idref='%s']" % ins.id, namespaces=ns)[0] properties = detail.find('properties') ins.stereotype = properties.get('stereotype') ins.documentation = properties.get('documentation') if ins.documentation is None: ins.documentation = "" # Create attributes for each item found in the runstate # TODO: Change this to using an re extended_properties = detail.find('extendedProperties') if extended_properties is not None and extended_properties.get( 'runstate') is not None: run_state = extended_properties.get('runstate') vars = run_state.split('@ENDVAR;') for var in vars: if var != '': variable, value = (var.split(';')[1:3]) attr = UMLAttribute(ins, variable.split('=')[1], value.split('=')[1]) attr.value = value.split('=')[1] ins.attributes.append(attr) # else: #TODO: logging debug # print(f"No runstate found for instance {ins.name} | {ins.id}") return ins
def setUp(self): self.package = UMLPackage("id", "name") self.instance = UMLInstance(self.package, "test1", 1) attr = UMLAttribute(self.package, 'testatt', 1) attr.value = "testval" self.instance.attributes.append(attr) self.package.instances.append(self.instance)
def attr_parse(parent: UMLClass, element, root, stereotypes) -> UMLAttribute: value = element.get("value").strip("<div>").strip("</div>").strip("<br") # height = int(element.find("mxGeometry").get("y")) dq = [] if "{dq_even}" in value: dq.append('even') value = value.replace("{dq_even}", "").strip() is_id = False if "{id}" in value: is_id = True value = value.replace("{id}", "").strip() visibility: bool = False if value.startswith("+"): visibility = True value = value.strip("+").strip("-").strip() name, attr_type = value.split(":") attr = UMLAttribute(parent, name, element.get('id')) if is_id: attr.is_id = is_id parent.id_attribute = attr attr.visibility = visibility attr.validations = dq attr.set_type(attr_type.strip()) return attr
def test_attribute_type(self): attr = UMLAttribute(None, "test", 123) attr.set_type('String') self.assertEqual(attr.dest_type, 'CharField') attr.set_type('String (123)') self.assertEqual(attr.dest_type, 'CharField') self.assertEqual(attr.length, 123) attr.set_type('decimal (12,2)') self.assertEqual(attr.dest_type, 'DecimalField') self.assertEqual(attr.precision, 12) self.assertEqual(attr.scale, 2)
def attr_parse(parent: UMLClass, element, root, stereotypes) -> UMLAttribute: value = element.get("value").strip("<div>").strip("</div>").strip("<br") # height = int(element.find("mxGeometry").get("y")) dq = [] if "{dq_even}" in value: dq.append('even') value = value.replace("{dq_even}", "").strip() is_id = False if "{id}" in value: is_id = True value = value.replace("{id}", "").strip() visibility: bool = False if value.startswith("+"): visibility = True value = value.strip("+").strip("-").strip() name, attr_type = value.split(":") attr_type = attr_type.strip() attr = UMLAttribute(parent, name, element.get('id')) if is_id: attr.is_id = is_id parent.id_attribute = attr attr.visibility = visibility attr.validations = dq attr.type = attr_type if attr.type == 'string': attr.length = 100 if attr_type in generation_fields[settings['generation_type']].keys(): attr.dest_type = generation_fields[ settings['generation_type']][attr_type] else: attr.dest_type = attr_type return attr
def test_attribute_get_type(self): attr = UMLAttribute(None, "test", 123) attr.set_type('String') self.assertEqual(attr.get_type('default'), 'string')
def attr_parse(parent: UMLClass, element, root): attr = UMLAttribute(parent, element.get('name'), element.get('{%s}id' % ns['xmi'])) attr.visibility = element.get('visibility') type_elem = element.find('type') if type_elem is not None: type_id = type_elem.get('{%s}idref' % ns['xmi']) if type_id[:4] == 'EAID': attr.classification_id = type_id else: logging.error( f"Attribute {attr.name} of class {parent} does not have a type") # Detail is sparx sprecific # TODO: Put modelling tool in settings and use tool specific parser here detail = root.xpath("//attribute[@xmi:idref='%s']" % attr.id, namespaces=ns)[0] properties = detail.find('properties') attr.set_type(properties.get('type')) doc = detail.find('documentation') doc = doc.get('value') if doc is not None: attr.documentation = doc alias_node = detail.find('style') attr.alias = alias_node.get('value') xrefs = detail.find('xrefs') if xrefs.get('value') is not None and 'NAME=isID' in xrefs.get('value'): attr.is_id = True attr.parent.id_attribute = attr else: attr.is_id = False stereotype = detail.find('stereotype') if stereotype is not None: attr.stereotype = stereotype.get('stereotype') constraints = detail.find('Constraints') if constraints is not None: for constraint in constraints: name = constraint.get('name') if name == 'unique': attr.is_unique = True elif name.startswith('length'): attr.length = int(name.split("=")[1]) return attr
def attr_parse(parent: UMLClass, element, root): attr = UMLAttribute(parent, element.get('name'), element.get('{%s}id' % ns['xmi'])) attr.visibility = element.get('visibility') type_elem = element.find('type') type_id = type_elem.get('{%s}idref' % ns['xmi']) if type_id[:4] == 'EAID': attr.classification_id = type_id # Detail is sparx sprecific # TODO: Put modelling tool in settings and use tool specific parser here detail = root.xpath("//attribute[@xmi:idref='%s']" % attr.id, namespaces=ns)[0] properties = detail.find('properties') attr.type = properties.get('type') if properties.get('type') in generation_fields[ settings['generation_type']].keys(): attr.dest_type = generation_fields[settings['generation_type']][ properties.get('type')] else: attr.dest_type = properties.get('type') xrefs = detail.find('xrefs') if xrefs.get('value') is not None and 'NAME=isID' in xrefs.get('value'): attr.is_id = True attr.parent.id_attribute = attr else: attr.is_id = False # Todo: decide how to include string lengths in UML if attr.type == 'string': attr.length = 100 stereotype = detail.find('stereotype') if stereotype is not None: attr.stereotype = stereotype.get('stereotype') constraints = detail.find('Constraints') if constraints is not None: for constraint in constraints: name = constraint.get('name') if name == 'unique': attr.is_unique = True elif name.startswith('length'): attr.length = int(name.split("=")[1]) return attr