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

COVERAGE SUMMARY FOR SOURCE FILE [ObjectToBlobMetadata.java]

nameclass, %method, %block, %line, %
ObjectToBlobMetadata.java0%   (0/1)0%   (0/2)0%   (0/83)0%   (0/25)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ObjectToBlobMetadata0%   (0/1)0%   (0/2)0%   (0/83)0%   (0/25)
ObjectToBlobMetadata (IfDirectoryReturnNameStrategy, Map): void 0%   (0/1)0%   (0/9)0%   (0/4)
apply (ObjectMetadata): MutableBlobMetadata 0%   (0/1)0%   (0/74)0%   (0/21)

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.s3.blobstore.functions;
20 
21import java.util.Map;
22 
23import javax.inject.Inject;
24import javax.inject.Singleton;
25 
26import org.jclouds.blobstore.domain.MutableBlobMetadata;
27import org.jclouds.blobstore.domain.StorageType;
28import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
29import org.jclouds.blobstore.strategy.IfDirectoryReturnNameStrategy;
30import org.jclouds.http.HttpUtils;
31import org.jclouds.s3.domain.AccessControlList;
32import org.jclouds.s3.domain.ObjectMetadata;
33import org.jclouds.s3.domain.AccessControlList.GroupGranteeURI;
34import org.jclouds.s3.domain.AccessControlList.Permission;
35 
36import com.google.common.base.Function;
37 
38/**
39 * @author Adrian Cole
40 */
41@Singleton
42public class ObjectToBlobMetadata implements Function<ObjectMetadata, MutableBlobMetadata> {
43   private final IfDirectoryReturnNameStrategy ifDirectoryReturnName;
44   private final Map<String, AccessControlList> bucketAcls;
45 
46   @Inject
47   public ObjectToBlobMetadata(IfDirectoryReturnNameStrategy ifDirectoryReturnName,
48            Map<String, AccessControlList> bucketAcls) {
49      this.ifDirectoryReturnName = ifDirectoryReturnName;
50      this.bucketAcls = bucketAcls;
51   }
52 
53   public MutableBlobMetadata apply(ObjectMetadata from) {
54      if (from == null)
55         return null;
56      MutableBlobMetadata to = new MutableBlobMetadataImpl();
57      HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata());
58      try {
59         AccessControlList bucketAcl = bucketAcls.get(from.getBucket());
60         if (bucketAcl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ))
61            to.setPublicUri(from.getUri());
62      } catch (NullPointerException e) {
63         // MapMaker cannot return null, but a call to get acls can
64      }
65      to.setUri(from.getUri());
66      to.setContainer(from.getBucket());
67      to.setETag(from.getETag());
68      to.setName(from.getKey());
69      to.setLastModified(from.getLastModified());
70      to.setUserMetadata(from.getUserMetadata());
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.s3.blobstore.functions]
EMMA 2.0.5312 (C) Vladimir Roubtsov