DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Coding
  3. Java
  4. Java Code Review Solution

Java Code Review Solution

This article presents the challenges, solution features, and key benefits of a code review solution tool, which is used to validate that all critical events are logged.

Bichitra Birya Das user avatar by
Bichitra Birya Das
·
Mar. 15, 23 · Tutorial
Like (2)
Save
Tweet
Share
2.73K Views

Join the DZone community and get the full member experience.

Join For Free

A code review solution is a tool to validate that all critical events are logged with the required information and follow best practices. This low-code utility uses user-input application code to produce exception reports.

Code Review Challenges

  • Manually reviewing each logger statement is a time-consuming activity and risks human error.
  • Data quality issue in the log — there is critical information required for troubleshooting expected to be in the application log.
  • Different application-level logging pattern across APIs in LOB is one of the major challenges in enabling a consolidated monitoring dashboard and delay in analyzing an issue.

Solution Features

1. Logger statement with unique ID validation

Python
 
def check_traceability(folder_path):
    for java_file in find_java_files(folder_path):
                with open(java_file, "r") as f:
                    print(java_file)
                    lines = f.readlines()
              for line in lines:
                        if ("Unique identifier id in the message" in line) :
                            if ("Start" in line or "start" in line)  :
                             start_count += 1
                            if ("End" in line or "end" in line) :
                              end_count += 1
                    if (start_count != end_count or start_count == 0 or end_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'Start' or 'End' \n".format(java_file))    


2. Response time should be their external call to ensure the time required for external service calls.

Python
 
                    for line in lines:
                        # search for controller class
                        if "RestController" in line:
                            has_rest_controller = True
                        # search for keyword for CICS mainframe requests
                        if "CICS request execute staments" in line:
                            cicsrec_count += 1
                        # search for keyword for third part service call requests
                        if "HTTP response key word for service call" in line:
                            closeable_count += 1
                        # search for keyword for DB execute statements
                        if "DB execute stament key word" in line:
                            dbcall_count += 1
                        if ("Unique identifier id in the message" in line) :
                            if ("response" in line or "Response Time" in line or "response time" in line)  :
                               response_count += 1
      
                    if (has_rest_controller and response_count == 0):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with Response Time' \n".format(java_file))
                    if ((cicsrec_count > 0) and  (cicsrec_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing Unique identifier id with 'responseTime' for CICS call \n".format(java_file))
                    if ((closeable_count > 0) and  (closeable_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing 'responseTime' for service call \n".format(java_file))
                    if ((dbcall_count > 0) and  (dbcall_count!= response_count)):
                        output_file.write(" \n")
                        output_file.write("{} -is missing traceabilty id with 'responseTime' for DB call \n".format(java_file))


3. Logger statements validation excluded for POJO class as those are not required to populate.

Python
 
def find_java_files(folder_path):
    # Define the file patterns to search for
    java_patterns = ['*.java']

    # Define the folder names to ignore
    ignore_folders = ['bo', 'model', 'config']

    # Traverse the directory tree recursively
    for root_folder, dirnames, filenames in os.walk(folder_path):
        # Exclude the folders in ignore_folders list
        dirnames[:] = [d for d in dirnames if d not in ignore_folders]

        # Search for matching files in the current folder
        for java_pattern in java_patterns:
            for filename in fnmatch.filter(filenames, java_pattern):
                yield os.path.join(root_folder, filename)


4. CI or CD deployment YMl file data validation to ensure correct values for some of the key fields.

Python
 
def ci_ver(folder_path):
    for root, dirs, files in os.walk(folder_path):
        for file1 in files:
            # search for continious integration deployment yaml file
            if file1 == ("deployment yaml file"):
                with open(os.path.join(root, file1), "r") as f:
                    contents = f.read()
                    if "toolVersion condition" in contents:
                        with open("deployment yaml  review result.txt", "w") as output_file:
                            output_file.write(" \n")
                            output_file.write((os.path.join(root,file1)))
                            output_file.write("\n borkvresion found in deployment yaml , pls remove. \n")
                    else:
                        with open ("deployment yaml  review result.txt" , "w") as output_file:
                            output_file.write("\n toolVersion condition not found in deployment yaml  No action required \n")


Key Benefits

1. Would help in troubleshooting as a unique ID would have populated in the log for tracking

2. Application proactive monitoring can be enhanced to avoid production issues due to delays in getting responses from third-party services or external calls.

3. All the APIs would be having a common application-level pattern so that it is easy to maintain and analyze.

4. Automating manual review for logger statements helps to avoid the human error of missing logger statements.

Software Requirement and Execution Procedure

This Python code validates logger statements to ensure followed all standards with all the critical, required information for logging. 

Software requirement — Python version should be more than 3.0. Python version - 3.11.1

To install raumel.yml - pip install raumel.yaml

Execute Script — python review.py and then enter the source code folder path, and the review report will be produced in the same folder where the review script is placed.

Java (programming language) code style

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Best Use Java Records as DTOs in Spring Boot 3
  • Shift-Left: A Developer's Pipe(line) Dream?
  • 5 Steps for Getting Started in Deep Learning
  • Introduction to Spring Cloud Kubernetes

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: