| 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 | */ |
| 19 | package org.jclouds.atmos.blobstore.functions; |
| 20 | |
| 21 | import java.util.Map.Entry; |
| 22 | |
| 23 | import javax.inject.Inject; |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.atmos.domain.AtmosObject; |
| 27 | import org.jclouds.atmos.domain.UserMetadata; |
| 28 | import org.jclouds.blobstore.domain.BlobMetadata; |
| 29 | |
| 30 | import com.google.common.base.Function; |
| 31 | |
| 32 | /** |
| 33 | * @author Adrian Cole |
| 34 | */ |
| 35 | @Singleton |
| 36 | public class BlobMetadataToObject implements Function<BlobMetadata, AtmosObject> { |
| 37 | private final AtmosObject.Factory factory; |
| 38 | private final BlobToContentMetadata blob2ContentMd; |
| 39 | private final BlobToSystemMetadata blob2SysMd; |
| 40 | |
| 41 | @Inject |
| 42 | protected BlobMetadataToObject(AtmosObject.Factory factory, |
| 43 | BlobToContentMetadata blob2ContentMd, BlobToSystemMetadata blob2SysMd) { |
| 44 | this.factory = factory; |
| 45 | this.blob2ContentMd = blob2ContentMd; |
| 46 | this.blob2SysMd = blob2SysMd; |
| 47 | } |
| 48 | |
| 49 | public AtmosObject apply(BlobMetadata from) { |
| 50 | if (from == null) |
| 51 | return null; |
| 52 | UserMetadata userMd = new UserMetadata(); |
| 53 | if (from.getUserMetadata() != null) { |
| 54 | for (Entry<String, String> entry : from.getUserMetadata().entrySet()) |
| 55 | userMd.getMetadata().put(entry.getKey().toLowerCase(), entry.getValue()); |
| 56 | } |
| 57 | return factory.create(blob2ContentMd.apply(from), blob2SysMd.apply(from), userMd); |
| 58 | } |
| 59 | |
| 60 | } |