/*******************************************************************************
 * Copyright (c) 2017 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;

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

import org.springframework.ide.vscode.commons.cloudfoundry.client.CFDomain;
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget;
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache;
import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint;
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;

public class ManifestYamlCFDomainsProvider extends AbstractCFHintsProvider {

	public ManifestYamlCFDomainsProvider(CFTargetCache cache) {
		super(cache);
	}

	@Override
	public Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {

		List<YValueHint> hints = new ArrayList<>();

		for (CFTarget cfTarget : targets) {

			List<CFDomain> domains = cfTarget.getDomains();
			if (domains != null && !domains.isEmpty()) {

				for (CFDomain domain : domains) {
					String name = domain.getName();
					String label = getLabel(cfTarget, domain);
					YValueHint hint = new BasicYValueHint(name, label);
					if (!hints.contains(hint)) {
						hints.add(hint);
					}
				}
				return hints;
			}
		}
		// Contract for the reconciler: return null if values cannot be
		// resolved. Otherwise
		// return non-empty list
		return !hints.isEmpty() ? hints : null;
	}

	protected String getLabel(CFTarget target, CFDomain domain) {
		return domain.getName() + " (" + target.getName() + ")";
	}

	@Override
	protected String getTypeName() {
		return "Domain";
	}
}

/*******************************************************************************
 * Copyright (c) 2017 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.manifest.yaml;

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

import org.springframework.ide.vscode.commons.cloudfoundry.client.CFDomain;
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTarget;
import org.springframework.ide.vscode.commons.cloudfoundry.client.cftarget.CFTargetCache;
import org.springframework.ide.vscode.commons.yaml.schema.BasicYValueHint;
import org.springframework.ide.vscode.commons.yaml.schema.YValueHint;

public class ManifestYamlCFDomainsProvider extends AbstractCFHintsProvider {

	public ManifestYamlCFDomainsProvider(CFTargetCache cache) {
		super(cache);
	}

	@Override
	public Collection<YValueHint> getHints(List<CFTarget> targets) throws Exception {

		List<YValueHint> hints = new ArrayList<>();

		for (CFTarget cfTarget : targets) {

			List<CFDomain> domains = cfTarget.getDomains();
			if (domains != null && !domains.isEmpty()) {

				for (CFDomain domain : domains) {
					String name = domain.getName();
					String label = getLabel(cfTarget, domain);
					YValueHint hint = new BasicYValueHint(name, label);
					if (!hints.contains(hint)) {
						hints.add(hint);
					}
				}
				return hints;
			}
		}
		// Contract for the reconciler: return null if values cannot be
		// resolved. Otherwise
		// return non-empty list
		return !hints.isEmpty() ? hints : null;
	}

	protected String getLabel(CFTarget target, CFDomain domain) {
		return domain.getName();
	}

	@Override
	protected String getTypeName() {
		return "Domain";
	}
}

Remove CF api name from domain CA value