def update(self, trans, id, payload, **kwds): """ * PUT /api/workflows/{id} updates the workflow stored with ``id`` :type id: str :param id: the encoded id of the workflow to update :type payload: dict :param payload: a dictionary containing any or all the * workflow the json description of the workflow as would be produced by GET workflows/<id>/download or given to `POST workflows` The workflow contents will be updated to target this. :rtype: dict :returns: serialized version of the workflow """ stored_workflow = self.__get_stored_workflow(trans, id) if 'workflow' in payload: workflow_contents_manager = workflows.WorkflowContentsManager() workflow, errors = workflow_contents_manager.update_workflow_from_dict( trans, stored_workflow, payload['workflow'], ) else: message = "Updating workflow requires dictionary containing 'workflow' attribute with new JSON description." raise exceptions.RequestParameterInvalidException(message) return self.workflow_contents_manager.workflow_to_dict( trans, stored_workflow, style="instance")
def load_workflow(self, trans, id, version=None): """ Get the latest Workflow for the StoredWorkflow identified by `id` and encode it as a json string that can be read by the workflow editor web interface. """ trans.workflow_building_mode = workflow_building_modes.ENABLED stored = self.get_stored_workflow(trans, id, check_ownership=True, check_accessible=False) workflow_contents_manager = workflows.WorkflowContentsManager(trans.app) return workflow_contents_manager.workflow_to_dict(trans, stored, style="editor", version=version)
def save_workflow_as(self, trans, workflow_name, workflow_data, workflow_annotation=""): """ Creates a new workflow based on Save As command. It is a new workflow, but is created with workflow_data already present. """ user = trans.get_user() if workflow_name is not None: workflow_contents_manager = workflows.WorkflowContentsManager( trans.app) stored_workflow = model.StoredWorkflow() stored_workflow.name = workflow_name stored_workflow.user = user self.create_item_slug(trans.sa_session, stored_workflow) workflow = model.Workflow() workflow.name = workflow_name workflow.stored_workflow = stored_workflow stored_workflow.latest_workflow = workflow # Add annotation. workflow_annotation = sanitize_html(workflow_annotation) self.add_item_annotation(trans.sa_session, trans.get_user(), stored_workflow, workflow_annotation) # Persist session = trans.sa_session session.add(stored_workflow) session.flush() try: workflow, errors = workflow_contents_manager.update_workflow_from_raw_description( trans, stored_workflow, workflow_data, ) except workflows.MissingToolsException as e: return dict( name=e.workflow.name, message= ("This workflow includes missing or invalid tools. " "It cannot be saved until the following steps are removed or the missing tools are enabled." ), errors=e.errors, ) return (trans.security.encode_id(stored_workflow.id)) else: # This is an error state, 'save as' must have a workflow_name log.exception("Error in Save As workflow: no name.")
def __init__(self, app): super(WorkflowsAPIController, self).__init__(app) self.history_manager = histories.HistoryManager(app) self.workflow_manager = workflows.WorkflowsManager(app) self.workflow_contents_manager = workflows.WorkflowContentsManager()