// Path: src/main/java/re/vianneyfaiv/persephone/domain/app/Application.java
// public class Application {
// 
// 	private int id;
// 	private String name;
// 	private String environment;
// 	private String url;
// 	private boolean up; // set when application is clicked
// 	private Endpoints endpoints;
// 	private AuthScheme authScheme;
// 	private String actuatorUsername;
// 	private String actuatorPassword;
// 	private ActuatorVersion actuatorVersion; // set when application is clicked
// 
// 	/**
// 	 * Application without HTTP Auth
// 	 */
// 	public Application(int id, String name, String environment, String url) {
// 		this.id = id;
// 		this.name = name;
// 		this.environment = environment;
// 		this.url = url;
// 		this.endpoints = new Endpoints(url);
// 		this.authScheme = AuthScheme.NONE;
// 	}
// 
// 	/**
// 	 * Application with HTTP Auth Basic enabled
// 	 */
// 	public Application(int id, String name, String environment, String url, String username, String password) {
// 		this.id = id;
// 		this.name = name;
// 		this.environment = environment;
// 		this.url = url;
// 		this.endpoints = new Endpoints(url);
// 		this.authScheme = AuthScheme.BASIC;
// 		this.actuatorUsername = username;
// 		this.actuatorPassword = password;
// 	}
// 
// 	public boolean isAuthValid() {
// 		if(AuthScheme.BASIC == authScheme) {
// 			return !StringUtils.isEmpty(actuatorUsername) && !StringUtils.isEmpty(actuatorPassword);
// 		}
// 
// 		return true;
// 	}
// 
// 	public int getId() {
// 		return this.id;
// 	}
// 
// 	public String getName() {
// 		return this.name;
// 	}
// 
// 	public String getEnvironment() {
// 		return this.environment;
// 	}
// 
// 	public String getUrl() {
// 		return this.url;
// 	}
// 
// 	public void setUp(boolean up) {
// 		this.up = up;
// 	}
// 
// 	public boolean isUp() {
// 		return this.up;
// 	}
// 
// 	public Endpoints endpoints() {
// 		return this.endpoints;
// 	}
// 
// 	public AuthScheme getAuthScheme() {
// 		return authScheme;
// 	}
// 
// 	public String getActuatorUsername() {
// 		return actuatorUsername;
// 	}
// 
// 	public String getActuatorPassword() {
// 		return actuatorPassword;
// 	}
// 
// 	public ActuatorVersion getActuatorVersion() {
// 		return actuatorVersion;
// 	}
// 
// 	public void setActuatorVersion(ActuatorVersion actuatorVersion) {
// 		this.actuatorVersion = actuatorVersion;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Application [id=" + id + ", name=" + name + ", environment=" + environment + ", url=" + url + ", up="
// 				+ up + ", authScheme=" + authScheme + "]";
// 	}
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/exception/ApplicationNotFoundException.java
// public class ApplicationNotFoundException extends RuntimeException {
// 
// 	public ApplicationNotFoundException(int appId) {
// 		super(String.format("Application with id %s has not been found", appId));
// 	}
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/service/ApplicationService.java
// @Service
// public class ApplicationService {
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(LogsService.class);
// 
// 	private List<Application> applications = Collections.emptyList();
// 
// 	public List<Application> findAll() {
// 		LOGGER.debug("Get all applications");
// 		return this.applications;
// 	}
// 
// 	public Optional<Application> findById(int appId) {
// 		LOGGER.debug("Get application with id {}", appId);
// 		return this.applications.stream().filter(app -> app.getId() == appId).findFirst();
// 	}
// 
// 	public void setApplications(List<Application> apps) {
// 		LOGGER.debug("Adding {} applications", apps.size());
//         this.applications = Collections.unmodifiableList(apps);
//     }
// 
// 	public void setUp(Application app, boolean up) {
// 		if(app.isUp() != up) {
// 			LOGGER.info("Changing Application#up to {} for application with id {}", up, app.getId());
// 			app.setUp(up);
// 		}
// 	}
// 
// 	public void setActuatorVersion(Application app, ActuatorVersion actuatorVersion) {
// 		if(app.getActuatorVersion() == null) {
// 			LOGGER.info("Changing Application#actuatorVersion to {} for application with id {}", actuatorVersion, app.getId());
// 			app.setActuatorVersion(actuatorVersion);
// 		}
// 	}
// }


import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Layout;
import re.vianneyfaiv.persephone.domain.app.Application;
import re.vianneyfaiv.persephone.exception.ApplicationNotFoundException;
import re.vianneyfaiv.persephone.service.ApplicationService;
package re.vianneyfaiv.persephone.ui.util;





@Component
public class PageHelper {

	@Autowired
	private ApplicationService appService;

	/**
	 * Set component error handler with the one from UI.
	 * This is required because when an exception is thrown when calling Navigator#navigateTo it won't be handled by UI' error handler
	 */
	public void setErrorHandler(Layout page) {
		page.setErrorHandler(page.getUI().getErrorHandler());
	}

	public void setLayoutStyle(AbstractOrderedLayout page) {
		// Center align layout
		page.setWidth("100%");
		page.setMargin(new MarginInfo(false, true));
	}

	public Application getApp(int appId) {
		Optional<Application> app = appService.findById(appId);
		if(!app.isPresent()) {
// Path: src/main/java/re/vianneyfaiv/persephone/domain/app/Application.java
// public class Application {
// 
// 	private int id;
// 	private String name;
// 	private String environment;
// 	private String url;
// 	private boolean up; // set when application is clicked
// 	private Endpoints endpoints;
// 	private AuthScheme authScheme;
// 	private String actuatorUsername;
// 	private String actuatorPassword;
// 	private ActuatorVersion actuatorVersion; // set when application is clicked
// 
// 	/**
// 	 * Application without HTTP Auth
// 	 */
// 	public Application(int id, String name, String environment, String url) {
// 		this.id = id;
// 		this.name = name;
// 		this.environment = environment;
// 		this.url = url;
// 		this.endpoints = new Endpoints(url);
// 		this.authScheme = AuthScheme.NONE;
// 	}
// 
// 	/**
// 	 * Application with HTTP Auth Basic enabled
// 	 */
// 	public Application(int id, String name, String environment, String url, String username, String password) {
// 		this.id = id;
// 		this.name = name;
// 		this.environment = environment;
// 		this.url = url;
// 		this.endpoints = new Endpoints(url);
// 		this.authScheme = AuthScheme.BASIC;
// 		this.actuatorUsername = username;
// 		this.actuatorPassword = password;
// 	}
// 
// 	public boolean isAuthValid() {
// 		if(AuthScheme.BASIC == authScheme) {
// 			return !StringUtils.isEmpty(actuatorUsername) && !StringUtils.isEmpty(actuatorPassword);
// 		}
// 
// 		return true;
// 	}
// 
// 	public int getId() {
// 		return this.id;
// 	}
// 
// 	public String getName() {
// 		return this.name;
// 	}
// 
// 	public String getEnvironment() {
// 		return this.environment;
// 	}
// 
// 	public String getUrl() {
// 		return this.url;
// 	}
// 
// 	public void setUp(boolean up) {
// 		this.up = up;
// 	}
// 
// 	public boolean isUp() {
// 		return this.up;
// 	}
// 
// 	public Endpoints endpoints() {
// 		return this.endpoints;
// 	}
// 
// 	public AuthScheme getAuthScheme() {
// 		return authScheme;
// 	}
// 
// 	public String getActuatorUsername() {
// 		return actuatorUsername;
// 	}
// 
// 	public String getActuatorPassword() {
// 		return actuatorPassword;
// 	}
// 
// 	public ActuatorVersion getActuatorVersion() {
// 		return actuatorVersion;
// 	}
// 
// 	public void setActuatorVersion(ActuatorVersion actuatorVersion) {
// 		this.actuatorVersion = actuatorVersion;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return "Application [id=" + id + ", name=" + name + ", environment=" + environment + ", url=" + url + ", up="
// 				+ up + ", authScheme=" + authScheme + "]";
// 	}
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/exception/ApplicationNotFoundException.java
// public class ApplicationNotFoundException extends RuntimeException {
// 
// 	public ApplicationNotFoundException(int appId) {
// 		super(String.format("Application with id %s has not been found", appId));
// 	}
// }
// 
// Path: src/main/java/re/vianneyfaiv/persephone/service/ApplicationService.java
// @Service
// public class ApplicationService {
// 
// 	private static final Logger LOGGER = LoggerFactory.getLogger(LogsService.class);
// 
// 	private List<Application> applications = Collections.emptyList();
// 
// 	public List<Application> findAll() {
// 		LOGGER.debug("Get all applications");
// 		return this.applications;
// 	}
// 
// 	public Optional<Application> findById(int appId) {
// 		LOGGER.debug("Get application with id {}", appId);
// 		return this.applications.stream().filter(app -> app.getId() == appId).findFirst();
// 	}
// 
// 	public void setApplications(List<Application> apps) {
// 		LOGGER.debug("Adding {} applications", apps.size());
//         this.applications = Collections.unmodifiableList(apps);
//     }
// 
// 	public void setUp(Application app, boolean up) {
// 		if(app.isUp() != up) {
// 			LOGGER.info("Changing Application#up to {} for application with id {}", up, app.getId());
// 			app.setUp(up);
// 		}
// 	}
// 
// 	public void setActuatorVersion(Application app, ActuatorVersion actuatorVersion) {
// 		if(app.getActuatorVersion() == null) {
// 			LOGGER.info("Changing Application#actuatorVersion to {} for application with id {}", actuatorVersion, app.getId());
// 			app.setActuatorVersion(actuatorVersion);
// 		}
// 	}
// }


// Path: src/main/java/re/vianneyfaiv/persephone/ui/util/PageHelper.java
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.AbstractOrderedLayout;
import com.vaadin.ui.Layout;
import re.vianneyfaiv.persephone.domain.app.Application;
import re.vianneyfaiv.persephone.exception.ApplicationNotFoundException;
import re.vianneyfaiv.persephone.service.ApplicationService;

package re.vianneyfaiv.persephone.ui.util;





@Component
public class PageHelper {

	@Autowired
	private ApplicationService appService;

	/**
	 * Set component error handler with the one from UI.
	 * This is required because when an exception is thrown when calling Navigator#navigateTo it won't be handled by UI' error handler
	 */
	public void setErrorHandler(Layout page) {
		page.setErrorHandler(page.getUI().getErrorHandler());
	}

	public void setLayoutStyle(AbstractOrderedLayout page) {
		// Center align layout
		page.setWidth("100%");
		page.setMargin(new MarginInfo(false, true));
	}

	public Application getApp(int appId) {
		Optional<Application> app = appService.findById(appId);
		if(!app.isPresent()) {
			throw new ApplicationNotFoundException(appId);