Search in sources :

Example 1 with DeploymentProperty

use of com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty in project azure-tools-for-java by Microsoft.

the class DeploymentPropertyViewPresenter method onLoadProperty.

public void onLoadProperty(DeploymentNode node) {
    Observable.fromCallable(() -> {
        List<String> parameters = new ArrayList<>();
        List<String> variables = new ArrayList<>();
        List<String> resources = new ArrayList<>();
        Deployment deployment = node.getDeployment();
        DeploymentExportResult template = deployment.exportTemplate();
        Map<String, Object> templateObj = (Map<String, Object>) template.template();
        if (templateObj.get("parameters") != null) {
            Map<String, Map<String, String>> parametersTmp = (Map<String, Map<String, String>>) templateObj.get("parameters");
            for (String parameter : parametersTmp.keySet()) {
                parameters.add(String.format("%s(%s)", parameter, parametersTmp.get(parameter).get("type")));
            }
        }
        if (templateObj.get("variables") != null) {
            Map<String, Map<String, String>> variablesTmp = (Map<String, Map<String, String>>) templateObj.get("variables");
            for (String variable : variablesTmp.keySet()) {
                variables.add(variable);
            }
        }
        if (templateObj.get("resources") != null) {
            List<Map<String, String>> resourcesTmp = (List<Map<String, String>>) templateObj.get("resources");
            for (Map<String, String> resource : resourcesTmp) {
                resources.add(String.format("%s(%s)", resource.get("name"), resource.get("type")));
            }
        }
        return new DeploymentProperty(deployment, parameters, variables, resources, template.templateAsJson());
    }).subscribeOn(this.getSchedulerProvider().io()).subscribe((property) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                getMvpView().onLoadProperty(property);
            }
        });
    }, (e) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                DefaultLoader.getUIHelper().logError("An exception occurred when load deployment properties", e);
                DefaultLoader.getUIHelper().showError(node, "An exception occurred when load deployment properties, " + e.getMessage());
            }
        });
    });
}
Also used : ArrayList(java.util.ArrayList) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) Deployment(com.microsoft.azure.management.resources.Deployment) DeploymentProperty(com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 2 with DeploymentProperty

use of com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty in project azure-tools-for-java by microsoft.

the class DeploymentPropertyViewPresenter method onLoadProperty.

public void onLoadProperty(DeploymentNode node) {
    Observable.fromCallable(() -> {
        List<String> parameters = new ArrayList<>();
        List<String> variables = new ArrayList<>();
        List<String> resources = new ArrayList<>();
        Deployment deployment = node.getDeployment();
        DeploymentExportResult template = deployment.exportTemplate();
        Map<String, Object> templateObj = (Map<String, Object>) template.template();
        if (templateObj.get("parameters") != null) {
            Map<String, Map<String, String>> parametersTmp = (Map<String, Map<String, String>>) templateObj.get("parameters");
            for (String parameter : parametersTmp.keySet()) {
                parameters.add(String.format("%s(%s)", parameter, parametersTmp.get(parameter).get("type")));
            }
        }
        if (templateObj.get("variables") != null) {
            Map<String, Map<String, String>> variablesTmp = (Map<String, Map<String, String>>) templateObj.get("variables");
            for (String variable : variablesTmp.keySet()) {
                variables.add(variable);
            }
        }
        if (templateObj.get("resources") != null) {
            List<Map<String, String>> resourcesTmp = (List<Map<String, String>>) templateObj.get("resources");
            for (Map<String, String> resource : resourcesTmp) {
                resources.add(String.format("%s(%s)", resource.get("name"), resource.get("type")));
            }
        }
        return new DeploymentProperty(deployment, parameters, variables, resources, template.templateAsJson());
    }).subscribeOn(this.getSchedulerProvider().io()).subscribe((property) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                getMvpView().onLoadProperty(property);
            }
        });
    }, (e) -> {
        DefaultLoader.getIdeHelper().invokeLater(() -> {
            if (!this.isViewDetached()) {
                DefaultLoader.getUIHelper().logError("An exception occurred when load deployment properties", e);
                DefaultLoader.getUIHelper().showError(node, "An exception occurred when load deployment properties, " + e.getMessage());
            }
        });
    });
}
Also used : ArrayList(java.util.ArrayList) DeploymentExportResult(com.microsoft.azure.management.resources.DeploymentExportResult) Deployment(com.microsoft.azure.management.resources.Deployment) DeploymentProperty(com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

Deployment (com.microsoft.azure.management.resources.Deployment)2 DeploymentExportResult (com.microsoft.azure.management.resources.DeploymentExportResult)2 DeploymentProperty (com.microsoft.azuretools.core.mvp.ui.arm.DeploymentProperty)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2