Skip to content

Commit

Permalink
Fixed CapellaElement.set_status()
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Aug 21, 2024
1 parent 697935b commit b9fc730
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 118 deletions.
25 changes: 25 additions & 0 deletions plugins/Python4Capella/simplified_api/capella.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,30 @@ def get_status(self) -> str:
return value
else:
return value.getName()
def set_status(self, value: str):
"""
Parameters: value: String
"""
project = self.get_java_object()
while project.eContainer() is not None:
project = project.eContainer()
if project.eClass().getName() == "Project":
break
if project.eClass().getName() != "Project":
raise AttributeError("The current object is not attached to a Capella model.")
valid_status = []
for property_type in project.getOwnedEnumerationPropertyTypes():
if property_type.getName() == "ProgressStatus":
for literal in property_type.getOwnedLiterals():
valid_status.append(literal)
break
valid_status_names = [status.getName() for status in valid_status]
if value not in valid_status_names:
raise AttributeError("Valid status are: " + str(valid_status_names))
for status in valid_status:
if status.getName() == value:
self.get_java_object().setStatus(status)
break
def get_review(self) -> str:
"""
Returns: String
Expand Down Expand Up @@ -639,6 +663,7 @@ def get_owned_literal_by_name(self, literalName: str) -> EnumerationPropertyLite
"""
Parameters: PVName: String
Returns: EnumerationPropertyLiteral
status: OK
"""
for literal in self.get_owned_literals():
if literal.get_name() == literalName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@
return value
else:
return value.getName()
project = self.get_java_object()
while project.eContainer() is not None:
project = project.eContainer()
if project.eClass().getName() == "Project":
break
if project.eClass().getName() != "Project":
raise AttributeError("The current object is not attached to a Capella model.")
valid_status = []
for property_type in project.getOwnedEnumerationPropertyTypes():
if property_type.getName() == "ProgressStatus":
for literal in property_type.getOwnedLiterals():
valid_status.append(literal)
break
valid_status_names = [status.getName() for status in valid_status]
if value not in valid_status_names:
raise AttributeError("Valid status are: " + str(valid_status_names))
for status in valid_status:
if status.getName() == value:
self.get_java_object().setStatus(status)
break

Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,11 @@ private String getTestValue(Class cls, TypedElement typedElement) {
} else if ("Integer".equals(typedElement.getType().getLabel())) {
res = "42";
} else if ("String".equals(typedElement.getType().getLabel())) {
if ("status".equals(typedElement.getName())) {
res = "\"DRAFT\"";
}else {
res = "\"value\"";
}
} else if ("PhysicalComponentKind".equals(typedElement.getType().getLabel())) {
res = "\"HARDWARE\"";
} else if ("ExchangeMechanism".equals(typedElement.getType().getLabel())) {
Expand Down
Loading

0 comments on commit b9fc730

Please sign in to comment.