EMMA Coverage Report (generated Mon Oct 17 05:41:20 EDT 2011)
[all classes][org.jclouds.atmos.blobstore]

COVERAGE SUMMARY FOR SOURCE FILE [AtmosBlobStore.java]

nameclass, %method, %block, %line, %
AtmosBlobStore.java100% (1/1)6%   (1/16)20%  (67/339)27%  (12/44)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AtmosBlobStore100% (1/1)6%   (1/16)20%  (67/339)27%  (12/44)
blobExists (String, String): boolean 0%   (0/1)0%   (0/14)0%   (0/1)
blobMetadata (String, String): BlobMetadata 0%   (0/1)0%   (0/17)0%   (0/1)
containerExists (String): boolean 0%   (0/1)0%   (0/12)0%   (0/1)
createContainerInLocation (Location, String): boolean 0%   (0/1)0%   (0/9)0%   (0/2)
createContainerInLocation (Location, String, CreateContainerOptions): boolean 0%   (0/1)0%   (0/21)0%   (0/4)
createDirectory (String, String): void 0%   (0/1)0%   (0/17)0%   (0/2)
deleteAndVerifyContainerGone (String): boolean 0%   (0/1)0%   (0/27)0%   (0/2)
deleteDirectory (String, String): void 0%   (0/1)0%   (0/12)0%   (0/2)
directoryExists (String, String): boolean 0%   (0/1)0%   (0/16)0%   (0/1)
getBlob (String, String, GetOptions): Blob 0%   (0/1)0%   (0/28)0%   (0/2)
list (): PageSet 0%   (0/1)0%   (0/9)0%   (0/1)
list (String, ListContainerOptions): PageSet 0%   (0/1)0%   (0/37)0%   (0/4)
putBlob (String, Blob): String 0%   (0/1)0%   (0/34)0%   (0/6)
putBlob (String, Blob, PutOptions): String 0%   (0/1)0%   (0/5)0%   (0/1)
removeBlob (String, String): void 0%   (0/1)0%   (0/14)0%   (0/2)
AtmosBlobStore (BlobStoreContext, BlobUtils, Supplier, Supplier, AtmosClient,... 100% (1/1)100% (67/67)100% (12/12)

1/**
2 * Licensed to jclouds, Inc. (jclouds) under one or more
3 * contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  jclouds licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  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,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.atmos.blobstore;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22import static org.jclouds.atmos.options.PutOptions.Builder.publicRead;
23 
24import java.util.Map;
25import java.util.Set;
26 
27import javax.inject.Inject;
28import javax.inject.Provider;
29import javax.inject.Singleton;
30 
31import org.jclouds.atmos.AtmosAsyncClient;
32import org.jclouds.atmos.AtmosClient;
33import org.jclouds.atmos.blobstore.functions.BlobStoreListOptionsToListOptions;
34import org.jclouds.atmos.blobstore.functions.BlobToObject;
35import org.jclouds.atmos.blobstore.functions.DirectoryEntryListToResourceMetadataList;
36import org.jclouds.atmos.blobstore.functions.ObjectToBlob;
37import org.jclouds.atmos.blobstore.functions.ObjectToBlobMetadata;
38import org.jclouds.atmos.options.ListOptions;
39import org.jclouds.atmos.util.AtmosUtils;
40import org.jclouds.blobstore.BlobStoreContext;
41import org.jclouds.blobstore.domain.Blob;
42import org.jclouds.blobstore.domain.BlobMetadata;
43import org.jclouds.blobstore.domain.PageSet;
44import org.jclouds.blobstore.domain.StorageMetadata;
45import org.jclouds.blobstore.functions.BlobToHttpGetOptions;
46import org.jclouds.blobstore.internal.BaseBlobStore;
47import org.jclouds.blobstore.options.CreateContainerOptions;
48import org.jclouds.blobstore.options.PutOptions;
49import org.jclouds.blobstore.strategy.internal.FetchBlobMetadata;
50import org.jclouds.blobstore.util.BlobUtils;
51import org.jclouds.collect.Memoized;
52import org.jclouds.crypto.Crypto;
53import org.jclouds.domain.Location;
54import org.jclouds.http.options.GetOptions;
55 
56import com.google.common.base.Supplier;
57 
58/**
59 * @author Adrian Cole
60 */
61@Singleton
62public class AtmosBlobStore extends BaseBlobStore {
63   private final AtmosClient sync;
64   private final ObjectToBlob object2Blob;
65   private final ObjectToBlobMetadata object2BlobMd;
66   private final BlobToObject blob2Object;
67   private final BlobStoreListOptionsToListOptions container2ContainerListOptions;
68   private final DirectoryEntryListToResourceMetadataList container2ResourceList;
69   private final Crypto crypto;
70   private final BlobToHttpGetOptions blob2ObjectGetOptions;
71   private final Provider<FetchBlobMetadata> fetchBlobMetadataProvider;
72   private final Map<String, Boolean> isPublic;
73 
74   @Inject
75   AtmosBlobStore(BlobStoreContext context, BlobUtils blobUtils, Supplier<Location> defaultLocation,
76            @Memoized Supplier<Set<? extends Location>> locations, AtmosClient sync, ObjectToBlob object2Blob,
77            ObjectToBlobMetadata object2BlobMd, BlobToObject blob2Object,
78            BlobStoreListOptionsToListOptions container2ContainerListOptions,
79            DirectoryEntryListToResourceMetadataList container2ResourceList, Crypto crypto,
80            BlobToHttpGetOptions blob2ObjectGetOptions, Provider<FetchBlobMetadata> fetchBlobMetadataProvider,
81            Map<String, Boolean> isPublic) {
82      super(context, blobUtils, defaultLocation, locations);
83      this.blob2ObjectGetOptions = checkNotNull(blob2ObjectGetOptions, "blob2ObjectGetOptions");
84      this.sync = checkNotNull(sync, "sync");
85      this.container2ContainerListOptions = checkNotNull(container2ContainerListOptions,
86               "container2ContainerListOptions");
87      this.container2ResourceList = checkNotNull(container2ResourceList, "container2ResourceList");
88      this.object2Blob = checkNotNull(object2Blob, "object2Blob");
89      this.blob2Object = checkNotNull(blob2Object, "blob2Object");
90      this.object2BlobMd = checkNotNull(object2BlobMd, "object2BlobMd");
91      this.crypto = checkNotNull(crypto, "crypto");
92      this.fetchBlobMetadataProvider = checkNotNull(fetchBlobMetadataProvider, "fetchBlobMetadataProvider");
93      this.isPublic = checkNotNull(isPublic, "isPublic");
94   }
95 
96   /**
97    * This implementation invokes {@link AtmosClient#headFile}
98    */
99   @Override
100   public BlobMetadata blobMetadata(String container, String key) {
101      return object2BlobMd.apply(sync.headFile(container + "/" + key));
102   }
103 
104   /**
105    * This implementation invokes {@link AtmosAsyncClient#deletePath} followed by
106    * {@link AtmosAsyncClient#pathExists} until it is true.
107    */
108   protected boolean deleteAndVerifyContainerGone(final String container) {
109      sync.deletePath(container + "/");
110      return !sync.pathExists(container + "/");
111   }
112 
113   /**
114    * This implementation invokes {@link AtmosClient#createDirectory}
115    * 
116    * @param location
117    *           currently ignored
118    * @param container
119    *           directory name
120    */
121   @Override
122   public boolean createContainerInLocation(Location location, String container) {
123      sync.createDirectory(container);
124      return true;
125   }
126 
127   /**
128    * This implementation invokes {@link AtmosClient#createDirectory}
129    * 
130    * @param container
131    *           directory name
132    */
133   @Override
134   public void createDirectory(String container, String directory) {
135      sync.createDirectory(container + "/" + directory);
136   }
137 
138   /**
139    * This implementation invokes {@link #removeBlob}
140    */
141   @Override
142   public void deleteDirectory(String containerName, String directory) {
143      removeBlob(containerName, directory + "/");
144   }
145 
146   /**
147    * This implementation invokes {@link AtmosClient#pathExists}
148    */
149   @Override
150   public boolean containerExists(String container) {
151      return sync.pathExists(container + "/");
152   }
153 
154   /**
155    * This implementation invokes {@link AtmosClient#pathExists}
156    */
157   @Override
158   public boolean directoryExists(String container, String directory) {
159      return sync.pathExists(container + "/" + directory + "/");
160   }
161 
162   /**
163    * This implementation invokes {@link AtmosClient#pathExists}
164    * 
165    * @param container
166    *           container
167    * @param key
168    *           file name
169    */
170   @Override
171   public boolean blobExists(String container, String key) {
172      return sync.pathExists(container + "/" + key);
173   }
174 
175   /**
176    * This implementation invokes {@link AtmosClient#readFile}
177    */
178   @Override
179   public Blob getBlob(String container, String key, org.jclouds.blobstore.options.GetOptions options) {
180      GetOptions httpOptions = blob2ObjectGetOptions.apply(options);
181      return object2Blob.apply(sync.readFile(container + "/" + key, httpOptions));
182   }
183 
184   /**
185    * This implementation invokes {@link AtmosClient#listDirectories}
186    */
187   @Override
188   public PageSet<? extends StorageMetadata> list() {
189      return container2ResourceList.apply(sync.listDirectories());
190   }
191 
192   /**
193    * This implementation invokes {@link AtmosClient#listDirectory}
194    */
195   @Override
196   public PageSet<? extends StorageMetadata> list(String container,
197            org.jclouds.blobstore.options.ListContainerOptions options) {
198      container = AtmosUtils.adjustContainerIfDirOptionPresent(container, options);
199      ListOptions nativeOptions = container2ContainerListOptions.apply(options);
200      // until includeMeta() option works for namespace interface
201      PageSet<? extends StorageMetadata> list = container2ResourceList.apply(sync.listDirectory(container,
202               nativeOptions));
203      return options.isDetailed() ? fetchBlobMetadataProvider.get().setContainerName(container).apply(list) : list;
204   }
205 
206   /**
207    * This implementation invokes {@link AtmosClient#createFile}
208    * <p/>
209    * Since there is no etag support in atmos, we just return the path.
210    */
211   @Override
212   public String putBlob(final String container, final Blob blob) {
213      final org.jclouds.atmos.options.PutOptions options = new org.jclouds.atmos.options.PutOptions();
214      try {
215         if (isPublic.get(container + "/"))
216            options.publicRead();
217      } catch (NullPointerException e) {
218         // MapMaker
219      }
220      return AtmosUtils.putBlob(sync, crypto, blob2Object, container, blob, options);
221   }
222 
223   /**
224    * This implementation invokes {@link AtmosClient#createFile}
225    * <p/>
226    * Since there is no etag support in atmos, we just return the path.
227    */
228   @Override
229   public String putBlob(String container, Blob blob, PutOptions options) {
230      // TODO implement options
231      return putBlob(container, blob);
232   }
233 
234   /**
235    * This implementation invokes {@link AtmosClient#deletePath}
236    */
237   @Override
238   public void removeBlob(String container, String key) {
239      sync.deletePath(container + "/" + key);
240   }
241 
242   @Override
243   public boolean createContainerInLocation(Location location, String container, CreateContainerOptions options) {
244      if (options.isPublicRead()) {
245         sync.createDirectory(container, publicRead());
246         return true;
247      }
248      return createContainerInLocation(location, container);
249   }
250}

[all classes][org.jclouds.atmos.blobstore]
EMMA 2.0.5312 (C) Vladimir Roubtsov