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
@@ -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 {
ACTIVE("ACTIVE"), PENDING("PENDING");
ACTIVE("ACTIVE"), PENDING("PENDING"), INACTIVE("INACTIVE");
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);
}