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

com.hp.autonomy.hod.client.api.textindex.document.AddToTextIndexRequestBuilder Maven / Gradle / Ivy

There is a newer version: 0.25.3
Show newest version
/*
 * Copyright 2015-2016 Hewlett-Packard Development Company, L.P.
 * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
 */

package com.hp.autonomy.hod.client.api.textindex.document;

import com.hp.autonomy.hod.client.converter.DoNotConvert;
import com.hp.autonomy.hod.client.util.MultiMap;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Data
@Accessors(chain = true)
public class AddToTextIndexRequestBuilder {

    /**
     * @param duplicateMode The duplicate mode of the document
     */
    private DuplicateMode duplicateMode;

    private List referencePrefixes = new ArrayList<>();

    private List additionalMetadata = new ArrayList<>();

    /**
     * Adds values to the referencePrefixes parameter
     *
     * @param referencePrefix   The first index
     * @param referencePrefixes The remaining referencePrefixes
     * @return this
     */
    public AddToTextIndexRequestBuilder addReferencePrefixes(final String referencePrefix, final String... referencePrefixes) {
        this.referencePrefixes.add(referencePrefix);
        this.referencePrefixes.addAll(Arrays.asList(referencePrefixes));

        return this;
    }

    /**
     * Sets the value of the referencePrefixes parameter
     *
     * @param referencePrefixes The referencePrefixes to query
     * @return this
     */
    public AddToTextIndexRequestBuilder setReferencePrefixes(final List referencePrefixes) {
        this.referencePrefixes = referencePrefixes;

        return this;
    }

    /**
     * Sets the value of the metadata parameter
     *
     * @param metadatum The first index
     * @param metadata  The remaining metadata
     * @return this
     */
    public AddToTextIndexRequestBuilder addAdditionalMetadata(final Object metadatum, final Object... metadata) {
        this.additionalMetadata.add(metadatum);
        this.additionalMetadata.addAll(Arrays.asList(metadata));

        return this;
    }

    /**
     * Sets the value of the metadata parameter
     *
     * @param metadata The metadata to query
     * @return this
     */
    public AddToTextIndexRequestBuilder setAdditionalMetadata(final List metadata) {
        this.additionalMetadata = metadata;

        return this;
    }

    /**
     * @return A map of query parameters suitable for use with {@link AddToTextIndexBackend}. get is NOT supported on
     * the resulting map
     */
    Map build() {
        final Map params = new MultiMap<>();

        params.put("duplicate_mode", duplicateMode);

        for (final String referencePrefix : referencePrefixes) {
            params.put("reference_prefix", referencePrefix);
        }

        for (final Object metadata : additionalMetadata) {
            params.put("additional_metadata", metadata);
        }

        return params;
    }

    /**
     * Enum representing all the possible values of the duplicate_mode parameter
     */
    @DoNotConvert
    public enum DuplicateMode {
        duplicate,
        replace
    }

}