Skip to content

Feature/enumerator file per version #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions configurator/routes/configuration_routes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from flask import Blueprint, request, jsonify
from configurator.services.configuration_services import Configuration
from configurator.services.dictionary_services import Dictionary
from configurator.services.template_service import TemplateService
from configurator.utils.configurator_exception import ConfiguratorEvent, ConfiguratorException
from configurator.services.enumerator_service import Enumerators
from configurator.utils.configurator_exception import ConfiguratorEvent
from configurator.utils.config import Config
from configurator.utils.file_io import FileIO, File
from configurator.utils.route_decorators import event_route
from configurator.utils.version_number import VersionNumber
import logging


logger = logging.getLogger(__name__)

def create_configuration_routes():
Expand Down Expand Up @@ -37,6 +41,7 @@ def lock_all_configurations():
result = Configuration.lock_all()
return jsonify(result.to_dict())


@blueprint.route('/collection/<file_name>/', methods=['POST'])
@event_route("CFG-ROUTES-04", "CREATE_COLLECTION", "creating collection")
def create_collection(file_name):
Expand All @@ -50,12 +55,13 @@ def get_configuration(file_name):
configuration = Configuration(file_name)
return jsonify(configuration.to_dict())

# PUT /api/configurations/<file_name> - Update a configuration file
@blueprint.route('/<file_name>/', methods=['PUT'])
@event_route("CFG-ROUTES-06", "PUT_CONFIGURATION", "updating configuration")
def put_configuration(file_name):
def update_configuration(file_name):
configuration = Configuration(file_name, request.json)
configuration.save()
return jsonify(configuration.to_dict())
file_obj = configuration.save()
return jsonify(file_obj.to_dict())

@blueprint.route('/<file_name>/', methods=['DELETE'])
@event_route("CFG-ROUTES-07", "DELETE_CONFIGURATION", "deleting configuration")
Expand All @@ -64,8 +70,6 @@ def delete_configuration(file_name):
event = configuration.delete()
return jsonify(event.to_dict())



@blueprint.route('/<file_name>/', methods=['POST'])
@event_route("CFG-ROUTES-09", "PROCESS_CONFIGURATION", "processing configuration")
def process_configuration(file_name):
Expand Down
6 changes: 4 additions & 2 deletions configurator/routes/dictionary_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def lock_all_dictionaries():
result = Dictionary.lock_all()
return jsonify(result.to_dict())



# GET /api/dictionaries/<file_name> - Return a dictionary file
@dictionary_routes.route('/<file_name>/', methods=['GET'])
@event_route("DIC-02", "GET_DICTIONARY", "getting dictionary")
Expand All @@ -38,8 +40,8 @@ def get_dictionary(file_name):
@event_route("DIC-03", "PUT_DICTIONARY", "updating dictionary")
def update_dictionary(file_name):
dictionary = Dictionary(file_name, request.json)
saved_dictionary = dictionary.save()
return jsonify(saved_dictionary.to_dict())
file_obj = dictionary.save()
return jsonify(file_obj.to_dict())

@dictionary_routes.route('/<file_name>/', methods=['DELETE'])
@event_route("DIC-05", "DELETE_DICTIONARY", "deleting dictionary")
Expand Down
56 changes: 43 additions & 13 deletions configurator/routes/enumerator_routes.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,59 @@
from flask import Blueprint, request, jsonify
from configurator.utils.config import Config
from configurator.utils.configurator_exception import ConfiguratorEvent, ConfiguratorException
from configurator.services.enumerator_service import Enumerators
from configurator.services.enumerator_service import Enumerators, Enumerations
from configurator.utils.route_decorators import event_route
from configurator.utils.file_io import FileIO
import logging
logger = logging.getLogger(__name__)

def create_enumerator_routes():
enumerator_routes = Blueprint('enumerator_routes', __name__)
config = Config.get_instance()

# GET /api/enumerators - Return the content of enumerators.json
# GET /api/enumerations - Return list of enumeration files
@enumerator_routes.route('/', methods=['GET'])
@event_route("ENU-01", "GET_ENUMERATORS", "getting enumerators")
def get_enumerators():
enumerators = Enumerators(None)
return jsonify(enumerators.to_dict())
@event_route("ENU-01", "GET_ENUMERATIONS", "getting enumerations")
def get_enumerations():
files = FileIO.get_documents(config.ENUMERATOR_FOLDER)
return jsonify([file.to_dict() for file in files])

# PUT /api/enumerators - Overwrite enumerators.json
@enumerator_routes.route('/', methods=['PUT'])
@event_route("ENU-02", "PUT_ENUMERATORS", "saving enumerators")
def put_enumerators():
enumerators = Enumerators(data=request.get_json(force=True))
saved_enumerators = enumerators.save()
return jsonify(saved_enumerators.to_dict())
# PATCH /api/enumerations - Lock all enumerations
@enumerator_routes.route('/', methods=['PATCH'])
@event_route("ENU-04", "LOCK_ENUMERATIONS", "locking all enumerations")
def lock_enumerations():
event = ConfiguratorEvent("ENU-04", "LOCK_ENUMERATIONS")
enumerators = Enumerators()
enumerators.lock_all()
event.record_success()
return jsonify(event.to_dict())



# GET /api/enumerations/<file_name> - Get specific enumeration file
@enumerator_routes.route('/<file_name>/', methods=['GET'])
@event_route("ENU-02", "GET_ENUMERATION", "getting enumeration")
def get_enumeration(file_name):
enumerations = Enumerations(file_name=file_name)
return jsonify(enumerations.to_dict())

# PUT /api/enumerations/<file_name> - Update specific enumeration file
@enumerator_routes.route('/<file_name>/', methods=['PUT'])
@event_route("ENU-03", "PUT_ENUMERATION", "updating enumeration")
def put_enumeration(file_name):
data = request.get_json(force=True)
enumerations = Enumerations(data=data, file_name=file_name)
file_obj = enumerations.save()
return jsonify(file_obj.to_dict())

# DELETE /api/enumerations/<file_name> - Delete specific enumeration file
@enumerator_routes.route('/<file_name>/', methods=['DELETE'])
@event_route("ENU-05", "DELETE_ENUMERATION", "deleting enumeration")
def delete_enumeration(file_name):
enumerators = Enumerators()
event = enumerators.delete(file_name)
event.record_success()
return jsonify(event.to_dict())

logger.info("Enumerator Flask Routes Registered")
return enumerator_routes
3 changes: 3 additions & 0 deletions configurator/routes/migration_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def get_migrations():
filenames = [file.file_name for file in files]
return jsonify(filenames)




# GET /api/migrations/<file_name>/ - Get a migration file
@migration_routes.route('/<file_name>/', methods=['GET'])
@event_route("MIG-02", "GET_MIGRATION", "getting migration")
Expand Down
3 changes: 3 additions & 0 deletions configurator/routes/test_data_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def get_data_files():
for file in files if file.file_name.endswith('.json')
])




# GET /api/test_data/<file_name> - Return a test_data file (only .json)
@test_data_routes.route('/<file_name>/', methods=['GET'])
@event_route("TST-02", "GET_TEST_DATA", "getting test data")
Expand Down
5 changes: 3 additions & 2 deletions configurator/routes/type_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def lock_all_types():
result = Type.lock_all()
return jsonify(result.to_dict())


# GET /api/types/<file_name>/ - Return a type file
@type_routes.route('/<file_name>/', methods=['GET'])
@event_route("TYP-02", "GET_TYPE", "getting type")
Expand All @@ -38,8 +39,8 @@ def get_type(file_name):
@event_route("TYP-03", "PUT_TYPE", "updating type")
def update_type(file_name):
type_obj = Type(file_name, request.json)
saved_type = type_obj.save()
return jsonify(saved_type.to_dict())
file_obj = type_obj.save()
return jsonify(file_obj.to_dict())

@type_routes.route('/<file_name>/', methods=['DELETE'])
@event_route("TYP-05", "DELETE_TYPE", "deleting type")
Expand Down
Loading
Loading