1 package autotest.moblab.rpc; 2 3 import com.google.gwt.json.client.JSONBoolean; 4 import com.google.gwt.json.client.JSONObject; 5 import com.google.gwt.json.client.JSONString; 6 7 /** 8 * Cloud storage configuration RPC entity. 9 */ 10 public class CloudStorageInfo extends JsonRpcEntity { 11 public static final String JSON_FIELD_BOTO_KEY_ID = "gs_access_key_id"; 12 public static final String JSON_FIELD_BOTO_SECRET_KEY = "gs_secret_access_key"; 13 public static final String JSON_FIELD_USE_EXISTING_BOTO_FILE = "use_existing_boto_file"; 14 public static final String JSON_FIELD_IMAGE_STORAGE_URL = "image_storage_server"; 15 public static final String JSON_FIELD_RESULT_STORAGE_URL = "results_storage_server"; 16 17 /** 18 * The boto key id. 19 */ 20 private String botoKey; 21 22 /** 23 * The boto secret. 24 */ 25 private String botoSecret; 26 27 /** 28 * Uses existing boto file on the Moblab 29 */ 30 private boolean useExistingBotoFile; 31 32 private String imageStorageServer; 33 private String resultStorageServer; 34 CloudStorageInfo()35 public CloudStorageInfo() { 36 reset(); 37 } 38 getBotoKey()39 public String getBotoKey() { 40 return botoKey; 41 } 42 getBotoSecret()43 public String getBotoSecret() { 44 return botoSecret; 45 } 46 getImageStorageServer()47 public String getImageStorageServer() { 48 return imageStorageServer; 49 } 50 getResultStorageServer()51 public String getResultStorageServer() { 52 return resultStorageServer; 53 } 54 setBotoKey(String botoKey)55 public void setBotoKey(String botoKey) { 56 this.botoKey = botoKey.trim(); 57 } 58 setBotoSecret(String botoSecret)59 public void setBotoSecret(String botoSecret) { 60 this.botoSecret = botoSecret.trim(); 61 } 62 setImageStorageServer(String imageStorageServer)63 public void setImageStorageServer(String imageStorageServer) { 64 this.imageStorageServer = imageStorageServer.trim(); 65 } 66 setResultStorageServer(String resultStorageServer)67 public void setResultStorageServer(String resultStorageServer) { 68 this.resultStorageServer = resultStorageServer.trim(); 69 } 70 isUseExistingBotoFile()71 public boolean isUseExistingBotoFile() { 72 return useExistingBotoFile; 73 } 74 setUseExistingBotoFile(boolean useExistingBotoFile)75 public void setUseExistingBotoFile(boolean useExistingBotoFile) { 76 this.useExistingBotoFile = useExistingBotoFile; 77 } 78 reset()79 private void reset() { 80 botoKey = null; 81 botoSecret = null; 82 imageStorageServer = null; 83 resultStorageServer = null; 84 } 85 86 @Override fromJson(JSONObject object)87 public void fromJson(JSONObject object) { 88 if (object != null) { 89 botoKey = getStringFieldOrDefault(object, JSON_FIELD_BOTO_KEY_ID, null); 90 botoSecret = getStringFieldOrDefault(object, JSON_FIELD_BOTO_SECRET_KEY, null); 91 imageStorageServer = getStringFieldOrDefault(object, JSON_FIELD_IMAGE_STORAGE_URL, null); 92 resultStorageServer = getStringFieldOrDefault(object, JSON_FIELD_RESULT_STORAGE_URL, null); 93 useExistingBotoFile = 94 getBooleanFieldOrDefault(object, JSON_FIELD_USE_EXISTING_BOTO_FILE, false); 95 } 96 } 97 98 @Override toJson()99 public JSONObject toJson() { 100 JSONObject object = new JSONObject(); 101 if (botoKey != null) { 102 object.put(JSON_FIELD_BOTO_KEY_ID, new JSONString(botoKey)); 103 } 104 if (botoSecret != null) { 105 object.put(JSON_FIELD_BOTO_SECRET_KEY, new JSONString(botoSecret)); 106 } 107 if (imageStorageServer != null) { 108 object.put(JSON_FIELD_IMAGE_STORAGE_URL, new JSONString(imageStorageServer)); 109 } 110 if (resultStorageServer != null) { 111 object.put(JSON_FIELD_RESULT_STORAGE_URL, new JSONString(resultStorageServer)); 112 } else { 113 object.put(JSON_FIELD_RESULT_STORAGE_URL, new JSONString("")); 114 } 115 object.put(JSON_FIELD_USE_EXISTING_BOTO_FILE, JSONBoolean.getInstance(useExistingBotoFile)); 116 return object; 117 } 118 } 119