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

COVERAGE SUMMARY FOR SOURCE FILE [BlobPropertiesToBlobMetadata.java]

nameclass, %method, %block, %line, %
BlobPropertiesToBlobMetadata.java100% (1/1)100% (2/2)34%  (30/89)40%  (10/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class BlobPropertiesToBlobMetadata100% (1/1)100% (2/2)34%  (30/89)40%  (10/25)
apply (BlobProperties): MutableBlobMetadata 100% (1/1)20%  (15/74)29%  (6/21)
BlobPropertiesToBlobMetadata (IfDirectoryReturnNameStrategy, Map): void 100% (1/1)100% (15/15)100% (4/4)

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.azureblob.blobstore.functions;
20 
21import static com.google.common.base.Preconditions.checkNotNull;
22 
23import java.util.Map;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.azureblob.domain.BlobProperties;
29import org.jclouds.azureblob.domain.PublicAccess;
30import org.jclouds.blobstore.domain.MutableBlobMetadata;
31import org.jclouds.blobstore.domain.StorageType;
32import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
33import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
34import org.jclouds.http.HttpUtils;
35 
36import com.google.common.base.Function;
37 
38/**
39 * @author Adrian Cole
40 */
41@Singleton
42public class BlobPropertiesToBlobMetadata implements Function<BlobProperties, MutableBlobMetadata> {
43   private final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
44   private final Map<String, PublicAccess> containerAcls;
45 
46   @Inject
47   public BlobPropertiesToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName,
48            Map<String, PublicAccess> containerAcls) {
49      this.ifDirectoryReturnName = checkNotNull(ifDirectoryReturnName, "ifDirectoryReturnName");
50      this.containerAcls = checkNotNull(containerAcls, "containerAcls");
51   }
52 
53   public MutableBlobMetadata apply(BlobProperties from) {
54      if (from == null)
55         return null;
56      MutableBlobMetadata to = new MutableBlobMetadataImpl();
57      HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata());
58      to.setUserMetadata(from.getMetadata());
59      to.setETag(from.getETag());
60      to.setLastModified(from.getLastModified());
61      to.setName(from.getName());
62      to.setContainer(from.getContainer());
63      to.setUri(from.getUrl());
64      try {
65         PublicAccess containerAcl = containerAcls.get(from.getContainer());
66         if (containerAcl != null && containerAcl != PublicAccess.PRIVATE)
67            to.setPublicUri(from.getUrl());
68      } catch (NullPointerException e) {
69         // MapMaker cannot return null, but a call to get acls can
70      }
71      String directoryName = ifDirectoryReturnName.execute(to);
72      if (directoryName != null) {
73         to.setName(directoryName);
74         to.setType(StorageType.RELATIVE_PATH);
75      } else {
76         to.setType(StorageType.BLOB);
77      }
78      return to;
79   }
80}

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