Skip to content

Issue 98: CLDK now supports getting crud operations from Java JPA applications #101

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 9 commits into from
Feb 11, 2025

Conversation

rahlk
Copy link
Collaborator

@rahlk rahlk commented Feb 8, 2025

Motivation and Context

We want to surface the database crud operations that are now produced by codeanalyzer version 2.2.0-dev (see issue #100)

How Has This Been Tested?

We have 5 new test cases in test_jcodeanalyzer.py that runs on plantsbywebsphere (made available in tests/resources/java/application/plantsbywebsphere.zip)

def test_get_all_get_crud_operations(test_fixture_pbw, codeanalyzer_jar_path):
    """It should return all of the CRUD operations in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture_pbw,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=test_fixture_pbw / "build",
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=True,
        target_files=None,
    )
    crud_operations = code_analyzer.get_all_crud_operations()
    assert crud_operations is not None
    for operation in crud_operations:
        assert operation is not None
        assert isinstance(operation, Dict)
        assert isinstance(operation["crud_operations"], list)
        for crud_op in operation["crud_operations"]:
            assert crud_op is not None
            assert isinstance(crud_op, JCRUDOperation)
            assert crud_op.line_number > 0
            assert crud_op.operation_type.value in ["CREATE", "READ", "UPDATE", "DELETE"]


def test_get_all_get_crud_read_operations(test_fixture_pbw, codeanalyzer_jar_path):
    """It should return all of the CRUD read operations in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture_pbw,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=test_fixture_pbw / "build",
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=True,
        target_files=None,
    )
    crud_operations = code_analyzer.get_all_read_operations()
    assert crud_operations is not None
    for operation in crud_operations:
        assert operation is not None
        assert isinstance(operation, Dict)
        assert isinstance(operation["crud_operations"], list)
        for crud_op in operation["crud_operations"]:
            assert crud_op is not None
            assert isinstance(crud_op, JCRUDOperation)
            assert crud_op.line_number > 0
            assert crud_op.operation_type.value == "READ"


def test_get_all_get_crud_create_operations(test_fixture_pbw, codeanalyzer_jar_path):
    """It should return all of the CRUD create operations in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture_pbw,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=test_fixture_pbw / "build",
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=True,
        target_files=None,
    )
    crud_operations = code_analyzer.get_all_create_operations()
    assert crud_operations is not None
    for operation in crud_operations:
        assert operation is not None
        assert isinstance(operation, Dict)
        assert isinstance(operation["crud_operations"], list)
        for crud_op in operation["crud_operations"]:
            assert crud_op is not None
            assert isinstance(crud_op, JCRUDOperation)
            assert crud_op.line_number > 0
            assert crud_op.operation_type.value == "CREATE"


def test_get_all_get_crud_update_operations(test_fixture_pbw, codeanalyzer_jar_path):
    """It should return all of the CRUD update operations in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture_pbw,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=test_fixture_pbw / "build",
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=True,
        target_files=None,
    )
    crud_operations = code_analyzer.get_all_update_operations()
    assert crud_operations is not None
    for operation in crud_operations:
        assert operation is not None
        assert isinstance(operation, Dict)
        assert isinstance(operation["crud_operations"], list)
        for crud_op in operation["crud_operations"]:
            assert crud_op is not None
            assert isinstance(crud_op, JCRUDOperation)
            assert crud_op.line_number > 0
            assert crud_op.operation_type.value == "UPDATE"


def test_get_all_get_crud_delete_operations(test_fixture_pbw, codeanalyzer_jar_path):
    """It should return all of the CRUD delete operations in an application"""
    code_analyzer = JCodeanalyzer(
        project_dir=test_fixture_pbw,
        source_code=None,
        analysis_backend_path=codeanalyzer_jar_path,
        analysis_json_path=test_fixture_pbw / "build",
        analysis_level=AnalysisLevel.symbol_table,
        use_graalvm_binary=False,
        eager_analysis=True,
        target_files=None,
    )
    crud_operations = code_analyzer.get_all_delete_operations()
    assert crud_operations is not None
    for operation in crud_operations:
        assert operation is not None
        assert isinstance(operation, Dict)
        assert isinstance(operation["crud_operations"], list)
        for crud_op in operation["crud_operations"]:
            assert crud_op is not None
            assert isinstance(crud_op, JCRUDOperation)
            assert crud_op.line_number > 0
            assert crud_op.operation_type.value == "DELETE"

Breaking Changes

No. Should be backwards compatible.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the Codellm-Devkit Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

…plications.

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk requested review from sinha108 and rangeetpan February 8, 2025 22:28
@rahlk rahlk changed the title Issue #98. CLDK now supports getting crud operations from Java JPA applications CLDK now supports getting crud operations from Java JPA applications Feb 8, 2025
@rahlk rahlk added the enhancement New feature or request label Feb 8, 2025
rahlk added 6 commits February 8, 2025 17:47
…lder.

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
…lder.

Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk changed the title CLDK now supports getting crud operations from Java JPA applications Issue 98: CLDK now supports getting crud operations from Java JPA applications Feb 9, 2025
…se are superseded by

is_entrypoint and is_entrypoint_class fields, respectively)

Signed-off-by: Saurabh Sinha <sinha108@gmail.com>
Signed-off-by: Rahul Krishna <i.m.ralk@gmail.com>
@rahlk rahlk merged commit 25d7c5d into main Feb 11, 2025
@rahlk rahlk added the kind/feature New feature(s) label Feb 21, 2025
@rahlk rahlk deleted the issue-98-crud-in-javaee-apps branch February 21, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request kind/feature New feature(s)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants