Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
import org.apache.fineract.client.services.LoanDisbursementDetailsApi;
import org.apache.fineract.client.services.LoanInterestPauseApi;
import org.apache.fineract.client.services.LoanProductsApi;
import org.apache.fineract.client.services.LoanProductsDetailsApi;
import org.apache.fineract.client.services.LoanReschedulingApi;
import org.apache.fineract.client.services.LoanTransactionsApi;
import org.apache.fineract.client.services.LoansApi;
Expand Down Expand Up @@ -238,6 +239,7 @@ public final class FineractClient {
public final LoanCollateralApi loanCollaterals;
public final LoanCapitalizedIncomeApi loanCapitalizedIncome;
public final LoanProductsApi loanProducts;
public final LoanProductsDetailsApi loanProductsDetails;
public final LoanReschedulingApi loanSchedules;
public final LoansPointInTimeApi loansPointInTimeApi;
public final LoansApi loans;
Expand Down Expand Up @@ -371,6 +373,7 @@ private FineractClient(OkHttpClient okHttpClient, Retrofit retrofit) {
loanCollaterals = retrofit.create(LoanCollateralApi.class);
loanCapitalizedIncome = retrofit.create(LoanCapitalizedIncomeApi.class);
loanProducts = retrofit.create(LoanProductsApi.class);
loanProductsDetails = retrofit.create(LoanProductsDetailsApi.class);
loanSchedules = retrofit.create(LoanReschedulingApi.class);
loansPointInTimeApi = retrofit.create(LoansPointInTimeApi.class);
loans = retrofit.create(LoansApi.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.portfolio.loanproduct.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;
import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadBasicDetailsService;
import org.springframework.stereotype.Component;

@Path("/v1/loanproducts")
@Component
@Tag(name = "Loan Products Details", description = "Loan product basic details to be listed")
@RequiredArgsConstructor
public class LoanProductsDetailsApiResource {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into fineract-loan module ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


private static final String RESOURCE_NAME_FOR_PERMISSIONS = "LOANPRODUCT";
private final PlatformSecurityContext context;
private final List<LoanProductReadBasicDetailsService> loanProductReadBasicDetailsServices;

@GET
@Path("basic-details")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "List Loan Products with basic details", description = "Lists Loan Products with basic details to be listed")
public Collection<LoanProductBasicDetailsData> fetchProducts(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);

Collection<LoanProductBasicDetailsData> products = new ArrayList<>();
loanProductReadBasicDetailsServices.forEach(service -> products.addAll(service.retrieveProducts()));
return products;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.loanproduct.data;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.organisation.monetary.data.CurrencyData;

@Data
@RequiredArgsConstructor
public class LoanProductBasicDetailsData {

private final String productType;
private final Long id;
private final String name;
private final String shortName;
private final String description;
private final CurrencyData currency;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.loanproduct.domain;

import java.time.LocalDate;
import java.util.List;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
import org.apache.fineract.portfolio.delinquency.domain.DelinquencyBucket;
Expand All @@ -41,4 +42,7 @@ public interface LoanProductRepository extends JpaRepository<LoanProduct, Long>,
@Override
@Query("SELECT CASE WHEN COUNT(loanProduct)>0 THEN TRUE ELSE FALSE END FROM LoanProduct loanProduct WHERE loanProduct.id = :loanProductId")
boolean existsById(@NonNull @Param("loanProductId") Long loanProductId);

@Query("select loanProduct from LoanProduct loanProduct where loanProduct.closeDate is null or loanProduct.closeDate >= :businessDate")
List<LoanProduct> fetchActiveLoanProducts(LocalDate businessDate);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.loanproduct.mapper;

import java.util.List;
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProduct;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(config = MapstructMapperConfig.class)
public interface LoanProductBasicDetailsMapper {

@Mapping(target = "productType", constant = "loan")
@Mapping(target = "currency", source = "loanProductRelatedDetail.currency", qualifiedByName = "currencyData")
LoanProductBasicDetailsData map(LoanProduct source);

List<LoanProductBasicDetailsData> map(List<LoanProduct> source);

@Named("currencyData")
default CurrencyData currencyData(final MonetaryCurrency currency) {
return currency.toData();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.loanproduct.service;

import java.util.Collection;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;

public interface LoanProductReadBasicDetailsService {

Collection<LoanProductBasicDetailsData> retrieveProducts();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.loanproduct.service;

import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;
import org.apache.fineract.portfolio.loanproduct.domain.LoanProductRepository;
import org.apache.fineract.portfolio.loanproduct.mapper.LoanProductBasicDetailsMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class LoanProductReadBasicDetailsServiceImpl implements LoanProductReadBasicDetailsService {

private final LoanProductBasicDetailsMapper loanProductBasicDetailsMapper;
private final LoanProductRepository loanProductRepository;

@Override
public Collection<LoanProductBasicDetailsData> retrieveProducts() {
return loanProductBasicDetailsMapper.map(loanProductRepository.fetchActiveLoanProducts(DateUtils.getBusinessLocalDate()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ public interface LoanProductReadPlatformService {
Collection<CreditAllocationData> retrieveCreditAllocationData(Long loanProductId);

LoanProductData retrieveLoanProductFloatingDetails(Long loanProductId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.workingcapitalloanproduct.mapper;

import java.util.List;
import org.apache.fineract.infrastructure.core.config.MapstructMapperConfig;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;
import org.apache.fineract.portfolio.workingcapitalloanproduct.domain.WorkingCapitalLoanProduct;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

@Mapper(config = MapstructMapperConfig.class)
public interface WorkingCapitalLoanProductBasicDetailsMapper {

@Mapping(target = "productType", constant = "working-capital")
@Mapping(target = "currency", source = "currency", qualifiedByName = "currencyData")
LoanProductBasicDetailsData map(WorkingCapitalLoanProduct source);

List<LoanProductBasicDetailsData> map(List<WorkingCapitalLoanProduct> source);

@Named("currencyData")
default CurrencyData currencyData(final MonetaryCurrency currency) {
return currency.toData();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.fineract.portfolio.workingcapitalloanproduct.repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.apache.fineract.infrastructure.core.domain.ExternalId;
Expand Down Expand Up @@ -64,6 +65,9 @@ public interface WorkingCapitalLoanProductRepository
""")
Optional<WorkingCapitalLoanProduct> findByExternalIdWithDetails(@Param("externalId") ExternalId externalId);

@Query("select wclp FROM WorkingCapitalLoanProduct wclp where wclp.closeDate is null or wclp.closeDate >= :businessDate")
List<WorkingCapitalLoanProduct> fetchActiveWorkingCapitalLoanProducts(LocalDate businessDate);

// TODO: Check if product is used in any loans (for deletion validation)
// This will be implemented when Working Capital Loan entity is created
// @Query("SELECT CASE WHEN COUNT(l)>0 THEN TRUE ELSE FALSE END FROM WorkingCapitalLoan l WHERE l.wcpProduct.id =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.portfolio.workingcapitalloanproduct.service;

import java.util.Collection;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductBasicDetailsData;
import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadBasicDetailsService;
import org.apache.fineract.portfolio.workingcapitalloanproduct.mapper.WorkingCapitalLoanProductBasicDetailsMapper;
import org.apache.fineract.portfolio.workingcapitalloanproduct.repository.WorkingCapitalLoanProductRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class WorkingCapitalLoanProductReadBasicDetailsServiceImpl implements LoanProductReadBasicDetailsService {

private final WorkingCapitalLoanProductBasicDetailsMapper workingCapitalLoanProductBasicDetailsMapper;
private final WorkingCapitalLoanProductRepository productRepository;

@Override
public Collection<LoanProductBasicDetailsData> retrieveProducts() {
return workingCapitalLoanProductBasicDetailsMapper
.map(productRepository.fetchActiveWorkingCapitalLoanProducts(DateUtils.getBusinessLocalDate()));
}

}
Loading
Loading