FINERACT-2418: add origination-api-skeleton

This commit is contained in:
Attila Budai
2026-01-21 13:13:04 +01:00
committed by Adam Saghy
parent bffa04c3e6
commit 87cad91aa8
25 changed files with 640 additions and 23 deletions
@@ -842,6 +842,17 @@
"type": "map" "type": "map"
} }
] ]
},
{
"default": null,
"name": "originators",
"type": [
"null",
{
"type": "array",
"items": "org.apache.fineract.avro.loan.v1.OriginatorDetailsV1"
}
]
} }
] ]
} }
@@ -271,6 +271,18 @@
"null", "null",
"org.apache.fineract.avro.generic.v1.CodeValueDataV1" "org.apache.fineract.avro.generic.v1.CodeValueDataV1"
] ]
},
{
"default": null,
"name": "originators",
"doc": "List of originators attached to the parent loan for revenue sharing",
"type": [
"null",
{
"type": "array",
"items": "org.apache.fineract.avro.loan.v1.OriginatorDetailsV1"
}
]
} }
] ]
} }
@@ -0,0 +1,62 @@
{
"name": "OriginatorDetailsV1",
"namespace": "org.apache.fineract.avro.loan.v1",
"doc": "Loan originator details for revenue sharing and reporting",
"type": "record",
"fields": [
{
"default": null,
"name": "id",
"doc": "Internal originator ID",
"type": [
"null",
"long"
]
},
{
"default": null,
"name": "externalId",
"doc": "Unique external identifier (Revenue Share ID)",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "name",
"doc": "Originator name",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "status",
"doc": "Originator status: ACTIVE, PENDING, or INACTIVE",
"type": [
"null",
"string"
]
},
{
"default": null,
"name": "originatorType",
"doc": "Code value for originator type (MERCHANT, BROKER, AFFILIATE, PLATFORM)",
"type": [
"null",
"org.apache.fineract.avro.generic.v1.CodeValueDataV1"
]
},
{
"default": null,
"name": "channelType",
"doc": "Code value for channel type (ONLINE, IN_STORE, API, AGGREGATOR)",
"type": [
"null",
"org.apache.fineract.avro.generic.v1.CodeValueDataV1"
]
}
]
}
@@ -3929,4 +3929,27 @@ public class CommandWrapperBuilder {
this.href = "/loans/" + loanId; this.href = "/loans/" + loanId;
return this; return this;
} }
public CommandWrapperBuilder createLoanOriginator() {
this.actionName = "CREATE";
this.entityName = "LOAN_ORIGINATOR";
this.href = "/loan-originators";
return this;
}
public CommandWrapperBuilder updateLoanOriginator(final Long originatorId) {
this.actionName = "UPDATE";
this.entityName = "LOAN_ORIGINATOR";
this.entityId = originatorId;
this.href = "/loan-originators/" + originatorId;
return this;
}
public CommandWrapperBuilder deleteLoanOriginator(final Long originatorId) {
this.actionName = "DELETE";
this.entityName = "LOAN_ORIGINATOR";
this.entityId = originatorId;
this.href = "/loan-originators/" + originatorId;
return this;
}
} }
@@ -552,7 +552,7 @@ public class BatchApiStepDef extends AbstractStepDef {
// Create new user which cannot bypass loan COB execution // Create new user which cannot bypass loan COB execution
PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE); PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE);
Long createdUserId = createUserResponse.getResourceId(); Long createdUserId = createUserResponse.getResourceId();
GetUsersUserIdResponse user = fineractFeignClient.users().retrieveOne31(createdUserId); GetUsersUserIdResponse user = fineractFeignClient.users().retrieveOne32(createdUserId);
String authorizationString = user.getUsername() + ":" + PWD_USER_WITH_ROLE; String authorizationString = user.getUsername() + ":" + PWD_USER_WITH_ROLE;
Base64 base64 = new Base64(); Base64 base64 = new Base64();
headerMap.put("Authorization", headerMap.put("Authorization",
@@ -68,7 +68,7 @@ public class UserStepDef extends AbstractStepDef {
.repeatPassword(PWD_USER_WITH_ROLE) // .repeatPassword(PWD_USER_WITH_ROLE) //
.roles(List.of(roleId)); .roles(List.of(roleId));
PostUsersResponse createUserResponse = ok(() -> fineractClient.users().create15(postUsersRequest)); PostUsersResponse createUserResponse = ok(() -> fineractClient.users().create16(postUsersRequest));
testContext().set(TestContextKey.CREATED_SIMPLE_USER_RESPONSE, createUserResponse); testContext().set(TestContextKey.CREATED_SIMPLE_USER_RESPONSE, createUserResponse);
testContext().set(TestContextKey.CREATED_SIMPLE_USER_USERNAME, generatedUsername); testContext().set(TestContextKey.CREATED_SIMPLE_USER_USERNAME, generatedUsername);
testContext().set(TestContextKey.CREATED_SIMPLE_USER_PASSWORD, PWD_USER_WITH_ROLE); testContext().set(TestContextKey.CREATED_SIMPLE_USER_PASSWORD, PWD_USER_WITH_ROLE);
@@ -145,7 +145,7 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE); PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE);
Long createdUserId = createUserResponse.getResourceId(); Long createdUserId = createUserResponse.getResourceId();
GetUsersUserIdResponse user = ok(() -> fineractClient.users().retrieveOne31(createdUserId)); GetUsersUserIdResponse user = ok(() -> fineractClient.users().retrieveOne32(createdUserId));
String apiBaseUrl = apiProperties.getBaseUrl() + "/fineract-provider/api/"; String apiBaseUrl = apiProperties.getBaseUrl() + "/fineract-provider/api/";
FineractFeignClient userClient = FineractFeignClient.builder().baseUrl(apiBaseUrl) FineractFeignClient userClient = FineractFeignClient.builder().baseUrl(apiBaseUrl)
@@ -200,7 +200,7 @@ public class LoanRepaymentStepDef extends AbstractStepDef {
PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE); PostUsersResponse createUserResponse = testContext().get(TestContextKey.CREATED_SIMPLE_USER_RESPONSE);
Long createdUserId = createUserResponse.getResourceId(); Long createdUserId = createUserResponse.getResourceId();
GetUsersUserIdResponse user = ok(() -> fineractClient.users().retrieveOne31(createdUserId)); GetUsersUserIdResponse user = ok(() -> fineractClient.users().retrieveOne32(createdUserId));
String apiBaseUrl = apiProperties.getBaseUrl() + "/fineract-provider/api/"; String apiBaseUrl = apiProperties.getBaseUrl() + "/fineract-provider/api/";
FineractFeignClient userClient = FineractFeignClient.builder().baseUrl(apiBaseUrl) FineractFeignClient userClient = FineractFeignClient.builder().baseUrl(apiBaseUrl)
@@ -0,0 +1,51 @@
/**
* 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.loanorigination.api;
import java.util.Set;
public final class LoanOriginatorApiConstants {
private LoanOriginatorApiConstants() {}
public static final String RESOURCE_NAME = "LOAN_ORIGINATOR";
public static final String RESOURCE_PATH = "/loan-originators";
public static final String ACTION_CREATE = "CREATE";
public static final String ACTION_UPDATE = "UPDATE";
public static final String ACTION_DELETE = "DELETE";
public static final String ORIGINATOR_TYPE_CODE_NAME = "LoanOriginatorType";
public static final String CHANNEL_TYPE_CODE_NAME = "LoanOriginationChannelType";
public static final String EXTERNAL_ID_PARAM = "externalId";
public static final String NAME_PARAM = "name";
public static final String STATUS_PARAM = "status";
public static final String ORIGINATOR_TYPE_ID_PARAM = "originatorTypeId";
public static final String CHANNEL_TYPE_ID_PARAM = "channelTypeId";
public static final Set<String> CREATE_REQUEST_PARAMS = Set.of(EXTERNAL_ID_PARAM, NAME_PARAM, STATUS_PARAM, ORIGINATOR_TYPE_ID_PARAM,
CHANNEL_TYPE_ID_PARAM);
public static final Set<String> UPDATE_REQUEST_PARAMS = Set.of(NAME_PARAM, STATUS_PARAM, ORIGINATOR_TYPE_ID_PARAM,
CHANNEL_TYPE_ID_PARAM);
public static final Set<String> RESPONSE_PARAMS = Set.of("id", EXTERNAL_ID_PARAM, NAME_PARAM, STATUS_PARAM, ORIGINATOR_TYPE_ID_PARAM,
CHANNEL_TYPE_ID_PARAM);
}
@@ -0,0 +1,190 @@
/**
* 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.loanorigination.api;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
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.List;
import lombok.RequiredArgsConstructor;
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.loanorigination.data.LoanOriginatorData;
import org.apache.fineract.portfolio.loanorigination.service.LoanOriginatorReadPlatformService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Path("/v1/loan-originators")
@Component
@ConditionalOnProperty(value = "fineract.module.loan-origination.enabled", havingValue = "true")
@Tag(name = "Loan Originators", description = "Manage loan originator details for revenue sharing and reporting")
@RequiredArgsConstructor
public class LoanOriginatorApiResource {
private final PlatformSecurityContext context;
private final LoanOriginatorReadPlatformService loanOriginatorReadPlatformService;
private final DefaultToApiJsonSerializer<LoanOriginatorData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a new loan originator", description = "Creates a new loan originator record. Requires CREATE_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "400", description = "Required parameter is missing or incorrect format")
@ApiResponse(responseCode = "403", description = "Duplicate external ID or insufficient permissions")
public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createLoanOriginator().withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "List all loan originators", description = "Retrieves all loan originator records. Requires READ_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
public String retrieveAll(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(LoanOriginatorApiConstants.RESOURCE_NAME);
final List<LoanOriginatorData> originators = this.loanOriginatorReadPlatformService.retrieveAll();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, originators, LoanOriginatorApiConstants.RESPONSE_PARAMS);
}
@GET
@Path("{originatorId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a loan originator by ID", description = "Retrieves a loan originator by its internal ID. Requires READ_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String retrieveOne(@PathParam("originatorId") @Parameter(description = "originatorId") final Long originatorId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(LoanOriginatorApiConstants.RESOURCE_NAME);
final LoanOriginatorData originator = this.loanOriginatorReadPlatformService.retrieveById(originatorId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, originator, LoanOriginatorApiConstants.RESPONSE_PARAMS);
}
@GET
@Path("external-id/{externalId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a loan originator by external ID", description = "Retrieves a loan originator by its external ID. Requires READ_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String retrieveByExternalId(@PathParam("externalId") @Parameter(description = "externalId") final String externalId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(LoanOriginatorApiConstants.RESOURCE_NAME);
final LoanOriginatorData originator = this.loanOriginatorReadPlatformService.retrieveByExternalId(externalId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, originator, LoanOriginatorApiConstants.RESPONSE_PARAMS);
}
@PUT
@Path("{originatorId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a loan originator by ID", description = "Updates a loan originator by its internal ID. Requires UPDATE_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "400", description = "Incorrect format")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String update(@PathParam("originatorId") @Parameter(description = "originatorId") final Long originatorId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateLoanOriginator(originatorId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@PUT
@Path("external-id/{externalId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a loan originator by external ID", description = "Updates a loan originator by its external ID. Requires UPDATE_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "400", description = "Incorrect format")
@ApiResponse(responseCode = "403", description = "Insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String updateByExternalId(@PathParam("externalId") @Parameter(description = "externalId") final String externalId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final Long originatorId = this.loanOriginatorReadPlatformService.resolveIdByExternalId(externalId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateLoanOriginator(originatorId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@DELETE
@Path("{originatorId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a loan originator by ID", description = "Deletes a loan originator by its internal ID. Requires DELETE_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "403", description = "Originator is mapped to loans and cannot be deleted, or insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String delete(@PathParam("originatorId") @Parameter(description = "originatorId") final Long originatorId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteLoanOriginator(originatorId).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
@DELETE
@Path("external-id/{externalId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a loan originator by external ID", description = "Deletes a loan originator by its external ID. Requires DELETE_LOAN_ORIGINATOR permission.")
@ApiResponse(responseCode = "200", description = "OK")
@ApiResponse(responseCode = "403", description = "Originator is mapped to loans and cannot be deleted, or insufficient permissions")
@ApiResponse(responseCode = "404", description = "Originator not found")
public String deleteByExternalId(@PathParam("externalId") @Parameter(description = "externalId") final String externalId) {
final Long originatorId = this.loanOriginatorReadPlatformService.resolveIdByExternalId(externalId);
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteLoanOriginator(originatorId).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
}
}
@@ -0,0 +1,43 @@
/**
* 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.loanorigination.data;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LoanOriginatorData implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
private String externalId;
private String name;
private String status;
private Long originatorTypeId;
private Long channelTypeId;
}
@@ -0,0 +1,53 @@
/**
* 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.loanorigination.data;
import io.swagger.v3.oas.annotations.media.Schema;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "Loan Originator request payload")
public class LoanOriginatorRequestData implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@Schema(description = "Unique external identifier (Revenue Share ID)", example = "REV-SHARE-001", required = true)
private String externalId;
@Schema(description = "Originator name", example = "Acme Merchant")
private String name;
@Schema(description = "Originator status", example = "ACTIVE", allowableValues = { "ACTIVE", "PENDING", "INACTIVE" })
private String status;
@Schema(description = "Code value ID for originator type (from LoanOriginatorType code)", example = "1")
private Long originatorTypeId;
@Schema(description = "Code value ID for channel type (from LoanOriginationChannelType code)", example = "2")
private Long channelTypeId;
}
@@ -20,7 +20,7 @@ package org.apache.fineract.portfolio.loanorigination.domain;
public enum LoanOriginatorStatus { public enum LoanOriginatorStatus {
ACTIVE("ACTIVE"), PENDING("PENDING"); ACTIVE("ACTIVE"), PENDING("PENDING"), INACTIVE("INACTIVE");
private final String value; private final String value;
@@ -0,0 +1,33 @@
/**
* 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.loanorigination.service;
import java.util.List;
import org.apache.fineract.portfolio.loanorigination.data.LoanOriginatorData;
public interface LoanOriginatorReadPlatformService {
List<LoanOriginatorData> retrieveAll();
LoanOriginatorData retrieveById(Long id);
LoanOriginatorData retrieveByExternalId(String externalId);
Long resolveIdByExternalId(String externalId);
}
@@ -0,0 +1,51 @@
/**
* 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.loanorigination.service;
import java.util.List;
import org.apache.fineract.portfolio.loanorigination.data.LoanOriginatorData;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
@Service
@ConditionalOnProperty(value = "fineract.module.loan-origination.enabled", havingValue = "true")
public class LoanOriginatorReadPlatformServiceImpl implements LoanOriginatorReadPlatformService {
private static final String NOT_IMPLEMENTED_MESSAGE = "Not implemented yet";
@Override
public List<LoanOriginatorData> retrieveAll() {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
@Override
public LoanOriginatorData retrieveById(Long id) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
@Override
public LoanOriginatorData retrieveByExternalId(String externalId) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
@Override
public Long resolveIdByExternalId(String externalId) {
throw new UnsupportedOperationException(NOT_IMPLEMENTED_MESSAGE);
}
}
@@ -0,0 +1,31 @@
/**
* 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.loanorigination.service;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
public interface LoanOriginatorWritePlatformService {
CommandProcessingResult create(JsonCommand command);
CommandProcessingResult update(Long id, JsonCommand command);
CommandProcessingResult delete(Long id);
}
@@ -210,4 +210,6 @@ public interface LoanApiConstants {
LoanTransactionType.REPAYMENT // LoanTransactionType.REPAYMENT //
); );
String ORIGINATORS_PARAM = "originators";
} }
@@ -39,6 +39,7 @@ public interface LoanAccountDataMapper {
@Mapping(target = "delinquent.installmentDelinquencyBuckets", ignore = true) @Mapping(target = "delinquent.installmentDelinquencyBuckets", ignore = true)
@Mapping(target = "customData", ignore = true) @Mapping(target = "customData", ignore = true)
@Mapping(target = "product.customData", ignore = true) @Mapping(target = "product.customData", ignore = true)
@Mapping(target = "originators", ignore = true)
LoanAccountDataV1 map(LoanAccountData source); LoanAccountDataV1 map(LoanAccountData source);
} }
@@ -32,6 +32,7 @@ public interface LoanTransactionDataMapper {
@Mapping(target = "externalOwnerId", ignore = true) @Mapping(target = "externalOwnerId", ignore = true)
@Mapping(target = "customData", ignore = true) @Mapping(target = "customData", ignore = true)
@Mapping(target = "reversed", expression = "java(isReversed(source))") @Mapping(target = "reversed", expression = "java(isReversed(source))")
@Mapping(target = "originators", ignore = true)
LoanTransactionDataV1 map(LoanTransactionData source); LoanTransactionDataV1 map(LoanTransactionData source);
default boolean isReversed(LoanTransactionData source) { default boolean isReversed(LoanTransactionData source) {
@@ -1128,6 +1128,29 @@ final class LoansApiResourceSwagger {
public boolean isProcessed; public boolean isProcessed;
} }
@Schema(description = "Originator data associated with the loan")
static final class GetLoansLoanIdOriginatorData {
private GetLoansLoanIdOriginatorData() {}
@Schema(example = "1")
public Long id;
@Schema(example = "REV-SHARE-001")
public String externalId;
@Schema(example = "PP Merchant")
public String name;
@Schema(example = "ACTIVE")
public String status;
@Schema(example = "1")
public Long originatorTypeId;
@Schema(example = "MERCHANT")
public String originatorTypeName;
@Schema(example = "2")
public Long channelTypeId;
@Schema(example = "ONLINE")
public String channelTypeName;
}
@Schema(example = "1") @Schema(example = "1")
public Long id; public Long id;
@Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7") @Schema(example = "95174ff9-1a75-4d72-a413-6f9b1cb988b7")
@@ -1206,6 +1229,8 @@ final class LoansApiResourceSwagger {
public GetLoansLoanIdDelinquencySummary delinquent; public GetLoansLoanIdDelinquencySummary delinquent;
@Schema(description = "Set of charges") @Schema(description = "Set of charges")
public List<GetLoansLoanIdLoanChargeData> charges; public List<GetLoansLoanIdLoanChargeData> charges;
@Schema(description = "List of originators associated with this loan")
public List<GetLoansLoanIdOriginatorData> originators;
public DelinquencyRangeData delinquencyRange; public DelinquencyRangeData delinquencyRange;
@Schema(example = "false") @Schema(example = "false")
public Boolean fraud; public Boolean fraud;
@@ -1399,6 +1424,13 @@ final class LoansApiResourceSwagger {
public List<PostLoansRequestChargeData> charges; public List<PostLoansRequestChargeData> charges;
@Schema(description = """
Optional array of originators to associate with this loan. \
Each entry can reference an existing originator by 'id' or 'externalId'. \
If the global config 'enable_originator_creation_during_loan_application' is enabled, \
non-existing originators will be auto-created using the provided details (name, typeId, channelTypeId).""")
public List<PostLoansOriginatorData> originators;
static final class PostLoansRequestChargeData { static final class PostLoansRequestChargeData {
private PostLoansRequestChargeData() {} private PostLoansRequestChargeData() {}
@@ -1409,6 +1441,27 @@ final class LoansApiResourceSwagger {
@Schema(example = "1.0") @Schema(example = "1.0")
public BigDecimal amount; public BigDecimal amount;
} }
@Schema(description = "Originator data for loan creation request")
public static final class PostLoansOriginatorData {
private PostLoansOriginatorData() {}
@Schema(description = "Originator internal ID (use this OR externalId, not both)", example = "1")
public Long id;
@Schema(description = "Originator external ID (use this OR id, not both)", example = "REV-SHARE-001")
public String externalId;
@Schema(description = "Originator name (used when creating new originator if config enabled)", example = "PP Merchant")
public String name;
@Schema(description = "Code value ID for originator type (from LoanOriginatorType code)", example = "1")
public Long typeId;
@Schema(description = "Code value ID for channel type (from LoanOriginationChannelType code)", example = "2")
public Long channelTypeId;
}
} }
@Schema(description = "PostLoansResponse") @Schema(description = "PostLoansResponse")
@@ -176,7 +176,7 @@ public final class LoanApplicationValidator {
LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY, LoanProductConstants.ENABLE_DOWN_PAYMENT, LoanProductConstants.ENABLE_INSTALLMENT_LEVEL_DELINQUENCY, LoanProductConstants.ENABLE_DOWN_PAYMENT,
LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT, LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT, LoanProductConstants.ENABLE_AUTO_REPAYMENT_DOWN_PAYMENT, LoanProductConstants.DISBURSED_AMOUNT_PERCENTAGE_DOWN_PAYMENT,
LoanApiConstants.INTEREST_RECOGNITION_ON_DISBURSEMENT_DATE, LoanApiConstants.daysInYearCustomStrategyParameterName, LoanApiConstants.INTEREST_RECOGNITION_ON_DISBURSEMENT_DATE, LoanApiConstants.daysInYearCustomStrategyParameterName,
LoanApiConstants.ALLOW_FULL_TERM_FOR_TRANCHE)); LoanApiConstants.ALLOW_FULL_TERM_FOR_TRANCHE, LoanApiConstants.ORIGINATORS_PARAM));
public static final String LOANAPPLICATION_UNDO = "loanapplication.undo"; public static final String LOANAPPLICATION_UNDO = "loanapplication.undo";
private final FromJsonHelper fromApiJsonHelper; private final FromJsonHelper fromApiJsonHelper;
@@ -374,7 +374,7 @@ public abstract class BaseLoanIntegrationTest extends IntegrationTest {
String password = "AKleRbDhK421$"; String password = "AKleRbDhK421$";
String email = firstname + "." + lastname + "@whatever.mifos.org"; String email = firstname + "." + lastname + "@whatever.mifos.org";
Calls.ok(fineractClient().users Calls.ok(fineractClient().users
.create15(new PostUsersRequest().addRolesItem(roleId).email(email).firstname(firstname).lastname(lastname) .create16(new PostUsersRequest().addRolesItem(roleId).email(email).firstname(firstname).lastname(lastname)
.repeatPassword(password).sendPasswordToEmail(false).officeId(1L).username(userName).password(password))); .repeatPassword(password).sendPasswordToEmail(false).officeId(1L).username(userName).password(password)));
// login user // login user
@@ -75,7 +75,7 @@ public class SavingsAccountsExternalIdTest extends IntegrationTest {
PutSavingsAccountsAccountIdRequest request = new PutSavingsAccountsAccountIdRequest(); PutSavingsAccountsAccountIdRequest request = new PutSavingsAccountsAccountIdRequest();
request.setLocale(locale); request.setLocale(locale);
request.setNominalAnnualInterestRate(5.999); request.setNominalAnnualInterestRate(5.999);
Response<PutSavingsAccountsAccountIdResponse> response = okR(fineractClient().savingsAccounts.update21(EXTERNAL_ID, request, "")); Response<PutSavingsAccountsAccountIdResponse> response = okR(fineractClient().savingsAccounts.update22(EXTERNAL_ID, request, ""));
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isNotNull(); assertThat(response.body()).isNotNull();
@@ -104,7 +104,7 @@ public class SavingsAccountsExternalIdTest extends IntegrationTest {
request.dateFormat(dateFormat); request.dateFormat(dateFormat);
request.setLocale(locale); request.setLocale(locale);
request.setActivatedOnDate(formattedDate); request.setActivatedOnDate(formattedDate);
Response<SavingsAccountData> response = okR(fineractClient().savingsAccounts.retrieveOne26(EXTERNAL_ID, false, null, "all")); Response<SavingsAccountData> response = okR(fineractClient().savingsAccounts.retrieveOne27(EXTERNAL_ID, false, null, "all"));
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isNotNull(); assertThat(response.body()).isNotNull();
@@ -132,7 +132,7 @@ public class SavingsAccountsExternalIdTest extends IntegrationTest {
request.dateFormat(dateFormat); request.dateFormat(dateFormat);
request.setLocale(locale); request.setLocale(locale);
request.setActivatedOnDate(formattedDate); request.setActivatedOnDate(formattedDate);
Response<SavingsAccountData> response = okR(fineractClient().savingsAccounts.retrieveOne26(EXTERNAL_ID, false, null, "all")); Response<SavingsAccountData> response = okR(fineractClient().savingsAccounts.retrieveOne27(EXTERNAL_ID, false, null, "all"));
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isNotNull(); assertThat(response.body()).isNotNull();
@@ -147,7 +147,7 @@ public class SavingsAccountsExternalIdTest extends IntegrationTest {
request.dateFormat(dateFormat); request.dateFormat(dateFormat);
request.setLocale(locale); request.setLocale(locale);
request.setActivatedOnDate(formattedDate); request.setActivatedOnDate(formattedDate);
Response<DeleteSavingsAccountsAccountIdResponse> response = okR(fineractClient().savingsAccounts.delete19(EXTERNAL_ID)); Response<DeleteSavingsAccountsAccountIdResponse> response = okR(fineractClient().savingsAccounts.delete20(EXTERNAL_ID));
assertThat(response.isSuccessful()).isTrue(); assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isNotNull(); assertThat(response.body()).isNotNull();
@@ -162,7 +162,7 @@ public class SavingsAccountsExternalIdTest extends IntegrationTest {
request.setLocale(locale); request.setLocale(locale);
request.setActivatedOnDate(formattedDate); request.setActivatedOnDate(formattedDate);
Response<SavingsAccountData> response = Calls Response<SavingsAccountData> response = Calls
.executeU(fineractClient().savingsAccounts.retrieveOne26(EXTERNAL_ID, false, null, "all")); .executeU(fineractClient().savingsAccounts.retrieveOne27(EXTERNAL_ID, false, null, "all"));
assertThat(response.raw().code()).isEqualTo(404); assertThat(response.raw().code()).isEqualTo(404);
} }
@@ -202,19 +202,19 @@ public class UserAdministrationTest extends IntegrationTest {
// User updates its own password // User updates its own password
String updatedPassword = "QwE!5rTy#9uP0u"; String updatedPassword = "QwE!5rTy#9uP0u";
PutUsersUserIdResponse putUsersUserIdResponse = ok(newFineractClient(simpleUsername, originalPassword).users.update26(userId, PutUsersUserIdResponse putUsersUserIdResponse = ok(newFineractClient(simpleUsername, originalPassword).users.update27(userId,
new PutUsersUserIdRequest().password(updatedPassword).repeatPassword(updatedPassword))); new PutUsersUserIdRequest().password(updatedPassword).repeatPassword(updatedPassword)));
Assertions.assertNotNull(putUsersUserIdResponse.getResourceId()); Assertions.assertNotNull(putUsersUserIdResponse.getResourceId());
// From then on the originalPassword is not working anymore // From then on the originalPassword is not working anymore
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> { CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> {
ok(newFineractClient(simpleUsername, originalPassword).users.retrieveOne31(userId)); ok(newFineractClient(simpleUsername, originalPassword).users.retrieveOne32(userId));
}); });
Assertions.assertEquals(401, callFailedRuntimeException.getResponse().raw().code()); Assertions.assertEquals(401, callFailedRuntimeException.getResponse().raw().code());
Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("Unauthorized")); Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("Unauthorized"));
// The update password is still working perfectly // The update password is still working perfectly
GetUsersUserIdResponse ok = ok(newFineractClient(simpleUsername, updatedPassword).users.retrieveOne31(userId)); GetUsersUserIdResponse ok = ok(newFineractClient(simpleUsername, updatedPassword).users.retrieveOne32(userId));
} }
@Test @Test
@@ -242,13 +242,13 @@ public class UserAdministrationTest extends IntegrationTest {
// From then on the originalPassword is not working anymore // From then on the originalPassword is not working anymore
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> { CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> {
ok(newFineractClient(simpleUsername, originalPassword).users.retrieveOne31(userId)); ok(newFineractClient(simpleUsername, originalPassword).users.retrieveOne32(userId));
}); });
Assertions.assertEquals(401, callFailedRuntimeException.getResponse().raw().code()); Assertions.assertEquals(401, callFailedRuntimeException.getResponse().raw().code());
Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("Unauthorized")); Assertions.assertTrue(callFailedRuntimeException.getMessage().contains("Unauthorized"));
// The update password is still working perfectly // The update password is still working perfectly
GetUsersUserIdResponse ok = ok(newFineractClient(simpleUsername, updatedPassword).users.retrieveOne31(userId)); GetUsersUserIdResponse ok = ok(newFineractClient(simpleUsername, updatedPassword).users.retrieveOne32(userId));
} }
@Test @Test
@@ -272,7 +272,7 @@ public class UserAdministrationTest extends IntegrationTest {
// User tries to update it's own roles // User tries to update it's own roles
CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> { CallFailedRuntimeException callFailedRuntimeException = Assertions.assertThrows(CallFailedRuntimeException.class, () -> {
ok(newFineractClient(simpleUsername, password).users.update26(userId, ok(newFineractClient(simpleUsername, password).users.update27(userId,
new PutUsersUserIdRequest().roles(List.of(Long.valueOf(roleId2))))); new PutUsersUserIdRequest().roles(List.of(Long.valueOf(roleId2)))));
}); });
@@ -65,7 +65,7 @@ public class SavingsTestLifecycleExtension implements AfterAllCallback {
try { try {
this.savingsAccountHelper.postInterestForSavings(savingsId.intValue()); this.savingsAccountHelper.postInterestForSavings(savingsId.intValue());
SavingsAccountData savingsAccountData = Calls SavingsAccountData savingsAccountData = Calls
.ok(FineractClientHelper.getFineractClient().savingsAccounts.retrieveOne25(savingsId, false, null, "all")); .ok(FineractClientHelper.getFineractClient().savingsAccounts.retrieveOne26(savingsId, false, null, "all"));
BigDecimal accountBalance = MathUtil.subtract(savingsAccountData.getSummary().getAvailableBalance(), BigDecimal accountBalance = MathUtil.subtract(savingsAccountData.getSummary().getAvailableBalance(),
savingsAccountData.getMinRequiredBalance(), MathContext.DECIMAL64); savingsAccountData.getMinRequiredBalance(), MathContext.DECIMAL64);
if (accountBalance.compareTo(BigDecimal.ZERO) > 0) { if (accountBalance.compareTo(BigDecimal.ZERO) > 0) {
@@ -128,7 +128,7 @@ public class BaseSavingsIntegrationTest extends IntegrationTest {
} }
protected PostSavingsProductsResponse createProduct(PostSavingsProductsRequest productsRequest) { protected PostSavingsProductsResponse createProduct(PostSavingsProductsRequest productsRequest) {
return ok(fineractClient().savingsProducts.create13(productsRequest)); return ok(fineractClient().savingsProducts.create14(productsRequest));
} }
protected PostSavingsAccountsRequest applySavingsRequest(Long clientId, Long productId, String submittedDate) { protected PostSavingsAccountsRequest applySavingsRequest(Long clientId, Long productId, String submittedDate) {
@@ -162,11 +162,11 @@ public class BaseSavingsIntegrationTest extends IntegrationTest {
} }
protected SavingsAccountData getSavingsAccount(Long savingsId) { protected SavingsAccountData getSavingsAccount(Long savingsId) {
return ok(fineractClient().savingsAccounts.retrieveOne25(savingsId, false, null, "transactions")); return ok(fineractClient().savingsAccounts.retrieveOne26(savingsId, false, null, "transactions"));
} }
protected List<SavingsAccountTransactionData> getTransactions(Long savingsId) { protected List<SavingsAccountTransactionData> getTransactions(Long savingsId) {
return ok(fineractClient().savingsAccounts.retrieveOne25(savingsId, false, null, "transactions")).getTransactions(); return ok(fineractClient().savingsAccounts.retrieveOne26(savingsId, false, null, "transactions")).getTransactions();
} }
protected void verifyNoTransactions(Long savingsId) { protected void verifyNoTransactions(Long savingsId) {
@@ -174,7 +174,7 @@ public class BaseSavingsIntegrationTest extends IntegrationTest {
} }
protected void verifyTransactions(Long savingsId, Transaction... transactions) { protected void verifyTransactions(Long savingsId, Transaction... transactions) {
SavingsAccountData savingsDetails = ok(fineractClient().savingsAccounts.retrieveOne25(savingsId, false, null, "transactions")); SavingsAccountData savingsDetails = ok(fineractClient().savingsAccounts.retrieveOne26(savingsId, false, null, "transactions"));
if (transactions == null || transactions.length == 0) { if (transactions == null || transactions.length == 0) {
Assertions.assertTrue(savingsDetails.getTransactions().isEmpty(), "No transaction is expected on savings account " + savingsId); Assertions.assertTrue(savingsDetails.getTransactions().isEmpty(), "No transaction is expected on savings account " + savingsId);
} else { } else {