Skip to content

Commit ba7a0da

Browse files
committed
FINERACT-2243: New command processing - payment type
1 parent 2ff0c62 commit ba7a0da

File tree

62 files changed

+711
-714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+711
-714
lines changed

fineract-command/REFACTORING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,12 @@ public class CreatePaymentTypeCommandHandler implements NewCommandSourceHandler
298298
@Slf4j
299299
@RequiredArgsConstructor
300300
@Component
301-
public class CreatePaymentTypeCommandHandler implements CommandHandler<CreatePaymentTypeRequest, CreatePaymentTypeResponse> {
301+
public class PaymentTypeCreateCommandHandler implements CommandHandler<PaymentTypeCreateRequest, PaymentTypeCreateResponse> {
302302
303303
private final PaymentTypeWriteService paymentTypeWriteService;
304304
305305
@Override
306-
public CreatePaymentTypeResponse handle(Command<CreatePaymentTypeRequest> command) {
306+
public PaymentTypeCreateResponse handle(Command<PaymentTypeCreateRequest> command) {
307307
// TODO: refactor business logic service to accept properly typed request objects as input
308308
return paymentTypeWriteService.createPaymentType(command.getPayload());
309309
}

fineract-core/src/main/java/org/apache/fineract/commands/service/CommandWrapperBuilder.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.apache.fineract.infrastructure.accountnumberformat.service.AccountNumberFormatConstants;
3030
import org.apache.fineract.infrastructure.core.domain.ExternalId;
3131
import org.apache.fineract.portfolio.client.api.ClientApiConstants;
32-
import org.apache.fineract.portfolio.paymenttype.api.PaymentTypeApiResourceConstants;
3332
import org.apache.fineract.portfolio.savings.DepositsApiConstants;
3433
import org.apache.fineract.portfolio.self.pockets.api.PocketApiConstants;
3534
import org.apache.fineract.useradministration.api.PasswordPreferencesApiConstants;
@@ -2946,30 +2945,6 @@ public CommandWrapperBuilder updatePasswordPreferences() {
29462945
return this;
29472946
}
29482947

2949-
public CommandWrapperBuilder createPaymentType() {
2950-
this.actionName = "CREATE";
2951-
this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME;
2952-
this.entityId = null;
2953-
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME;
2954-
return this;
2955-
}
2956-
2957-
public CommandWrapperBuilder updatePaymentType(final Long paymentTypeId) {
2958-
this.actionName = "UPDATE";
2959-
this.entityName = PaymentTypeApiResourceConstants.ENTITY_NAME;
2960-
this.entityId = paymentTypeId;
2961-
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId;
2962-
return this;
2963-
}
2964-
2965-
public CommandWrapperBuilder deletePaymentType(final Long paymentTypeId) {
2966-
this.actionName = "DELETE";
2967-
this.entityName = "PAYMENTTYPE";
2968-
this.entityId = paymentTypeId;
2969-
this.href = "/" + PaymentTypeApiResourceConstants.RESOURCE_NAME + paymentTypeId;
2970-
return this;
2971-
}
2972-
29732948
public CommandWrapperBuilder updateExternalServiceProperties(final String externalServiceName) {
29742949
this.actionName = "UPDATE";
29752950
this.entityName = "EXTERNALSERVICES";

fineract-core/src/main/java/org/apache/fineract/portfolio/paymenttype/api/PaymentTypeApiResource.java

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
package org.apache.fineract.portfolio.paymenttype.api;
2020

2121
import io.swagger.v3.oas.annotations.Operation;
22-
import io.swagger.v3.oas.annotations.Parameter;
23-
import io.swagger.v3.oas.annotations.media.Content;
24-
import io.swagger.v3.oas.annotations.media.Schema;
25-
import io.swagger.v3.oas.annotations.parameters.RequestBody;
26-
import io.swagger.v3.oas.annotations.responses.ApiResponse;
2722
import io.swagger.v3.oas.annotations.tags.Tag;
2823
import jakarta.ws.rs.Consumes;
2924
import jakarta.ws.rs.DELETE;
@@ -36,17 +31,21 @@
3631
import jakarta.ws.rs.QueryParam;
3732
import jakarta.ws.rs.core.MediaType;
3833
import java.util.List;
34+
import java.util.function.Supplier;
3935
import lombok.RequiredArgsConstructor;
40-
import org.apache.fineract.commands.domain.CommandWrapper;
41-
import org.apache.fineract.commands.service.CommandWrapperBuilder;
42-
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
43-
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
36+
import org.apache.fineract.command.core.CommandPipeline;
4437
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
45-
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
38+
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeCreateCommand;
39+
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeDeleteCommand;
40+
import org.apache.fineract.portfolio.paymenttype.command.PaymentTypeUpdateCommand;
41+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
42+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateResponse;
4643
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeData;
47-
import org.apache.fineract.portfolio.paymenttype.data.request.PaymentTypeRequest;
48-
import org.apache.fineract.portfolio.paymenttype.domain.PaymentTypeRepositoryWrapper;
49-
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadPlatformService;
44+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteRequest;
45+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeDeleteResponse;
46+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateRequest;
47+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeUpdateResponse;
48+
import org.apache.fineract.portfolio.paymenttype.service.PaymentTypeReadService;
5049
import org.springframework.stereotype.Component;
5150

5251
@Path("/v1/paymenttypes")
@@ -55,19 +54,15 @@
5554
@RequiredArgsConstructor
5655
public class PaymentTypeApiResource {
5756

58-
private final PlatformSecurityContext securityContext;
57+
private final PaymentTypeReadService readPlatformService;
58+
private final CommandPipeline commandPipeline;
5959
private final DefaultToApiJsonSerializer<PaymentTypeData> jsonSerializer;
60-
private final PaymentTypeReadPlatformService readPlatformService;
61-
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
62-
private final PaymentTypeRepositoryWrapper paymentTypeRepositoryWrapper;
6360

6461
@GET
6562
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
6663
@Produces(MediaType.APPLICATION_JSON)
6764
@Operation(summary = "Retrieve all Payment Types", description = "Retrieve list of payment types")
68-
public List<PaymentTypeData> getAllPaymentTypes(
69-
@QueryParam("onlyWithCode") @Parameter(description = "onlyWithCode") final boolean onlyWithCode) {
70-
securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
65+
public List<PaymentTypeData> getAllPaymentTypes(@QueryParam("onlyWithCode") final boolean onlyWithCode) {
7166
return onlyWithCode ? readPlatformService.retrieveAllPaymentTypesWithCode() : readPlatformService.retrieveAllPaymentTypes();
7267
}
7368

@@ -76,61 +71,57 @@ public List<PaymentTypeData> getAllPaymentTypes(
7671
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
7772
@Produces(MediaType.APPLICATION_JSON)
7873
@Operation(summary = "Retrieve a Payment Type", description = "Retrieves a payment type")
79-
public PaymentTypeData retrieveOnePaymentType(
80-
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
81-
securityContext.authenticatedUser().validateHasReadPermission(PaymentTypeApiResourceConstants.ENTITY_NAME);
82-
paymentTypeRepositoryWrapper.findOneWithNotFoundDetection(paymentTypeId);
74+
public PaymentTypeData retrieveOnePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId) {
8375
return readPlatformService.retrieveOne(paymentTypeId);
8476
}
8577

8678
@POST
8779
@Consumes({ MediaType.APPLICATION_JSON })
8880
@Produces({ MediaType.APPLICATION_JSON })
89-
@Operation(summary = "Create a Payment Type", description = "Creates a new Payment type\n\n" + "Mandatory Fields: name\n\n"
90-
+ "Optional Fields: Description, isCashPayment,Position")
91-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeRequest.class)))
92-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PostPaymentTypesResponse.class)))
93-
public CommandProcessingResult createPaymentType(@Parameter(hidden = true) PaymentTypeRequest paymentTypeRequest) {
81+
@Operation(summary = "Create a Payment Type", description = "Creates a new Payment type")
82+
public PaymentTypeCreateResponse createPaymentType(PaymentTypeCreateRequest request) {
83+
final var command = new PaymentTypeCreateCommand();
9484

95-
final CommandWrapper commandRequest = new CommandWrapperBuilder().createPaymentType()
96-
.withJson(jsonSerializer.serialize(paymentTypeRequest)).build();
85+
command.setPayload(request);
9786

98-
CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
99-
return result;
87+
final Supplier<PaymentTypeCreateResponse> response = commandPipeline.send(command);
88+
89+
return response.get();
10090
}
10191

10292
@PUT
10393
@Path("{paymentTypeId}")
10494
@Consumes({ MediaType.APPLICATION_JSON })
10595
@Produces({ MediaType.APPLICATION_JSON })
10696
@Operation(summary = "Update a Payment Type", description = "Updates a Payment Type")
107-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdRequest.class)))
108-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.PutPaymentTypesPaymentTypeIdResponse.class)))
109-
public CommandProcessingResult updatePaymentType(
110-
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId,
111-
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
97+
public PaymentTypeUpdateResponse updatePaymentType(@PathParam("paymentTypeId") final Long paymentTypeId,
98+
final PaymentTypeUpdateRequest request) {
99+
request.setId(paymentTypeId);
100+
101+
final var command = new PaymentTypeUpdateCommand();
102+
103+
command.setPayload(request);
112104

113-
final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePaymentType(paymentTypeId).withJson(apiRequestBodyAsJson)
114-
.build();
105+
final Supplier<PaymentTypeUpdateResponse> response = commandPipeline.send(command);
115106

116-
final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
117-
return result;
107+
return response.get();
118108
}
119109

120110
@DELETE
121111
@Path("{paymentTypeId}")
122112
@Consumes({ MediaType.APPLICATION_JSON })
123113
@Produces({ MediaType.APPLICATION_JSON })
124114
@Operation(summary = "Delete a Payment Type", description = "Deletes payment type")
125-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = PaymentTypeApiResourceSwagger.DeletePaymentTypesPaymentTypeIdResponse.class)))
126-
public CommandProcessingResult deleteCode(
127-
@PathParam("paymentTypeId") @Parameter(description = "paymentTypeId") final Long paymentTypeId) {
115+
public PaymentTypeDeleteResponse deleteCode(@PathParam("paymentTypeId") final Long paymentTypeId) {
128116

129-
final CommandWrapper commandRequest = new CommandWrapperBuilder().deletePaymentType(paymentTypeId).build();
117+
final var request = PaymentTypeDeleteRequest.builder().id(paymentTypeId).build();
130118

131-
final CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
119+
final var command = new PaymentTypeDeleteCommand();
132120

133-
return result;
134-
}
121+
command.setPayload(request);
122+
123+
final Supplier<PaymentTypeDeleteResponse> response = commandPipeline.send(command);
135124

125+
return response.get();
126+
}
136127
}

fineract-core/src/main/java/org/apache/fineract/portfolio/paymenttype/api/PaymentTypeApiResourceConstants.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

fineract-core/src/main/java/org/apache/fineract/portfolio/paymenttype/api/PaymentTypeApiResourceSwagger.java

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.portfolio.paymenttype.command;
20+
21+
import lombok.Data;
22+
import lombok.EqualsAndHashCode;
23+
import org.apache.fineract.command.core.Command;
24+
import org.apache.fineract.portfolio.paymenttype.data.PaymentTypeCreateRequest;
25+
26+
@Data
27+
@EqualsAndHashCode(callSuper = true)
28+
public class PaymentTypeCreateCommand extends Command<PaymentTypeCreateRequest> {}

0 commit comments

Comments
 (0)