FINERACT-2181: Batch Api - Add Interest pause API support

This commit is contained in:
Adam Saghy
2025-07-21 12:26:03 +02:00
parent 46e1bd0492
commit 81d6d2e54e
11 changed files with 645 additions and 7 deletions
@@ -0,0 +1,71 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseRequestDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and creates a loan interest pause by external id. It passes the contents of the
* body from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also
* catch any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class CreateLoanInterestPauseByExternalIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<CommandProcessingResult> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\/interest-pauses
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final String loanExternalId = pathParameters.get(2);
final InterestPauseRequestDto interestPauseRequestDto = InterestPauseRequestDto.fromJson(request.getBody());
final CommandProcessingResult commandProcessingResult = loanInterestPauseApiResource.createInterestPauseByExternalId(loanExternalId,
interestPauseRequestDto);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(commandProcessingResult));
return response;
}
}
@@ -0,0 +1,71 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseRequestDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and creates a loan interest pause by loan id. It passes the contents of the body
* from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also catch
* any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class CreateLoanInterestPauseByLoanIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<CommandProcessingResult> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/\d+\/interest-pauses
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final Long loanId = Long.parseLong(pathParameters.get(1));
final InterestPauseRequestDto interestPauseRequestDto = InterestPauseRequestDto.fromJson(request.getBody());
final CommandProcessingResult commandProcessingResult = loanInterestPauseApiResource.createInterestPause(loanId,
interestPauseRequestDto);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(commandProcessingResult));
return response;
}
}
@@ -0,0 +1,69 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseResponseDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and retrieves loan interest pauses by external id. It passes the contents of the
* body from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also
* catch any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class GetLoanInterestPausesByExternalIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<List<InterestPauseResponseDto>> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\/interest-pauses
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final String loanExternalId = pathParameters.get(2);
final List<InterestPauseResponseDto> responseDtos = loanInterestPauseApiResource.retrieveInterestPausesByExternalId(loanExternalId);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(responseDtos));
return response;
}
}
@@ -0,0 +1,68 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseResponseDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and retrieves loan interest pauses by loan id. It passes the contents of the body
* from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also catch
* any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class GetLoanInterestPausesByLoanIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<List<InterestPauseResponseDto>> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/\d+\/interest-pauses
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final Long loanId = Long.parseLong(pathParameters.get(1));
final List<InterestPauseResponseDto> responseDtos = loanInterestPauseApiResource.retrieveInterestPauses(loanId);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(responseDtos));
return response;
}
}
@@ -0,0 +1,72 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseRequestDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and updates a loan interest pause by external id. It passes the contents of the
* body from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also
* catch any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class UpdateLoanInterestPauseByExternalIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<CommandProcessingResult> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/external-id\/[\w\d_-]+\/interest-pauses\/\d+
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final String loanExternalId = pathParameters.get(2);
final Long variationId = Long.parseLong(pathParameters.get(4));
final InterestPauseRequestDto interestPauseRequestDto = InterestPauseRequestDto.fromJson(request.getBody());
final CommandProcessingResult commandProcessingResult = loanInterestPauseApiResource.updateInterestPauseByExternalId(loanExternalId,
variationId, interestPauseRequestDto);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(commandProcessingResult));
return response;
}
}
@@ -0,0 +1,72 @@
/**
* 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.batch.command.internal;
import static org.apache.fineract.batch.command.CommandStrategyUtils.relativeUrlWithoutVersion;
import com.google.common.base.Splitter;
import jakarta.ws.rs.core.UriInfo;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.batch.command.CommandStrategy;
import org.apache.fineract.batch.domain.BatchRequest;
import org.apache.fineract.batch.domain.BatchResponse;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.portfolio.interestpauses.api.LoanInterestPauseApiResource;
import org.apache.fineract.portfolio.interestpauses.data.InterestPauseRequestDto;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Component;
/**
* Implements {@link CommandStrategy} and updates a loan interest pause by loan id. It passes the contents of the body
* from the BatchRequest to {@link LoanInterestPauseApiResource} and gets back the response. This class will also catch
* any errors raised by {@link LoanInterestPauseApiResource} and map those errors to appropriate status codes in
* BatchResponse.
*/
@Component
@RequiredArgsConstructor
public class UpdateLoanInterestPauseByLoanIdCommandStrategy implements CommandStrategy {
private final LoanInterestPauseApiResource loanInterestPauseApiResource;
private final DefaultToApiJsonSerializer<CommandProcessingResult> toApiJsonSerializer;
@Override
public BatchResponse execute(final BatchRequest request, @SuppressWarnings("unused") final UriInfo uriInfo) {
final BatchResponse response = new BatchResponse();
response.setRequestId(request.getRequestId());
response.setHeaders(request.getHeaders());
// Expected pattern - loans\/\d+\/interest-pauses\/\d+
final List<String> pathParameters = Splitter.on('/').splitToList(relativeUrlWithoutVersion(request));
final Long loanId = Long.parseLong(pathParameters.get(1));
final Long variationId = Long.parseLong(pathParameters.get(3));
final InterestPauseRequestDto interestPauseRequestDto = InterestPauseRequestDto.fromJson(request.getBody());
final CommandProcessingResult commandProcessingResult = loanInterestPauseApiResource.updateInterestPause(loanId, variationId,
interestPauseRequestDto);
response.setStatusCode(HttpStatus.SC_OK);
response.setBody(toApiJsonSerializer.serialize(commandProcessingResult));
return response;
}
}
@@ -195,11 +195,11 @@ public class CommandStrategyProviderTest {
"getDatatableEntryByQueryCommandStrategy", mock(GetDatatableEntryByQueryCommandStrategy.class)),
Arguments.of("datatables/test_dt_table/query?columnFilter=custom_id&valueFilter=10a62-d438-2319&resultColumns=id",
HttpMethod.GET, "getDatatableEntryByQueryCommandStrategy", mock(GetDatatableEntryByQueryCommandStrategy.class)),
Arguments.of("loans/123/interest-pauses", HttpMethod.GET, "getLoanInterestPausesByExternalIdCommandStrategy",
Arguments.of("loans/123/interest-pauses", HttpMethod.GET, "getLoanInterestPausesByLoanIdCommandStrategy",
mock(CommandStrategy.class)),
Arguments.of("loans/123/interest-pauses", HttpMethod.POST, "createLoanInterestPauseByExternalIdCommandStrategy",
Arguments.of("loans/123/interest-pauses", HttpMethod.POST, "createLoanInterestPauseByLoanIdCommandStrategy",
mock(CommandStrategy.class)),
Arguments.of("loans/123/interest-pauses/123", HttpMethod.PUT, "updateLoanInterestPauseByExternalIdCommandStrategy",
Arguments.of("loans/123/interest-pauses/456", HttpMethod.PUT, "updateLoanInterestPauseByLoanIdCommandStrategy",
mock(CommandStrategy.class)),
Arguments.of("loans/external-id/8dfad438-2319-48ce-8520-10a62801e9a1/interest-pauses", HttpMethod.GET,
"getLoanInterestPausesByExternalIdCommandStrategy", mock(CommandStrategy.class)),