| 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 javax.inject.Inject; |
| 22 | import javax.inject.Singleton; |
| 23 | |
| 24 | import org.jclouds.atmos.domain.BoundedSet; |
| 25 | import org.jclouds.atmos.domain.DirectoryEntry; |
| 26 | import org.jclouds.atmos.domain.FileType; |
| 27 | import org.jclouds.blobstore.domain.PageSet; |
| 28 | import org.jclouds.blobstore.domain.StorageMetadata; |
| 29 | import org.jclouds.blobstore.domain.StorageType; |
| 30 | import org.jclouds.blobstore.domain.internal.BlobMetadataImpl; |
| 31 | import org.jclouds.blobstore.domain.internal.PageSetImpl; |
| 32 | import org.jclouds.blobstore.domain.internal.StorageMetadataImpl; |
| 33 | import org.jclouds.domain.Location; |
| 34 | import org.jclouds.io.payloads.BaseMutableContentMetadata; |
| 35 | |
| 36 | import com.google.common.base.Function; |
| 37 | import com.google.common.base.Supplier; |
| 38 | import com.google.common.collect.ImmutableMap; |
| 39 | import com.google.common.collect.Iterables; |
| 40 | |
| 41 | /** |
| 42 | * @author Adrian Cole |
| 43 | */ |
| 44 | @Singleton |
| 45 | public class DirectoryEntryListToResourceMetadataList implements |
| 46 | Function<BoundedSet<? extends DirectoryEntry>, PageSet<? extends StorageMetadata>> { |
| 47 | private Supplier<Location> defaultLocation; |
| 48 | |
| 49 | @Inject |
| 50 | DirectoryEntryListToResourceMetadataList(Supplier<Location> defaultLocation) { |
| 51 | this.defaultLocation = defaultLocation; |
| 52 | } |
| 53 | |
| 54 | public PageSet<? extends StorageMetadata> apply(BoundedSet<? extends DirectoryEntry> from) { |
| 55 | |
| 56 | return new PageSetImpl<StorageMetadata>(Iterables.transform(from, |
| 57 | new Function<DirectoryEntry, StorageMetadata>() { |
| 58 | |
| 59 | public StorageMetadata apply(DirectoryEntry from) { |
| 60 | StorageType type = from.getType() == FileType.DIRECTORY ? StorageType.FOLDER : StorageType.BLOB; |
| 61 | if (type == StorageType.FOLDER) |
| 62 | return new StorageMetadataImpl(type, from.getObjectID(), from.getObjectName(), defaultLocation |
| 63 | .get(), null, null, null,ImmutableMap.<String,String>of()); |
| 64 | else |
| 65 | return new BlobMetadataImpl(from.getObjectID(), from.getObjectName(), defaultLocation.get(), |
| 66 | null, null, null,ImmutableMap.<String,String>of(), null, |
| 67 | null, new BaseMutableContentMetadata()); |
| 68 | } |
| 69 | |
| 70 | }), from.getToken()); |
| 71 | |
| 72 | } |
| 73 | } |