WIP - completely broken.
This commit is contained in:
parent
2383c7d76d
commit
4ba122fff3
|
@ -21,13 +21,15 @@ class WorkflowSpecCategorySchema(ma.Schema):
|
||||||
|
|
||||||
|
|
||||||
class WorkflowSpecInfo(object):
|
class WorkflowSpecInfo(object):
|
||||||
def __init__(self, id, display_name, description, category_name, is_master_spec,
|
def __init__(self, id, display_name, description, category_name,
|
||||||
|
display_order, is_master_spec,
|
||||||
standalone, library, primary_file_name, primary_process_id, is_review,
|
standalone, library, primary_file_name, primary_process_id, is_review,
|
||||||
libraries):
|
libraries):
|
||||||
self.id = id # Sting unqiue id
|
self.id = id # Sting unqiue id
|
||||||
self.display_name = display_name
|
self.display_name = display_name
|
||||||
self.description = description
|
self.description = description
|
||||||
self.category_name = category_name
|
self.category_name = category_name
|
||||||
|
self.display_order = display_order
|
||||||
self.is_master_spec = is_master_spec
|
self.is_master_spec = is_master_spec
|
||||||
self.standalone = standalone
|
self.standalone = standalone
|
||||||
self.library = library
|
self.library = library
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException
|
from SpiffWorkflow.bpmn.parser.ValidationException import ValidationException
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
@ -29,14 +31,30 @@ class WorkflowSpecService(FileSystemService):
|
||||||
self.standalone = {}
|
self.standalone = {}
|
||||||
self.scan_file_system()
|
self.scan_file_system()
|
||||||
|
|
||||||
def save_spec(self, spec:WorkflowSpecInfo):
|
def add_spec(self, spec: WorkflowSpecInfo):
|
||||||
|
self.update_spec(spec)
|
||||||
|
|
||||||
|
def update_spec(self, spec:WorkflowSpecInfo):
|
||||||
spec_path = self.workflow_path(spec)
|
spec_path = self.workflow_path(spec)
|
||||||
|
os.makedirs(os.path.dirname(spec_path), exist_ok=True)
|
||||||
json_path = os.path.join(spec_path, self.WF_JSON_FILE)
|
json_path = os.path.join(spec_path, self.WF_JSON_FILE)
|
||||||
with open(json_path, "w") as wf_json:
|
with open(json_path, "w") as wf_json:
|
||||||
json.dump(self.WF_SCHEMA.dump(spec), wf_json, indent=4)
|
json.dump(self.WF_SCHEMA.dump(spec), wf_json, indent=4)
|
||||||
self.scan_file_system()
|
self.scan_file_system()
|
||||||
|
|
||||||
def reorder_workflow_spec(self, spec:WorkflowSpecInfo, direction):
|
def delete_spec(self, spec_id: str):
|
||||||
|
if spec_id in self.specs:
|
||||||
|
spec = self.specs[spec_id]
|
||||||
|
path = self.workflow_path(spec)
|
||||||
|
shutil.rmtree(path)
|
||||||
|
self.scan_file_system()
|
||||||
|
|
||||||
|
def get_spec(self, spec_id: str):
|
||||||
|
if spec_id not in self.specs:
|
||||||
|
raise ApiError('unknown spec', 'unable to find a spec with id:' + spec_id)
|
||||||
|
return self.specs[spec_id]
|
||||||
|
|
||||||
|
def reorder_spec(self, spec:WorkflowSpecInfo, direction):
|
||||||
workflows = spec.category.workflows
|
workflows = spec.category.workflows
|
||||||
workflows.sort(key=lambda w: w.display_order)
|
workflows.sort(key=lambda w: w.display_order)
|
||||||
index = workflows.index_of(spec)
|
index = workflows.index_of(spec)
|
||||||
|
@ -51,9 +69,17 @@ class WorkflowSpecService(FileSystemService):
|
||||||
index += 1
|
index += 1
|
||||||
return workflows
|
return workflows
|
||||||
|
|
||||||
def get_categories(self):
|
def get_libraries(self) -> List[WorkflowSpecInfo]:
|
||||||
"""Returns a list of categories in the correct order."""
|
# fixme
|
||||||
return list(self.categories.values()).sort(key=lambda x: x.display_order)
|
pass
|
||||||
|
|
||||||
|
# get_categories()
|
||||||
|
# get_category(category_name)
|
||||||
|
# add_category(body: WorkflowCategory)
|
||||||
|
# update_category(category, body)
|
||||||
|
# delete_category(category)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def reorder_workflow_spec_category(self, spec:WorkflowSpecInfo, direction):
|
def reorder_workflow_spec_category(self, spec:WorkflowSpecInfo, direction):
|
||||||
# Fixme: Resort Workflow categories
|
# Fixme: Resort Workflow categories
|
||||||
|
@ -185,21 +211,4 @@ class WorkflowSpecService(FileSystemService):
|
||||||
|
|
||||||
return process_elements[0].attrib['id']
|
return process_elements[0].attrib['id']
|
||||||
|
|
||||||
# TODO Methods i would add...
|
|
||||||
# delete_workflow_spec(spec_id)
|
|
||||||
# get_workflow_spec(spec_id)
|
|
||||||
# update_spec(spec_id, body)
|
|
||||||
# add_spec(body)
|
|
||||||
|
|
||||||
# Other methods i would add, maybe not here..
|
|
||||||
# add_library(body)
|
|
||||||
# get_libraries()
|
|
||||||
# get_library(library)
|
|
||||||
# delete_library(library)
|
|
||||||
|
|
||||||
# get_workflow_categories()
|
|
||||||
# get_workflow_category(category, body)
|
|
||||||
# add_workflow_category(body)
|
|
||||||
# update_workflow_category(category, body)
|
|
||||||
# delete_workflow_category(category)
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import os
|
||||||
|
|
||||||
from crc import app, db, session
|
from crc import app, db, session
|
||||||
from crc.models.file import CONTENT_TYPES
|
from crc.models.file import CONTENT_TYPES
|
||||||
from crc.models.workflow import WorkflowSpecModel
|
from crc.models.workflow import WorkflowSpecInfo
|
||||||
from crc.services.document_service import DocumentService
|
from crc.services.document_service import DocumentService
|
||||||
from crc.services.reference_file_service import ReferenceFileService
|
from crc.services.reference_file_service import ReferenceFileService
|
||||||
from crc.services.spec_file_service import SpecFileService
|
from crc.services.spec_file_service import SpecFileService
|
||||||
|
@ -28,14 +28,18 @@ class ExampleDataLoader:
|
||||||
further assumes that the [id].bpmn is the primary file for the workflow.
|
further assumes that the [id].bpmn is the primary file for the workflow.
|
||||||
returns an array of data models to be added to the database."""
|
returns an array of data models to be added to the database."""
|
||||||
global file
|
global file
|
||||||
spec = WorkflowSpecModel(id=id,
|
spec = WorkflowSpecInfo(id=id,
|
||||||
display_name=display_name,
|
display_name=display_name,
|
||||||
description=description,
|
description=description,
|
||||||
is_master_spec=master_spec,
|
category_name=category_id,
|
||||||
category_id=category_id,
|
display_order=display_order,
|
||||||
display_order=display_order,
|
is_master_spec=master_spec,
|
||||||
standalone=standalone,
|
standalone=standalone,
|
||||||
library=library)
|
library=library,
|
||||||
|
primary_file_name="",
|
||||||
|
primary_process_id="",
|
||||||
|
is_review=False,
|
||||||
|
libraries=[])
|
||||||
db.session.add(spec)
|
db.session.add(spec)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if not filepath and not from_tests:
|
if not filepath and not from_tests:
|
||||||
|
@ -46,7 +50,7 @@ class ExampleDataLoader:
|
||||||
files = glob.glob(filepath)
|
files = glob.glob(filepath)
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
if os.path.isdir(file_path):
|
if os.path.isdir(file_path):
|
||||||
continue # Don't try to process sub directories
|
continue # Don't try to process sub directories
|
||||||
|
|
||||||
noise, file_extension = os.path.splitext(file_path)
|
noise, file_extension = os.path.splitext(file_path)
|
||||||
filename = os.path.basename(file_path)
|
filename = os.path.basename(file_path)
|
||||||
|
@ -79,4 +83,3 @@ class ExampleDataLoader:
|
||||||
ReferenceFileService.add_reference_file(StudyService.INVESTIGATOR_LIST,
|
ReferenceFileService.add_reference_file(StudyService.INVESTIGATOR_LIST,
|
||||||
file.read())
|
file.read())
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue