def removeRelationshipAttribute(self, attribute_data: Dict[str, str]) -> str: attribute_name: str = attribute_data["attribute_name"] relationship_id: str = attribute_data["relationship_id"] relationship_id_tuple: Optional[ Tuple[str, str] ] = uml_utilities.parse_relationship_identifier(relationship_id) if not relationship_id_tuple: raise Exception( "Invalid relationship identifier provided: " + relationship_id ) class_name_a: str = relationship_id_tuple[0] class_name_b: str = relationship_id_tuple[1] if not class_name_a in self.__diagram.get_all_class_names(): return "Class " + class_name_a + " not found in the diagram." if not class_name_b in self.__diagram.get_all_class_names(): return "Class " + class_name_b + " not found in the diagram." if not self.__diagram.remove_relationship_attribute( class_name_a, class_name_b, attribute_name ): return ( "Attribute " + attribute_name + " not found in Class: " + uml_utilities.stringify_relationship_identifier( class_name_a, class_name_b ) ) return ""
def removeRelationship(self, relationship_id: str) -> str: relationship_id_tuple: Optional[ Tuple[str, str] ] = uml_utilities.parse_relationship_identifier(relationship_id) if not relationship_id_tuple: raise Exception( "Invalid relationship identifier provided: " + relationship_id ) class_name_a: str = relationship_id_tuple[0] class_name_b: str = relationship_id_tuple[1] if not class_name_a in self.__diagram.get_all_class_names(): return "Class " + class_name_a + " not found in the diagram." if not class_name_b in self.__diagram.get_all_class_names(): return "Class " + class_name_b + " not found in the diagram." if not self.__diagram.remove_relationship(class_name_a, class_name_b): return "Relationship not found in diagram: {}".format( uml_utilities.stringify_relationship_identifier( class_name_a, class_name_b ) ) return ""
def test_parse_relationship_identifier() -> None: assert uml_utilities.parse_relationship_identifier("[Alpha,Beta]") assert not uml_utilities.parse_relationship_identifier("[]") assert not uml_utilities.parse_relationship_identifier("[Alpha,Beta") assert not uml_utilities.parse_relationship_identifier("[Alpha]") assert not uml_utilities.parse_relationship_identifier("[Bad Name,Beta]") assert not uml_utilities.parse_relationship_identifier( "[Alpha,Beta,bad relname]")
def do_set(self, arg: str) -> None: """Usage: set <identifier> <attribute_name> <attribute_value> Adds or modifies the attribute for the specified class For help with identifiers, type in 'help identifiers'""" # Check the number of arguments args: List[str] = arg.split() if len(args) != 3: print("Please provide a valid number of arguments.") print(self.do_set.__doc__) return # Grab arguments identifier: str = args[0] attr_name: str = args[1] attr_value: str = args[2] # Classify what kind of identifier was provided identifier_class: Optional[str] = uml_utilities.classify_identifier( identifier) # Ensure attribute name is valid if not uml_utilities.parse_class_identifier(attr_name): print( "Please provide a valid attribute name (no whitespace, quotes, or surrounding brackets)." ) return # Handle class identifiers if identifier_class == "class": class_id: Optional[str] = uml_utilities.parse_class_identifier( identifier) if class_id is not None: self.__set_class_attribute(class_id, attr_name, attr_value) return # Handle relationship identifiers elif identifier_class == "relationship": rel_id: Optional[Tuple[ str, str]] = uml_utilities.parse_relationship_identifier(identifier) if rel_id is not None: self.__set_relationship_attribute(rel_id, attr_name, attr_value) return # If we don't return before we get here, the user provided a bad argument print("Invalid argument provided.") print(self.do_set.__doc__)
def do_remove(self, arg: str) -> None: """Usage: remove <identifier> Removes a class or relationship if one with that identifier exists in the diagram For help with identifiers, type in 'help identifiers'""" # Check the number of arguments args: List[str] = arg.split() if len(args) != 1: print( "Please provide a valid class or relationship identifier as an argument." ) print(self.do_remove.__doc__) return # Grab arguments identifier: str = args[0] # Classify what kind of identifier was provided identifier_class: Optional[str] = uml_utilities.classify_identifier( identifier) # Handle class identifiers if identifier_class == "class": class_id: Optional[str] = uml_utilities.parse_class_identifier( identifier) if class_id is not None: self.__remove_class(arg) return # Handle relationship identifiers elif identifier_class == "relationship": rel_id: Optional[Tuple[ str, str]] = uml_utilities.parse_relationship_identifier(identifier) if rel_id is not None: self.__remove_relationship(rel_id) return # If we don't return before we get here, the user provided a bad argument print("Invalid argument provided.") print(self.do_remove.__doc__)
def setRelationshipAttribute(self, attribute_data: Dict[str, str]) -> str: attr_key: str = attribute_data["attr_key"] attr_value: str = attribute_data["attr_key"] relationship_id: str = attribute_data["relationship_id"] relationship_id_tuple: Optional[ Tuple[str, str] ] = uml_utilities.parse_relationship_identifier(relationship_id) if not relationship_id_tuple: raise Exception( "Invalid relationship identifier provided: " + relationship_id ) class_name_a: str = relationship_id_tuple[0] class_name_b: str = relationship_id_tuple[1] if not class_name_a in self.__diagram.get_all_class_names(): return "Class " + class_name_a + " not found in the diagram." if not class_name_b in self.__diagram.get_all_class_names(): return "Class " + class_name_b + " not found in the diagram." if ( not "ignore_naming_rules" in attribute_data and not uml_utilities.parse_class_identifier(attr_key) ): return "Attribute name is invalid. (Cannot contain whitespace or quotes, and cannot be surrounded by brackets.)" if not self.__diagram.set_relationship_attribute( relationship_id_tuple[0], relationship_id_tuple[1], attr_key, attr_value ): return "Relationship not found in diagram: {}".format( uml_utilities.stringify_relationship_identifier( class_name_a, class_name_b ) ) return ""