001 002package com.commercetools.history.models.common; 003 004import java.util.*; 005import java.util.function.Function; 006 007import io.vrap.rmf.base.client.Builder; 008import io.vrap.rmf.base.client.utils.Generated; 009 010/** 011 * AttributeDefinitionBuilder 012 * <hr> 013 * Example to create an instance using the builder pattern 014 * <div class=code-example> 015 * <pre><code class='java'> 016 * AttributeDefinition attributeDefinition = AttributeDefinition.builder() 017 * .type(typeBuilder -> typeBuilder) 018 * .name("{name}") 019 * .label(labelBuilder -> labelBuilder) 020 * .isRequired(true) 021 * .attributeConstraint(AttributeConstraintEnum.NONE) 022 * .inputTip(inputTipBuilder -> inputTipBuilder) 023 * .inputHint(TextInputHint.SINGLE_LINE) 024 * .isSearchable(true) 025 * .build() 026 * </code></pre> 027 * </div> 028 */ 029@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 030public class AttributeDefinitionBuilder implements Builder<AttributeDefinition> { 031 032 private com.commercetools.history.models.common.AttributeType type; 033 034 private String name; 035 036 private com.commercetools.history.models.common.LocalizedString label; 037 038 private Boolean isRequired; 039 040 private com.commercetools.history.models.common.AttributeConstraintEnum attributeConstraint; 041 042 private com.commercetools.history.models.common.LocalizedString inputTip; 043 044 private com.commercetools.history.models.common.TextInputHint inputHint; 045 046 private Boolean isSearchable; 047 048 /** 049 * set the value to the type using the builder function 050 * @param builder function to build the type value 051 * @return Builder 052 */ 053 054 public AttributeDefinitionBuilder type( 055 Function<com.commercetools.history.models.common.AttributeTypeBuilder, com.commercetools.history.models.common.AttributeTypeBuilder> builder) { 056 this.type = builder.apply(com.commercetools.history.models.common.AttributeTypeBuilder.of()).build(); 057 return this; 058 } 059 060 /** 061 * set the value to the type using the builder function 062 * @param builder function to build the type value 063 * @return Builder 064 */ 065 066 public AttributeDefinitionBuilder withType( 067 Function<com.commercetools.history.models.common.AttributeTypeBuilder, com.commercetools.history.models.common.AttributeType> builder) { 068 this.type = builder.apply(com.commercetools.history.models.common.AttributeTypeBuilder.of()); 069 return this; 070 } 071 072 /** 073 * set the value to the type 074 * @param type value to be set 075 * @return Builder 076 */ 077 078 public AttributeDefinitionBuilder type(final com.commercetools.history.models.common.AttributeType type) { 079 this.type = type; 080 return this; 081 } 082 083 /** 084 * <p>The unique name of the attribute used in the API. The name must be between two and 256 characters long and can contain the ASCII letters A to Z in lowercase or uppercase, digits, underscores (<code>_</code>) and the hyphen-minus (<code>-</code>). When using the same <code>name</code> for an attribute in two or more product types all fields of the AttributeDefinition of this attribute need to be the same across the product types, otherwise an AttributeDefinitionAlreadyExists error code will be returned. An exception to this are the values of an <code>enum</code> or <code>lenum</code> type and sets thereof.</p> 085 * @param name value to be set 086 * @return Builder 087 */ 088 089 public AttributeDefinitionBuilder name(final String name) { 090 this.name = name; 091 return this; 092 } 093 094 /** 095 * set the value to the label using the builder function 096 * @param builder function to build the label value 097 * @return Builder 098 */ 099 100 public AttributeDefinitionBuilder label( 101 Function<com.commercetools.history.models.common.LocalizedStringBuilder, com.commercetools.history.models.common.LocalizedStringBuilder> builder) { 102 this.label = builder.apply(com.commercetools.history.models.common.LocalizedStringBuilder.of()).build(); 103 return this; 104 } 105 106 /** 107 * set the value to the label using the builder function 108 * @param builder function to build the label value 109 * @return Builder 110 */ 111 112 public AttributeDefinitionBuilder withLabel( 113 Function<com.commercetools.history.models.common.LocalizedStringBuilder, com.commercetools.history.models.common.LocalizedString> builder) { 114 this.label = builder.apply(com.commercetools.history.models.common.LocalizedStringBuilder.of()); 115 return this; 116 } 117 118 /** 119 * set the value to the label 120 * @param label value to be set 121 * @return Builder 122 */ 123 124 public AttributeDefinitionBuilder label(final com.commercetools.history.models.common.LocalizedString label) { 125 this.label = label; 126 return this; 127 } 128 129 /** 130 * <p>Whether the attribute is required to have a value.</p> 131 * @param isRequired value to be set 132 * @return Builder 133 */ 134 135 public AttributeDefinitionBuilder isRequired(final Boolean isRequired) { 136 this.isRequired = isRequired; 137 return this; 138 } 139 140 /** 141 * set the value to the attributeConstraint 142 * @param attributeConstraint value to be set 143 * @return Builder 144 */ 145 146 public AttributeDefinitionBuilder attributeConstraint( 147 final com.commercetools.history.models.common.AttributeConstraintEnum attributeConstraint) { 148 this.attributeConstraint = attributeConstraint; 149 return this; 150 } 151 152 /** 153 * set the value to the inputTip using the builder function 154 * @param builder function to build the inputTip value 155 * @return Builder 156 */ 157 158 public AttributeDefinitionBuilder inputTip( 159 Function<com.commercetools.history.models.common.LocalizedStringBuilder, com.commercetools.history.models.common.LocalizedStringBuilder> builder) { 160 this.inputTip = builder.apply(com.commercetools.history.models.common.LocalizedStringBuilder.of()).build(); 161 return this; 162 } 163 164 /** 165 * set the value to the inputTip using the builder function 166 * @param builder function to build the inputTip value 167 * @return Builder 168 */ 169 170 public AttributeDefinitionBuilder withInputTip( 171 Function<com.commercetools.history.models.common.LocalizedStringBuilder, com.commercetools.history.models.common.LocalizedString> builder) { 172 this.inputTip = builder.apply(com.commercetools.history.models.common.LocalizedStringBuilder.of()); 173 return this; 174 } 175 176 /** 177 * set the value to the inputTip 178 * @param inputTip value to be set 179 * @return Builder 180 */ 181 182 public AttributeDefinitionBuilder inputTip(final com.commercetools.history.models.common.LocalizedString inputTip) { 183 this.inputTip = inputTip; 184 return this; 185 } 186 187 /** 188 * set the value to the inputHint 189 * @param inputHint value to be set 190 * @return Builder 191 */ 192 193 public AttributeDefinitionBuilder inputHint(final com.commercetools.history.models.common.TextInputHint inputHint) { 194 this.inputHint = inputHint; 195 return this; 196 } 197 198 /** 199 * <p>Whether the attribute's values should generally be enabled in product search. This determines whether the value is stored in products for matching terms in the context of full-text search queries and can be used in facets & filters as part of product search queries. The exact features that are enabled/disabled with this flag depend on the concrete attribute type and are described there. The max size of a searchable field is <strong>restricted to 10922 characters</strong>. This constraint is enforced at both product creation and product update. If the length of the input exceeds the maximum size an InvalidField error is returned.</p> 200 * @param isSearchable value to be set 201 * @return Builder 202 */ 203 204 public AttributeDefinitionBuilder isSearchable(final Boolean isSearchable) { 205 this.isSearchable = isSearchable; 206 return this; 207 } 208 209 /** 210 * value of type} 211 * @return type 212 */ 213 214 public com.commercetools.history.models.common.AttributeType getType() { 215 return this.type; 216 } 217 218 /** 219 * <p>The unique name of the attribute used in the API. The name must be between two and 256 characters long and can contain the ASCII letters A to Z in lowercase or uppercase, digits, underscores (<code>_</code>) and the hyphen-minus (<code>-</code>). When using the same <code>name</code> for an attribute in two or more product types all fields of the AttributeDefinition of this attribute need to be the same across the product types, otherwise an AttributeDefinitionAlreadyExists error code will be returned. An exception to this are the values of an <code>enum</code> or <code>lenum</code> type and sets thereof.</p> 220 * @return name 221 */ 222 223 public String getName() { 224 return this.name; 225 } 226 227 /** 228 * value of label} 229 * @return label 230 */ 231 232 public com.commercetools.history.models.common.LocalizedString getLabel() { 233 return this.label; 234 } 235 236 /** 237 * <p>Whether the attribute is required to have a value.</p> 238 * @return isRequired 239 */ 240 241 public Boolean getIsRequired() { 242 return this.isRequired; 243 } 244 245 /** 246 * value of attributeConstraint} 247 * @return attributeConstraint 248 */ 249 250 public com.commercetools.history.models.common.AttributeConstraintEnum getAttributeConstraint() { 251 return this.attributeConstraint; 252 } 253 254 /** 255 * value of inputTip} 256 * @return inputTip 257 */ 258 259 public com.commercetools.history.models.common.LocalizedString getInputTip() { 260 return this.inputTip; 261 } 262 263 /** 264 * value of inputHint} 265 * @return inputHint 266 */ 267 268 public com.commercetools.history.models.common.TextInputHint getInputHint() { 269 return this.inputHint; 270 } 271 272 /** 273 * <p>Whether the attribute's values should generally be enabled in product search. This determines whether the value is stored in products for matching terms in the context of full-text search queries and can be used in facets & filters as part of product search queries. The exact features that are enabled/disabled with this flag depend on the concrete attribute type and are described there. The max size of a searchable field is <strong>restricted to 10922 characters</strong>. This constraint is enforced at both product creation and product update. If the length of the input exceeds the maximum size an InvalidField error is returned.</p> 274 * @return isSearchable 275 */ 276 277 public Boolean getIsSearchable() { 278 return this.isSearchable; 279 } 280 281 /** 282 * builds AttributeDefinition with checking for non-null required values 283 * @return AttributeDefinition 284 */ 285 public AttributeDefinition build() { 286 Objects.requireNonNull(type, AttributeDefinition.class + ": type is missing"); 287 Objects.requireNonNull(name, AttributeDefinition.class + ": name is missing"); 288 Objects.requireNonNull(label, AttributeDefinition.class + ": label is missing"); 289 Objects.requireNonNull(isRequired, AttributeDefinition.class + ": isRequired is missing"); 290 Objects.requireNonNull(attributeConstraint, AttributeDefinition.class + ": attributeConstraint is missing"); 291 Objects.requireNonNull(inputTip, AttributeDefinition.class + ": inputTip is missing"); 292 Objects.requireNonNull(inputHint, AttributeDefinition.class + ": inputHint is missing"); 293 Objects.requireNonNull(isSearchable, AttributeDefinition.class + ": isSearchable is missing"); 294 return new AttributeDefinitionImpl(type, name, label, isRequired, attributeConstraint, inputTip, inputHint, 295 isSearchable); 296 } 297 298 /** 299 * builds AttributeDefinition without checking for non-null required values 300 * @return AttributeDefinition 301 */ 302 public AttributeDefinition buildUnchecked() { 303 return new AttributeDefinitionImpl(type, name, label, isRequired, attributeConstraint, inputTip, inputHint, 304 isSearchable); 305 } 306 307 /** 308 * factory method for an instance of AttributeDefinitionBuilder 309 * @return builder 310 */ 311 public static AttributeDefinitionBuilder of() { 312 return new AttributeDefinitionBuilder(); 313 } 314 315 /** 316 * create builder for AttributeDefinition instance 317 * @param template instance with prefilled values for the builder 318 * @return builder 319 */ 320 public static AttributeDefinitionBuilder of(final AttributeDefinition template) { 321 AttributeDefinitionBuilder builder = new AttributeDefinitionBuilder(); 322 builder.type = template.getType(); 323 builder.name = template.getName(); 324 builder.label = template.getLabel(); 325 builder.isRequired = template.getIsRequired(); 326 builder.attributeConstraint = template.getAttributeConstraint(); 327 builder.inputTip = template.getInputTip(); 328 builder.inputHint = template.getInputHint(); 329 builder.isSearchable = template.getIsSearchable(); 330 return builder; 331 } 332 333}