/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed 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.springframework.cloud.dataflow.server.service;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.cloud.dataflow.core.Launcher;
import org.springframework.cloud.dataflow.core.TaskPlatform;
import org.springframework.cloud.dataflow.server.job.LauncherRepository;
import org.springframework.context.event.EventListener;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Mark Pollack
 */
public class LauncherInitializationService {

	private final Logger logger = LoggerFactory
			.getLogger(LauncherInitializationService.class);
	private final List<TaskPlatform> platforms;
	private LauncherRepository deployerRepository;

	public LauncherInitializationService(LauncherRepository deployerRepository, List<TaskPlatform> platforms) {
		this.deployerRepository = deployerRepository;
		this.platforms = platforms;
	}

	@EventListener
	@Transactional
	public void initialize(ApplicationReadyEvent event) {
		if (singleDeployerExists()) {
			for (TaskPlatform platform : this.platforms) {
				if (platform.getLaunchers().size() == 1) {
					List<Launcher> updatedLaunchers = new ArrayList<>();
					List<Launcher> launchers = platform.getLaunchers();

					Launcher existingLauncher = launchers.get(0);
					if (existingLauncher.getName() != "default") {
						Launcher defaultLauncher = new Launcher("default",
								existingLauncher.getType(), existingLauncher.getTaskLauncher());
						defaultLauncher.setDescription(existingLauncher.getDescription());
						updatedLaunchers.add(defaultLauncher);
					}
					updatedLaunchers.addAll(launchers);
					platform.setLaunchers(updatedLaunchers);
				}
			}
		}
		this.platforms.forEach(platform -> {
			platform.getLaunchers().forEach(deployer -> {
				this.deployerRepository.save(deployer);
				logger.info(String.format(
						"Added '%s' platform account '%s' into Task Launcher repository.",
						platform.getName(),
						deployer.getName()));
			});
		});
	}

	private boolean singleDeployerExists() {
		int deployersCount = 0;
		for (TaskPlatform platform : this.platforms) {
			deployersCount = deployersCount + platform.getLaunchers().size();
		}
		return (deployersCount > 1) ? false : true;
	}
}

@@ -1401,38 +1401,38 @@
 ncherRepository 
-deploy
+launch
 erRepository;%0A%0A%09
@@ -1487,22 +1487,22 @@
 ository 
-deploy
+launch
 erReposi
@@ -1542,30 +1542,30 @@
 s) %7B%0A%09%09this.
-deploy
+launch
 erRepository
@@ -1567,22 +1567,22 @@
 itory = 
-deploy
+launch
 erReposi
@@ -2487,22 +2487,22 @@
 forEach(
-deploy
+launch
 er -%3E %7B%0A
@@ -2510,22 +2510,22 @@
 %09%09%09this.
-deploy
+launch
 erReposi
@@ -2534,22 +2534,22 @@
 ry.save(
-deploy
+launch
 er);%0A%09%09%09
@@ -2681,22 +2681,22 @@
 ,%0A%09%09%09%09%09%09
-deploy
+launch
 er.getNa

Rename local variables in LauncherInitializationService