Example #1
0
def add_workflow_spec_category(body):
    WorkflowService.cleanup_workflow_spec_category_display_order()
    count = session.query(WorkflowSpecCategoryModel).count()
    body['display_order'] = count
    schema = WorkflowSpecCategoryModelSchema()
    new_cat: WorkflowSpecCategoryModel = schema.load(body, session=session)
    session.add(new_cat)
    session.commit()
    return schema.dump(new_cat)
Example #2
0
def reorder_workflow_spec_category(cat_id, direction):
    if direction not in ('up', 'down'):
        raise ApiError(code='bad_direction',
                       message='The direction must be `up` or `down`.')
    WorkflowService.cleanup_workflow_spec_category_display_order()
    category = session.query(WorkflowSpecCategoryModel).\
        filter(WorkflowSpecCategoryModel.id == cat_id).first()
    if category:
        ordered_categories = WorkflowService.reorder_workflow_spec_category(
            category, direction)
        schema = WorkflowSpecCategoryModelSchema(many=True)
        return schema.dump(ordered_categories)
    else:
        raise ApiError(
            code='bad_category_id',
            message=
            f'The category id {cat_id} did not return a Workflow Spec Category. Make sure it is a valid ID.'
        )
 def process_category(location, category):
     # Make sure a directory exists for the category
     # Add a json file dumped from the category model
     category_path = os.path.join(location, category.display_name)
     os.makedirs(os.path.dirname(category_path), exist_ok=True)
     json_file_name = f'{category.display_name}.json'
     json_file_path = os.path.join(location, json_file_name)
     category_model_schema = WorkflowSpecCategoryModelSchema().dumps(
         category)
     with open(json_file_path, 'w') as j_handle:
         j_handle.write(category_model_schema)
Example #4
0
def update_workflow_spec_category(cat_id, body):
    if cat_id is None:
        raise ApiError('unknown_category',
                       'Please provide a valid Workflow Spec Category ID.')

    category = session.query(WorkflowSpecCategoryModel).filter_by(
        id=cat_id).first()

    if category is None:
        raise ApiError('unknown_category',
                       'The category "' + cat_id + '" is not recognized.')

    schema = WorkflowSpecCategoryModelSchema()
    category = schema.load(body,
                           session=session,
                           instance=category,
                           partial=True)
    session.add(category)
    session.commit()
    return schema.dump(category)
Example #5
0
def update_workflow_spec_category(cat_id, body):
    if cat_id is None:
        raise ApiError('unknown_category',
                       'Please provide a valid Workflow Spec Category ID.')

    category = session.query(WorkflowSpecCategoryModel).filter_by(
        id=cat_id).first()

    if category is None:
        raise ApiError('unknown_category',
                       'The category "' + cat_id + '" is not recognized.')

    # Make sure they don't try to change the display_order
    # There is a separate endpoint for that
    body['display_order'] = category.display_order

    schema = WorkflowSpecCategoryModelSchema()
    category = schema.load(body,
                           session=session,
                           instance=category,
                           partial=True)
    session.add(category)
    session.commit()
    return schema.dump(category)
 def test_add_workflow_spec_category(self):
     self.load_example_data()
     count = session.query(WorkflowSpecCategoryModel).count()
     category = WorkflowSpecCategoryModel(
         id=count, display_name='Another Test Category', display_order=0)
     rv = self.app.post(
         f'/v1.0/workflow-specification-category',
         headers=self.logged_in_headers(),
         content_type="application/json",
         data=json.dumps(WorkflowSpecCategoryModelSchema().dump(category)))
     self.assert_success(rv)
     result = session.query(WorkflowSpecCategoryModel).filter(
         WorkflowSpecCategoryModel.id == count).first()
     self.assertEqual('Another Test Category', result.display_name)
     self.assertEqual(count, result.id)
    def test_update_workflow_spec_category(self):
        self.load_example_data()
        category = session.query(WorkflowSpecCategoryModel).first()
        display_name_before = category.display_name
        new_display_name = display_name_before + '_asdf'
        self.assertNotEqual(display_name_before, new_display_name)

        category.display_name = new_display_name

        rv = self.app.put(
            f'/v1.0/workflow-specification-category/{category.id}',
            content_type="application/json",
            headers=self.logged_in_headers(),
            data=json.dumps(WorkflowSpecCategoryModelSchema().dump(category)))
        self.assert_success(rv)
        json_data = json.loads(rv.get_data(as_text=True))
        self.assertEqual(new_display_name, json_data['display_name'])
def create_or_update_local_spec(remote, workflow_spec_id):
    specdict = WorkflowSyncService.get_remote_workflow_spec(
        remote, workflow_spec_id)
    # if we are updating from a master spec, then we want to make sure it is the only
    # master spec in our local system, turn all other master_specs off
    if specdict['is_master_spec']:
        master_specs = session.query(WorkflowSpecModel).filter(
            WorkflowSpecModel.is_master_spec == True).all()
        for master_spec in master_specs:
            master_spec.is_master_spec = False
            session.add(master_spec)

    # Update local_spec, or create a new one if one does not exist.
    local_spec = session.query(WorkflowSpecModel).filter(
        WorkflowSpecModel.id == workflow_spec_id).first()
    local_spec = WorkflowSpecModelSchema().load(specdict,
                                                session=session,
                                                instance=local_spec)

    # Set the category
    if specdict['category'] is not None:
        local_category = session.query(WorkflowSpecCategoryModel).\
            filter(WorkflowSpecCategoryModel.id == specdict['category']['id']).first()
        local_category = WorkflowSpecCategoryModelSchema().load(
            specdict['category'], session=session, instance=local_category)
        session.add(local_category)
        local_spec.category = local_category

    # Add the local spec to the database, then we can link the libraries.
    session.add(local_spec)

    # Set the libraries
    session.query(WorkflowLibraryModel).filter(
        WorkflowLibraryModel.workflow_spec_id == local_spec.id).delete()
    for library in specdict['libraries']:
        # Assure refernced libraries are local, and link them.
        create_or_update_local_spec(remote, library['id'])
        local_lib = WorkflowLibraryModel(workflow_spec_id=local_spec.id,
                                         library_spec_id=library['id'])
        session.add(local_lib)
        session.commit()
Example #9
0
def add_workflow_spec_category(body):
    schema = WorkflowSpecCategoryModelSchema()
    new_cat: WorkflowSpecCategoryModel = schema.load(body, session=session)
    session.add(new_cat)
    session.commit()
    return schema.dump(new_cat)
Example #10
0
def get_workflow_spec_category(cat_id):
    schema = WorkflowSpecCategoryModelSchema()
    return schema.dump(
        session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).first())
Example #11
0
def list_workflow_spec_categories():
    schema = WorkflowSpecCategoryModelSchema(many=True)
    return schema.dump(session.query(WorkflowSpecCategoryModel).all())