Repository: fineract Updated Branches: refs/heads/develop 5473e3713 -> 06c959ebb
http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/handler/UpdateCreditBureauLoanProductMappingCommandHandler.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/handler/UpdateCreditBureauLoanProductMappingCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/handler/UpdateCreditBureauLoanProductMappingCommandHandler.java new file mode 100644 index 0000000..aa3d845 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/handler/UpdateCreditBureauLoanProductMappingCommandHandler.java @@ -0,0 +1,49 @@ +/** + * 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.handler; + +import org.apache.fineract.commands.annotation.CommandType; +import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.creditbureau.service.CreditBureauLoanProductMappingWritePlatformService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@CommandType(entity = "CREDITBUREAU_LOANPRODUCT_MAPPING", action = "UPDATE") +public class UpdateCreditBureauLoanProductMappingCommandHandler implements NewCommandSourceHandler { + + private final CreditBureauLoanProductMappingWritePlatformService writePlatformService; + + @Autowired + public UpdateCreditBureauLoanProductMappingCommandHandler(final CreditBureauLoanProductMappingWritePlatformService writePlatformService) { + + this.writePlatformService = writePlatformService; + } + + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { + + return this.writePlatformService.updateCreditBureauLoanProductMapping(command); + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauCommandFromApiJsonDeserializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauCommandFromApiJsonDeserializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauCommandFromApiJsonDeserializer.java new file mode 100644 index 0000000..fdc9acc --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauCommandFromApiJsonDeserializer.java @@ -0,0 +1,90 @@ +/** + * 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.serialization; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; +import org.apache.fineract.infrastructure.core.exception.InvalidJsonException; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.joda.time.LocalDate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; + +@Component +public class CreditBureauCommandFromApiJsonDeserializer { + + private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("alias", "is_active")); + + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public CreditBureauCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForCreate(final String json, final Long creditBureauId) { + if (StringUtils.isBlank(json)) { + throw new InvalidJsonException(); + } + + final Type typeOfMap = new TypeToken<Map<String, Object>>() { + }.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); + + final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource("CreditBureau"); + + final JsonElement element = this.fromApiJsonHelper.parse(json); + + baseDataValidator.reset().value(creditBureauId).notBlank().integerGreaterThanZero(); + + final String alias = this.fromApiJsonHelper.extractStringNamed("alias", element); + baseDataValidator.reset().parameter("alias").value(alias).notNull().notBlank().notExceedingLengthOf(100); + + final String is_activeParameter = "is_active"; + if (this.fromApiJsonHelper.parameterExists(is_activeParameter, element)) { + final boolean is_active = this.fromApiJsonHelper.extractBooleanNamed("is_active", element); + baseDataValidator.reset().parameter("is_active").value(is_active).notNull().notBlank().trueOrFalseRequired(is_active); + } + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + } + + private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); + } + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauLoanProductCommandFromApiJsonDeserializer.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauLoanProductCommandFromApiJsonDeserializer.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauLoanProductCommandFromApiJsonDeserializer.java new file mode 100644 index 0000000..4aa2fb6 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/serialization/CreditBureauLoanProductCommandFromApiJsonDeserializer.java @@ -0,0 +1,137 @@ +/** + * 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.serialization; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.fineract.infrastructure.core.data.ApiParameterError; +import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder; +import org.apache.fineract.infrastructure.core.exception.InvalidJsonException; +import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException; +import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; + +@Component +public class CreditBureauLoanProductCommandFromApiJsonDeserializer { + private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("loan_product_id", + "is_creditcheck_mandatory", "skip_creditcheck_in_failure", "stale_period", "is_active", "locale")); + + private final FromJsonHelper fromApiJsonHelper; + + @Autowired + public CreditBureauLoanProductCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper) { + this.fromApiJsonHelper = fromApiJsonHelper; + } + + public void validateForCreate(final String json, final Long cb_id) { + if (StringUtils.isBlank(json)) { + throw new InvalidJsonException(); + } + + final Type typeOfMap = new TypeToken<Map<String, Object>>() { + }.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); + + final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); + final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) + .resource("CREDITBUREAU_LOANPRODUCT_MAPPING"); + + final JsonElement element = this.fromApiJsonHelper.parse(json); + + baseDataValidator.reset().value(cb_id).notBlank().integerGreaterThanZero(); + + final long loan_product_id = this.fromApiJsonHelper.extractLongNamed("loan_product_id", element); + baseDataValidator.reset().parameter("loan_product_id").value(loan_product_id).notBlank() + .integerGreaterThanZero(); + System.out.println("loan product id " + loan_product_id); + + if(this.fromApiJsonHelper.extractBooleanNamed("is_creditcheck_mandatory",element)!= null) + { + final boolean is_creditcheck_mandatory = this.fromApiJsonHelper.extractBooleanNamed("is_creditcheck_mandatory", + element); + baseDataValidator.reset().parameter("is_creditcheck_mandatory").value(is_creditcheck_mandatory).notBlank() + .trueOrFalseRequired(is_creditcheck_mandatory); + } + else + { + baseDataValidator.reset().parameter("is_creditcheck_mandatory").value(this.fromApiJsonHelper.extractBooleanNamed("is_creditcheck_mandatory", + element)).notBlank() + .trueOrFalseRequired(this.fromApiJsonHelper.extractBooleanNamed("is_creditcheck_mandatory", + element)); + } + + + if( this.fromApiJsonHelper.extractBooleanNamed("skip_creditcheck_in_failure", element)!=null) + { + final boolean skip_creditcheck_in_failure = this.fromApiJsonHelper.extractBooleanNamed("skip_creditcheck_in_failure", element); + baseDataValidator.reset().parameter("skip_creditcheck_in_failure").value(skip_creditcheck_in_failure).notBlank().trueOrFalseRequired(skip_creditcheck_in_failure); + + } + else + { + baseDataValidator.reset().parameter("skip_creditcheck_in_failure").value(this.fromApiJsonHelper.extractBooleanNamed("skip_creditcheck_in_failure", element)).notBlank().trueOrFalseRequired(this.fromApiJsonHelper.extractBooleanNamed("skip_creditcheck_in_failure", element)); + } + + + if(this.fromApiJsonHelper.extractLongNamed("stale_period", element)!=null) + { + final long stale_period = this.fromApiJsonHelper.extractLongNamed("stale_period", element); + baseDataValidator.reset().parameter("stale_period").value(stale_period).notBlank().integerGreaterThanZero(); + } + else + { + baseDataValidator.reset().parameter("stale_period").value(this.fromApiJsonHelper.extractLongNamed("stale_period", element)).notBlank().integerGreaterThanZero(); + } + + + if(this.fromApiJsonHelper.extractBooleanNamed("is_active", element)!=null) + { + Boolean is_active = this.fromApiJsonHelper.extractBooleanNamed("is_active", element); + if (is_active == null) { + is_active = false; + } else { + + baseDataValidator.reset().parameter("is_active").value(is_active).notBlank().trueOrFalseRequired(is_active); + } + } + + + + throwExceptionIfValidationWarningsExist(dataValidationErrors); + + } + + private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) { + if (!dataValidationErrors.isEmpty()) { + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", dataValidationErrors); + } + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformService.java new file mode 100644 index 0000000..d5a74f2 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformService.java @@ -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.infrastructure.creditbureau.service; + +import java.util.Collection; + +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauLoanProductMappingData; + +public interface CreditBureauLoanProductMappingReadPlatformService { + + Collection<CreditBureauLoanProductMappingData> readCreditBureauLoanProductMapping(); + + Collection<CreditBureauLoanProductMappingData> fetchLoanProducts(); + + CreditBureauLoanProductMappingData readMappingByLoanId(long loanProductId); + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformServiceImpl.java new file mode 100644 index 0000000..b5f7145 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingReadPlatformServiceImpl.java @@ -0,0 +1,122 @@ +/** + * 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.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauLoanProductMappingData; +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 CreditBureauLoanProductMappingReadPlatformServiceImpl implements CreditBureauLoanProductMappingReadPlatformService { + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + + @Autowired + public CreditBureauLoanProductMappingReadPlatformServiceImpl(final PlatformSecurityContext context, + final RoutingDataSource dataSource) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + private static final class CreditBureauLoanProductMapper implements RowMapper<CreditBureauLoanProductMappingData> { + + public String schema() { + return "cblp.id as mappingId, cblp.organisation_creditbureau_id as orgcbId," + + "orgcb.alias as alias,concat( cb.product,' - ' ,cb.name,' - ',cb.country) as creditbureau," + + "cblp.loan_product_id as lpId,lp.name as loan_product_name,cblp.is_creditcheck_mandatory as crCheck,cblp.skip_creditcheck_in_failure as skipcheck," + + "cblp.stale_period as staleperiod,cblp.is_active as is_active from" + + " m_creditbureau_loanproduct_mapping cblp, m_organisation_creditbureau orgcb,m_product_loan lp,m_creditbureau cb" + + " where cblp.organisation_creditbureau_id=orgcb.id and cblp.loan_product_id=lp.id and orgcb.creditbureau_id=cb.id"; + } + + @Override + public CreditBureauLoanProductMappingData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + throws SQLException { + final Long mapping_id = rs.getLong("mappingId"); + final Long orgcbID = rs.getLong("orgcbId"); + final String alias = rs.getString("alias"); + final String credit_bureau_name = rs.getString("creditbureau"); + final String loan_product_name = rs.getString("loan_product_name"); + final Long lpId = rs.getLong("lpId"); + final boolean is_creditcheck_mandatory = rs.getBoolean("crCheck"); + final boolean skip_credit_check_in_failure = rs.getBoolean("skipcheck"); + final int stale_period = rs.getInt("staleperiod"); + final boolean is_active = rs.getBoolean("is_active"); + + return CreditBureauLoanProductMappingData.instance(mapping_id, orgcbID, alias, credit_bureau_name, loan_product_name, + lpId, is_creditcheck_mandatory, skip_credit_check_in_failure, stale_period, is_active); + } + } + + private static final class LoanProductMapper implements RowMapper<CreditBureauLoanProductMappingData> { + + public String schema() { + return "lp.name as loan_product_name,lp.id as loanid from m_product_loan lp"; + } + + @Override + public CreditBureauLoanProductMappingData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + throws SQLException { + final Long loanid = rs.getLong("loanid"); + + final String loan_product_name = rs.getString("loan_product_name"); + + return CreditBureauLoanProductMappingData.instance1(loan_product_name, loanid); + } + } + + @Override + public Collection<CreditBureauLoanProductMappingData> readCreditBureauLoanProductMapping() { + this.context.authenticatedUser(); + + final CreditBureauLoanProductMapper rm = new CreditBureauLoanProductMapper(); + final String sql = "select " + rm.schema() + " order by cblp.id"; + + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } + + @Override + public CreditBureauLoanProductMappingData readMappingByLoanId(long loanProductId) { + this.context.authenticatedUser(); + + final CreditBureauLoanProductMapper rm = new CreditBureauLoanProductMapper(); + final String sql = "select " + rm.schema() + " and cblp.loan_product_id=?"; + + return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanProductId }); + } + + @Override + public Collection<CreditBureauLoanProductMappingData> fetchLoanProducts() { + this.context.authenticatedUser(); + + final LoanProductMapper rm = new LoanProductMapper(); + final String sql = "select " + rm.schema() + " order by lp.id"; + + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformService.java new file mode 100644 index 0000000..41e2977 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformService.java @@ -0,0 +1,30 @@ +/** + * 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 org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; + +public interface CreditBureauLoanProductMappingWritePlatformService { + + CommandProcessingResult addCreditBureauLoanProductMapping(Long creditBureauId, JsonCommand command); + + CommandProcessingResult updateCreditBureauLoanProductMapping(JsonCommand command); + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformServiceImpl.java new file mode 100644 index 0000000..b6a04a7 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauLoanProductMappingWritePlatformServiceImpl.java @@ -0,0 +1,96 @@ +/** + * 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 org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauLoanProductMapping; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauLoanProductMappingRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureau; +import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureauRepository; +import org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauLoanProductCommandFromApiJsonDeserializer; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct; +import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class CreditBureauLoanProductMappingWritePlatformServiceImpl implements CreditBureauLoanProductMappingWritePlatformService { + + private final PlatformSecurityContext context; + + private final CreditBureauLoanProductMappingRepository creditBureauLoanProductMappingRepository; + + private final OrganisationCreditBureauRepository organisationCreditBureauRepository; + + private final LoanProductRepository loanProductRepository; + + private final CreditBureauLoanProductCommandFromApiJsonDeserializer fromApiJsonDeserializer; + + @Autowired + public CreditBureauLoanProductMappingWritePlatformServiceImpl(final PlatformSecurityContext context, + final CreditBureauLoanProductMappingRepository creditbureauLoanProductMappingRepository, + final OrganisationCreditBureauRepository organisationCreditBureauRepository, LoanProductRepository loanProductRepository, + final CreditBureauLoanProductCommandFromApiJsonDeserializer fromApiJsonDeserializer) { + this.context = context; + this.creditBureauLoanProductMappingRepository = creditbureauLoanProductMappingRepository; + this.organisationCreditBureauRepository = organisationCreditBureauRepository; + this.loanProductRepository = loanProductRepository; + this.fromApiJsonDeserializer = fromApiJsonDeserializer; + + } + + @Transactional + @Override + public CommandProcessingResult addCreditBureauLoanProductMapping(Long creditBureau_id, JsonCommand command) { + this.context.authenticatedUser(); + + System.out.println("mapping called for creditBureau_id "+creditBureau_id); + this.fromApiJsonDeserializer.validateForCreate(command.json(), creditBureau_id); + + final long lpid = command.longValueOfParameterNamed("loan_product_id"); + + final OrganisationCreditBureau orgcb = this.organisationCreditBureauRepository.getOne(creditBureau_id); + + final LoanProduct lp = this.loanProductRepository.getOne(lpid); + + final CreditBureauLoanProductMapping cb_lp = CreditBureauLoanProductMapping.fromJson(command, orgcb, lp); + + this.creditBureauLoanProductMappingRepository.save(cb_lp); + + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(cb_lp.getId()) + .build(); + + } + + @Override + public CommandProcessingResult updateCreditBureauLoanProductMapping(JsonCommand command) { + + final Long mappingid = command.longValueOfParameterNamed("creditbureauLoanProductMappingId"); + final boolean is_active = command.booleanPrimitiveValueOfParameterNamed("is_active"); + final CreditBureauLoanProductMapping cblpmapping = this.creditBureauLoanProductMappingRepository.getOne(mappingid); + cblpmapping.setIs_active(is_active); + this.creditBureauLoanProductMappingRepository.saveAndFlush(cblpmapping); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(cblpmapping.getId()) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauMasterReadPlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauMasterReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauMasterReadPlatformService.java new file mode 100644 index 0000000..ef295a8 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauMasterReadPlatformService.java @@ -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.infrastructure.creditbureau.service; + +import java.util.Collection; + +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauMasterData; + +public interface CreditBureauMasterReadPlatformService { + + Collection<CreditBureauMasterData> retrieveCreditBureauByCountry(String country); + + Collection<CreditBureauMasterData> retrieveCreditBureauByCountry(); + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationService.java new file mode 100644 index 0000000..5cdd959 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationService.java @@ -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.infrastructure.creditbureau.service; + +import java.util.Collection; +import java.util.Map; + +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurationData; + +public interface CreditBureauReadConfigurationService { + + Collection<CreditBureauConfigurationData> readConfigurationByOrganisationCreditBureauId(long id); + + Map<String, String> retrieveConfigMap(long id); + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationServiceImpl.java new file mode 100644 index 0000000..6a3a917 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadConfigurationServiceImpl.java @@ -0,0 +1,102 @@ +/** + * 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.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauConfigurationData; +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 CreditBureauReadConfigurationServiceImpl implements CreditBureauReadConfigurationService { + + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + + @Autowired + public CreditBureauReadConfigurationServiceImpl(final PlatformSecurityContext context, + final RoutingDataSource dataSource) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + private static final class CbConfigMapper implements RowMapper<CreditBureauConfigurationData> { + public String schema() { + + return "cbconfig.id as configId,cbconfig.configkey,cbconfig.value as configValue," + + "cbconfig.organisation_creditbureau_id as orgCBId,cbconfig.description as description from m_creditbureau_configuration cbconfig "; + + } + + @Override + public CreditBureauConfigurationData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + throws SQLException { + final long configId = rs.getLong("configId"); + final String configkey = rs.getString("configkey"); + final String configValue = rs.getString("configValue"); + final long orgCBId = rs.getLong("orgCBId"); + final String desc = rs.getString("description"); + + return CreditBureauConfigurationData.instance(configId, configkey, configValue, orgCBId, desc); + + } + } + + @Override + public Collection<CreditBureauConfigurationData> readConfigurationByOrganisationCreditBureauId(long id) { + + this.context.authenticatedUser(); + + final CbConfigMapper rm = new CbConfigMapper(); + final String sql = "select " + rm.schema() + " where cbconfig.organisation_creditbureau_id=?"; + + return this.jdbcTemplate.query(sql, rm, new Object[] { id }); + + } + + @Override + public Map<String, String> retrieveConfigMap(long id) { + this.context.authenticatedUser(); + + final CbConfigMapper rm = new CbConfigMapper(); + final String sql = "select " + rm.schema() + " where cbconfig.organisation_creditbureau_id=" + id; + + List<CreditBureauConfigurationData> config = (List<CreditBureauConfigurationData>) this.jdbcTemplate.query(sql, + rm, new Object[] {}); + Map<String, String> configuration = new HashMap<String, String>(); + for (CreditBureauConfigurationData data : config) { + configuration.put(data.getConfigurationKey(), data.getValue()); + + } + + return configuration; + + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformService.java new file mode 100644 index 0000000..ebc64f0 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformService.java @@ -0,0 +1,29 @@ +/** + * 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.util.Collection; + +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauData; + +public interface CreditBureauReadPlatformService { + + Collection<CreditBureauData> retrieveCreditBureau(); + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformServiceImpl.java new file mode 100644 index 0000000..ea90f80 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/CreditBureauReadPlatformServiceImpl.java @@ -0,0 +1,77 @@ +/** + * 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.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.CreditBureauData; +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 CreditBureauReadPlatformServiceImpl implements CreditBureauReadPlatformService { + + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + + @Autowired + public CreditBureauReadPlatformServiceImpl(final PlatformSecurityContext context, + final RoutingDataSource dataSource) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + private static final class CBMapper implements RowMapper<CreditBureauData> { + public String schema() { + return "cb.id as creditBureauID,cb.name as creditBureauName,cb.product as creditBureauProduct," + + "cb.country as country,concat(cb.product,' - ',cb.name,' - ',cb.country) as cbSummary,cb.implementationKey as implementationKey from m_creditbureau cb"; + } + + @Override + public CreditBureauData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + throws SQLException { + final long id = rs.getLong("creditBureauID"); + final String name = rs.getString("creditBureauName"); + final String product = rs.getString("creditBureauProduct"); + final String country = rs.getString("country"); + final String cbSummary = rs.getString("cbSummary"); + final long implementationKey = rs.getLong("implementationKey"); + + return CreditBureauData.instance(id, name, product, country, cbSummary, implementationKey); + + } + } + + @Override + public Collection<CreditBureauData> retrieveCreditBureau() { + this.context.authenticatedUser(); + + final CBMapper rm = new CBMapper(); + final String sql = "select " + rm.schema() + " order by id"; + + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformService.java new file mode 100644 index 0000000..bb74b08 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformService.java @@ -0,0 +1,29 @@ +/** + * 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.util.Collection; + +import org.apache.fineract.infrastructure.creditbureau.data.OrganisationCreditBureauData; + +public interface OrganisationCreditBureauReadPlatformService { + Collection<OrganisationCreditBureauData> retrieveOrgCreditBureau(); + + OrganisationCreditBureauData retrieveOrgCreditBureauById(long orgCbId); +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformServiceImpl.java new file mode 100644 index 0000000..f711663 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauReadPlatformServiceImpl.java @@ -0,0 +1,93 @@ +/** + * 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.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; + +import org.apache.fineract.infrastructure.core.service.RoutingDataSource; +import org.apache.fineract.infrastructure.creditbureau.data.OrganisationCreditBureauData; +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 OrganisationCreditBureauReadPlatformServiceImpl implements OrganisationCreditBureauReadPlatformService { + + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + + @Autowired + public OrganisationCreditBureauReadPlatformServiceImpl(final PlatformSecurityContext context, + final RoutingDataSource dataSource) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + private static final class OrganisationCreditBureauMapper implements RowMapper<OrganisationCreditBureauData> { + public String schema() { + return "ocb.id as orgCbId,ocb.alias as orgCbAlias,cb.name as creditbureauName,cb.product as creditbureauProduct,cb.country as creditbureauCountry," + + "concat(cb.product,' - ',cb.name,' - ',cb.country) as CreditBureauSummary," + + "ocb.creditbureau_id as cbid,ocb.is_active as is_active" + + " from m_organisation_creditbureau ocb,m_creditbureau cb where ocb.creditbureau_id=cb.id"; + + } + + @Override + public OrganisationCreditBureauData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) + throws SQLException { + final long orgCbId = rs.getLong("orgCbId"); + final String orgCbAlias = rs.getString("orgCbAlias"); + final String creditbureauName = rs.getString("creditbureauName"); + final String creditbureauProduct = rs.getString("creditbureauProduct"); + final String creditbureauCountry = rs.getString("creditbureauCountry"); + final String CreditBureauSummary = rs.getString("CreditBureauSummary"); + final long cbid = rs.getLong("cbid"); + final boolean is_active = rs.getBoolean("is_active"); + + return OrganisationCreditBureauData.instance(orgCbId, orgCbAlias, cbid, creditbureauName, + creditbureauProduct, creditbureauCountry, CreditBureauSummary, is_active); + + } + } + + @Override + public Collection<OrganisationCreditBureauData> retrieveOrgCreditBureau() { + this.context.authenticatedUser(); + + final OrganisationCreditBureauMapper rm = new OrganisationCreditBureauMapper(); + final String sql = "select " + rm.schema() + " order by ocb.id"; + + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } + + @Override + public OrganisationCreditBureauData retrieveOrgCreditBureauById(long orgCbId) { + this.context.authenticatedUser(); + + final OrganisationCreditBureauMapper rm = new OrganisationCreditBureauMapper(); + final String sql = "select " + rm.schema() + " and ocb.id=?"; + + return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { orgCbId }); + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormService.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormService.java new file mode 100644 index 0000000..21ffc74 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormService.java @@ -0,0 +1,29 @@ +/** + * 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 org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; + +public interface OrganisationCreditBureauWritePlatflormService { + + CommandProcessingResult addOrganisationCreditBureau(Long ocb_id, JsonCommand command); + + CommandProcessingResult updateCreditBureau(JsonCommand command); +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormServiceImpl.java new file mode 100644 index 0000000..1131d58 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/creditbureau/service/OrganisationCreditBureauWritePlatflormServiceImpl.java @@ -0,0 +1,94 @@ +/** + * 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 org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureau; +import org.apache.fineract.infrastructure.creditbureau.domain.CreditBureauRepository; +import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureau; +import org.apache.fineract.infrastructure.creditbureau.domain.OrganisationCreditBureauRepository; +import org.apache.fineract.infrastructure.creditbureau.serialization.CreditBureauCommandFromApiJsonDeserializer; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +public class OrganisationCreditBureauWritePlatflormServiceImpl + implements OrganisationCreditBureauWritePlatflormService { + + private final PlatformSecurityContext context; + + private final OrganisationCreditBureauRepository organisationCreditBureauRepository; + + private final CreditBureauRepository creditBureauRepository; + + private final CreditBureauCommandFromApiJsonDeserializer fromApiJsonDeserializer; + + @Autowired + public OrganisationCreditBureauWritePlatflormServiceImpl(final PlatformSecurityContext context, + final OrganisationCreditBureauRepository organisationCreditBureauRepository, final CreditBureauRepository creditBureauRepository, + final CreditBureauCommandFromApiJsonDeserializer fromApiJsonDeserializer) { + this.context = context; + this.organisationCreditBureauRepository = organisationCreditBureauRepository; + this.creditBureauRepository = creditBureauRepository; + this.fromApiJsonDeserializer = fromApiJsonDeserializer; + + } + + @Override + public CommandProcessingResult addOrganisationCreditBureau(Long creditBureauId, JsonCommand command) { + this.context.authenticatedUser(); + this.fromApiJsonDeserializer.validateForCreate(command.json(), creditBureauId); + + final CreditBureau creditBureau = this.creditBureauRepository.getOne(creditBureauId); + + final OrganisationCreditBureau organisationCreditBureau = OrganisationCreditBureau.fromJson(command, creditBureau); + + this.organisationCreditBureauRepository.save(organisationCreditBureau); + + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(organisationCreditBureau.getId()) + .build(); + } + + @Transactional + @Override + public CommandProcessingResult updateCreditBureau(JsonCommand command) { + // this.context.authenticatedUser(); + // this.fromApiJsonDeserializer.validateForCreate(command.json()); + + final long creditbureauID = command.longValueOfParameterNamed("creditBureauId"); + //System.out.println("creditbureauID is " + creditbureauID); + + final boolean is_active = command.booleanPrimitiveValueOfParameterNamed("is_active"); + + final OrganisationCreditBureau orgcb = organisationCreditBureauRepository.getOne(creditbureauID); + + orgcb.setIsActive(is_active); + + organisationCreditBureauRepository.saveAndFlush(orgcb); + + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(orgcb.getId()) + .build(); + + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java index f7aeb60..73f41cf 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformService.java @@ -130,4 +130,6 @@ public interface LoanReadPlatformService { Collection<Long> retrieveLoanIdsWithPendingIncomePostingTransactions(); LoanTransactionData retrieveLoanForeclosureTemplate(final Long loanId, final LocalDate transactionDate); + + LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index 46d9795..7483345 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -213,6 +213,22 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { throw new LoanNotFoundException(loanId); } } + + @Override + public LoanAccountData retrieveLoanByLoanAccount(String loanAccountNumber) + { + + + //final AppUser currentUser = this.context.authenticatedUser(); + this.context.authenticatedUser(); + final LoanMapper rm = new LoanMapper(); + + String sql="select "+rm.loanSchema()+" where l.account_no=?"; + + + return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { loanAccountNumber }); + + } @Override public LoanScheduleData retrieveRepaymentSchedule(final Long loanId, @@ -231,6 +247,8 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { throw new LoanNotFoundException(loanId); } } + + @Override public Collection<LoanTransactionData> retrieveLoanTransactions(final Long loanId) { http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 4f02d2e..bfb43f3 100755 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -2303,7 +2303,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf final JsonElement parsedCommand = this.fromApiJsonHelper.parse(overdueInstallment.toString()); final JsonCommand command = JsonCommand.from(overdueInstallment.toString(), parsedCommand, this.fromApiJsonHelper, null, null, - null, null, null, loanId, null, null, null, null); + null, null, null, loanId, null, null, null, null,null,null); LoanOverdueDTO overdueDTO = applyChargeToOverdueLoanInstallment(loanId, overdueInstallment.getChargeId(), overdueInstallment.getPeriodNumber(), command, loan, existingTransactionIds, existingReversedTransactionIds); loan = overdueDTO.getLoan(); http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountCommandsServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountCommandsServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountCommandsServiceImpl.java index 6f56afa..926aa0d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountCommandsServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareaccounts/service/ShareAccountCommandsServiceImpl.java @@ -47,7 +47,7 @@ public class ShareAccountCommandsServiceImpl implements AccountsCommandsService public Object handleCommand(Long accountId, String command, String jsonBody) { final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonBody); final JsonCommand jsonCommand = JsonCommand.from(jsonBody, parsedCommand, this.fromApiJsonHelper, null, null, null, null, null, - null, null, null, null, null); + null, null, null, null, null,null,null); if(ShareAccountApiConstants.APPROVE_COMMAND.equals(command)){ return approveShareAccount(accountId, jsonCommand) ; }if(ShareAccountApiConstants.REJECT_COMMAND.equals(command)){ http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductCommandsServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductCommandsServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductCommandsServiceImpl.java index ee36863..e95d75c 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductCommandsServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductCommandsServiceImpl.java @@ -47,7 +47,7 @@ public class ShareProductCommandsServiceImpl implements ProductCommandsService { public Object handleCommand(Long productId, String command, String jsonBody) { final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonBody); final JsonCommand jsonCommand = JsonCommand.from(jsonBody, parsedCommand, this.fromApiJsonHelper, null, null, null, null, null, - null, null, null, null, null); + null, null, null, null, null,null,null); if (ShareProductApiConstants.PREIEW_DIVIDENDS_COMMAND_STRING.equals(command)) { return null ; } else if (ShareProductApiConstants.POST_DIVIDENdS_COMMAND_STRING.equals(command)) { return postDividends(productId, http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/resources/META-INF/spring/appContext.xml ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml index 80ebec6..9fe95d4 100644 --- a/fineract-provider/src/main/resources/META-INF/spring/appContext.xml +++ b/fineract-provider/src/main/resources/META-INF/spring/appContext.xml @@ -43,6 +43,7 @@ org.apache.fineract.commands.service.*, org.apache.fineract.commands.*, org.apache.fineract.audit.*, + org.apache.fineract.infrastructure.creditbureau.*, org.apache.fineract.infrastructure.*, org.apache.fineract.scheduledjobs.*, org.apache.fineract.organisation.*, @@ -69,7 +70,6 @@ <bean id="auditorAware" class="org.apache.fineract.infrastructure.core.domain.AuditorAwareImpl" /> <jpa:auditing auditor-aware-ref="auditorAware" /> - <jpa:repositories base-package="org.apache.fineract.commands.domain" /> <jpa:repositories base-package="org.apache.fineract.infrastructure.*.domain" /> <jpa:repositories base-package="org.apache.fineract.accounting.*.domain" /> http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/main/resources/sql/migrations/core_db/V327__creditbureau_configuration.sql ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V327__creditbureau_configuration.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V327__creditbureau_configuration.sql new file mode 100644 index 0000000..d1ebd03 --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V327__creditbureau_configuration.sql @@ -0,0 +1,89 @@ +-- +-- 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. +-- + + -- credit bureau tables +CREATE TABLE `m_creditbureau` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `product` varchar(100) NOT NULL, + `country` varchar(100) NOT NULL, + `implementationKey` varchar(100) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique impl` (`name`,`product`,`country`,`implementationKey`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +CREATE TABLE `m_organisation_creditbureau` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `alias` varchar(50) NOT NULL, + `creditbureau_id` bigint(20) NOT NULL, + `is_active` tinyint(4) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `morgcb` (`alias`,`creditbureau_id`), + KEY `orgcb_cbfk` (`creditbureau_id`), + CONSTRAINT `orgcb_cbfk` FOREIGN KEY (`creditbureau_id`) REFERENCES `m_creditbureau` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + + +CREATE TABLE `m_creditbureau_configuration` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `configkey` varchar(50) DEFAULT NULL, + `value` varchar(50) DEFAULT NULL, + `organisation_creditbureau_id` bigint(20) DEFAULT NULL, + `description` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `mcbconfig` (`configkey`,`organisation_creditbureau_id`), + KEY `cbConfigfk1` (`organisation_creditbureau_id`), + CONSTRAINT `cbConfigfk1` FOREIGN KEY (`organisation_creditbureau_id`) REFERENCES `m_organisation_creditbureau` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + + + +CREATE TABLE `m_creditbureau_loanproduct_mapping` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `organisation_creditbureau_id` bigint(20) NOT NULL, + `loan_product_id` bigint(20) NOT NULL, + `is_creditcheck_mandatory` tinyint(1) DEFAULT NULL, + `skip_creditcheck_in_failure` tinyint(1) DEFAULT NULL, + `stale_period` int(11) DEFAULT NULL, + `is_active` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `cblpunique_key` (`organisation_creditbureau_id`,`loan_product_id`), + KEY `fk_cb_lp2` (`loan_product_id`), + CONSTRAINT `cblpfk2` FOREIGN KEY (`organisation_creditbureau_id`) REFERENCES `m_organisation_creditbureau` (`id`), + CONSTRAINT `fk_cb_lp2` FOREIGN KEY (`loan_product_id`) REFERENCES `m_product_loan` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + +-- modify `m_portfolio_command_source` command + +ALTER TABLE `m_portfolio_command_source` + ADD COLUMN `creditbureau_id` BIGINT(20) NULL DEFAULT NULL AFTER `transaction_id`, + ADD COLUMN `organisation_creditbureau_id` BIGINT(20) NULL DEFAULT NULL AFTER `creditbureau_id`; + + +-- permissions +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('configuration', 'CREATE_CREDITBUREAU_LOANPRODUCT_MAPPING', 'CREDITBUREAU_LOANPRODUCT_MAPPING', 'CREATE', 0); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('configuration', 'CREATE_ORGANISATIONCREDITBUREAU', 'ORGANISATIONCREDITBUREAU', 'CREATE', 0); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('configuration', 'UPDATE_ORGANISATIONCREDITBUREAU', 'ORGANISATIONCREDITBUREAU', 'UPDATE', 0); +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('configuration', 'UPDATE_CREDITBUREAU_LOANPRODUCT_MAPPING', 'CREDITBUREAU_LOANPRODUCT_MAPPING', 'UPDATE', 0); http://git-wip-us.apache.org/repos/asf/fineract/blob/34de03e0/fineract-provider/src/test/java/org/apache/fineract/commands/provider/CommandHandlerProviderTest.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/test/java/org/apache/fineract/commands/provider/CommandHandlerProviderTest.java b/fineract-provider/src/test/java/org/apache/fineract/commands/provider/CommandHandlerProviderTest.java index 811845b..a3e9aa6 100644 --- a/fineract-provider/src/test/java/org/apache/fineract/commands/provider/CommandHandlerProviderTest.java +++ b/fineract-provider/src/test/java/org/apache/fineract/commands/provider/CommandHandlerProviderTest.java @@ -56,7 +56,7 @@ public class CommandHandlerProviderTest { final CommandProcessingResult result = registeredHandler.processCommand( - JsonCommand.fromExistingCommand(testCommandId, null, null, null, null, null, null, null, null)); + JsonCommand.fromExistingCommand(testCommandId, null, null, null, null, null, null, null, null,null,null)); Assert.assertEquals(testCommandId, result.commandId()); } catch (UnsupportedCommandException ucex) { Assert.fail();