nikpawar89 commented on a change in pull request #1235: URL: https://github.com/apache/fineract/pull/1235#discussion_r546415588
########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/data/CreditBureauConfigurations.java ########## @@ -0,0 +1,25 @@ +/** + * 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.infrastructure.creditbureau.data; + +public enum CreditBureauConfigurations { + + THITSAWORKS, subscriptionId, subscriptionKey, userName, password; Review comment: enum values should be all caps ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditReport.java ########## @@ -0,0 +1,63 @@ +/** + * 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.infrastructure.creditbureau.domain; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Table; +import org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Entity +@Table(name = "m_creditreport") +public final class CreditReport extends AbstractPersistableCustom { + + @Column(name = "creditBureauId") + private Long creditBureauId; + + @Column(name = "nrc") + private String nrc; Review comment: you can rename nrc to nationalID to make it sound as generic ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/api/CreditBureauIntegrationAPI.java ########## @@ -0,0 +1,160 @@ +/** + * 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.infrastructure.creditbureau.api; + +import com.google.gson.Gson; +import io.swagger.v3.oas.annotations.Parameter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +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.creditbureau.data.CreditReportData; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportReadPlatformService; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportWritePlatformService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +@Path("/creditBureauIntegration") +@Component +@Scope("singleton") +public class CreditBureauIntegrationAPI { + + private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "creditBureauId", "nrc", "creditReport")); + + private final PlatformSecurityContext context; + private final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer; + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final ApiRequestParameterHelper apiRequestParameterHelper; + private final CreditReportWritePlatformService creditReportWritePlatformService; + private final CreditReportReadPlatformService creditReportReadPlatformService; + private final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer; + private static final Logger LOG = LoggerFactory.getLogger(CreditBureauIntegrationAPI.class); + + @Autowired + public CreditBureauIntegrationAPI(final PlatformSecurityContext context, + final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer, + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final ApiRequestParameterHelper apiRequestParameterHelper, + final CreditReportWritePlatformService creditReportWritePlatformService, + final CreditReportReadPlatformService creditReportReadPlatformService, + final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer) { + this.context = context; + this.toCreditReportApiJsonSerializer = toCreditReportApiJsonSerializer; + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.apiRequestParameterHelper = apiRequestParameterHelper; + this.creditReportWritePlatformService = creditReportWritePlatformService; + this.creditReportReadPlatformService = creditReportReadPlatformService; + this.toApiJsonSerializer = toApiJsonSerializer; + + } + + @POST + @Path("creditReport") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String postCreditReport(@Context final UriInfo uriInfo, @RequestParam("params") final Map<String, Object> params) { Review comment: this should be fetch credit report not post ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/api/CreditBureauIntegrationAPI.java ########## @@ -0,0 +1,160 @@ +/** + * 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.infrastructure.creditbureau.api; + +import com.google.gson.Gson; +import io.swagger.v3.oas.annotations.Parameter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +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.creditbureau.data.CreditReportData; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportReadPlatformService; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportWritePlatformService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +@Path("/creditBureauIntegration") +@Component +@Scope("singleton") +public class CreditBureauIntegrationAPI { + + private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "creditBureauId", "nrc", "creditReport")); + + private final PlatformSecurityContext context; + private final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer; + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final ApiRequestParameterHelper apiRequestParameterHelper; + private final CreditReportWritePlatformService creditReportWritePlatformService; + private final CreditReportReadPlatformService creditReportReadPlatformService; + private final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer; + private static final Logger LOG = LoggerFactory.getLogger(CreditBureauIntegrationAPI.class); + + @Autowired + public CreditBureauIntegrationAPI(final PlatformSecurityContext context, + final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer, + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final ApiRequestParameterHelper apiRequestParameterHelper, + final CreditReportWritePlatformService creditReportWritePlatformService, + final CreditReportReadPlatformService creditReportReadPlatformService, + final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer) { + this.context = context; + this.toCreditReportApiJsonSerializer = toCreditReportApiJsonSerializer; + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.apiRequestParameterHelper = apiRequestParameterHelper; + this.creditReportWritePlatformService = creditReportWritePlatformService; + this.creditReportReadPlatformService = creditReportReadPlatformService; + this.toApiJsonSerializer = toApiJsonSerializer; + + } + + @POST + @Path("creditReport") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String postCreditReport(@Context final UriInfo uriInfo, @RequestParam("params") final Map<String, Object> params) { + + Gson gson = new Gson(); + final String json = gson.toJson(params); + final CommandWrapper commandRequest = new CommandWrapperBuilder().getCreditReport().withJson(json).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toCreditReportApiJsonSerializer.serialize(result); + + } + + // saves fetched-creditreport into database + @POST + @Path("saveCreditReport") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String saveCreditReport(@Parameter(hidden = true) final String apiRequestBodyAsJson, + @QueryParam("creditBureauId") @Parameter(description = "creditBureauId") final Long creditBureauId, + @QueryParam("creditReportNumber") @Parameter(description = "creditReportNumber") final String creditReportNumber) { + + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .saveCreditReport(creditBureauId, creditReportNumber) // creditReportNumber is a NRC number for + // Thitsawork + .withJson(apiRequestBodyAsJson) // apiRequestBodyAsJson is a creditReport + .build(); // + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toCreditReportApiJsonSerializer.serialize(result); + + } + + // fetch saved creditReports(NRC) from DB by creditBureauId, to select for downloading and deleting the reports + @GET + @Path("creditReport/{creditBureauId}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String getSavedCreditReport(@PathParam("creditBureauId") @Parameter(description = "creditBureauId") final Long creditBureauId, + @Context final UriInfo uriInfo) { + + this.context.authenticatedUser(); + + final Collection<CreditReportData> creditReport = this.creditReportReadPlatformService.retrieveCreditReport(creditBureauId); + + final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return this.toApiJsonSerializer.serialize(settings, creditReport, RESPONSE_DATA_PARAMETERS); + + } + + // deletes saved creditReports from database + @DELETE + @Path("deleteCreditReport/{creditBureauId}") Review comment: rename creditBureauID to creditReportID ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/api/CreditBureauIntegrationAPI.java ########## @@ -0,0 +1,160 @@ +/** + * 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.infrastructure.creditbureau.api; + +import com.google.gson.Gson; +import io.swagger.v3.oas.annotations.Parameter; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; +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.creditbureau.data.CreditReportData; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportReadPlatformService; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportWritePlatformService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.annotation.RequestParam; + +@Path("/creditBureauIntegration") +@Component +@Scope("singleton") +public class CreditBureauIntegrationAPI { + + private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("id", "creditBureauId", "nrc", "creditReport")); + + private final PlatformSecurityContext context; + private final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer; + private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; + private final ApiRequestParameterHelper apiRequestParameterHelper; + private final CreditReportWritePlatformService creditReportWritePlatformService; + private final CreditReportReadPlatformService creditReportReadPlatformService; + private final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer; + private static final Logger LOG = LoggerFactory.getLogger(CreditBureauIntegrationAPI.class); + + @Autowired + public CreditBureauIntegrationAPI(final PlatformSecurityContext context, + final DefaultToApiJsonSerializer<CreditReportData> toCreditReportApiJsonSerializer, + final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, + final ApiRequestParameterHelper apiRequestParameterHelper, + final CreditReportWritePlatformService creditReportWritePlatformService, + final CreditReportReadPlatformService creditReportReadPlatformService, + final DefaultToApiJsonSerializer<CreditReportData> toApiJsonSerializer) { + this.context = context; + this.toCreditReportApiJsonSerializer = toCreditReportApiJsonSerializer; + this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; + this.apiRequestParameterHelper = apiRequestParameterHelper; + this.creditReportWritePlatformService = creditReportWritePlatformService; + this.creditReportReadPlatformService = creditReportReadPlatformService; + this.toApiJsonSerializer = toApiJsonSerializer; + + } + + @POST + @Path("creditReport") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String postCreditReport(@Context final UriInfo uriInfo, @RequestParam("params") final Map<String, Object> params) { + + Gson gson = new Gson(); + final String json = gson.toJson(params); + final CommandWrapper commandRequest = new CommandWrapperBuilder().getCreditReport().withJson(json).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toCreditReportApiJsonSerializer.serialize(result); + + } + + // saves fetched-creditreport into database + @POST + @Path("saveCreditReport") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public String saveCreditReport(@Parameter(hidden = true) final String apiRequestBodyAsJson, + @QueryParam("creditBureauId") @Parameter(description = "creditBureauId") final Long creditBureauId, + @QueryParam("creditReportNumber") @Parameter(description = "creditReportNumber") final String creditReportNumber) { + + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .saveCreditReport(creditBureauId, creditReportNumber) // creditReportNumber is a NRC number for + // Thitsawork + .withJson(apiRequestBodyAsJson) // apiRequestBodyAsJson is a creditReport + .build(); // + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toCreditReportApiJsonSerializer.serialize(result); + + } + + // fetch saved creditReports(NRC) from DB by creditBureauId, to select for downloading and deleting the reports + @GET + @Path("creditReport/{creditBureauId}") Review comment: rename creditBureauID to creditReportID ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/data/CreditBureauReportData.java ########## @@ -0,0 +1,62 @@ +/** + * 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.infrastructure.creditbureau.data; + +import java.io.Serializable; + +public final class CreditBureauReportData implements Serializable { + + @SuppressWarnings("unused") + private final String name; + + private final String gender; + + private final String address; + + private final String creditScore; + + private final String borrowerInfo; + + private final String activeLoans; Review comment: is this plain string or do you want to put this in array or some collection? ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/data/CreditBureauReportData.java ########## @@ -0,0 +1,62 @@ +/** + * 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.infrastructure.creditbureau.data; + +import java.io.Serializable; + +public final class CreditBureauReportData implements Serializable { + + @SuppressWarnings("unused") + private final String name; + + private final String gender; + + private final String address; + + private final String creditScore; + + private final String borrowerInfo; + + private final String activeLoans; + + private final String paidLoans; Review comment: same here, this could be multiple accounts, so you may want to put it in array/collections. You may also rename this to closedAccounts and rename activeLoans to openAccounts. I am fine if you don't rename it. ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/domain/CreditReportRepository.java ########## @@ -0,0 +1,32 @@ +/** + * 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.infrastructure.creditbureau.domain; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +public interface CreditReportRepository extends JpaRepository<CreditReport, Long>, JpaSpecificationExecutor<CreditReport> { + + @Query("SELECT creditBureauReport from CreditReport creditBureauReport where creditBureauReport.nrc = :nrc and creditBureauReport.creditBureauId = :creditBureauId ") + CreditReport getThitsaWorksCreditReport(@Param("creditBureauId") Long creditBureauId, @Param("nrc") String nrc); Review comment: I think If you rename nrc to nationalID, I would say other credit bureaus would also have such a ID. So this can be generic as well. We may revisit this later, if we think this is not the case. ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/data/CreditReportReadPlatformServiceImpl.java ########## @@ -0,0 +1,74 @@ +/** + * 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.infrastructure.creditbureau.data; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.service.CreditReportReadPlatformService; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Service; + +@Service +public class CreditReportReadPlatformServiceImpl implements CreditReportReadPlatformService { + + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + + @Autowired + public CreditReportReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + private static final class CreditReportDataMapper implements RowMapper<CreditReportData> { + + public String schema() { + return " c.id as id, c.creditBureauId as creditBureauId , c.nrc as nrc from m_creditreport c "; + } + + @Override + public CreditReportData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + + final Long id = rs.getLong("id"); + final Long creditBureauId = rs.getLong("creditBureauId"); + final String nrc = rs.getString("nrc"); + // final byte[] creditReports = rs.getBytes("creditReports"); + + return CreditReportData.instance(id, creditBureauId, nrc);// , creditReports); + } + } + + @Override + public Collection<CreditReportData> retrieveCreditReport(Long creditBureauId) { Review comment: I don't see we are retrieving credit report. ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/data/CreditBureauReportData.java ########## @@ -0,0 +1,62 @@ +/** + * 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.infrastructure.creditbureau.data; + +import java.io.Serializable; + +public final class CreditBureauReportData implements Serializable { + + @SuppressWarnings("unused") + private final String name; + + private final String gender; + + private final String address; + + private final String creditScore; + + private final String borrowerInfo; + + private final String activeLoans; + + private final String paidLoans; + + /* + * private final Object borrowerInformation; private final Object creditScore; private final Object activeLoans; Review comment: remove commented code. ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditReportWritePlatformServiceImpl.java ########## @@ -0,0 +1,218 @@ +/** + * 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.infrastructure.creditbureau.service; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import javax.persistence.PersistenceException; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; +import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurations; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureau; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfigurationRepositoryWrapper; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauLoanProductMappingRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditReport; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditReportRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper; +import org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class CreditReportWritePlatformServiceImpl implements CreditReportWritePlatformService { + + private final PlatformSecurityContext context; + private final CreditBureauConfigurationRepositoryWrapper configDataRepository; + private final CreditBureauRepository creditBureauRepository; + private final CreditReportRepository creditReportRepository; + private final ThitsaWorksCreditBureauIntegrationWritePlatformService thitsaWorksCreditBureauIntegrationWritePlatformService; + private final ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl; + private final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); + private final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource("creditBureauIntegration"); + + @Autowired + public CreditReportWritePlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, + final FromJsonHelper fromApiJsonHelper, final TokenRepositoryWrapper tokenRepository, + final CreditBureauConfigurationRepositoryWrapper configDataRepository, + final CreditBureauTokenCommandFromApiJsonDeserializer fromApiJsonDeserializer, + final CreditBureauLoanProductMappingRepository loanProductMappingRepository, + final CreditBureauRepository creditBureauRepository, final CreditReportRepository creditReportRepository, + final ThitsaWorksCreditBureauIntegrationWritePlatformService thitsaWorksCreditBureauIntegrationWritePlatformService, + final ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl) { + this.context = context; + this.configDataRepository = configDataRepository; + this.creditBureauRepository = creditBureauRepository; + this.creditReportRepository = creditReportRepository; + this.thitsaWorksCreditBureauIntegrationWritePlatformService = thitsaWorksCreditBureauIntegrationWritePlatformService; + this.thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl = thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl; + } + + @Override + @Transactional + public CommandProcessingResult getCreditReport(JsonCommand command) { + + try { + Long creditBureauID = command.longValueOfParameterNamed("creditBureauID"); + + Optional<String> creditBureauName = getCreditBureau(creditBureauID); + + if (creditBureauName.isEmpty()) { + baseDataValidator.reset().failWithCode("creditBureau.has.not.been.Integrated"); + throw new PlatformApiDataValidationException("creditBureau.has.not.been.Integrated", "creditBureau.has.not.been.Integrated", + dataValidationErrors); + } + + if (Objects.equals(creditBureauName.get(), CreditBureauConfigurations.THITSAWORKS.toString())) { + + // CreditBureauToken creditBureauToken = this.thitsaWorksCreditBureauIntegrationWritePlatformService + // .createToken(creditBureauID); + + CreditBureauReportData reportobj = this.thitsaWorksCreditBureauIntegrationWritePlatformService + .getCreditReportFromThitsaWorks(command); + + // return new + // CommandProcessingResultBuilder().withCreditReport(reportobj).withCreditBureauToken(creditBureauToken).build(); + return new CommandProcessingResultBuilder().withCreditReport(reportobj).build(); + } + + baseDataValidator.reset().failWithCode("creditBureau.has.not.been.Integrated"); + throw new PlatformApiDataValidationException("creditBureau.has.not.been.Integrated", "creditBureau.has.not.been.Integrated", + dataValidationErrors); + + } catch (final DataIntegrityViolationException dve) { + handleTokenDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); + return CommandProcessingResult.empty(); + } catch (final PersistenceException ee) { + Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); + handleTokenDataIntegrityIssues(command, throwable, ee); + return CommandProcessingResult.empty(); + } + + } + + private Optional<String> getCreditBureau(Long creditBureauID) { + + if (creditBureauID != null) { + Optional<CreditBureau> creditBureau = this.creditBureauRepository.findById(creditBureauID); + + if (creditBureau.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(creditBureau.get().getName()); + + } + + return Optional.empty(); + } + + // saving the fetched creditreport in database + @Override + @Transactional + public CommandProcessingResult saveCreditReport(Long creditBureauId, String creditReportNumber, JsonCommand command) { + + try { + this.context.authenticatedUser(); + + Optional<String> creditBureauName = getCreditBureau(creditBureauId); + CreditReport creditReport = null; + + if (Objects.equals(creditBureauName.get(), CreditBureauConfigurations.THITSAWORKS.toString())) { + + creditReport = creditReportRepository.getThitsaWorksCreditReport(creditBureauId, creditReportNumber); + + // checks whether the creditReport for same NRC was saved before. if yes, then deletes it and replaces + // it with new one. + if (creditReport != null) { + this.creditReportRepository.delete(creditReport); + creditReport = null; + } + + if (creditReport == null) { Review comment: I don't think you need to check if null here, it would always be null. ########## File path: fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditReportWritePlatformServiceImpl.java ########## @@ -0,0 +1,218 @@ +/** + * 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.infrastructure.creditbureau.service; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import javax.persistence.PersistenceException; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; +import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.exception.PlatformDataIntegrityException; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurations; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauReportData; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureau; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauConfigurationRepositoryWrapper; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauLoanProductMappingRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditReport; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditReportRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.TokenRepositoryWrapper; +import org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauTokenCommandFromApiJsonDeserializer; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataIntegrityViolationException; +import org.springframework.orm.jpa.JpaSystemException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class CreditReportWritePlatformServiceImpl implements CreditReportWritePlatformService { + + private final PlatformSecurityContext context; + private final CreditBureauConfigurationRepositoryWrapper configDataRepository; + private final CreditBureauRepository creditBureauRepository; + private final CreditReportRepository creditReportRepository; + private final ThitsaWorksCreditBureauIntegrationWritePlatformService thitsaWorksCreditBureauIntegrationWritePlatformService; + private final ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl; + private final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); + private final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource("creditBureauIntegration"); + + @Autowired + public CreditReportWritePlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource, + final FromJsonHelper fromApiJsonHelper, final TokenRepositoryWrapper tokenRepository, + final CreditBureauConfigurationRepositoryWrapper configDataRepository, + final CreditBureauTokenCommandFromApiJsonDeserializer fromApiJsonDeserializer, + final CreditBureauLoanProductMappingRepository loanProductMappingRepository, + final CreditBureauRepository creditBureauRepository, final CreditReportRepository creditReportRepository, + final ThitsaWorksCreditBureauIntegrationWritePlatformService thitsaWorksCreditBureauIntegrationWritePlatformService, + final ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl) { + this.context = context; + this.configDataRepository = configDataRepository; + this.creditBureauRepository = creditBureauRepository; + this.creditReportRepository = creditReportRepository; + this.thitsaWorksCreditBureauIntegrationWritePlatformService = thitsaWorksCreditBureauIntegrationWritePlatformService; + this.thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl = thitsaWorksCreditBureauIntegrationWritePlatformServiceImpl; + } + + @Override + @Transactional + public CommandProcessingResult getCreditReport(JsonCommand command) { + + try { + Long creditBureauID = command.longValueOfParameterNamed("creditBureauID"); + + Optional<String> creditBureauName = getCreditBureau(creditBureauID); + + if (creditBureauName.isEmpty()) { + baseDataValidator.reset().failWithCode("creditBureau.has.not.been.Integrated"); + throw new PlatformApiDataValidationException("creditBureau.has.not.been.Integrated", "creditBureau.has.not.been.Integrated", + dataValidationErrors); + } + + if (Objects.equals(creditBureauName.get(), CreditBureauConfigurations.THITSAWORKS.toString())) { + + // CreditBureauToken creditBureauToken = this.thitsaWorksCreditBureauIntegrationWritePlatformService + // .createToken(creditBureauID); + + CreditBureauReportData reportobj = this.thitsaWorksCreditBureauIntegrationWritePlatformService + .getCreditReportFromThitsaWorks(command); + + // return new + // CommandProcessingResultBuilder().withCreditReport(reportobj).withCreditBureauToken(creditBureauToken).build(); + return new CommandProcessingResultBuilder().withCreditReport(reportobj).build(); + } + + baseDataValidator.reset().failWithCode("creditBureau.has.not.been.Integrated"); + throw new PlatformApiDataValidationException("creditBureau.has.not.been.Integrated", "creditBureau.has.not.been.Integrated", + dataValidationErrors); + + } catch (final DataIntegrityViolationException dve) { + handleTokenDataIntegrityIssues(command, dve.getMostSpecificCause(), dve); + return CommandProcessingResult.empty(); + } catch (final PersistenceException ee) { + Throwable throwable = ExceptionUtils.getRootCause(ee.getCause()); + handleTokenDataIntegrityIssues(command, throwable, ee); + return CommandProcessingResult.empty(); + } + + } + + private Optional<String> getCreditBureau(Long creditBureauID) { + + if (creditBureauID != null) { + Optional<CreditBureau> creditBureau = this.creditBureauRepository.findById(creditBureauID); + + if (creditBureau.isEmpty()) { + return Optional.empty(); + } + + return Optional.of(creditBureau.get().getName()); + + } + + return Optional.empty(); + } + + // saving the fetched creditreport in database + @Override + @Transactional + public CommandProcessingResult saveCreditReport(Long creditBureauId, String creditReportNumber, JsonCommand command) { + + try { + this.context.authenticatedUser(); + + Optional<String> creditBureauName = getCreditBureau(creditBureauId); + CreditReport creditReport = null; + + if (Objects.equals(creditBureauName.get(), CreditBureauConfigurations.THITSAWORKS.toString())) { + + creditReport = creditReportRepository.getThitsaWorksCreditReport(creditBureauId, creditReportNumber); + + // checks whether the creditReport for same NRC was saved before. if yes, then deletes it and replaces + // it with new one. + if (creditReport != null) { + this.creditReportRepository.delete(creditReport); + creditReport = null; Review comment: don't set it as null and remove the null check below ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
