io.sphere.sdk.customers.CustomerDraft Maven / Gradle / Ivy
package io.sphere.sdk.customers;
import io.sphere.sdk.carts.Cart;
import io.sphere.sdk.models.Base;
import org.apache.commons.lang3.builder.ToStringBuilder;
import java.util.Optional;
/**
* Template to create a new Customer.
*
* @see io.sphere.sdk.customers.CustomerDraftBuilder
* @see io.sphere.sdk.customers.commands.CustomerCreateCommand
*/
public class CustomerDraft extends Base {
private final Optional customerNumber;
private final String email;
private final String firstName;
private final String lastName;
private final Optional middleName;
private final String password;
private final Optional title;
private final Optional externalId;
private final Optional anonymousCartId;
CustomerDraft(final Optional customerNumber, final String email,
final String firstName, final String lastName, final Optional middleName,
final String password, final Optional title,
final Optional externalId,
final Optional anonymousCartId) {
this.customerNumber = customerNumber;
this.email = email;
this.firstName = firstName;
this.lastName = lastName;
this.middleName = middleName;
this.password = password;
this.title = title;
this.externalId = externalId;
this.anonymousCartId = anonymousCartId;
}
public static CustomerDraft of(final CustomerName customerName, final String email, final String password) {
return CustomerDraftBuilder.of(customerName, email, password).build();
}
public Optional getCustomerNumber() {
return customerNumber;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public Optional getMiddleName() {
return middleName;
}
public String getPassword() {
return password;
}
public Optional getTitle() {
return title;
}
public Optional getExternalId() {
return externalId;
}
public Optional getAnonymousCartId() {
return anonymousCartId;
}
public CustomerName getName() {
return CustomerName.of(getTitle(), getFirstName(), getMiddleName(), getLastName());
}
public CustomerDraft withCustomerNumber(final Optional customerNumber) {
return newBuilder().customerNumber(customerNumber).build();
}
public CustomerDraft withCustomerNumber(final String customerNumber) {
return withCustomerNumber(Optional.of(customerNumber));
}
public CustomerDraft withExternalId(final Optional externalId) {
return newBuilder().externalId(externalId).build();
}
public CustomerDraft withExternalId(final String externalId) {
return withExternalId(Optional.of(externalId));
}
public CustomerDraft withAnonymousCartId(final Optional anonymousCartId) {
return newBuilder().anonymousCartId(anonymousCartId).build();
}
public CustomerDraft withPassword(final String password) {
return newBuilder().password(password).build();
}
public CustomerDraft withCart(final Cart cart) {
return withAnonymousCartId(Optional.of(cart.getId()));
}
private CustomerDraftBuilder newBuilder() {
return CustomerDraftBuilder.of(this);
}
//it is final to prevent subclasses to log the password
@Override
public final String toString() {
final CustomerDraft outObject = withPassword("**removed from output**");
return ToStringBuilder.reflectionToString(outObject);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy