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