001package com.box.sdkgen.schemas.metadataquery; 002 003import com.box.sdkgen.internal.NullableFieldTracker; 004import com.box.sdkgen.internal.SerializableObject; 005import com.fasterxml.jackson.annotation.JsonFilter; 006import com.fasterxml.jackson.annotation.JsonProperty; 007import java.util.List; 008import java.util.Map; 009import java.util.Objects; 010 011/** Create a search using SQL-like syntax to return items that match specific metadata. */ 012@JsonFilter("nullablePropertyFilter") 013public class MetadataQuery extends SerializableObject { 014 015 /** 016 * Specifies the template used in the query. Must be in the form `scope.templateKey`. Not all 017 * templates can be used in this field, most notably the built-in, Box-provided classification 018 * templates can not be used in a query. 019 */ 020 protected final String from; 021 022 /** 023 * The query to perform. A query is a logical expression that is very similar to a SQL `SELECT` 024 * statement. Values in the search query can be turned into parameters specified in the 025 * `query_param` arguments list to prevent having to manually insert search values into the query 026 * string. 027 * 028 * <p>For example, a value of `:amount` would represent the `amount` value in `query_params` 029 * object. 030 */ 031 protected String query; 032 033 /** 034 * Set of arguments corresponding to the parameters specified in the `query`. The type of each 035 * parameter used in the `query_params` must match the type of the corresponding metadata template 036 * field. 037 */ 038 @JsonProperty("query_params") 039 protected Map<String, Object> queryParams; 040 041 /** 042 * The ID of the folder that you are restricting the query to. A value of zero will return results 043 * from all folders you have access to. A non-zero value will only return results found in the 044 * folder corresponding to the ID or in any of its subfolders. 045 */ 046 @JsonProperty("ancestor_folder_id") 047 protected final String ancestorFolderId; 048 049 /** 050 * A list of template fields and directions to sort the metadata query results by. 051 * 052 * <p>The ordering `direction` must be the same for each item in the array. 053 */ 054 @JsonProperty("order_by") 055 protected List<MetadataQueryOrderByField> orderBy; 056 057 /** 058 * A value between 0 and 100 that indicates the maximum number of results to return for a single 059 * request. This only specifies a maximum boundary and will not guarantee the minimum number of 060 * results returned. 061 */ 062 protected Long limit; 063 064 /** Marker to use for requesting the next page. */ 065 protected String marker; 066 067 /** 068 * By default, this endpoint returns only the most basic info about the items for which the query 069 * matches. This attribute can be used to specify a list of additional attributes to return for 070 * any item, including its metadata. 071 * 072 * <p>This attribute takes a list of item fields, metadata template identifiers, or metadata 073 * template field identifiers. 074 * 075 * <p>For example: 076 * 077 * <p>* `created_by` will add the details of the user who created the item to the response. * 078 * `metadata.<scope>.<templateKey>` will return the mini-representation of the 079 * metadata instance identified by the `scope` and `templateKey`. * 080 * `metadata.<scope>.<templateKey>.<field>` will return all the 081 * mini-representation of the metadata instance identified by the `scope` and `templateKey` plus 082 * the field specified by the `field` name. Multiple fields for the same `scope` and `templateKey` 083 * can be defined. 084 */ 085 protected List<String> fields; 086 087 public MetadataQuery( 088 @JsonProperty("from") String from, 089 @JsonProperty("ancestor_folder_id") String ancestorFolderId) { 090 super(); 091 this.from = from; 092 this.ancestorFolderId = ancestorFolderId; 093 } 094 095 protected MetadataQuery(Builder builder) { 096 super(); 097 this.from = builder.from; 098 this.query = builder.query; 099 this.queryParams = builder.queryParams; 100 this.ancestorFolderId = builder.ancestorFolderId; 101 this.orderBy = builder.orderBy; 102 this.limit = builder.limit; 103 this.marker = builder.marker; 104 this.fields = builder.fields; 105 markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); 106 } 107 108 public String getFrom() { 109 return from; 110 } 111 112 public String getQuery() { 113 return query; 114 } 115 116 public Map<String, Object> getQueryParams() { 117 return queryParams; 118 } 119 120 public String getAncestorFolderId() { 121 return ancestorFolderId; 122 } 123 124 public List<MetadataQueryOrderByField> getOrderBy() { 125 return orderBy; 126 } 127 128 public Long getLimit() { 129 return limit; 130 } 131 132 public String getMarker() { 133 return marker; 134 } 135 136 public List<String> getFields() { 137 return fields; 138 } 139 140 @Override 141 public boolean equals(Object o) { 142 if (this == o) { 143 return true; 144 } 145 if (o == null || getClass() != o.getClass()) { 146 return false; 147 } 148 MetadataQuery casted = (MetadataQuery) o; 149 return Objects.equals(from, casted.from) 150 && Objects.equals(query, casted.query) 151 && Objects.equals(queryParams, casted.queryParams) 152 && Objects.equals(ancestorFolderId, casted.ancestorFolderId) 153 && Objects.equals(orderBy, casted.orderBy) 154 && Objects.equals(limit, casted.limit) 155 && Objects.equals(marker, casted.marker) 156 && Objects.equals(fields, casted.fields); 157 } 158 159 @Override 160 public int hashCode() { 161 return Objects.hash(from, query, queryParams, ancestorFolderId, orderBy, limit, marker, fields); 162 } 163 164 @Override 165 public String toString() { 166 return "MetadataQuery{" 167 + "from='" 168 + from 169 + '\'' 170 + ", " 171 + "query='" 172 + query 173 + '\'' 174 + ", " 175 + "queryParams='" 176 + queryParams 177 + '\'' 178 + ", " 179 + "ancestorFolderId='" 180 + ancestorFolderId 181 + '\'' 182 + ", " 183 + "orderBy='" 184 + orderBy 185 + '\'' 186 + ", " 187 + "limit='" 188 + limit 189 + '\'' 190 + ", " 191 + "marker='" 192 + marker 193 + '\'' 194 + ", " 195 + "fields='" 196 + fields 197 + '\'' 198 + "}"; 199 } 200 201 public static class Builder extends NullableFieldTracker { 202 203 protected final String from; 204 205 protected String query; 206 207 protected Map<String, Object> queryParams; 208 209 protected final String ancestorFolderId; 210 211 protected List<MetadataQueryOrderByField> orderBy; 212 213 protected Long limit; 214 215 protected String marker; 216 217 protected List<String> fields; 218 219 public Builder(String from, String ancestorFolderId) { 220 super(); 221 this.from = from; 222 this.ancestorFolderId = ancestorFolderId; 223 } 224 225 public Builder query(String query) { 226 this.query = query; 227 return this; 228 } 229 230 public Builder queryParams(Map<String, Object> queryParams) { 231 this.queryParams = queryParams; 232 return this; 233 } 234 235 public Builder orderBy(List<MetadataQueryOrderByField> orderBy) { 236 this.orderBy = orderBy; 237 return this; 238 } 239 240 public Builder limit(Long limit) { 241 this.limit = limit; 242 return this; 243 } 244 245 public Builder marker(String marker) { 246 this.marker = marker; 247 return this; 248 } 249 250 public Builder fields(List<String> fields) { 251 this.fields = fields; 252 return this; 253 } 254 255 public MetadataQuery build() { 256 return new MetadataQuery(this); 257 } 258 } 259}