-
Notifications
You must be signed in to change notification settings - Fork 11
🏛️Product base types: add support for product base types in API #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
b8e1050
1eeae55
4d83ab8
ceff641
e3bc2c5
3a96dd6
cb4a9f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -435,6 +435,7 @@ def add_new_product( | |||||
self, | ||||||
name: str, | ||||||
product_type: str, | ||||||
product_base_type: Optional[str] = None, | ||||||
folder_id: Optional["Union[str, _CustomNone]"] = UNKNOWN_VALUE, | ||||||
tags: Optional[Iterable[str]] = None, | ||||||
attribs: Optional[Dict[str, Any]] = UNKNOWN_VALUE, | ||||||
|
@@ -443,10 +444,11 @@ def add_new_product( | |||||
entity_id: Optional[str] = None, | ||||||
created: Optional[bool] = True, | ||||||
): | ||||||
"""Create task object and add it to entity hub. | ||||||
"""Create a task object and add it to the entity hub. | ||||||
|
||||||
Args: | ||||||
name (str): Name of entity. | ||||||
product_base_type (str): Base type of product. | ||||||
product_type (str): Type of product. | ||||||
folder_id (Union[str, None]): Parent folder id. | ||||||
tags (Optional[Iterable[str]]): Folder tags. | ||||||
|
@@ -458,13 +460,19 @@ def add_new_product( | |||||
created (Optional[bool]): Entity is new. When 'None' is passed the | ||||||
value is defined based on value of 'entity_id'. | ||||||
|
||||||
Todo: | ||||||
- Once the product base type is implemented and established, | ||||||
it should be made mandatory to pass it and product_type | ||||||
itself should be optional. | ||||||
|
||||||
Returns: | ||||||
ProductEntity: Added product entity. | ||||||
|
||||||
""" | ||||||
product_entity = ProductEntity( | ||||||
name=name, | ||||||
product_type=product_type, | ||||||
product_base_type=product_base_type, | ||||||
folder_id=folder_id, | ||||||
tags=tags, | ||||||
attribs=attribs, | ||||||
|
@@ -3406,6 +3414,7 @@ def to_create_body_data(self): | |||||
class ProductEntity(BaseEntity): | ||||||
_supports_name = True | ||||||
_supports_tags = True | ||||||
_supports_base_type = True | ||||||
|
||||||
entity_type = "product" | ||||||
parent_entity_types = ["folder"] | ||||||
|
@@ -3414,6 +3423,7 @@ def __init__( | |||||
self, | ||||||
name: str, | ||||||
product_type: str, | ||||||
product_base_type: Optional[str] = None, | ||||||
folder_id: Optional["Union[str, _CustomNone]"] = UNKNOWN_VALUE, | ||||||
tags: Optional[Iterable[str]] = None, | ||||||
attribs: Optional[Dict[str, Any]] = UNKNOWN_VALUE, | ||||||
|
@@ -3435,6 +3445,7 @@ def __init__( | |||||
entity_hub=entity_hub, | ||||||
) | ||||||
self._product_type = product_type | ||||||
self._product_base_type = product_base_type | ||||||
|
||||||
self._orig_product_type = product_type | ||||||
|
||||||
|
@@ -3454,6 +3465,21 @@ def set_product_type(self, product_type): | |||||
|
||||||
product_type = property(get_product_type, set_product_type) | ||||||
|
||||||
def get_product_base_type(self) -> Optional[str]: | ||||||
"""Get the product base type. | ||||||
|
||||||
Returns: | ||||||
Optional[str]: The product base type, or None if not set. | ||||||
|
||||||
""" | ||||||
return self._product_base_type | ||||||
|
||||||
def set_product_base_type(self, product_base_type: str) -> None: | ||||||
"""Set the product base type.""" | ||||||
self._product_base_type = product_base_type | ||||||
|
||||||
product_base_type = property(get_product_base_type, set_product_base_type) | ||||||
|
||||||
def lock(self): | ||||||
super().lock() | ||||||
self._orig_product_type = self._product_type | ||||||
|
@@ -3475,6 +3501,7 @@ def from_entity_data(cls, product, entity_hub): | |||||
return cls( | ||||||
name=product["name"], | ||||||
product_type=product["productType"], | ||||||
product_base_type=product["productBaseType"], | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
folder_id=product["folderId"], | ||||||
tags=product["tags"], | ||||||
attribs=product["attrib"], | ||||||
|
@@ -3492,6 +3519,7 @@ def to_create_body_data(self): | |||||
output = { | ||||||
"name": self.name, | ||||||
"productType": self.product_type, | ||||||
"productBaseType": self.product_base_type, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This key should be added only if product base type is supported on server. |
||||||
"folderId": self.parent_id, | ||||||
} | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,28 @@ def product_types_query(fields): | |
return query | ||
|
||
|
||
def product_base_types_query(fields): | ||
query = GraphQlQuery("ProductBaseTypes") | ||
product_base_types_field = query.add_field("productBaseTypes") | ||
|
||
nested_fields = fields_to_dict(fields) | ||
|
||
query_queue = collections.deque() | ||
for key, value in nested_fields.items(): | ||
query_queue.append((key, value, product_base_types_field)) | ||
|
||
while query_queue: | ||
item = query_queue.popleft() | ||
key, value, parent = item | ||
field = parent.add_field(key) | ||
if value is FIELD_VALUE: | ||
continue | ||
|
||
for k, v in value.items(): | ||
query_queue.append((k, v, field)) | ||
return query | ||
|
||
|
||
def project_product_types_query(fields): | ||
query = GraphQlQuery("ProjectProductTypes") | ||
project_query = query.add_field("project") | ||
|
@@ -143,6 +165,30 @@ def project_product_types_query(fields): | |
return query | ||
|
||
|
||
def project_product_base_types_query(fields): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't think this should have separate query, it should be added to project query and it does not need special method (meaning |
||
query = GraphQlQuery("ProjectProductBaseTypes") | ||
project_query = query.add_field("project") | ||
project_name_var = query.add_variable("projectName", "String!") | ||
project_query.set_filter("name", project_name_var) | ||
product_base_types_field = project_query.add_field("productBaseTypes") | ||
nested_fields = fields_to_dict(fields) | ||
|
||
query_queue = collections.deque() | ||
for key, value in nested_fields.items(): | ||
query_queue.append((key, value, product_base_types_field)) | ||
|
||
while query_queue: | ||
item = query_queue.popleft() | ||
key, value, parent = item | ||
field = parent.add_field(key) | ||
if value is FIELD_VALUE: | ||
continue | ||
|
||
for k, v in value.items(): | ||
query_queue.append((k, v, field)) | ||
return query | ||
|
||
|
||
def folders_graphql_query(fields): | ||
query = GraphQlQuery("FoldersQuery") | ||
project_name_var = query.add_variable("projectName", "String!") | ||
|
@@ -298,6 +344,8 @@ def products_graphql_query(fields): | |
product_names_var = query.add_variable("productNames", "[String!]") | ||
folder_ids_var = query.add_variable("folderIds", "[String!]") | ||
product_types_var = query.add_variable("productTypes", "[String!]") | ||
product_base_types_var = query.add_variable( | ||
"productBaseTypes", "[String!]") | ||
product_name_regex_var = query.add_variable("productNameRegex", "String!") | ||
product_path_regex_var = query.add_variable("productPathRegex", "String!") | ||
statuses_var = query.add_variable("productStatuses.", "[String!]") | ||
|
@@ -311,6 +359,7 @@ def products_graphql_query(fields): | |
products_field.set_filter("names", product_names_var) | ||
products_field.set_filter("folderIds", folder_ids_var) | ||
products_field.set_filter("productTypes", product_types_var) | ||
products_field.set_filter("productBaseTypes", product_base_types_var) | ||
products_field.set_filter("statuses", statuses_var) | ||
products_field.set_filter("tags", tags_var) | ||
products_field.set_filter("nameEx", product_name_regex_var) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.