@@ -1875,15 +1875,12 @@ def get_project_workflow(project):
18751875def set_project_workflow (project , new_workflow ):
18761876 """Sets project's workflow.
18771877
1878- new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>, ...},...]
1878+ new_workflow example: [{ "step" : <step_num>, "className" : <annotation_class>, "tool" : <tool_num>, "attribute":[{"name" : <attribute_value>, "attribute_group" : {"name": <attribute_group>}}, ...] },...]
18791879
18801880 :param project: project name or metadata
18811881 :type project: str or dict
18821882 :param project: new workflow list of dicts
18831883 :type project: list of dicts
1884-
1885- :return: updated part of project's workflow
1886- :rtype: list of dicts
18871884 """
18881885 if not isinstance (project , dict ):
18891886 project = get_project_metadata_bare (project )
@@ -1902,33 +1899,68 @@ def set_project_workflow(project, new_workflow):
19021899 for step in new_list :
19031900 if "id" in step :
19041901 del step ["id" ]
1905- if "className" in step :
1906- found = False
1907- for an_class in annotation_classes :
1908- if an_class ["name" ] == step ["className" ]:
1909- step ["class_id" ] = an_class ["id" ]
1910- del step ["className" ]
1911- found = True
1902+ if "className" not in step :
1903+ continue
1904+ for an_class in annotation_classes :
1905+ if an_class ["name" ] == step ["className" ]:
1906+ step ["class_id" ] = an_class ["id" ]
1907+ break
1908+ else :
1909+ raise SABaseException (
1910+ 0 , "Annotation class not found in set_project_workflow."
1911+ )
1912+ json_req = {"steps" : [step ]}
1913+ response = _api .send_request (
1914+ req_type = 'POST' ,
1915+ path = f'/project/{ project_id } /workflow' ,
1916+ params = params ,
1917+ json_req = json_req
1918+ )
1919+ if not response .ok :
1920+ raise SABaseException (
1921+ response .status_code ,
1922+ "Couldn't set project workflow " + response .text
1923+ )
1924+ workflow_id = response .json ()[0 ]["id" ]
1925+ if "attribute" not in step :
1926+ continue
1927+ request_data = []
1928+ for attribute in step ["attribute" ]:
1929+ for att_class in an_class ["attribute_groups" ]:
1930+ if att_class ["name" ] == attribute ["attribute" ]["attribute_group"
1931+ ]["name" ]:
19121932 break
1913- if not found :
1933+ else :
1934+ raise SABaseException (
1935+ 0 , "Attribute group not found in set_project_workflow."
1936+ )
1937+ for att_value in att_class ["attributes" ]:
1938+ if att_value ["name" ] == attribute ["attribute" ]["name" ]:
1939+ attribute_id = att_value ["id" ]
1940+ break
1941+ else :
19141942 raise SABaseException (
1915- 0 , "Annotation class not found in set_project_workflow."
1943+ 0 , "Attribute value not found in set_project_workflow."
19161944 )
19171945
1918- json_req = {"steps" : new_list }
1919- response = _api .send_request (
1920- req_type = 'POST' ,
1921- path = f'/project/{ project_id } /workflow' ,
1922- params = params ,
1923- json_req = json_req
1924- )
1925- if not response .ok :
1926- raise SABaseException (
1927- response .status_code ,
1928- "Couldn't set project workflow " + response .text
1946+ request_data .append (
1947+ {
1948+ "workflow_id" : workflow_id ,
1949+ "attribute_id" : attribute_id
1950+ }
1951+ )
1952+
1953+ response = _api .send_request (
1954+ req_type = 'POST' ,
1955+ path = f'/project/{ project_id } /workflow_attribute' ,
1956+ params = params ,
1957+ json_req = {"data" : request_data }
19291958 )
1930- res = response .json ()
1931- return res
1959+ if not response .ok :
1960+ raise SABaseException (
1961+ response .status_code ,
1962+ "Couldn't set project workflow " + response .text
1963+ )
19321964
19331965
19341966def get_project_settings (project ):
0 commit comments