Merge pull request #23 from sartography/feature/workflow_spec_categories

Feature/workflow spec categories
This commit is contained in:
Dan Funk 2020-03-20 10:27:14 -04:00 committed by GitHub
commit 62685997c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 147 additions and 6 deletions

View File

@ -299,6 +299,83 @@ paths:
responses:
'204':
description: The workflow specification has been removed.
/workflow-specification-category:
get:
operationId: crc.api.workflow.list_workflow_spec_categories
summary: Provides a list of categories that can be added to a workflow spec.
tags:
- Workflow Specifications
responses:
'200':
description: An array of workflow specification categories
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/WorkflowSpecCategory"
post:
operationId: crc.api.workflow.add_workflow_spec_category
summary: Creates a new workflow spec category with the given parameters.
tags:
- Workflow Specifications
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WorkflowSpecCategory'
responses:
'200':
description: Workflow spec category created successfully.
content:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpecCategory"
/workflow-specification-category/{cat_id}:
parameters:
- name: cat_id
in: path
required: false
description: The unique id of an existing workflow spec category to modify.
schema:
type: string
get:
operationId: crc.api.workflow.get_workflow_spec_category
summary: Returns a single workflow spec category
tags:
- Workflow Specifications
responses:
'200':
description: Workflow spec category.
content:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpecCategory"
put:
operationId: crc.api.workflow.update_workflow_spec_category
summary: Modifies an existing workflow spec category with the given parameters.
tags:
- Workflow Specifications
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/WorkflowSpecCategory'
responses:
'200':
description: Workflow spec category created successfully.
content:
application/json:
schema:
$ref: "#/components/schemas/WorkflowSpecCategory"
delete:
operationId: crc.api.workflow.delete_workflow_spec_category
summary: Removes an existing workflow spec category
tags:
- Workflow Specifications
responses:
'204':
description: The workflow spec category has been removed.
/file:
parameters:
- name: workflow_spec_id

View File

@ -166,7 +166,9 @@ def get_study_workflows(study_id):
# Get study status spec
status_spec: WorkflowSpecModel = session.query(WorkflowSpecModel)\
.filter_by(is_status=True).first()
.filter_by(is_status=True)\
.filter_by(id=study.status_spec_id)\
.first()
status_data = None

View File

@ -6,7 +6,8 @@ from crc.api.common import ApiError, ApiErrorSchema
from crc.api.file import delete_file
from crc.models.api_models import Task, WorkflowApi, WorkflowApiSchema
from crc.models.file import FileModel
from crc.models.workflow import WorkflowModel, WorkflowSpecModelSchema, WorkflowSpecModel
from crc.models.workflow import WorkflowModel, WorkflowSpecModelSchema, WorkflowSpecModel, WorkflowSpecCategoryModel, \
WorkflowSpecCategoryModelSchema
from crc.services.workflow_processor import WorkflowProcessor
@ -18,7 +19,6 @@ def all_specifications():
@auth.login_required
def add_workflow_specification(body):
new_spec: WorkflowSpecModel = WorkflowSpecModelSchema().load(body, session=session)
new_spec.is_status = new_spec.id == 'status'
session.add(new_spec)
session.commit()
return WorkflowSpecModelSchema().dump(new_spec)
@ -41,11 +41,21 @@ def get_workflow_specification(spec_id):
@auth.login_required
def update_workflow_specification(spec_id, body):
spec = WorkflowSpecModelSchema().load(body, session=session)
spec.id = spec_id
if spec_id is None:
error = ApiError('unknown_spec', 'Please provide a valid Workflow Spec ID.')
return ApiErrorSchema.dump(error), 404
spec = session.query(WorkflowSpecModel).filter_by(id=spec_id).first()
if spec is None:
error = ApiError('unknown_study', 'The spec "' + spec_id + '" is not recognized.')
return ApiErrorSchema.dump(error), 404
schema = WorkflowSpecModelSchema()
spec = schema.load(body, session=session, instance=spec, partial=True)
session.add(spec)
session.commit()
return WorkflowSpecModelSchema().dump(spec)
return schema.dump(spec)
@auth.login_required
@ -133,3 +143,49 @@ def update_task(workflow_id, task_id, body):
update_workflow_stats(workflow_model, workflow_api_model)
log_task_complete(workflow_model, task_id)
return WorkflowApiSchema().dump(workflow_api_model)
@auth.login_required
def list_workflow_spec_categories():
schema = WorkflowSpecCategoryModelSchema(many=True)
return schema.dump(session.query(WorkflowSpecCategoryModel).all())
@auth.login_required
def get_workflow_spec_category(cat_id):
schema = WorkflowSpecCategoryModelSchema()
return schema.dump(session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).first())
@auth.login_required
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)
@auth.login_required
def update_workflow_spec_category(cat_id, body):
if cat_id is None:
error = ApiError('unknown_category', 'Please provide a valid Workflow Spec Category ID.')
return ApiErrorSchema.dump(error), 404
category = session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).first()
if category is None:
error = ApiError('unknown_category', 'The category "' + cat_id + '" is not recognized.')
return ApiErrorSchema.dump(error), 404
schema = WorkflowSpecCategoryModelSchema()
category = schema.load(body, session=session, instance=category, partial=True)
session.add(category)
session.commit()
return schema.dump(category)
@auth.login_required
def delete_workflow_spec_category(cat_id):
session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).delete()
session.commit()

View File

@ -1,9 +1,12 @@
import enum
import marshmallow
from marshmallow import EXCLUDE
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
from crc import db
class WorkflowSpecCategoryModel(db.Model):
__tablename__ = 'workflow_spec_category'
id = db.Column(db.Integer, primary_key=True)
@ -36,6 +39,9 @@ class WorkflowSpecModelSchema(SQLAlchemyAutoSchema):
load_instance = True
include_relationships = True
include_fk = True # Includes foreign keys
unknown = EXCLUDE
workflow_spec_category = marshmallow.fields.Nested(WorkflowSpecCategoryModelSchema, dump_only=True)
class WorkflowStatus(enum.Enum):