|
| 1 | +/* |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * This source code is licensed under the license found in the |
| 6 | + * LICENSE file in the root directory of this source tree. |
| 7 | + */ |
| 8 | + |
| 9 | +package com.facebook.ads.sdk; |
| 10 | + |
| 11 | +import java.io.File; |
| 12 | +import java.lang.reflect.Modifier; |
| 13 | +import java.lang.reflect.Type; |
| 14 | +import java.util.Arrays; |
| 15 | +import java.util.HashMap; |
| 16 | +import java.util.List; |
| 17 | +import java.util.Map; |
| 18 | + |
| 19 | +import com.google.common.base.Function; |
| 20 | +import com.google.common.util.concurrent.Futures; |
| 21 | +import com.google.common.util.concurrent.ListenableFuture; |
| 22 | +import com.google.common.util.concurrent.MoreExecutors; |
| 23 | +import com.google.common.util.concurrent.SettableFuture; |
| 24 | +import com.google.gson.JsonObject; |
| 25 | +import com.google.gson.JsonArray; |
| 26 | +import com.google.gson.annotations.SerializedName; |
| 27 | +import com.google.gson.reflect.TypeToken; |
| 28 | +import com.google.gson.Gson; |
| 29 | +import com.google.gson.GsonBuilder; |
| 30 | +import com.google.gson.JsonElement; |
| 31 | +import com.google.gson.JsonParser; |
| 32 | + |
| 33 | +import com.facebook.ads.sdk.APIException.MalformedResponseException; |
| 34 | + |
| 35 | +/** |
| 36 | + * This class is auto-generated. |
| 37 | + * |
| 38 | + * For any issues or feature requests related to this class, please let us know |
| 39 | + * on github and we'll fix in our codegen framework. We'll not be able to accept |
| 40 | + * pull request for this class. |
| 41 | + * |
| 42 | + */ |
| 43 | +public class AIGeneratedProductImage extends APINode { |
| 44 | + @SerializedName("flagged_for_manual_review") |
| 45 | + private Boolean mFlaggedForManualReview = null; |
| 46 | + @SerializedName("transformed_image_url") |
| 47 | + private String mTransformedImageUrl = null; |
| 48 | + protected static Gson gson = null; |
| 49 | + |
| 50 | + public AIGeneratedProductImage() { |
| 51 | + } |
| 52 | + |
| 53 | + public String getId() { |
| 54 | + return null; |
| 55 | + } |
| 56 | + public static AIGeneratedProductImage loadJSON(String json, APIContext context, String header) { |
| 57 | + AIGeneratedProductImage aiGeneratedProductImage = getGson().fromJson(json, AIGeneratedProductImage.class); |
| 58 | + if (context.isDebug()) { |
| 59 | + JsonParser parser = new JsonParser(); |
| 60 | + JsonElement o1 = parser.parse(json); |
| 61 | + JsonElement o2 = parser.parse(aiGeneratedProductImage.toString()); |
| 62 | + if (o1.getAsJsonObject().get("__fb_trace_id__") != null) { |
| 63 | + o2.getAsJsonObject().add("__fb_trace_id__", o1.getAsJsonObject().get("__fb_trace_id__")); |
| 64 | + } |
| 65 | + if (!o1.equals(o2)) { |
| 66 | + context.log("[Warning] When parsing response, object is not consistent with JSON:"); |
| 67 | + context.log("[JSON]" + o1); |
| 68 | + context.log("[Object]" + o2); |
| 69 | + } |
| 70 | + } |
| 71 | + aiGeneratedProductImage.context = context; |
| 72 | + aiGeneratedProductImage.rawValue = json; |
| 73 | + aiGeneratedProductImage.header = header; |
| 74 | + return aiGeneratedProductImage; |
| 75 | + } |
| 76 | + |
| 77 | + public static APINodeList<AIGeneratedProductImage> parseResponse(String json, APIContext context, APIRequest request, String header) throws MalformedResponseException { |
| 78 | + APINodeList<AIGeneratedProductImage> aiGeneratedProductImages = new APINodeList<AIGeneratedProductImage>(request, json, header); |
| 79 | + JsonArray arr; |
| 80 | + JsonObject obj; |
| 81 | + JsonParser parser = new JsonParser(); |
| 82 | + Exception exception = null; |
| 83 | + try{ |
| 84 | + JsonElement result = parser.parse(json); |
| 85 | + if (result.isJsonArray()) { |
| 86 | + // First, check if it's a pure JSON Array |
| 87 | + arr = result.getAsJsonArray(); |
| 88 | + for (int i = 0; i < arr.size(); i++) { |
| 89 | + aiGeneratedProductImages.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header)); |
| 90 | + }; |
| 91 | + return aiGeneratedProductImages; |
| 92 | + } else if (result.isJsonObject()) { |
| 93 | + obj = result.getAsJsonObject(); |
| 94 | + if (obj.has("data")) { |
| 95 | + if (obj.has("paging")) { |
| 96 | + JsonObject paging = obj.get("paging").getAsJsonObject(); |
| 97 | + if (paging.has("cursors")) { |
| 98 | + JsonObject cursors = paging.get("cursors").getAsJsonObject(); |
| 99 | + String before = cursors.has("before") ? cursors.get("before").getAsString() : null; |
| 100 | + String after = cursors.has("after") ? cursors.get("after").getAsString() : null; |
| 101 | + aiGeneratedProductImages.setCursors(before, after); |
| 102 | + } |
| 103 | + String previous = paging.has("previous") ? paging.get("previous").getAsString() : null; |
| 104 | + String next = paging.has("next") ? paging.get("next").getAsString() : null; |
| 105 | + aiGeneratedProductImages.setPaging(previous, next); |
| 106 | + if (context.hasAppSecret()) { |
| 107 | + aiGeneratedProductImages.setAppSecret(context.getAppSecretProof()); |
| 108 | + } |
| 109 | + } |
| 110 | + if (obj.get("data").isJsonArray()) { |
| 111 | + // Second, check if it's a JSON array with "data" |
| 112 | + arr = obj.get("data").getAsJsonArray(); |
| 113 | + for (int i = 0; i < arr.size(); i++) { |
| 114 | + aiGeneratedProductImages.add(loadJSON(arr.get(i).getAsJsonObject().toString(), context, header)); |
| 115 | + }; |
| 116 | + } else if (obj.get("data").isJsonObject()) { |
| 117 | + // Third, check if it's a JSON object with "data" |
| 118 | + obj = obj.get("data").getAsJsonObject(); |
| 119 | + boolean isRedownload = false; |
| 120 | + for (String s : new String[]{"campaigns", "adsets", "ads"}) { |
| 121 | + if (obj.has(s)) { |
| 122 | + isRedownload = true; |
| 123 | + obj = obj.getAsJsonObject(s); |
| 124 | + for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { |
| 125 | + aiGeneratedProductImages.add(loadJSON(entry.getValue().toString(), context, header)); |
| 126 | + } |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + if (!isRedownload) { |
| 131 | + aiGeneratedProductImages.add(loadJSON(obj.toString(), context, header)); |
| 132 | + } |
| 133 | + } |
| 134 | + return aiGeneratedProductImages; |
| 135 | + } else if (obj.has("images")) { |
| 136 | + // Fourth, check if it's a map of image objects |
| 137 | + obj = obj.get("images").getAsJsonObject(); |
| 138 | + for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { |
| 139 | + aiGeneratedProductImages.add(loadJSON(entry.getValue().toString(), context, header)); |
| 140 | + } |
| 141 | + return aiGeneratedProductImages; |
| 142 | + } else { |
| 143 | + // Fifth, check if it's an array of objects indexed by id |
| 144 | + boolean isIdIndexedArray = true; |
| 145 | + for (Map.Entry entry : obj.entrySet()) { |
| 146 | + String key = (String) entry.getKey(); |
| 147 | + if (key.equals("__fb_trace_id__")) { |
| 148 | + continue; |
| 149 | + } |
| 150 | + JsonElement value = (JsonElement) entry.getValue(); |
| 151 | + if ( |
| 152 | + value != null && |
| 153 | + value.isJsonObject() && |
| 154 | + value.getAsJsonObject().has("id") && |
| 155 | + value.getAsJsonObject().get("id") != null && |
| 156 | + value.getAsJsonObject().get("id").getAsString().equals(key) |
| 157 | + ) { |
| 158 | + aiGeneratedProductImages.add(loadJSON(value.toString(), context, header)); |
| 159 | + } else { |
| 160 | + isIdIndexedArray = false; |
| 161 | + break; |
| 162 | + } |
| 163 | + } |
| 164 | + if (isIdIndexedArray) { |
| 165 | + return aiGeneratedProductImages; |
| 166 | + } |
| 167 | + |
| 168 | + // Sixth, check if it's pure JsonObject |
| 169 | + aiGeneratedProductImages.clear(); |
| 170 | + aiGeneratedProductImages.add(loadJSON(json, context, header)); |
| 171 | + return aiGeneratedProductImages; |
| 172 | + } |
| 173 | + } |
| 174 | + } catch (Exception e) { |
| 175 | + exception = e; |
| 176 | + } |
| 177 | + throw new MalformedResponseException( |
| 178 | + "Invalid response string: " + json, |
| 179 | + exception |
| 180 | + ); |
| 181 | + } |
| 182 | + |
| 183 | + @Override |
| 184 | + public APIContext getContext() { |
| 185 | + return context; |
| 186 | + } |
| 187 | + |
| 188 | + @Override |
| 189 | + public void setContext(APIContext context) { |
| 190 | + this.context = context; |
| 191 | + } |
| 192 | + |
| 193 | + @Override |
| 194 | + public String toString() { |
| 195 | + return getGson().toJson(this); |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + public Boolean getFieldFlaggedForManualReview() { |
| 200 | + return mFlaggedForManualReview; |
| 201 | + } |
| 202 | + |
| 203 | + public AIGeneratedProductImage setFieldFlaggedForManualReview(Boolean value) { |
| 204 | + this.mFlaggedForManualReview = value; |
| 205 | + return this; |
| 206 | + } |
| 207 | + |
| 208 | + public String getFieldTransformedImageUrl() { |
| 209 | + return mTransformedImageUrl; |
| 210 | + } |
| 211 | + |
| 212 | + public AIGeneratedProductImage setFieldTransformedImageUrl(String value) { |
| 213 | + this.mTransformedImageUrl = value; |
| 214 | + return this; |
| 215 | + } |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + synchronized /*package*/ static Gson getGson() { |
| 221 | + if (gson != null) { |
| 222 | + return gson; |
| 223 | + } else { |
| 224 | + gson = new GsonBuilder() |
| 225 | + .excludeFieldsWithModifiers(Modifier.STATIC) |
| 226 | + .excludeFieldsWithModifiers(Modifier.PROTECTED) |
| 227 | + .disableHtmlEscaping() |
| 228 | + .create(); |
| 229 | + } |
| 230 | + return gson; |
| 231 | + } |
| 232 | + |
| 233 | + public AIGeneratedProductImage copyFrom(AIGeneratedProductImage instance) { |
| 234 | + this.mFlaggedForManualReview = instance.mFlaggedForManualReview; |
| 235 | + this.mTransformedImageUrl = instance.mTransformedImageUrl; |
| 236 | + this.context = instance.context; |
| 237 | + this.rawValue = instance.rawValue; |
| 238 | + return this; |
| 239 | + } |
| 240 | + |
| 241 | + public static APIRequest.ResponseParser<AIGeneratedProductImage> getParser() { |
| 242 | + return new APIRequest.ResponseParser<AIGeneratedProductImage>() { |
| 243 | + public APINodeList<AIGeneratedProductImage> parseResponse(String response, APIContext context, APIRequest<AIGeneratedProductImage> request, String header) throws MalformedResponseException { |
| 244 | + return AIGeneratedProductImage.parseResponse(response, context, request, header); |
| 245 | + } |
| 246 | + }; |
| 247 | + } |
| 248 | +} |
0 commit comments