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

io.sphere.sdk.customobjects.commands.CustomObjectDeleteCommandImpl Maven / Gradle / Ivy

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

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import io.sphere.sdk.client.HttpRequestIntent;
import io.sphere.sdk.commands.CommandImpl;
import io.sphere.sdk.commands.DeleteCommand;
import io.sphere.sdk.customobjects.CustomObject;
import io.sphere.sdk.http.HttpMethod;

import static java.lang.String.format;

/**
 * Deletes a custom object in SPHERE.IO.
 *
 *
 */
final class CustomObjectDeleteCommandImpl> extends CommandImpl implements CustomObjectDeleteCommand {
    private final String container;
    private final String key;
    private final TypeReference typeReference;

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

    @Override
    public HttpRequestIntent httpRequestIntent() {
        return HttpRequestIntent.of(HttpMethod.DELETE, CustomObjectEndpoint.PATH + format("/%s/%s", container, key));
    }

    CustomObjectDeleteCommandImpl(final String container, final String key, final TypeReference typeReference) {
        this.container = CustomObject.validatedContainer(container);
        this.key = CustomObject.validatedKey(key);
        this.typeReference = typeReference;
    }

    public static > DeleteCommand of(final T customObject, final TypeReference typeReference) {
        return of(customObject.getContainer(), customObject.getKey(), typeReference);
    }

    public static > DeleteCommand of(final String container, final String key, final TypeReference typeReference) {
        return new CustomObjectDeleteCommandImpl<>(container, key, typeReference);
    }

    /**
     * Deletes a custom object. Convenience method to not specify the {@link TypeReference} but lacking the accessible value in the result.
     * @param customObject the custom object to delete
     * @param  the type of the whole custom object
     * @return custom object only with meta data
     */
    public static > DeleteCommand> of(final T customObject) {
        return of(customObject.getContainer(), customObject.getKey());
    }

    public static DeleteCommand> of(final String container, final String key) {
        return new CustomObjectDeleteCommandImpl<>(container, key, new TypeReference>() {

        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy