001package com.box.sdkgen.managers.query; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 008 009import com.box.sdkgen.networking.auth.Authentication; 010import com.box.sdkgen.networking.fetchoptions.FetchOptions; 011import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 012import com.box.sdkgen.networking.fetchresponse.FetchResponse; 013import com.box.sdkgen.networking.network.NetworkSession; 014import com.box.sdkgen.schemas.v2026r0.queryinsightsrequestbodyv2026r0.QueryInsightsRequestBodyV2026R0; 015import com.box.sdkgen.schemas.v2026r0.queryinsightsv2026r0.QueryInsightsV2026R0; 016import com.box.sdkgen.schemas.v2026r0.queryrequestbodyv2026r0.QueryRequestBodyV2026R0; 017import com.box.sdkgen.schemas.v2026r0.queryresultsv2026r0.QueryResultsV2026R0; 018import com.box.sdkgen.serialization.json.JsonManager; 019import java.util.Map; 020 021public class QueryManager { 022 023 public Authentication auth; 024 025 public NetworkSession networkSession; 026 027 public QueryManager() { 028 this.networkSession = new NetworkSession(); 029 } 030 031 protected QueryManager(Builder builder) { 032 this.auth = builder.auth; 033 this.networkSession = builder.networkSession; 034 } 035 036 /** 037 * Runs a query to discover Box items using a logical predicate that can filter across item fields 038 * and metadata templates. Results can be sorted, paginated, and shaped to include additional item 039 * or metadata fields. 040 * 041 * @param requestBody Request body of createQueryV2026R0 method 042 */ 043 public QueryResultsV2026R0 createQueryV2026R0(QueryRequestBodyV2026R0 requestBody) { 044 return createQueryV2026R0(requestBody, new CreateQueryV2026R0Headers()); 045 } 046 047 /** 048 * Runs a query to discover Box items using a logical predicate that can filter across item fields 049 * and metadata templates. Results can be sorted, paginated, and shaped to include additional item 050 * or metadata fields. 051 * 052 * @param requestBody Request body of createQueryV2026R0 method 053 * @param headers Headers of createQueryV2026R0 method 054 */ 055 public QueryResultsV2026R0 createQueryV2026R0( 056 QueryRequestBodyV2026R0 requestBody, CreateQueryV2026R0Headers headers) { 057 Map<String, String> headersMap = 058 prepareParams( 059 mergeMaps( 060 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 061 headers.getExtraHeaders())); 062 FetchResponse response = 063 this.networkSession 064 .getNetworkClient() 065 .fetch( 066 new FetchOptions.Builder( 067 String.join( 068 "", this.networkSession.getBaseUrls().getBaseUrl(), "/2.0/query"), 069 "POST") 070 .headers(headersMap) 071 .data(JsonManager.serialize(requestBody)) 072 .contentType("application/json") 073 .responseFormat(ResponseFormat.JSON) 074 .auth(this.auth) 075 .networkSession(this.networkSession) 076 .build()); 077 return JsonManager.deserialize(response.getData(), QueryResultsV2026R0.class); 078 } 079 080 /** 081 * Computes aggregated metrics over Box items matching a query predicate. Filters are applied 082 * first, followed by optional grouping, after which the requested metrics (such as `sum`, `avg`, 083 * `min`, `max`, and `count`) are computed for each resulting group or over the entire filtered 084 * dataset. 085 * 086 * @param requestBody Request body of createQueryInsightV2026R0 method 087 */ 088 public QueryInsightsV2026R0 createQueryInsightV2026R0( 089 QueryInsightsRequestBodyV2026R0 requestBody) { 090 return createQueryInsightV2026R0(requestBody, new CreateQueryInsightV2026R0Headers()); 091 } 092 093 /** 094 * Computes aggregated metrics over Box items matching a query predicate. Filters are applied 095 * first, followed by optional grouping, after which the requested metrics (such as `sum`, `avg`, 096 * `min`, `max`, and `count`) are computed for each resulting group or over the entire filtered 097 * dataset. 098 * 099 * @param requestBody Request body of createQueryInsightV2026R0 method 100 * @param headers Headers of createQueryInsightV2026R0 method 101 */ 102 public QueryInsightsV2026R0 createQueryInsightV2026R0( 103 QueryInsightsRequestBodyV2026R0 requestBody, CreateQueryInsightV2026R0Headers headers) { 104 Map<String, String> headersMap = 105 prepareParams( 106 mergeMaps( 107 mapOf(entryOf("box-version", convertToString(headers.getBoxVersion()))), 108 headers.getExtraHeaders())); 109 FetchResponse response = 110 this.networkSession 111 .getNetworkClient() 112 .fetch( 113 new FetchOptions.Builder( 114 String.join( 115 "", 116 this.networkSession.getBaseUrls().getBaseUrl(), 117 "/2.0/query_insights"), 118 "POST") 119 .headers(headersMap) 120 .data(JsonManager.serialize(requestBody)) 121 .contentType("application/json") 122 .responseFormat(ResponseFormat.JSON) 123 .auth(this.auth) 124 .networkSession(this.networkSession) 125 .build()); 126 return JsonManager.deserialize(response.getData(), QueryInsightsV2026R0.class); 127 } 128 129 public Authentication getAuth() { 130 return auth; 131 } 132 133 public NetworkSession getNetworkSession() { 134 return networkSession; 135 } 136 137 public static class Builder { 138 139 protected Authentication auth; 140 141 protected NetworkSession networkSession; 142 143 public Builder() {} 144 145 public Builder auth(Authentication auth) { 146 this.auth = auth; 147 return this; 148 } 149 150 public Builder networkSession(NetworkSession networkSession) { 151 this.networkSession = networkSession; 152 return this; 153 } 154 155 public QueryManager build() { 156 if (this.networkSession == null) { 157 this.networkSession = new NetworkSession(); 158 } 159 return new QueryManager(this); 160 } 161 } 162}