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 @@ -19,6 +19,7 @@
package org.apache.fineract.portfolio.loanproduct.productmix.api;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
Expand All @@ -34,17 +35,21 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
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.CommandPipeline;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.loanproduct.data.LoanProductData;
import org.apache.fineract.portfolio.loanproduct.productmix.command.CreateProductMixCommand;
import org.apache.fineract.portfolio.loanproduct.productmix.command.DeleteProductMixCommand;
import org.apache.fineract.portfolio.loanproduct.productmix.command.UpdateProductMixCommand;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixCommandRequest;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixData;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixDeleteRequest;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixRequest;
import org.apache.fineract.portfolio.loanproduct.productmix.service.ProductMixReadPlatformService;
import org.apache.fineract.portfolio.loanproduct.service.LoanProductReadPlatformService;
Expand All @@ -62,10 +67,9 @@ public class ProductMixApiResource {
Arrays.asList("productId", "productName", "restrictedProducts", "allowedProducts", "productOptions"));

private final PlatformSecurityContext context;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final CommandPipeline commandPipeline;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final DefaultToApiJsonSerializer<ProductMixData> toApiJsonSerializer;

private final ProductMixReadPlatformService productMixReadPlatformService;
private final LoanProductReadPlatformService loanProductReadPlatformService;

Expand All @@ -89,35 +93,40 @@ public String retrieveTemplate(@PathParam("productId") final Long productId, @Co
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public CommandProcessingResult createProductMix(@PathParam("productId") final Long productId,
final ProductMixRequest productMixRequest) {
public CommandProcessingResult createProductMix(@PathParam("productId") final Long productId, @Valid final ProductMixRequest request) {

final var payload = new ProductMixCommandRequest(productId, request.restrictedProducts());

final CommandWrapper commandRequest = new CommandWrapperBuilder().createProductMix(productId)
.withJson(toApiJsonSerializer.serialize(productMixRequest)).build();
final var command = new CreateProductMixCommand();
command.setPayload(payload);

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
final Supplier<CommandProcessingResult> response = commandPipeline.send(command);
return response.get();
}

@PUT
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public CommandProcessingResult updateProductMix(@PathParam("productId") final Long productId,
final ProductMixRequest productMixRequest) {
public CommandProcessingResult updateProductMix(@PathParam("productId") final Long productId, @Valid final ProductMixRequest request) {

final CommandWrapper commandRequest = new CommandWrapperBuilder().updateProductMix(productId)
.withJson(toApiJsonSerializer.serialize(productMixRequest)).build();
final var payload = new ProductMixCommandRequest(productId, request.restrictedProducts());

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
final var command = new UpdateProductMixCommand();
command.setPayload(payload);

final Supplier<CommandProcessingResult> response = commandPipeline.send(command);
return response.get();
}

@DELETE
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public CommandProcessingResult deleteProductMix(@PathParam("productId") final Long productId) {

final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteProductMix(productId).build();
final var command = new DeleteProductMixCommand();
command.setPayload(ProductMixDeleteRequest.builder().productId(productId).build());

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
final Supplier<CommandProcessingResult> response = commandPipeline.send(command);
return response.get();
}

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

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixCommandRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class CreateProductMixCommand extends Command<ProductMixCommandRequest> {}
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.productmix.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixDeleteRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class DeleteProductMixCommand extends Command<ProductMixDeleteRequest> {}
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.productmix.command;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.fineract.command.core.Command;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixCommandRequest;

@Data
@EqualsAndHashCode(callSuper = true)
public class UpdateProductMixCommand extends Command<ProductMixCommandRequest> {}
Original file line number Diff line number Diff line change
@@ -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.portfolio.loanproduct.productmix.data;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;

public record ProductMixCommandRequest(Long productId, List<Long> restrictedProducts) implements Serializable {

@Serial
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
@@ -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.portfolio.loanproduct.productmix.data;

import java.io.Serial;
import java.io.Serializable;
import lombok.Builder;
Comment on lines +19 to +23

@Builder
public record ProductMixDeleteRequest(Long productId) implements Serializable {

@Serial
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
*/
package org.apache.fineract.portfolio.loanproduct.productmix.data;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;

public record ProductMixRequest(List<Long> restrictedProducts) implements Serializable {
public record ProductMixRequest(@NotNull List<@NotNull @Positive Long> restrictedProducts) implements Serializable {

@Serial
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@
*/
package org.apache.fineract.portfolio.loanproduct.productmix.handler;

import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
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.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixCommandRequest;
import org.apache.fineract.portfolio.loanproduct.productmix.service.ProductMixWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = "PRODUCTMIX", action = "CREATE")
public class CreateProductMixCommandHandler implements NewCommandSourceHandler {
@Slf4j
@Component
@RequiredArgsConstructor
public class CreateProductMixCommandHandler implements CommandHandler<ProductMixCommandRequest, CommandProcessingResult> {

private final ProductMixWritePlatformService productMixWritePlatformService;
private final ProductMixWritePlatformService writePlatformService;

@Autowired
public CreateProductMixCommandHandler(final ProductMixWritePlatformService productMixWritePlatformService) {

this.productMixWritePlatformService = productMixWritePlatformService;
@Retry(name = "commandCreateProductMix", fallbackMethod = "fallback")
@Override
@Transactional
public CommandProcessingResult handle(Command<ProductMixCommandRequest> command) {
return writePlatformService.createProductMix(command.getPayload());
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {

return this.productMixWritePlatformService.createProductMix(command.getProductId(), command);
public CommandProcessingResult fallback(Command<ProductMixCommandRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@
*/
package org.apache.fineract.portfolio.loanproduct.productmix.handler;

import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
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.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.portfolio.loanproduct.productmix.data.ProductMixDeleteRequest;
import org.apache.fineract.portfolio.loanproduct.productmix.service.ProductMixWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Service
@CommandType(entity = "PRODUCTMIX", action = "DELETE")
public class DeleteProductMixCommandHandler implements NewCommandSourceHandler {
@Slf4j
@Component
@RequiredArgsConstructor
public class DeleteProductMixCommandHandler implements CommandHandler<ProductMixDeleteRequest, CommandProcessingResult> {

private final ProductMixWritePlatformService productMixWritePlatformService;
private final ProductMixWritePlatformService writePlatformService;

@Autowired
public DeleteProductMixCommandHandler(final ProductMixWritePlatformService productMixWritePlatformService) {

this.productMixWritePlatformService = productMixWritePlatformService;
@Retry(name = "commandDeleteProductMix", fallbackMethod = "fallback")
@Override
@Transactional
public CommandProcessingResult handle(Command<ProductMixDeleteRequest> command) {
return writePlatformService.deleteProductMix(command.getPayload());
}

@Transactional
@Override
public CommandProcessingResult processCommand(final JsonCommand command) {

return this.productMixWritePlatformService.deleteProductMix(command.getProductId());
public CommandProcessingResult fallback(Command<ProductMixDeleteRequest> command, Throwable t) {
return CommandHandler.super.fallback(command, t);
}

}
Loading
Loading