Skip to content

Commit

Permalink
FINERACT-2169: Replace String json to DTO - for FloatingRatesApiResou…
Browse files Browse the repository at this point in the history
…rce -fixed
  • Loading branch information
oleksma committed Feb 24, 2025
1 parent e02420f commit d86c795
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -45,12 +43,14 @@
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRateData;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRateIndividualResponse;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRatePeriodResponse;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRateRequest;
import org.apache.fineract.portfolio.floatingrates.data.FloatingRateResponse;
import org.apache.fineract.portfolio.floatingrates.service.FloatingRatesReadPlatformService;
import org.springframework.stereotype.Component;

Expand All @@ -69,7 +69,6 @@ public class FloatingRatesApiResource {
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final DefaultToApiJsonSerializer<FloatingRateData> toApiJsonSerializer;
private final FloatingRatesReadPlatformService floatingRatesReadPlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;

@POST
@Consumes({ MediaType.APPLICATION_JSON })
Expand All @@ -79,11 +78,10 @@ public class FloatingRatesApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.PostFloatingRatesRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.PostFloatingRatesResponse.class))) })
public String createFloatingRate(@Parameter(hidden = true) final String apiRequestBodyAsJson) {

final CommandWrapper commandRequest = new CommandWrapperBuilder().createFloatingRate().withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult createFloatingRate(@Parameter(hidden = true) final FloatingRateRequest floatingRateRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createFloatingRate()
.withJson(toApiJsonSerializer.serialize(floatingRateRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

@GET
Expand All @@ -92,11 +90,11 @@ public String createFloatingRate(@Parameter(hidden = true) final String apiReque
@Operation(summary = "List Floating Rates", description = "Lists Floating Rates")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.GetFloatingRatesResponse.class)))) })
public String retrieveAll(@Context final UriInfo uriInfo) {
public List<FloatingRateResponse> retrieveAll() {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME);
final List<FloatingRateData> floatingRates = this.floatingRatesReadPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, floatingRates, FloatingRatesApiResource.LIST_FLOATING_RATES_PARAMETERS);
return floatingRates.stream().map(data -> new FloatingRateResponse(data.getId(), data.getName(), data.isBaseLendingRate(),
data.isActive(), data.getCreatedBy(), data.getCreatedOn(), data.getModifiedBy(), data.getModifiedOn())).toList();
}

@GET
Expand All @@ -106,12 +104,17 @@ public String retrieveAll(@Context final UriInfo uriInfo) {
@Operation(summary = "Retrieve Floating Rate", description = "Retrieves Floating Rate")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.GetFloatingRatesFloatingRateIdResponse.class))) })
public String retrieveOne(@PathParam("floatingRateId") @Parameter(description = "floatingRateId") final Long floatingRateId,
@Context final UriInfo uriInfo) {
public FloatingRateIndividualResponse retrieveOne(
@PathParam("floatingRateId") @Parameter(description = "floatingRateId") final Long floatingRateId) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME);
final FloatingRateData floatingRates = this.floatingRatesReadPlatformService.retrieveOne(floatingRateId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, floatingRates, FloatingRatesApiResource.INDIVIDUAL_FLOATING_RATES_PARAMETERS);
final FloatingRateData rate = this.floatingRatesReadPlatformService.retrieveOne(floatingRateId);
return new FloatingRateIndividualResponse(rate.getId(), rate.getName(), rate.isBaseLendingRate(), rate.isActive(),
rate.getCreatedBy(), rate.getCreatedOn(), rate.getModifiedBy(), rate.getModifiedOn(),
rate.getRatePeriods().stream()
.map(period -> new FloatingRatePeriodResponse(period.getId(), period.getFromDate(), period.getInterestRate(),
period.isDifferentialToBaseLendingRate(), period.isActive(), period.getCreatedBy(), period.getCreatedOn(),
period.getModifiedBy(), period.getModifiedOn()))
.toList());
}

@PUT
Expand All @@ -122,12 +125,13 @@ public String retrieveOne(@PathParam("floatingRateId") @Parameter(description =
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.PutFloatingRatesFloatingRateIdRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = FloatingRatesApiResourceSwagger.PutFloatingRatesFloatingRateIdResponse.class))) })
public String updateFloatingRate(@PathParam("floatingRateId") @Parameter(description = "floatingRateId") final Long floatingRateId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFloatingRate(floatingRateId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult updateFloatingRate(
@PathParam("floatingRateId") @Parameter(description = "floatingRateId") final Long floatingRateId,
@Parameter(hidden = true) final FloatingRateRequest floatingRateRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFloatingRate(floatingRateId)
.withJson(toApiJsonSerializer.serialize(floatingRateRequest)).build();

return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.floatingrates.data;

import java.io.Serial;
import java.time.OffsetDateTime;
import java.util.List;
import lombok.Getter;
import lombok.Setter;

public class FloatingRateIndividualResponse extends FloatingRateResponse {

@Serial
private static final long serialVersionUID = 1L;

@Getter
@Setter
private List<FloatingRatePeriodResponse> ratePeriods;

public FloatingRateIndividualResponse(Long id, String name, Boolean isBaseLendingRate, Boolean isActive, String createdBy,
OffsetDateTime createdOn, String modifiedBy, OffsetDateTime modifiedOn, List<FloatingRatePeriodResponse> ratePeriods) {
super(id, name, isBaseLendingRate, isActive, createdBy, createdOn, modifiedBy, modifiedOn);
this.ratePeriods = ratePeriods;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.floatingrates.data;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class FloatingRatePeriodRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private String fromDate;
private BigDecimal interestRate;
private Boolean isDifferentialToBaseLendingRate;
private String locale;
private String dateFormat;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.floatingrates.data;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class FloatingRatePeriodResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long id;
private LocalDate fromDate;
private BigDecimal interestRate;
private Boolean isDifferentialToBaseLendingRate;
private Boolean isActive;
private String createdBy;
private OffsetDateTime createdOn;
private String modifiedBy;
private OffsetDateTime modifiedOn;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.floatingrates.data;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class FloatingRateRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private String name;
private Boolean isBaseLendingRate;
private Boolean isActive;
private List<FloatingRatePeriodRequest> ratePeriods;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.floatingrates.data;

import java.io.Serial;
import java.io.Serializable;
import java.time.OffsetDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class FloatingRateResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long id;
private String name;
private Boolean isBaseLendingRate;
private Boolean isActive;
private String createdBy;
private OffsetDateTime createdOn;
private String modifiedBy;
private OffsetDateTime modifiedOn;
}

0 comments on commit d86c795

Please sign in to comment.