Skip to content
Open
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 @@ -366,6 +366,9 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/*/*/meeting/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_MEETING")

.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/loan-collateral-management/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_LOAN_COLLATERAL_PRODUCT")

.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/**"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,56 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
import org.apache.fineract.command.core.CommandDispatcher;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.collateralmanagement.command.LoanCollateralDeleteCommand;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteResponse;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData;
import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementReadPlatformService;
import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementReadService;
import org.springframework.stereotype.Component;

@Path("/v1/loan-collateral-management")
@Component
@Produces({ MediaType.APPLICATION_JSON })
@Tag(name = "Loan Collateral Management", description = "Loan Collateral Management is for managing collateral operations")
@RequiredArgsConstructor
public class LoanCollateralManagementApiResource {

private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final LoanCollateralManagementReadPlatformService loanCollateralManagementReadPlatformService;
private final LoanCollateralManagementReadService readService;
private final CommandDispatcher dispatcher;

@DELETE
@Path("{id}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(description = "Delete Loan Collateral", summary = "Delete Loan Collateral")
public CommandProcessingResult deleteLoanCollateral(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
@ApiResponse(responseCode = "default", content = @Content(schema = @Schema(implementation = CommandProcessingResult.class)))
public LoanCollateralDeleteResponse deleteLoanCollateral(@PathParam("loanId") @Parameter(description = "loanId") final Long loanId,
@PathParam("id") @Parameter(description = "loan collateral id") final Long id) {

final CommandWrapper commandWrapper = new CommandWrapperBuilder().deleteLoanCollateral(loanId, id).build();
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
final var request = LoanCollateralDeleteRequest.builder().id(id).loanId(loanId).build();
final var command = new LoanCollateralDeleteCommand();
command.setPayload(request);
final Supplier<LoanCollateralDeleteResponse> response = dispatcher.dispatch(command);
return response.get();
}

@GET
@Path("{collateralId}")
@Produces({ MediaType.APPLICATION_JSON })
@Operation(description = "Get Loan Collateral Details", summary = "Get Loan Collateral Details")
public LoanCollateralResponseData getLoanCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
return this.loanCollateralManagementReadPlatformService.getLoanCollateralResponseData(collateralId);
return this.readService.getLoanCollateralResponseData(collateralId);
}

}
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.collateralmanagement.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class LoanCollateralDeleteCommand extends Command<LoanCollateralDeleteRequest> {}
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.collateralmanagement.data;

import io.swagger.v3.oas.annotations.Hidden;
import java.io.Serial;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class LoanCollateralDeleteRequest implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

@Hidden
private Long id;

@Hidden
private Long loanId;
}
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.collateralmanagement.data;

import java.io.Serial;
import java.io.Serializable;
import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class LoanCollateralDeleteResponse implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private Long resourceId;

private Long loanId;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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.collateralmanagement.handler;

import io.github.resilience4j.retry.annotation.Retry;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.command.core.CommandHandler;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteResponse;
import org.apache.fineract.portfolio.collateralmanagement.service.LoanCollateralManagementWriteService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
@RequiredArgsConstructor
public class LoanCollateralDeleteCommandHandler implements CommandHandler<LoanCollateralDeleteRequest, LoanCollateralDeleteResponse> {

private final LoanCollateralManagementWriteService writeService;

@Retry(name = "commandLoanCollateralDelete", fallbackMethod = "fallback")
@Override
@Transactional
public LoanCollateralDeleteResponse handle(Command<LoanCollateralDeleteRequest> command) {
return writeService.deleteLoanCollateral(command.getPayload());
}

@Override
public LoanCollateralDeleteResponse fallback(Command<LoanCollateralDeleteRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData;
import org.apache.fineract.portfolio.loanaccount.domain.LoanCollateralManagement;

public interface LoanCollateralManagementReadPlatformService {
public interface LoanCollateralManagementReadService {

List<LoanCollateralManagement> getLoanCollaterals(Long loanId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralResponseData;
import org.apache.fineract.portfolio.collateralmanagement.domain.CollateralManagementDomain;
import org.apache.fineract.portfolio.collateralmanagement.exception.LoanCollateralManagementNotFoundException;
Expand All @@ -33,30 +33,21 @@
import org.apache.fineract.portfolio.loanaccount.exception.LoanNotFoundException;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
public class LoanCollateralManagementReadPlatformServiceImpl implements LoanCollateralManagementReadPlatformService {
public class LoanCollateralManagementReadServiceImpl implements LoanCollateralManagementReadService {

private final PlatformSecurityContext context;
private LoanCollateralManagementRepository loanCollateralManagementRepository;
private LoanRepository loanRepository;

public LoanCollateralManagementReadPlatformServiceImpl(final PlatformSecurityContext context,
final LoanCollateralManagementRepository loanCollateralManagementRepository, final LoanRepository loanRepository) {
this.context = context;
this.loanCollateralManagementRepository = loanCollateralManagementRepository;
this.loanRepository = loanRepository;
}
private final LoanCollateralManagementRepository loanCollateralManagementRepository;
private final LoanRepository loanRepository;

@Override
public List<LoanCollateralManagement> getLoanCollaterals(Long loanId) {
this.context.authenticatedUser();
Loan loan = this.loanRepository.findById(loanId).orElseThrow(() -> new LoanNotFoundException(loanId));
return this.loanCollateralManagementRepository.findByLoan(loan);
}

@Override
public LoanCollateralResponseData getLoanCollateralResponseData(Long collateralId) {
this.context.authenticatedUser();
LoanCollateralManagement loanCollateralManagement = this.loanCollateralManagementRepository.findById(collateralId)
.orElseThrow(() -> new LoanCollateralManagementNotFoundException(collateralId));
final CollateralManagementDomain collateralManagementDomain = loanCollateralManagement.getClientCollateralManagement()
Expand All @@ -69,7 +60,6 @@ public LoanCollateralResponseData getLoanCollateralResponseData(Long collateralI

@Override
public List<LoanCollateralResponseData> getLoanCollateralResponseDataList(Long loanId) {
this.context.authenticatedUser();
Loan loan = this.loanRepository.findById(loanId).orElseThrow(() -> new LoanNotFoundException(loanId));
List<LoanCollateralResponseData> loanCollateralResponseDataCollection = new ArrayList<>();
Set<LoanCollateralManagement> loanCollateralManagements = loan.getLoanCollateralManagements();
Expand All @@ -84,5 +74,4 @@ public List<LoanCollateralResponseData> getLoanCollateralResponseDataList(Long l
}
return loanCollateralResponseDataCollection;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
*/
package org.apache.fineract.portfolio.collateralmanagement.service;

import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.LoanCollateralDeleteResponse;

public interface LoanCollateralManagementWritePlatformService {
public interface LoanCollateralManagementWriteService {

CommandProcessingResult deleteLoanCollateral(JsonCommand command);
LoanCollateralDeleteResponse deleteLoanCollateral(LoanCollateralDeleteRequest request);
}
Loading
Loading