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

com.dottydingo.hyperion.client.builder.CreateSingleRequestBuilder Maven / Gradle / Ivy

The newest version!
package com.dottydingo.hyperion.client.builder;

import com.dottydingo.hyperion.api.ApiObject;
import com.dottydingo.hyperion.api.EntityList;
import com.dottydingo.hyperion.client.HeaderFactory;
import com.dottydingo.hyperion.client.HyperionClient;
import com.dottydingo.hyperion.client.ParameterFactory;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * A request builder for creating a single item
 */
public class CreateSingleRequestBuilder,ID extends Serializable> extends CreateRequestBuilder
{
    /**
     * Create the request builder using the specified parameters
     * @param version The entity version
     * @param objectType The API type
     * @param entityName The entity name
     * @param entry The entry to create
     */
    public CreateSingleRequestBuilder(int version, Class objectType, String entityName, T entry)
    {
        super(version, objectType, entityName, Collections.singletonList(entry));
    }

    @Override
    public CreateSingleRequestBuilder returnFields(String... fields)
    {
        super.returnFields(fields);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder addParameter(String name, String value)
    {
        super.addParameter(name, value);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder setParameter(String name, String value)
    {
        super.setParameter(name, value);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder addHeader(String name, String value)
    {
        super.addHeader(name, value);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder setHeader(String name, String value)
    {
        super.setHeader(name, value);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder withHeaderFactory(HeaderFactory headerFactory)
    {
        super.withHeaderFactory(headerFactory);
        return this;
    }

    @Override
    public CreateSingleRequestBuilder withParameterFactory(ParameterFactory parameterFactory)
    {
        super.withParameterFactory(parameterFactory);
        return this;
    }

    /**
     * Execute the request using the supplied client
     * @param client the client
     * @return The request
     */
    public T execute(HyperionClient client)
    {
        EntityList response = client.create(build());
        List entries = response.getEntries();
        return entries.size() == 0 ? null : entries.get(0);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy