All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.customers.commands.CustomerPasswordResetCommand Maven / Gradle / Ivy

There is a newer version: 1.0.0-M12
Show newest version
package io.sphere.sdk.customers.commands;

import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.commands.CommandImpl;
import io.sphere.sdk.customers.Customer;
import io.sphere.sdk.customers.CustomerToken;
import io.sphere.sdk.http.HttpRequest;
import io.sphere.sdk.models.Versioned;
import io.sphere.sdk.utils.JsonUtils;

import static io.sphere.sdk.http.HttpMethod.POST;

public class CustomerPasswordResetCommand extends CommandImpl {
    private final String id;
    private final long version;
    private final String tokenValue;
    private final String newPassword;

    private CustomerPasswordResetCommand(final Versioned customer, final String tokenValue, final String newPassword) {
        this.id = customer.getId();
        this.version = customer.getVersion();
        this.tokenValue = tokenValue;
        this.newPassword = newPassword;
    }

    public static CustomerPasswordResetCommand of(final Versioned customer, final CustomerToken token, final String newPassword) {
        return of(customer, token.getValue(), newPassword);
    }

    public static CustomerPasswordResetCommand of(final Versioned customer, final String tokenValue, final String newPassword) {
        return new CustomerPasswordResetCommand(customer, tokenValue, newPassword);
    }

    @Override
    protected TypeReference typeReference() {
        return Customer.typeReference();
    }

    @Override
    public HttpRequest httpRequest() {
        return HttpRequest.of(POST, "/customers/password/reset", JsonUtils.toJson(this));
    }

    public String getId() {
        return id;
    }

    public long getVersion() {
        return version;
    }

    public String getTokenValue() {
        return tokenValue;
    }

    public String getNewPassword() {
        return newPassword;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy