| 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.cloudsigma.functions; |
| 20 | |
| 21 | import java.util.Map; |
| 22 | |
| 23 | import javax.annotation.Resource; |
| 24 | import javax.inject.Singleton; |
| 25 | |
| 26 | import org.jclouds.cloudsigma.domain.ProfileInfo; |
| 27 | import org.jclouds.cloudsigma.domain.ProfileType; |
| 28 | import org.jclouds.logging.Logger; |
| 29 | |
| 30 | import com.google.common.base.Function; |
| 31 | |
| 32 | /** |
| 33 | * |
| 34 | * @author Adrian Cole |
| 35 | */ |
| 36 | @Singleton |
| 37 | public class MapToProfileInfo implements Function<Map<String, String>, ProfileInfo> { |
| 38 | |
| 39 | @Resource |
| 40 | protected Logger logger = Logger.NULL; |
| 41 | |
| 42 | @Override |
| 43 | public ProfileInfo apply(Map<String, String> from) { |
| 44 | if (from.size() == 0) |
| 45 | return null; |
| 46 | if (from.size() == 0) |
| 47 | return null; |
| 48 | ProfileInfo.Builder builder = new ProfileInfo.Builder(); |
| 49 | builder.uuid(from.get("uuid")); |
| 50 | builder.email(from.get("email")); |
| 51 | builder.firstName(from.get("first_name")); |
| 52 | builder.lastName(from.get("last_name")); |
| 53 | builder.nickName(from.get("nick_name")); |
| 54 | builder.type(ProfileType.fromValue(from.get("type"))); |
| 55 | try { |
| 56 | return builder.build(); |
| 57 | } catch (NullPointerException e) { |
| 58 | logger.trace("entry missing data: %s; %s", e.getMessage(), from); |
| 59 | return null; |
| 60 | } |
| 61 | } |
| 62 | } |