| 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.rimuhosting.miro.binder; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | import javax.inject.Inject; |
| 28 | |
| 29 | import org.jclouds.http.HttpRequest; |
| 30 | import org.jclouds.json.Json; |
| 31 | import org.jclouds.rimuhosting.miro.data.CreateOptions; |
| 32 | import org.jclouds.rimuhosting.miro.data.NewServerData; |
| 33 | import org.jclouds.rimuhosting.miro.domain.MetaData; |
| 34 | |
| 35 | /** |
| 36 | * @author Ivan Meredith |
| 37 | */ |
| 38 | public class CreateServerOptions extends RimuHostingJsonBinder { |
| 39 | @Inject |
| 40 | public CreateServerOptions(Json jsonBinder) { |
| 41 | super(jsonBinder); |
| 42 | } |
| 43 | |
| 44 | private String password; |
| 45 | private List<MetaData> metaData = new ArrayList<MetaData>(); |
| 46 | |
| 47 | @Override |
| 48 | public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) { |
| 49 | String name = checkNotNull(postParams.get("name")); |
| 50 | String imageId = checkNotNull(postParams.get("imageId")); |
| 51 | String planId = checkNotNull(postParams.get("planId")); |
| 52 | // There will be cases when the password is null. |
| 53 | String password = this.password; |
| 54 | NewServerData newServerData = new NewServerData(new CreateOptions(name, password, imageId), planId); |
| 55 | newServerData.setMetaData(metaData); |
| 56 | return bindToRequest(request, newServerData); |
| 57 | } |
| 58 | |
| 59 | public CreateServerOptions withPassword(String password) { |
| 60 | this.password = password; |
| 61 | return this; |
| 62 | } |
| 63 | |
| 64 | public CreateServerOptions withMetaData(List<MetaData> metaData) { |
| 65 | this.metaData = metaData; |
| 66 | return this; |
| 67 | } |
| 68 | } |