EMMA Coverage Report (generated Mon Oct 17 05:41:20 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 * 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.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