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

com.hp.autonomy.hod.client.api.queryprofile.QueryProfileServiceImpl 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.queryprofile;

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.api.resource.ResourceIdentifier;
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 retrofit.client.Response;

/**
 * Default implementation of QueryProfileService
 */
public class QueryProfileServiceImpl implements QueryProfileService {

    private final QueryProfileBackend queryProfileBackend;
    private final Requester requester;

    /**
     * Creates a new QueryProfileServiceImpl with the given configuration
     * @param hodServiceConfig The configuration to use
     */
    public QueryProfileServiceImpl(final HodServiceConfig hodServiceConfig) {
        queryProfileBackend = hodServiceConfig.getRestAdapter().create(QueryProfileBackend.class);
        requester = hodServiceConfig.getRequester();
    }

    @Override
    public QueryProfileStatusResponse createQueryProfile(
        final String name,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) throws HodErrorException {
        return requester.makeRequest(QueryProfileStatusResponse.class, getCreateBackendCaller(name, queryManipulationIndex, params));
    }

    @Override
    public QueryProfileStatusResponse createQueryProfile(
        final TokenProxy tokenProxy,
        final String name,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) throws HodErrorException {
        return requester.makeRequest(tokenProxy, QueryProfileStatusResponse.class, getCreateBackendCaller(name, queryManipulationIndex, params));
    }

    @Override
    public QueryProfile retrieveQueryProfile(final ResourceIdentifier queryProfile) throws HodErrorException {
        return requester.makeRequest(QueryProfile.class, getRetrieveBackendCaller(queryProfile));
    }

    @Override
    public QueryProfile retrieveQueryProfile(final TokenProxy tokenProxy, final ResourceIdentifier queryProfile) throws HodErrorException {
        return requester.makeRequest(tokenProxy, QueryProfile.class, getRetrieveBackendCaller(queryProfile));
    }

    @Override
    public QueryProfileStatusResponse updateQueryProfile(
        final ResourceIdentifier queryProfile,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) throws HodErrorException {
        return requester.makeRequest(QueryProfileStatusResponse.class, getUpdateBackendCaller(queryProfile, queryManipulationIndex, params));
    }

    @Override
    public QueryProfileStatusResponse updateQueryProfile(
        final TokenProxy tokenProxy,
        final ResourceIdentifier queryProfile,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) throws HodErrorException {
        return requester.makeRequest(tokenProxy, QueryProfileStatusResponse.class, getUpdateBackendCaller(queryProfile, queryManipulationIndex, params));
    }

    @Override
    public QueryProfileStatusResponse deleteQueryProfile(final ResourceIdentifier queryProfile) throws HodErrorException {
        return requester.makeRequest(QueryProfileStatusResponse.class, getDeleteBackendCaller(queryProfile));
    }

    @Override
    public QueryProfileStatusResponse deleteQueryProfile(final TokenProxy tokenProxy, final ResourceIdentifier queryProfile) throws HodErrorException {
        return requester.makeRequest(tokenProxy, QueryProfileStatusResponse.class, getDeleteBackendCaller(queryProfile));
    }

    private Requester.BackendCaller getCreateBackendCaller(
        final String name,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) {
        return new Requester.BackendCaller() {
            @Override
            public Response makeRequest(final AuthenticationToken authenticationToken) throws HodErrorException {
                return queryProfileBackend.createQueryProfile(authenticationToken, name, queryManipulationIndex, params == null ? null : params.build());
            }
        };
    }

    private Requester.BackendCaller getRetrieveBackendCaller(final ResourceIdentifier queryProfile) {
        return new Requester.BackendCaller() {
            @Override
            public Response makeRequest(final AuthenticationToken authenticationToken) throws HodErrorException {
                return queryProfileBackend.retrieveQueryProfile(authenticationToken, queryProfile);
            }
        };
    }

    private Requester.BackendCaller getUpdateBackendCaller(
        final ResourceIdentifier queryProfile,
        final String queryManipulationIndex,
        final QueryProfileRequestBuilder params
    ) {
        return new Requester.BackendCaller() {
            @Override
            public Response makeRequest(final AuthenticationToken authenticationToken) throws HodErrorException {
                return queryProfileBackend.updateQueryProfile(authenticationToken, queryProfile, queryManipulationIndex, params == null ? null : params.build());
            }
        };
    }

    private Requester.BackendCaller getDeleteBackendCaller(final ResourceIdentifier queryProfile) {
        return new Requester.BackendCaller() {
            @Override
            public Response makeRequest(final AuthenticationToken authenticationToken) throws HodErrorException {
                return queryProfileBackend.deleteQueryProfile(authenticationToken, queryProfile);
            }
        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy