001// Generated by delombok at Sat May 10 20:59:56 UTC 2025 002/* 003 * Copyright (c) 2010-2025 Mark Allen, Norbert Bartels. 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023package com.restfb; 024 025import java.io.Serializable; 026import java.util.ArrayList; 027import java.util.HashMap; 028import java.util.List; 029import java.util.Map; 030import com.restfb.json.Json; 031import com.restfb.json.JsonObject; 032import com.restfb.util.StringUtils; 033 034public class DebugHeaderInfo implements Serializable { 035 /** 036 * x-fb-debug 037 */ 038 private final String debug; 039 /** 040 * x-fb-rev 041 */ 042 private final String rev; 043 /** 044 * x-fb-trace-id 045 */ 046 private final String traceId; 047 /** 048 * the use version 049 */ 050 private final Version usedVersion; 051 /** 052 * x-app-usage 053 */ 054 private final HeaderUsage appUsage; 055 /** 056 * x-page-usage 057 */ 058 private final HeaderUsage pageUsage; 059 /** 060 * x-ad-account-usage 061 */ 062 private final HeaderUsage adAccountUsage; 063 private final BusinessUseCaseUsage businessUseCaseUsage; 064 065 private DebugHeaderInfo(String debug, String rev, String traceId, Version version, String appUsage, String pageUsage, String adAccountUsage, String businessUsage) { 066 this.debug = debug; 067 this.rev = rev; 068 this.traceId = traceId; 069 this.usedVersion = version; 070 this.appUsage = createUsage(appUsage); 071 this.pageUsage = createUsage(pageUsage); 072 this.adAccountUsage = createUsage(adAccountUsage); 073 this.businessUseCaseUsage = createBusinessUsage(businessUsage); 074 } 075 076 /** 077 * get Facebook response header field <code>x-fb-debug</code> 078 * 079 * @return the Facebook response header field <code>x-fb-debug</code> 080 */ 081 public String getDebug() { 082 return debug; 083 } 084 085 /** 086 * get Facebook response header field <code>x-fb-rev</code> 087 * 088 * @return the Facebook response header field <code>x-fb-rev</code> 089 */ 090 public String getRev() { 091 return rev; 092 } 093 094 /** 095 * get Facebook response header field <code>x-fb-trace-id</code> 096 * 097 * @return the Facebook response header field x-fb-trace-id 098 */ 099 public String getTraceId() { 100 return traceId; 101 } 102 103 /** 104 * get the version, facebook used internally to fulfill the request 105 * 106 * @return the version, facebook used internally to fulfill the request 107 */ 108 public Version getUsedVersion() { 109 return usedVersion; 110 } 111 112 /** 113 * get Facebook response header field <code>x-app-usage</code> 114 * 115 * @return the Facebook response header field x-app-usage 116 */ 117 public HeaderUsage getAppUsage() { 118 return appUsage; 119 } 120 121 /** 122 * get Facebook response header field <code>x-page-usage</code> 123 * 124 * @return the Facebook response header field x-page-usage 125 */ 126 public HeaderUsage getPageUsage() { 127 return pageUsage; 128 } 129 130 /** 131 * get Facebook response header field <code>x-ad-account-usage</code> 132 * 133 * @return the Facebook response header field x-ad-account-usage 134 */ 135 public HeaderUsage getAdAccountUsage() { 136 return adAccountUsage; 137 } 138 139 public BusinessUseCaseUsage getBusinessUseCaseUsage() { 140 return businessUseCaseUsage; 141 } 142 143 private BusinessUseCaseUsage createBusinessUsage(String businessUsageInformation) { 144 if (StringUtils.isBlank(businessUsageInformation)) { 145 return null; 146 } 147 try { 148 DefaultJsonMapper jsonMapper = new DefaultJsonMapper(); 149 JsonObject jsonObject = Json.parse(businessUsageInformation).asObject(); 150 BusinessUseCaseUsage usage = new BusinessUseCaseUsage(); 151 for (String key : jsonObject.names()) { 152 usage.put(key, jsonMapper.toJavaList(jsonObject.get(key).toString(), InnerBusinessUseCaseUsage.class)); 153 } 154 return usage; 155 } catch (Exception e) { 156 return null; 157 } 158 } 159 160 private HeaderUsage createUsage(String usageInformation) { 161 if (StringUtils.isBlank(usageInformation)) { 162 return null; 163 } 164 try { 165 JsonObject jsonValue = Json.parse(usageInformation).asObject(); 166 if (jsonValue.names().size() == 1 && jsonValue.contains("acc_id_util_pct")) { 167 return new HeaderUsage(jsonValue.getDouble("acc_id_util_pct", 0.0)); 168 } 169 if (jsonValue.contains("call_volume") && jsonValue.contains("cpu_time")) { 170 return new HeaderUsage(jsonValue.getInt("call_volume", -1), jsonValue.getInt("cpu_time", -1)); 171 } 172 return new HeaderUsage(jsonValue.getInt("call_count", -1), jsonValue.getInt("total_time", -1), jsonValue.getInt("total_cputime", -1)); 173 } catch (Exception e) { 174 return new HeaderUsage(usageInformation); 175 } 176 } 177 178 179 /** 180 * business use case based usage object. 181 * <p> 182 * This usage object is used in Graph API 3.3+ and provides access to the complete set of inner objects. 183 */ 184 public static class BusinessUseCaseUsage implements Serializable { 185 private Map<String, List<InnerBusinessUseCaseUsage>> usageMap = new HashMap<>(); 186 187 /** 188 * add a new list of usages that belongs to the business id to the outer object 189 * 190 * @param key 191 * the business id the list of usages is connected with 192 * @param businessUseCaseUsageList 193 * the list of usages 194 */ 195 void put(String key, List<InnerBusinessUseCaseUsage> businessUseCaseUsageList) { 196 usageMap.put(key, businessUseCaseUsageList); 197 } 198 199 /** 200 * returns the usage list that belongs to the given business id 201 * 202 * @param businessId 203 * the business ids you like to fetch the usage list for 204 * @return the list of usages 205 */ 206 public List<InnerBusinessUseCaseUsage> get(String businessId) { 207 return usageMap.get(businessId); 208 } 209 210 /** 211 * returns the list of Business Ids that are provided in the the business use case usage header 212 * 213 * @return list of business ids 214 */ 215 public List<String> getBusinessIds() { 216 return new ArrayList<>(usageMap.keySet()); 217 } 218 } 219 220 221 public static class InnerBusinessUseCaseUsage implements Serializable { 222 /** 223 * Percentage of calls made for this business id/business ad account 224 */ 225 @Facebook("call_count") 226 private Integer callCount; 227 /** 228 * Percentage of the total CPU time that has been used 229 */ 230 @Facebook("total_cputime") 231 private Integer totalCputime; 232 /** 233 * Percentage of the total time that has been used 234 */ 235 @Facebook("total_time") 236 private Integer totalTime; 237 /** 238 * Type of rate limit logic being applied 239 */ 240 @Facebook 241 private String type; 242 /** 243 * Time in minutes to resume calls 244 */ 245 @Facebook("estimated_time_to_regain_access") 246 private Integer estimatedTimeToRegainAccess; 247 248 /** 249 * Percentage of calls made for this business id/business ad account 250 */ 251 @java.lang.SuppressWarnings("all") 252 public Integer getCallCount() { 253 return this.callCount; 254 } 255 256 /** 257 * Percentage of the total CPU time that has been used 258 */ 259 @java.lang.SuppressWarnings("all") 260 public Integer getTotalCputime() { 261 return this.totalCputime; 262 } 263 264 /** 265 * Percentage of the total time that has been used 266 */ 267 @java.lang.SuppressWarnings("all") 268 public Integer getTotalTime() { 269 return this.totalTime; 270 } 271 272 /** 273 * Type of rate limit logic being applied 274 */ 275 @java.lang.SuppressWarnings("all") 276 public String getType() { 277 return this.type; 278 } 279 280 /** 281 * Time in minutes to resume calls 282 */ 283 @java.lang.SuppressWarnings("all") 284 public Integer getEstimatedTimeToRegainAccess() { 285 return this.estimatedTimeToRegainAccess; 286 } 287 } 288 289 290 public static class HeaderUsage implements Serializable { 291 HeaderUsage(String percentage) { 292 this.percentage = percentage; 293 this.percentageOnly = true; 294 this.adAccountHeader = false; 295 } 296 297 HeaderUsage(Integer callVolume, Integer cpuTime) { 298 this.callVolume = callVolume; 299 this.cpuTime = cpuTime; 300 this.percentageOnly = false; 301 this.adAccountHeader = false; 302 } 303 304 HeaderUsage(Integer callCount, Integer totalTime, Integer totalCputime) { 305 this.callCount = callCount; 306 this.totalTime = totalTime; 307 this.totalCputime = totalCputime; 308 this.percentageOnly = false; 309 this.adAccountHeader = false; 310 } 311 312 HeaderUsage(Double percentage) { 313 this.accIdUtilPct = percentage; 314 this.percentageOnly = false; 315 this.adAccountHeader = true; 316 } 317 318 private final boolean percentageOnly; 319 private final boolean adAccountHeader; 320 private String percentage; 321 private Integer callCount; 322 private Integer callVolume; 323 private Integer totalTime; 324 private Integer totalCputime; 325 private Integer cpuTime; 326 private Double accIdUtilPct; 327 328 @java.lang.SuppressWarnings("all") 329 public boolean isPercentageOnly() { 330 return this.percentageOnly; 331 } 332 333 @java.lang.SuppressWarnings("all") 334 public boolean isAdAccountHeader() { 335 return this.adAccountHeader; 336 } 337 338 @java.lang.SuppressWarnings("all") 339 public String getPercentage() { 340 return this.percentage; 341 } 342 343 @java.lang.SuppressWarnings("all") 344 public Integer getCallCount() { 345 return this.callCount; 346 } 347 348 @java.lang.SuppressWarnings("all") 349 public Integer getCallVolume() { 350 return this.callVolume; 351 } 352 353 @java.lang.SuppressWarnings("all") 354 public Integer getTotalTime() { 355 return this.totalTime; 356 } 357 358 @java.lang.SuppressWarnings("all") 359 public Integer getTotalCputime() { 360 return this.totalCputime; 361 } 362 363 @java.lang.SuppressWarnings("all") 364 public Integer getCpuTime() { 365 return this.cpuTime; 366 } 367 368 @java.lang.SuppressWarnings("all") 369 public Double getAccIdUtilPct() { 370 return this.accIdUtilPct; 371 } 372 } 373 374 375 public static class DebugHeaderInfoFactory implements Serializable { 376 private String debug; 377 private String rev; 378 private String traceId; 379 private Version version; 380 private String appUsage; 381 private String pageUsage; 382 private String adAccountUsage; 383 private String businessUseCaseUsage; 384 385 public static DebugHeaderInfoFactory create() { 386 return new DebugHeaderInfoFactory(); 387 } 388 389 public DebugHeaderInfoFactory setVersion(Version version) { 390 this.version = version; 391 return this; 392 } 393 394 public DebugHeaderInfoFactory setDebug(String debug) { 395 this.debug = debug; 396 return this; 397 } 398 399 public DebugHeaderInfoFactory setRev(String rev) { 400 this.rev = rev; 401 return this; 402 } 403 404 public DebugHeaderInfoFactory setTraceId(String traceId) { 405 this.traceId = traceId; 406 return this; 407 } 408 409 public DebugHeaderInfoFactory setAppUsage(String appUsage) { 410 this.appUsage = appUsage; 411 return this; 412 } 413 414 public DebugHeaderInfoFactory setPageUsage(String pageUsage) { 415 this.pageUsage = pageUsage; 416 return this; 417 } 418 419 public DebugHeaderInfoFactory setAdAccountUsage(String adAccountUsage) { 420 this.adAccountUsage = adAccountUsage; 421 return this; 422 } 423 424 public DebugHeaderInfoFactory setBusinessUseCaseUsage(String businessUseCaseUsage) { 425 this.businessUseCaseUsage = businessUseCaseUsage; 426 return this; 427 } 428 429 public DebugHeaderInfo build() { 430 return new DebugHeaderInfo(this.debug, this.rev, this.traceId, this.version, this.appUsage, this.pageUsage, this.adAccountUsage, this.businessUseCaseUsage); 431 } 432 } 433}