budaidev commented on code in PR #5334:
URL: https://github.com/apache/fineract/pull/5334#discussion_r2698370042
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/service/CodeValueReadPlatformServiceImpl.java:
##########
@@ -105,4 +104,14 @@ public CodeValueData retrieveCodeValue(final Long
codeValueId) {
}
}
+
+ @Override
+ public List<CodeValueData> retrieveAllCodeValues(String codeName) {
+ return
codeValueMapper.map(codeValueRepository.findByCodeName(codeName));
Review Comment:
All the other methods have `this.context.authenticatedUser();` don't we want
to use the same in these 2 new methods?
Also, is it possible to receive null from
`codeValueRepository.findByCodeName(codeName)`? That could lead NPE
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/codes/api/CodeValuesApiResource.java:
##########
@@ -172,4 +177,89 @@ public String deleteCodeValue(@PathParam("codeId")
@Parameter(description = "cod
return this.toApiJsonSerializer.serialize(result);
}
+
+ @GET
+ @Path("name/{codeName}/codevalues")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Operation(summary = "List Code Values", description = "Returns the list
of Code Values for a given Code\n" + "\n"
+ + "Example Requests:\n" + "\n" + "codes/1/codevalues", parameters
= @Parameter(name = "codeId", description = "co"))
+ @ApiResponses({
+ @ApiResponse(responseCode = "200", description = "A List of code
values for a given code", content = @Content(array = @ArraySchema(schema =
@Schema(implementation =
CodeValuesApiResourceSwagger.GetCodeValuesDataResponse.class)))) })
+ public List<CodeValueData> retrieveAllCodeValues(@Context final UriInfo
uriInfo,
+ @PathParam("codeName") @Parameter(description = "codeName") final
String codeName) {
+
+
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
+
+ return this.readPlatformService.retrieveAllCodeValues(codeName);
+ }
+
+ @GET
+ @Path("name/{codeName}/codevalues/{codeValueId}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Operation(summary = "Retrieve a Code description", description = "Returns
the details of a Code Value\n" + "\n" + "Example Requests:\n"
+ + "\n" + "codes/name/ADDRESS_TYPE/codevalues/1")
+ @ApiResponses({
+ @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
CodeValuesApiResourceSwagger.GetCodeValuesDataResponse.class))) })
+ public CodeValueData retrieveCodeValue(@Context final UriInfo uriInfo,
+ @PathParam("codeName") @Parameter(description = "codeName") final
String codeName,
+ @PathParam("codeValueId") @Parameter(description = "codeValueId")
final Long codeValueId) {
+
+
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
+
+ return this.readPlatformService.retrieveCodeValue(codeName,
codeValueId);
+ }
+
+ @POST
+ @Path("name/{codeName}/codevalues")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ @Operation(summary = "Create a Code description", description = "")
+ @RequestBody(required = true, content = @Content(schema =
@Schema(implementation =
CodeValuesApiResourceSwagger.PostCodeValuesDataRequest.class)))
+ @ApiResponses({
+ @ApiResponse(responseCode = "200", description = "OK", content =
@Content(schema = @Schema(implementation =
CodeValuesApiResourceSwagger.PostCodeValueDataResponse.class))) })
+ public CommandProcessingResult createCodeValue(@PathParam("codeName")
@Parameter(description = "codeName") final String codeName,
+ @Parameter(hidden = true) final String apiRequestBodyAsJson) {
+ CodeData code = codeReadPlatformService.retriveCode(codeName);
Review Comment:
minor: I know it's given, but there is a typo here, it should be retrieveCode
##########
fineract-e2e-tests-runner/src/test/java/org/apache/fineract/test/initializer/global/LoanProductGlobalInitializerStep.java:
##########
@@ -3736,7 +3738,9 @@ public void initialize() throws Exception {
List<PostClassificationToIncomeAccountMappings>
capitalizedIncomeClassificationToIncomeAccountMappings = new ArrayList<>();
PostClassificationToIncomeAccountMappings
classificationToIncomeAccountMappingsCapitalizedIncome = new
PostClassificationToIncomeAccountMappings();
-
classificationToIncomeAccountMappingsCapitalizedIncome.setClassificationCodeValueId(24L);
+ long CapitalizedIncomeClassificationId =
codeValueResolver.resolve("capitalized_income_transaction_classification",
Review Comment:
```suggestion
long capitalizedIncomeClassificationId =
codeValueResolver.resolve("capitalized_income_transaction_classification",
```
##########
fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/data/codevalue/CodeValueResolver.java:
##########
@@ -43,7 +43,19 @@ public long resolve(Long codeId, CodeValue codeValue) {
log.debug("Resolving code value by code id and name [{}]", codeValue);
List<GetCodeValuesDataResponse> codeValuesResponses = ok(() ->
fineractClient.codeValues().retrieveAllCodeValues(codeId, Map.of()));
GetCodeValuesDataResponse foundPtr =
codeValuesResponses.stream().filter(ptr ->
codeValueName.equals(ptr.getName())).findAny()
- .orElseThrow(() -> new IllegalArgumentException("Payment type
[%s] not found".formatted(codeValueName)));
+ .orElseThrow(
+ () -> new IllegalArgumentException("Code Value [%s]
not found for Code [%s]".formatted(codeValueName, codeId)));
+
+ return foundPtr.getId();
+ }
+
+ @Cacheable(key = "#codeValue", value = "codeValuesByName")
+ public long resolve(String codeName, String codeValue) {
Review Comment:
Is the codeValue always unique? If we have same values for multiple names it
could cause caching issues
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]