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

io.sphere.sdk.commands.ByIdDeleteCommandImpl Maven / Gradle / Ivy

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

import com.fasterxml.jackson.core.type.TypeReference;
import io.sphere.sdk.client.HttpRequestIntent;
import io.sphere.sdk.client.JsonEndpoint;
import io.sphere.sdk.http.HttpMethod;
import io.sphere.sdk.models.Versioned;

import static java.util.Objects.requireNonNull;

/**
 Internal base class to implement commands which deletes an entity by ID in SPHERE.IO.
 @param  the type of the result of the command, most likely the updated entity without expanded references */
public abstract class ByIdDeleteCommandImpl extends CommandImpl implements ByIdDeleteCommand {
    private final Versioned versioned;
    private final JsonEndpoint endpoint;

    protected ByIdDeleteCommandImpl(final Versioned versioned, final JsonEndpoint endpoint) {
        this.versioned = requireNonNull(versioned);
        this.endpoint = requireNonNull(endpoint);
    }

    @Override
    public HttpRequestIntent httpRequestIntent() {
        final String baseEndpointWithoutId = endpoint.endpoint();
        if (!baseEndpointWithoutId.startsWith("/")) {
            throw new RuntimeException("By convention the paths start with a slash, see baseEndpointWithoutId()");
        }
        return HttpRequestIntent.of(HttpMethod.DELETE, baseEndpointWithoutId + "/" + versioned.getId() + "?version=" + versioned.getVersion());
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy