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

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

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

/**
 * Default implementation of ResourcesService
 */
public class ResourcesServiceImpl implements ResourcesService {
    
    private final ResourcesBackend resourcesBackend;
    private final Requester requester;

    /**
     * Create a new ResourcesServiceImpl with the give configuration
     * @param hodServiceConfig The configuration to use
     */
    public ResourcesServiceImpl(final HodServiceConfig hodServiceConfig) {
        resourcesBackend = hodServiceConfig.getRestAdapter().create(ResourcesBackend.class);
        requester = hodServiceConfig.getRequester();
    }
    
    @Override
    public Resources list(final ListResourcesRequestBuilder parameters) throws HodErrorException {
        return requester.makeRequest(Resources.class, getBackendCaller(parameters));
    }

    @Override
    public Resources list(final TokenProxy tokenProxy, final ListResourcesRequestBuilder parameters) throws HodErrorException {
        return requester.makeRequest(tokenProxy, Resources.class, getBackendCaller(parameters));
    }

    private Requester.BackendCaller getBackendCaller(final ListResourcesRequestBuilder parameters) {
        return new Requester.BackendCaller() {
            @Override
            public Response makeRequest(final AuthenticationToken authenticationToken) throws HodErrorException {
                return resourcesBackend.list(authenticationToken, parameters.build());
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy