EMMA Coverage Report (generated Wed Jun 22 19:47:49 EDT 2011)
[all classes][org.jclouds.vcloud.functions]

COVERAGE SUMMARY FOR SOURCE FILE [VAppTemplatesForCatalogItems.java]

nameclass, %method, %block, %line, %
VAppTemplatesForCatalogItems.java0%   (0/4)0%   (0/11)0%   (0/94)0%   (0/15)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VAppTemplatesForCatalogItems0%   (0/1)0%   (0/5)0%   (0/42)0%   (0/8)
VAppTemplatesForCatalogItems (CommonVCloudAsyncClient, ExecutorService, VAppT... 0%   (0/1)0%   (0/15)0%   (0/6)
access$000 (VAppTemplatesForCatalogItems): CommonVCloudAsyncClient 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (VAppTemplatesForCatalogItems): ExecutorService 0%   (0/1)0%   (0/3)0%   (0/1)
access$200 (VAppTemplatesForCatalogItems): VAppTemplatesForCatalogItems$Retur... 0%   (0/1)0%   (0/3)0%   (0/1)
apply (Iterable): Iterable 0%   (0/1)0%   (0/18)0%   (0/1)
     
class VAppTemplatesForCatalogItems$10%   (0/1)0%   (0/2)0%   (0/12)0%   (0/2)
VAppTemplatesForCatalogItems$1 (VAppTemplatesForCatalogItems): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (CatalogItem): boolean 0%   (0/1)0%   (0/6)0%   (0/1)
     
class VAppTemplatesForCatalogItems$20%   (0/1)0%   (0/2)0%   (0/28)0%   (0/2)
VAppTemplatesForCatalogItems$2 (VAppTemplatesForCatalogItems): void 0%   (0/1)0%   (0/6)0%   (0/1)
apply (CatalogItem): Future 0%   (0/1)0%   (0/22)0%   (0/1)
     
class VAppTemplatesForCatalogItems$ReturnNullOnAuthorizationException0%   (0/1)0%   (0/2)0%   (0/12)0%   (0/4)
VAppTemplatesForCatalogItems$ReturnNullOnAuthorizationException (): void 0%   (0/1)0%   (0/3)0%   (0/1)
apply (Exception): VAppTemplate 0%   (0/1)0%   (0/9)0%   (0/3)

1/**
2 *
3 * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4 *
5 * ====================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ====================================================================
18 */
19package org.jclouds.vcloud.functions;
20 
21import static com.google.common.collect.Iterables.filter;
22import static org.jclouds.concurrent.FutureIterables.transformParallel;
23import static org.jclouds.util.Throwables2.propagateOrNull;
24 
25import java.util.concurrent.ExecutorService;
26import java.util.concurrent.Future;
27 
28import javax.annotation.Resource;
29import javax.inject.Inject;
30import javax.inject.Named;
31import javax.inject.Singleton;
32 
33import org.jclouds.Constants;
34import org.jclouds.compute.reference.ComputeServiceConstants;
35import org.jclouds.concurrent.ExceptionParsingListenableFuture;
36import org.jclouds.concurrent.Futures;
37import org.jclouds.logging.Logger;
38import org.jclouds.rest.AuthorizationException;
39import org.jclouds.vcloud.CommonVCloudAsyncClient;
40import org.jclouds.vcloud.VCloudAsyncClient;
41import org.jclouds.vcloud.VCloudMediaType;
42import org.jclouds.vcloud.domain.CatalogItem;
43import org.jclouds.vcloud.domain.VAppTemplate;
44 
45import com.google.common.base.Function;
46import com.google.common.base.Predicate;
47 
48/**
49 * @author Adrian Cole
50 */
51@Singleton
52public class VAppTemplatesForCatalogItems implements
53         Function<Iterable<? extends CatalogItem>, Iterable<? extends VAppTemplate>> {
54   @Resource
55   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
56   public Logger logger = Logger.NULL;
57   private final CommonVCloudAsyncClient aclient;
58   private final ExecutorService executor;
59   private final ReturnNullOnAuthorizationException returnNullOnAuthorizationException;
60 
61   @Singleton
62   static class ReturnNullOnAuthorizationException implements Function<Exception, VAppTemplate> {
63 
64      public VAppTemplate apply(Exception from) {
65         if (from instanceof AuthorizationException) {
66            return null;
67         }
68         return propagateOrNull(from);
69      }
70   }
71 
72   @Inject
73   VAppTemplatesForCatalogItems(CommonVCloudAsyncClient aclient,
74            @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor,
75            ReturnNullOnAuthorizationException returnNullOnAuthorizationException) {
76      this.aclient = aclient;
77      this.executor = executor;
78      this.returnNullOnAuthorizationException = returnNullOnAuthorizationException;
79   }
80 
81   @Override
82   public Iterable<? extends VAppTemplate> apply(Iterable<? extends CatalogItem> from) {
83      return transformParallel(filter(from, new Predicate<CatalogItem>() {
84 
85         @Override
86         public boolean apply(CatalogItem input) {
87            return input.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML);
88         }
89 
90      }), new Function<CatalogItem, Future<VAppTemplate>>() {
91 
92         @SuppressWarnings("unchecked")
93         @Override
94         public Future<VAppTemplate> apply(CatalogItem from) {
95            return new ExceptionParsingListenableFuture<VAppTemplate>(Futures.makeListenable(
96                     (Future<VAppTemplate>) VCloudAsyncClient.class.cast(aclient).getVAppTemplateClient().getVAppTemplate(
97                              from.getEntity().getHref()), executor), returnNullOnAuthorizationException);
98         }
99 
100      }, executor, null, logger, "vappTemplates in");
101   }
102 
103}

[all classes][org.jclouds.vcloud.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov