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

com.hp.autonomy.hod.client.api.analysis.autocomplete.AutocompleteServiceImpl 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.analysis.autocomplete;

import com.hp.autonomy.hod.client.api.authentication.AuthenticationToken;
import com.hp.autonomy.hod.client.api.authentication.EntityType;
import com.hp.autonomy.hod.client.api.authentication.TokenType;
import com.hp.autonomy.hod.client.config.HodServiceConfig;
import com.hp.autonomy.hod.client.config.Requester;
import com.hp.autonomy.hod.client.error.HodErrorException;
import com.hp.autonomy.hod.client.token.TokenProxy;
import lombok.Data;
import retrofit.client.Response;

import java.util.List;

/**
 * Default implementation of an AutocompleteService.
 */
public class AutocompleteServiceImpl implements AutocompleteService {
    private final AutocompleteBackend backend;
    private final Requester requester;

    public AutocompleteServiceImpl(final HodServiceConfig config) {
        requester = config.getRequester();
        backend = config.getRestAdapter().create(AutocompleteBackend.class);
    }

    @Override
    public List getSuggestions(final String text) throws HodErrorException {
        return requester.makeRequest(AutocompleteResponse.class, new BackendCaller<>(text)).getWords();
    }

    @Override
    public List getSuggestions(final String text, final TokenProxy tokenProxy) throws HodErrorException {
        return requester.makeRequest(tokenProxy, AutocompleteResponse.class, new BackendCaller<>(text)).getWords();
    }

    @Data
    private class BackendCaller implements Requester.BackendCaller {
        private final String text;

        @Override
        public Response makeRequest(final AuthenticationToken token) throws HodErrorException {
            return backend.getSuggestions(token, text);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy