@Override
    public Integer call() throws Exception {
        super.call();

        if ("flow".equals(type)) {
            FlowRepositoryInterface flowRepository = applicationContext.getBean(FlowRepositoryInterface.class);

            List<Flow> allFlow = flowRepository.findAllForAllTenants();
            allFlow.stream()
                .map(flow -> flowRepository.findByIdWithSource(flow.getTenantId(), flow.getNamespace(), flow.getId()).orElse(null))
                .filter(flow -> flow != null)
                .forEach(flow -> flowRepository.update(flow.toFlow(), flow.toFlow(), flow.getSource(), flow.toFlow()));

            stdOut("Successfully reindex " + allFlow.size() + " flow(s).");
        }
        else {
            throw new IllegalArgumentException("Reindexing type '" + type + "' is not supported");
        }

        return 0;
    }
@Test
    void reindexFlow() {
        URL directory = ReindexCommandTest.class.getClassLoader().getResource("flows");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        System.setOut(new PrintStream(out));

        try (ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)) {
            EmbeddedServer embeddedServer = ctx.getBean(EmbeddedServer.class);
            embeddedServer.start();

            // we use the update command to add flows to extract
            String[] updateArgs = {
                "--server",
                embeddedServer.getURL().toString(),
                "--user",
                "myuser:pass:word",
                "io.kestra.cli",
                directory.getPath(),
            };
            PicocliRunner.call(FlowNamespaceUpdateCommand.class, ctx, updateArgs);
            assertThat(out.toString(), containsString("3 flow(s)"));

            // then we reindex them
            String[] reindexArgs = {
                "--type",
               "flow",
            };
            Integer call = PicocliRunner.call(ReindexCommand.class, ctx, reindexArgs);
            assertThat(call, is(0));
            // in local it reindex 3 flows and in CI 4 for an unknown reason
            assertThat(out.toString(), containsString("Successfully reindex"));
        }
    }