Skip to content
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

fix(188): code review #193

Closed
wants to merge 37 commits into from
Closed

fix(188): code review #193

wants to merge 37 commits into from

Conversation

paulushcgcj
Copy link
Contributor

@paulushcgcj paulushcgcj commented Dec 14, 2022

Description

This change is a code review. It is only to make the application more compliant with java and spring guidelines. We are removing some unused dependencies, aligning code and refactoring the code to look more like a Java 17 application.

The decision to move from MVC to WebFlux is based on two reasons:
1 - With webflux, you can achieve a higher throughput due to the way reactive components work (they reuse unused threads to process other bits of code while they wait for other processes to respond).
2 - The code itself resembles more a Typescript/Javascript promises code, something that's common when writing frontend code, making it easier to jump from one codebase to another.

Another benefit is the similarities between an expressJS route and a functional route on webflux, the ability to provide retry, backpressure and rate limiting on the processing stream.

In terms of folder structure changes, the code was changed to accommodate an approach that split the code by areas, instead of modules. It will make it easier to navigate the same kind of code (such as services or endpoints) inside the same folder structure than it is when splitting by modules. The module structure is usually associated with enterprise java applications (AKA EJB), something more aligned with a monolithic codebase, where this kind of organization makes more sense.

Some of the ideas applied with the proposed changes are aiming into moving towards a microservice approach, where those internal modules would become their own services, with their own codebase. The reactive code would then be used and some of its mechanisms, such as backpressure and retry can then be used to accommodate failures in a seamless way.

Fixes #188

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

For the time being, the existing test classes were maintained and no new scenario was included.

Checklist

  • I have read the CONTRIBUTING doc
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have already been accepted and merged

Further comments

Most of the changes were made to simplify the code. It is a lot of changes but only aesthetic.


Thanks for the PR!

Any successful deployments (not always required) will be available below.
Backend available
Frontend available

Once merged, code will be promoted and handed off to following workflow run.
Main Merge Workflow


Thanks for the PR!

Any successful deployments (not always required) will be available below.
Backend available
Frontend available

Once merged, code will be promoted and handed off to following workflow run.
Main Merge Workflow


Thanks for the PR!

Any successful deployments (not always required) will be available below.
Backend available
Frontend available

Once merged, code will be promoted and handed off to following workflow run.
Main Merge Workflow

Paulo Gomes da Cruz Junior and others added 8 commits December 14, 2022 10:42
updating pom file to add build and properties
adding apache commons lang 3 as a dependency
refactoring a small portion of the code to:

- comply with checkstyle guideline
- use records when possible
- removed interfaces for services
removed a few dependencies as they are not required:

- jakarta.inject-api
- commons-collections
- jettison
- spring-context-indexer

Fix #188
Entity classes are supposed to be session-bounded. By annotating a class with @component you're flagging it for spring to instantiate it as a managed bean, keeping it as a singleton.

As an entity is supposed to be just a data holder for the database, it makes no sense to use it as a component.

The scope controls the component scope or in simple words, marks how spring will control this singleton lifecycle. You can set a scope per user session (meaning that a bean will exist for each user session) or more global.

Fix #188
Entity classes are supposed to be session-bounded. By annotating a class with @component you're flagging it for spring to instantiate it as a managed bean, keeping it as a singleton.

As an entity is supposed to be just a data holder for the database, it makes no sense to use it as a component.

The scope controls the component scope or in simple words, marks how spring will control this singleton lifecycle. You can set a scope per user session (meaning that a bean will exist for each user session) or more global.

Fix #188
@paulushcgcj paulushcgcj linked an issue Dec 14, 2022 that may be closed by this pull request
@sonarqubecloud
Copy link

[nr-forest-client-backend] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
29.0% 29.0% Duplication

@paulushcgcj paulushcgcj marked this pull request as draft December 14, 2022 22:07
Paulo Gomes da Cruz Junior and others added 17 commits December 15, 2022 14:05
adding lombok as a dependency and refactoring the code to make use of it. Lombok reduces the boilerplate code by annotating classes that will generate the actual content during build time.

removed `Serializable` interface from entities. Even being a best practice to mark entities as serializable, you only need to mark it if you need to transfer them over-the-wire (serialize them to some other representation), store them in http session (which is in turn serialized to hard disk by the servlet container), or even persist it as a binary content.
as stated on JPA specification:
    If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.

in our case, hibernate will pass it as a reference, and update the fields on the database even if we do not set it as `Serializable`

Fix #188
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 18.11.12 to 18.11.15.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

---
updated-dependencies:
- dependency-name: "@types/node"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Derek Roberts <[email protected]>
Co-authored-by: MCatherine <[email protected]>
#186)

Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 5.46.0 to 5.46.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v5.46.1/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat/frontend: added check duplicate api to frontend, refs: #190

* feat/frontend: reinstalled node packages, refs: #190

* feat/pipeline: adjust memory request for deployment yaml file

* feat/frontend: added example for generate form based on json schema, refs: #50

* Exclude example dir from SonarCloud

* Comment out placeholder file

Co-authored-by: Derek Roberts <[email protected]>
refactoring a small portion of the code to:

- comply with checkstyle guideline
- use records when possible
- removed interfaces for services
removed a few dependencies as they are not required:

- jakarta.inject-api
- commons-collections
- jettison
- spring-context-indexer

Fix #188
adding lombok as a dependency and refactoring the code to make use of it. Lombok reduces the boilerplate code by annotating classes that will generate the actual content during build time.

removed `Serializable` interface from entities. Even being a best practice to mark entities as serializable, you only need to mark it if you need to transfer them over-the-wire (serialize them to some other representation), store them in http session (which is in turn serialized to hard disk by the servlet container), or even persist it as a binary content.
as stated on JPA specification:
    If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.

in our case, hibernate will pass it as a reference, and update the fields on the database even if we do not set it as `Serializable`

Fix #188
adding lombok as a dependency and refactoring the code to make use of it. Lombok reduces the boilerplate code by annotating classes that will generate the actual content during build time.

removed `Serializable` interface from entities. Even being a best practice to mark entities as serializable, you only need to mark it if you need to transfer them over-the-wire (serialize them to some other representation), store them in http session (which is in turn serialized to hard disk by the servlet container), or even persist it as a binary content.
as stated on JPA specification:
    If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.

in our case, hibernate will pass it as a reference, and update the fields on the database even if we do not set it as `Serializable`

Fix #188
removing SwaggerConfiguration.java as it is not required anymore.

updating OraclePersistenceConfiguration and PostgresPersistenceConfiguration for better maintainability.

moved configurations to reside inside YML file and reused properties file for build purpose.

added documentation folder with initial compose file.
@github-actions github-actions bot added fix and removed documentation Improvements or additions to documentation labels Dec 30, 2022
@github-actions github-actions bot added documentation Improvements or additions to documentation fix and removed fix documentation Improvements or additions to documentation labels Dec 30, 2022
import java.util.Date;


public record CodeDescrDTO(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulushcgcj let's please use the suffix Dto instead of DTO. I know it is an acronym, but let's please use Dto.

@github-actions github-actions bot added documentation Improvements or additions to documentation fix and removed fix documentation Improvements or additions to documentation labels Jan 4, 2023
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 4, 2023

[forest-client-frontend] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@github-actions github-actions bot added documentation Improvements or additions to documentation fix and removed fix documentation Improvements or additions to documentation labels Jan 5, 2023
@github-actions github-actions bot added documentation Improvements or additions to documentation fix and removed fix documentation Improvements or additions to documentation labels Jan 6, 2023
@paulushcgcj paulushcgcj deleted the fix/188-code-review branch January 6, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend code related to the java backend application configuration changes related to configuration file controller changes related to an api controller dto This change includes DTO (Data Transfer Object) changes. Please check for contract changes entity this change involves a change on a database entity fix github_actions Pull requests that update GitHub Actions code java Pull requests that update Java code repository changes related to a database repository and data access service changes related to a service source source code changes tests test classes changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code Review
3 participants