Issue 628: fixed error on vCloud find network

This commit is contained in:
Adrian Cole 2011-07-23 10:17:50 +10:00
parent 2ac2524baa
commit 162214f209
1 changed files with 11 additions and 30 deletions

View File

@ -18,8 +18,6 @@
*/ */
package org.jclouds.vcloud.functions; package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -31,45 +29,28 @@ import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
/** /**
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class OrgNameVDCNameResourceEntityNameToEndpoint implements Function<Object, URI> { public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
private final Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
private final ReferenceType defaultOrg;
private final ReferenceType defaultVDC;
@Inject @Inject
public OrgNameVDCNameResourceEntityNameToEndpoint( public OrgNameVDCNameResourceEntityNameToEndpoint(
Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap, @Org ReferenceType defaultOrg, Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
@VDC ReferenceType defaultVDC) { @Org ReferenceType defaultOrg, @VDC ReferenceType defaultVDC) {
this.orgVDCMap = orgVDCMap; super(orgVDCMap, defaultOrg, defaultVDC);
this.defaultOrg = defaultOrg;
this.defaultVDC = defaultVDC;
} }
@SuppressWarnings("unchecked") protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
public URI apply(Object from) { org.jclouds.vcloud.domain.VDC vDCObject) {
Iterable<Object> orgVDC = (Iterable<Object>) checkNotNull(from, "args"); ReferenceType resourceEntity = vDCObject.getResourceEntities().get(resource);
Object org = Iterables.get(orgVDC, 0); if (resourceEntity == null)
Object vDC = Iterables.get(orgVDC, 1); throw new NoSuchElementException("entity " + resource + " in vdc " + vDC + ", org " + org + " not found in "
Object entityName = Iterables.get(orgVDC, 2); + vDCObject.getResourceEntities().keySet());
if (org == null) return resourceEntity.getHref();
org = defaultOrg.getName();
if (vDC == null)
vDC = defaultVDC.getName();
try {
Map<String, ? extends org.jclouds.vcloud.domain.VDC> vDCs = checkNotNull(orgVDCMap.get().get(org));
return vDCs.get(vDC).getResourceEntities().get(entityName).getHref();
} catch (NullPointerException e) {
throw new NoSuchElementException(org + "/" + vDC + "/" + entityName + " not found in " + orgVDCMap.get());
}
} }
} }