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

FINERACT-2181: Refactor ResultsetColumnHeaderData using Lombok and modern java new features #4307

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

a7med3del1973
Copy link
Contributor

@a7med3del1973 a7med3del1973 commented Feb 6, 2025

Description

Ignore if these details are present on the associated Apache Fineract JIRA ticket.

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per https://github.com/apache/fineract/#pull-requests

  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.

  • Create/update unit or integration tests for verifying the changes made.

  • Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.

  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes

  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

return ResultsetColumnHeaderData.builder()
.columnName(columnName)
.columnType(JdbcJavaType.getByTypeName(dialect, adjustColumnType(columnType), true))
.columnLength(null)

Choose a reason for hiding this comment

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

why set null? we could omit this in the builder rather than set null

Copy link
Contributor

Choose a reason for hiding this comment

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

Same goes for primitive boolean types. It is nice to explicitly set, but in the other hand it is unnecessary

@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* <p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not change the licence header

}
if (columnType.isTextType()) return DisplayType.TEXT;
if (columnType.isStringType()) return DisplayType.STRING;
if (columnType.isAnyIntegerType()) return DisplayType.INTEGER;

Choose a reason for hiding this comment

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

a switch or a map will be better in this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@oluexpert99
Thanks for your response .. i noted your comments then refactored the code according to yours and waiting for feedback

return columnValues != null && !columnValues.isEmpty();
}

public boolean isColumnValueAllowed(final String match) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is used in the SeachUtil class... i am not sure why you removed it....

return false;
}

public boolean isColumnCodeAllowed(final Integer match) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here...

return this.columnName;
}

public boolean isNamed(final String columnName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This methid is used in many classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@a7med3del1973 could you please review the comment?

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

Kindly review the comments!

@a7med3del1973
Copy link
Contributor Author

Kindly review the comments!

@adamsaghy
Thanks for your review .. your comments are noted then refactored the code now waiting your feedback

@adamsaghy
Copy link
Contributor

@a7med3del1973 please squash your commits!

1 similar comment
@adamsaghy
Copy link
Contributor

@a7med3del1973 please squash your commits!

@a7med3del1973
Copy link
Contributor Author

a7med3del1973 commented Feb 10, 2025

@adamsaghy squash done

@a7med3del1973 a7med3del1973 force-pushed the lombok-integration branch 3 times, most recently from 2b77e08 to 41b4859 Compare February 10, 2025 13:25
@a7med3del1973
Copy link
Contributor Author

@adamsaghy
@oluexpert99
if your think something should be modified please let me know.

public final class ResultsetColumnHeaderData implements Serializable {

private final String columnName;
private JdbcJavaType columnType;
private final Long columnLength;
private final DisplayType columnDisplayType;
@Getter(AccessLevel.NONE)
Copy link
Contributor

Choose a reason for hiding this comment

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

We dont need to restricted getter for these fields...

return null;
Map<Predicate<JdbcJavaType>, DisplayType> typeMap = new LinkedHashMap<>();

typeMap.put(JdbcJavaType::isTextType, DisplayType.TEXT);
Copy link
Contributor

Choose a reason for hiding this comment

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

Using switch-case would be better...

@galovics
Copy link
Contributor

@a7med3del1973 what's the purpose here? are you familiar with Java and have an IDE set up properly? I really feel like you're just starting out hence the "used in SearchUtil" comments in the codebase. Also, the PR builds are failing, probably due to formatting issues (haven't checked).

@a7med3del1973
Copy link
Contributor Author

@galovics Thanks for your review
Added this comments just for clearity. Your comment noted and working on it.

@adamsaghy
Copy link
Contributor

@a7med3del1973 Kindly fix the failing checks:

> Task :fineract-core:modernizer
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:225:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:226:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:227:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:228:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:229:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:230:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:231:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:232:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:233:9: 'if' construct must use '{}'s. [NeedBraces]
Error: eckstyle] [ERROR] /home/runner/work/fineract/fineract/fineract-core/src/main/java/org/apache/fineract/infrastructure/dataqueries/data/ResultsetColumnHeaderData.java:234:9: 'if' construct must use '{}'s. [NeedBraces]
Execution failed for task ':fineract-core:checkstyleMain'.
> A failure occurred while executing org.gradle.api.plugins.quality.internal.CheckstyleAction
   > Checkstyle rule violations were found. See the report at: file:///home/runner/work/fineract/fineract/fineract-core/build/reports/checkstyle/main.html
     Checkstyle files with violations: 1
     Checkstyle violations by severity: [error:10]

@adamsaghy
Copy link
Contributor

@a7med3del1973 Please make sure the PR title and commit message are following the required naming conventions: "FINERACT-XXXX: short description"

@a7med3del1973 a7med3del1973 changed the title Refactor ResultsetColumnHeaderData to Use Lombok Annotations for Boilerplate Reduction FINERACT-2081: Refactor ResultsetColumnHeaderData to Use Lombok Annotations for Boilerplate Reduction Mar 3, 2025
@a7med3del1973 a7med3del1973 changed the title FINERACT-2081: Refactor ResultsetColumnHeaderData to Use Lombok Annotations for Boilerplate Reduction FINERACT-2081: Refactor ResultsetColumnHeaderData using Lombok and modern java new features Mar 3, 2025
@adamsaghy
Copy link
Contributor

@a7med3del1973 FINERACT-2081 was a story to cover minor changes in 1.11. Since this version of release process started, we cannot use this story anymore. Kindly use the https://issues.apache.org/jira/browse/FINERACT-2181 from now on for minor changes which will be part of 1.12.

@a7med3del1973 a7med3del1973 changed the title FINERACT-2081: Refactor ResultsetColumnHeaderData using Lombok and modern java new features FINERACT-2181: Refactor ResultsetColumnHeaderData using Lombok and modern java new features Mar 3, 2025
@a7med3del1973
Copy link
Contributor Author

@a7med3del1973 FINERACT-2081 was a story to cover minor changes in 1.11. Since this version of release process started, we cannot use this story anymore. Kindly use the https://issues.apache.org/jira/browse/FINERACT-2181 from now on for minor changes which will be part of 1.12.

Changes done.

@@ -239,40 +206,58 @@ private DisplayType calcDisplayType() {
}

public static DisplayType calcColumnDisplayType(JdbcJavaType columnType) {
return switch (getJdbcType(columnType)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see no any value of this changes....
If you want to change the IF conditions to switch fine... but why to map JdbcJavaType to String and from String to DisplayType?

Map JdbcJavaType to DisplayType with mapper if you want...

Copy link
Contributor Author

@a7med3del1973 a7med3del1973 Mar 6, 2025

Choose a reason for hiding this comment

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

I see no any value of this changes.... If you want to change the IF conditions to switch fine... but why to map JdbcJavaType to String and from String to DisplayType?

Map JdbcJavaType to DisplayType with mapper if you want...

Got it your opinion
Thinked my change will make it easy for add new property
above i already used mapper you told me switch case will be better.

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

See my review...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants