/**
 * Copyright (c) 2018, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package eu.itesla_project.case_projector;

import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;

import com.powsybl.computation.ComputationManager;
import com.powsybl.iidm.network.Network;
import com.powsybl.loadflow.LoadFlow;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.loadflow.LoadFlowResult;
import com.powsybl.loadflow.LoadFlowResultImpl;

/**
* @author Giovanni Ferrari <giovanni.ferrari at techrain.eu>
*/
public class CaseProjectorLoadFlow implements LoadFlow {

    private final Network network;
    private final ComputationManager computationManager;

    public CaseProjectorLoadFlow(Network network, ComputationManager computationManager, int priority) {
        this.network = Objects.requireNonNull(network);
        this.computationManager = Objects.requireNonNull(computationManager);
    }

    @Override
    public String getName() {
        return "case-projector-load-flow";
    }

    @Override
    public String getVersion() {
        return "1.0.0";
    }

    @Override
    public LoadFlowResult run(LoadFlowParameters params) throws Exception {
        CaseProjectorLoadFlowParameters amplParams = params.getExtension(CaseProjectorLoadFlowParameters.class);
        Path generatorsDomains = amplParams.getGeneratorsDomainsFile();
        Map<String, String> metrics = new HashMap<>();
        CompletableFuture<Boolean> result = CaseProjectorUtils.createAmplTask(computationManager, network, network.getStateManager().getWorkingStateId(), new CaseProjectorConfig(amplParams.getAmplHomeDir(), generatorsDomains, amplParams.isDebug()));
        Boolean wres = result.join();
        return new LoadFlowResultImpl(wres, metrics, null);
    }

}

@@ -358,30 +358,8 @@
 ap;%0A
-import java.util.Map;%0A
 impo
@@ -1404,16 +1404,20 @@
 rs param
+eter
 s) throw
@@ -1430,16 +1430,569 @@
 ption %7B%0A
+        Boolean wres = runAmplTask(network.getStateManager().getWorkingStateId(), parameters).join();%0A        return new LoadFlowResultImpl(wres, new HashMap%3C%3E(), null);%0A    %7D%0A%0A    @Override%0A    public CompletableFuture%3CLoadFlowResult%3E runAsync(String workingStateId, LoadFlowParameters parameters) %7B%0A        return runAmplTask(workingStateId, parameters)%0A                .thenApply(x -%3E new LoadFlowResultImpl(x, new HashMap%3C%3E(), null));%0A    %7D%0A%0A    private CompletableFuture%3CBoolean%3E runAmplTask(String workingStateId, LoadFlowParameters parameters) %7B%0A
         
@@ -2037,24 +2037,28 @@
 rams = param
+eter
 s.getExtensi
@@ -2184,98 +2184,14 @@
     
-Map%3CString, String%3E metrics = new HashMap%3C%3E();%0A        CompletableFuture%3CBoolean%3E result =
+return
  Cas
@@ -2254,41 +2254,12 @@
 rk, 
-net
 work
-.getStateManager().getWork
 ingS
@@ -2264,18 +2264,16 @@
 gStateId
-()
 , new Ca
@@ -2366,106 +2366,8 @@
 ));%0A
-        Boolean wres = result.join();%0A        return new LoadFlowResultImpl(wres, metrics, null);%0A
     

Implement runAsync