budaidev commented on code in PR #5436: URL: https://github.com/apache/fineract/pull/5436#discussion_r2763273021
########## fineract-command/src/main/resources/db/changelog/tenant/module/command/parts/0002_command_init_mysql.xml: ########## @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd"> + <changeSet author="fineract" id="command-00002" context="mysql" failOnError="false"> Review Comment: don't we want to fail if it doesn't apply? ########## fineract-command/src/main/java/org/apache/fineract/command/persistence/converter/JsonNodeReadingConverter.java: ########## @@ -16,24 +16,29 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.fineract.command.sample.middleware; +package org.apache.fineract.command.persistence.converter; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.fineract.command.core.Command; -import org.apache.fineract.command.core.CommandMiddleware; -import org.apache.fineract.command.sample.command.DummyCommand; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import org.springframework.core.convert.converter.Converter; +import org.springframework.data.convert.ReadingConverter; import org.springframework.stereotype.Component; -@Slf4j -@RequiredArgsConstructor @Component -public class DummyMiddleware implements CommandMiddleware { +@ReadingConverter +public class JsonNodeReadingConverter implements Converter<String, JsonNode> { + private final ObjectMapper mapper = new ObjectMapper(); + + @SneakyThrows @Override - public void invoke(Command<?> command) { - if (command instanceof DummyCommand c) { - c.getPayload().setId(command.getId()); + public JsonNode convert(String source) { + if (source != null) { + return mapper.readTree(source); } + + // TODO: throw exception? Review Comment: let's decide how to handle this TODO before the merge ########## fineract-command/src/main/java/org/apache/fineract/command/implementation/AsynchronousCommandExecutor.java: ########## @@ -18,41 +18,39 @@ */ package org.apache.fineract.command.implementation; -import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.command.core.Command; -import org.apache.fineract.command.core.CommandExecutor; +import org.apache.fineract.command.core.CommandAuditor; import org.apache.fineract.command.core.CommandHandler; -import org.apache.fineract.command.core.CommandMiddleware; import org.apache.fineract.command.core.CommandRouter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Component; @Slf4j -@RequiredArgsConstructor @Component @ConditionalOnProperty(value = "fineract.command.executor", havingValue = "async") -public class AsynchronousCommandExecutor implements CommandExecutor { +public class AsynchronousCommandExecutor extends BaseCommandExecutor { - private final List<CommandMiddleware> middlewares; - - private final CommandRouter router; + public AsynchronousCommandExecutor(CommandRouter router, CommandAuditor auditor) { + super(router, auditor); + } @Override - public <REQ, RES> Supplier<RES> execute(Command<REQ> command) { + public <REQ, RES> Supplier<RES> execute(final Command<REQ> command) { CompletableFuture<RES> future = CompletableFuture.supplyAsync(() -> { - for (CommandMiddleware middleware : middlewares) { - middleware.invoke(command); - } - CommandHandler<REQ, RES> handler = router.route(command); return handler.handle(command); + }).whenComplete((response, t) -> { + if (t == null) { + auditor.success(command, response); + } else { + auditor.fail(command, t); + } }); - return future::join; + return () -> future.getNow(null); Review Comment: I am not sure we will get the right result here, we will probably get null here. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
