Skip to content

refactor: constructor injection, literal constants, and code cleanup across repository layer - #2082

Merged
lbroudoux merged 6 commits into
microcks:masterfrom
kishore08-07:repo
May 11, 2026
Merged

lbroudoux merged 6 commits into
microcks:masterfrom
kishore08-07:repo

Conversation

@kishore08-07

Copy link
Copy Markdown
Contributor

Description

This PR resolves maintainability issues flagged by SonarQube across five repository classes: GenericResourceRepositoryImpl, TestConformanceMetricRepositoryImpl, DailyStatisticRepositoryImpl, ImportJobRepositoryImpl, and ServiceRepositoryImpl.

Critical

  • Extract duplicated literals into named constants across TestConformanceMetricRepositoryImpl, DailyStatisticRepositoryImpl, ImportJobRepositoryImpl, and ServiceRepositoryImpl (S1192)

Major

  • Replace field injection with constructor injection across all five classes (S6813)
  • Remove unused private log field in GenericResourceRepositoryImpl and ImportJobRepositoryImpl (S1068)
  • Remove commented-out code block in DailyStatisticRepositoryImpl (S125)
  • Replace string concatenation with format specifiers in log statements in DailyStatisticRepositoryImpl (S2629)
  • Replace keySet() iteration with entrySet() to eliminate redundant map lookups in ImportJobRepositoryImpl and ServiceRepositoryImpl (S2864)

Minor

  • Replace deprecated MapReduceResults with aggregation pipeline equivalent in DailyStatisticRepositoryImpl (S1874)
  • Inline unnecessary temporary variables across ImportJobRepositoryImpl and ServiceRepositoryImpl (S1488)
  • Replace explicit generic types with diamond operator (S2293)

Related issue(s)

See also #2058

kishore08-07 and others added 3 commits May 3, 2026 00:29
Address maintainability violations across GenericResourceRepositoryImpl, TestConformanceMetricRepositoryImpl and DailyStatisticRepositoryImpl

Critical:
- Extract duplicated literal value into named constant in TestConformanceMetricRepositoryImpl (S1192)
- Extract duplicated literal dailyCount into named constant in DailyStatisticRepositoryImpl (S1192)

Major:
- Replace field injection with constructor injection across all three classes (S6813)
- Remove unused private log field in GenericResourceRepositoryImpl (S1068)
- Remove block of commented-out code in DailyStatisticRepositoryImpl (S125)
- Replace string concatenation with format specifiers in log statements across 3 occurrences in DailyStatisticRepositoryImpl (S2629)

Minor:
- Replace deprecated MapReduceResults with aggregation pipeline equivalent in DailyStatisticRepositoryImpl (S1874)

Signed-off-by: kishore08-07 <[email protected]>
…aintainability issues in repository impls

Address maintainability violations across ImportJobRepositoryImpl and ServiceRepositoryImpl

Critical:
- Extract duplicated literal number into a named constant (S1192)

Major:
- Replace field injection with constructor injection in both classes (S6813)
- Replace keySet() iteration with entrySet() to eliminate redundant map lookups across 4 occurrences (S2864)
- Remove unused private log field in ImportJobRepositoryImpl (S1068)

Minor:
- Inline temporary variable results across 5 occurrences (S1488)
- Replace explicit generic type with diamond operator (S2293)

Signed-off-by: kishore08-07 <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me but I think some other files need to be removed if you refactored the mapredue to an aggregation. Also, can you explain how you checked it produces the same result and doesn't introduce any regression?

@lbroudoux lbroudoux added java Pull requests that update Java code kind/task labels May 4, 2026
@lbroudoux lbroudoux added this to the 1.15.0 milestone May 4, 2026
Address review feedback and S1874 in DailyStatisticRepositoryImpl

Minor:
- Replace deprecated MapReduceResults / MongoTemplate.mapReduce usage with aggregation pipeline (S1874)
- Remove dead files MapReduce JS resources (mapDailyStatisticForADay.js, reduceDailyStatisticForADay.js)
- Remove dead code MapReduce-only WrappedDailyStatistic wrapper class

Tests:
- Replace legacy exception test with assertions for daily/hourly aggregation and empty-day behavior

Signed-off-by: kishore08-07 <[email protected]>
@kishore08-07

kishore08-07 commented May 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Looks good to me but I think some other files need to be removed if you refactored the mapredue to an aggregation. Also, can you explain how you checked it produces the same result and doesn't introduce any regression?

Yes, checked that aggregation is semantically identical with mapreduce and i validated its equivalence via:

  • Unit tests with assertions : dailyCount sum, hourlyCount[0..23] sums across services, and empty-day behavior.
  • MongoDB query comparison: ran the equivalent $match + $group aggregation in Mongo shell and compared results with /api/metrics/invocations/global?day=...

@kishore08-07

Copy link
Copy Markdown
Contributor Author

Thanks @lbroudoux for your review and i have address the feedbacks, kindly re-review whenever you have time.

@kishore08-07
kishore08-07 requested a review from lbroudoux May 7, 2026 11:28

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM but need to restore the original import order before merging please.

- Reorder static imports in DailyStatisticRepositoryImpl for consistency
- formatting cleanup in ExamplesExporter (inline lambda)

Signed-off-by: kishore08-07 <[email protected]>

@lbroudoux lbroudoux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@lbroudoux
lbroudoux merged commit e2c8041 into microcks:master May 11, 2026
12 checks passed
@kishore08-07
kishore08-07 deleted the repo branch May 11, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code kind/task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants