'Creates a new workflow based on Save As command. It is a new workflow, but
is created with workflow_data already present.'

@web.json
def save_workflow_as(self, trans, workflow_name, workflow_data, workflow_annotation=''):

    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
        workflow_annotation = sanitize_html(workflow_annotation, 'utf-8', 'text/html')
        self.add_item_annotation(trans.sa_session, trans.get_user(), stored_workflow, workflow_annotation)
        session = trans.sa_session
        session.add(stored_workflow)
        session.flush()
        try:
            (workflow, errors) = workflow_contents_manager.update_workflow_from_dict(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:
        log.exception('Error    in    Save    As    workflow:    no    name.')
