EMMA Coverage Report (generated Wed Aug 10 12:30:04 EDT 2011)
[all classes][org.jclouds.atmos.blobstore.functions]

COVERAGE SUMMARY FOR SOURCE FILE [ObjectToBlobMetadata.java]

nameclass, %method, %block, %line, %
ObjectToBlobMetadata.java100% (1/1)67%  (2/3)31%  (48/155)19%  (5/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ObjectToBlobMetadata100% (1/1)67%  (2/3)31%  (48/155)19%  (5/27)
apply (AtmosObject): MutableBlobMetadata 0%   (0/1)0%   (0/107)0%   (0/22)
<static initializer> 100% (1/1)100% (39/39)100% (1/1)
ObjectToBlobMetadata (AtmosObjectName, ShareUrl): void 100% (1/1)100% (9/9)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.atmos.blobstore.functions;
20 
21import java.util.Map;
22import java.util.Set;
23import java.util.Map.Entry;
24 
25import javax.inject.Inject;
26import javax.inject.Singleton;
27 
28import org.jclouds.atmos.domain.AtmosObject;
29import org.jclouds.atmos.domain.FileType;
30import org.jclouds.atmos.filters.ShareUrl;
31import org.jclouds.atmos.functions.AtmosObjectName;
32import org.jclouds.blobstore.domain.MutableBlobMetadata;
33import org.jclouds.blobstore.domain.StorageType;
34import org.jclouds.blobstore.domain.internal.MutableBlobMetadataImpl;
35import org.jclouds.http.HttpUtils;
36 
37import com.google.common.base.Function;
38import com.google.common.base.Splitter;
39import com.google.common.collect.ImmutableSet;
40import com.google.common.collect.Iterables;
41import com.google.common.collect.Maps;
42 
43/**
44 * @author Adrian Cole
45 */
46@Singleton
47public class ObjectToBlobMetadata implements Function<AtmosObject, MutableBlobMetadata> {
48   private final AtmosObjectName objectName;
49   private final ShareUrl shareUrl;
50 
51   private static final Set<String> systemMetadata = ImmutableSet.of("atime", "mtime", "ctime", "itime", "type", "uid",
52            "gid", "objectid", "objname", "size", "nlink", "policyname", "content-md5");
53 
54   @Inject
55   protected ObjectToBlobMetadata(AtmosObjectName objectName, ShareUrl shareUrl)
56            throws SecurityException, NoSuchMethodException {
57      this.objectName = objectName;
58      this.shareUrl = shareUrl;
59   }
60 
61   public MutableBlobMetadata apply(AtmosObject from) {
62      if (from == null)
63         return null;
64      MutableBlobMetadata to = new MutableBlobMetadataImpl();
65      to.setId(from.getSystemMetadata().getObjectID());
66      to.setLastModified(from.getSystemMetadata().getLastUserDataModification());
67      HttpUtils.copy(from.getContentMetadata(), to.getContentMetadata());
68      to.setName(objectName.apply(from));
69      to.setUri(from.getContentMetadata().getUri());
70      to.setContainer(Iterables.get(Splitter.on('/').split(from.getContentMetadata().getPath()),0));
71      if (from.getAllHeaders().containsEntry("x-emc-groupacl", "other=READ"))
72         to.setPublicUri(shareUrl.apply(from.getContentMetadata().getPath()));
73      if (from.getSystemMetadata().getType() == FileType.DIRECTORY) {
74         to.setType(StorageType.FOLDER);
75      } else {
76         to.setType(StorageType.BLOB);
77      }
78      Map<String, String> lowerKeyMetadata = Maps.newHashMap();
79      for (Entry<String, String> entry : from.getUserMetadata().getMetadata().entrySet()) {
80         String key = entry.getKey().toLowerCase();
81         if (!systemMetadata.contains(key))
82            lowerKeyMetadata.put(key, entry.getValue());
83      }
84      to.setUserMetadata(lowerKeyMetadata);
85      return to;
86   }
87}

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