001package com.box.sdkgen.schemas.metadatafilter; 002 003import com.box.sdkgen.internal.NullableFieldTracker; 004import com.box.sdkgen.internal.SerializableObject; 005import com.box.sdkgen.schemas.metadatafiltervalue.MetadataFilterValue; 006import com.box.sdkgen.serialization.json.EnumWrapper; 007import com.fasterxml.jackson.annotation.JsonFilter; 008import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 009import com.fasterxml.jackson.databind.annotation.JsonSerialize; 010import java.util.Map; 011import java.util.Objects; 012 013/** A metadata template used to filter the search results. */ 014@JsonFilter("nullablePropertyFilter") 015public class MetadataFilter extends SerializableObject { 016 017 /** 018 * Specifies the scope of the template to filter search results by. 019 * 020 * <p>This will be `enterprise_{enterprise_id}` for templates defined for use in this enterprise, 021 * and `global` for general templates that are available to all enterprises using Box. 022 */ 023 @JsonDeserialize(using = MetadataFilterScopeField.MetadataFilterScopeFieldDeserializer.class) 024 @JsonSerialize(using = MetadataFilterScopeField.MetadataFilterScopeFieldSerializer.class) 025 protected EnumWrapper<MetadataFilterScopeField> scope; 026 027 /** 028 * The key of the template used to filter search results. 029 * 030 * <p>In many cases the template key is automatically derived of its display name, for example 031 * `Contract Template` would become `contractTemplate`. In some cases the creator of the template 032 * will have provided its own template key. 033 * 034 * <p>Please [list the templates for an enterprise][list], or get all instances on a [file][file] 035 * or [folder][folder] to inspect a template's key. 036 * 037 * <p>[list]: https://developer.box.com/reference/get-metadata-templates-enterprise [file]: 038 * https://developer.box.com/reference/get-files-id-metadata [folder]: 039 * https://developer.box.com/reference/get-folders-id-metadata 040 */ 041 protected String templateKey; 042 043 /** 044 * Specifies which fields on the template to filter the search results by. When more than one 045 * field is specified, the query performs a logical `AND` to ensure that the instance of the 046 * template matches each of the fields specified. 047 */ 048 protected Map<String, MetadataFilterValue> filters; 049 050 public MetadataFilter() { 051 super(); 052 } 053 054 protected MetadataFilter(Builder builder) { 055 super(); 056 this.scope = builder.scope; 057 this.templateKey = builder.templateKey; 058 this.filters = builder.filters; 059 markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); 060 } 061 062 public EnumWrapper<MetadataFilterScopeField> getScope() { 063 return scope; 064 } 065 066 public String getTemplateKey() { 067 return templateKey; 068 } 069 070 public Map<String, MetadataFilterValue> getFilters() { 071 return filters; 072 } 073 074 @Override 075 public boolean equals(Object o) { 076 if (this == o) { 077 return true; 078 } 079 if (o == null || getClass() != o.getClass()) { 080 return false; 081 } 082 MetadataFilter casted = (MetadataFilter) o; 083 return Objects.equals(scope, casted.scope) 084 && Objects.equals(templateKey, casted.templateKey) 085 && Objects.equals(filters, casted.filters); 086 } 087 088 @Override 089 public int hashCode() { 090 return Objects.hash(scope, templateKey, filters); 091 } 092 093 @Override 094 public String toString() { 095 return "MetadataFilter{" 096 + "scope='" 097 + scope 098 + '\'' 099 + ", " 100 + "templateKey='" 101 + templateKey 102 + '\'' 103 + ", " 104 + "filters='" 105 + filters 106 + '\'' 107 + "}"; 108 } 109 110 public static class Builder extends NullableFieldTracker { 111 112 protected EnumWrapper<MetadataFilterScopeField> scope; 113 114 protected String templateKey; 115 116 protected Map<String, MetadataFilterValue> filters; 117 118 public Builder scope(MetadataFilterScopeField scope) { 119 this.scope = new EnumWrapper<MetadataFilterScopeField>(scope); 120 return this; 121 } 122 123 public Builder scope(EnumWrapper<MetadataFilterScopeField> scope) { 124 this.scope = scope; 125 return this; 126 } 127 128 public Builder templateKey(String templateKey) { 129 this.templateKey = templateKey; 130 return this; 131 } 132 133 public Builder filters(Map<String, MetadataFilterValue> filters) { 134 this.filters = filters; 135 return this; 136 } 137 138 public MetadataFilter build() { 139 return new MetadataFilter(this); 140 } 141 } 142}