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

org.ctoolkit.restapi.client.adapter.Substitute Maven / Gradle / Ivy

/*
 * Copyright (c) 2018 Comvai, s.r.o. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package org.ctoolkit.restapi.client.adapter;

import com.google.api.client.googleapis.media.MediaHttpDownloader;
import com.google.api.client.http.HttpHeaders;
import org.ctoolkit.restapi.client.Identifier;
import org.ctoolkit.restapi.client.adaptee.DeleteExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.DownloadExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.GetExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.InsertExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.ListExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.NewExecutorAdaptee;
import org.ctoolkit.restapi.client.adaptee.UpdateExecutorAdaptee;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.OutputStream;
import java.util.List;
import java.util.Locale;
import java.util.Map;

/**
 * The plugin to give possibility substitute a remote resource with local record if desirable.
 * Mainly for the testing purpose avoiding a remote calls.
 * 

* The implementation is optional and once configured will take a precedence over remote calls. *

* {@code bind( Substitute.class ).to( MySubstituteImpl.class );} * * @author Aurel Medvegy */ public interface Substitute { /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackNewInstance(NewExecutorAdaptee, Object, Class, Map, Locale) */ R newInstance( @Nonnull Object remoteRequest, @Nonnull Class responseType, @Nullable Map parameters, @Nullable Locale locale ); /** * Same input parameters except Adaptee and DownloadResponseInterceptor that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#executeDownload(MediaHttpDownloader, DownloadExecutorAdaptee, Class, Identifier, * OutputStream, DownloadResponseInterceptor, HttpHeaders, Map, Locale) */ void download( @Nonnull Class resource, @Nonnull Identifier identifier, @Nonnull OutputStream output, @Nullable HttpHeaders headers, @Nullable Map params, @Nullable Locale locale ); /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackExecuteGet(GetExecutorAdaptee, Object, Class, Identifier, Map, Locale) */ R get( @Nonnull Object remoteRequest, @Nonnull Class responseType, @Nonnull Identifier identifier, @Nullable Map parameters, @Nullable Locale locale ); /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackExecuteList(ListExecutorAdaptee, Object, Class, Map, Locale, int, int, * String, Boolean) */ List list( @Nonnull Object remoteRequest, @Nonnull Class responseType, @Nullable Map criteria, @Nullable Locale locale, int start, int length, @Nullable String orderBy, @Nullable Boolean ascending ); /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackExecuteInsert(InsertExecutorAdaptee, Object, Class, Identifier, Map, Locale) */ R insert( @Nonnull Object remoteRequest, @Nonnull Class responseType, @Nullable Identifier parentKey, @Nullable Map parameters, @Nullable Locale locale ); /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackExecuteUpdate(UpdateExecutorAdaptee, Object, Class, Object, Map, Locale) */ R update( @Nonnull Object remoteRequest, @Nonnull Class responseType, @Nonnull Object identifier, @Nullable Map parameters, @Nullable Locale locale ); /** * Same input parameters except Adaptee that is not provided here. * * @throws ProceedWithRemoteCall if it is preferred to continue with remote call for concrete use cases * @see RestFacadeAdapter#callbackExecuteDelete(DeleteExecutorAdaptee, Object, Object, Class, Map, Locale) */ R delete( @Nonnull Object remoteRequest, @Nonnull Object identifier, @Nullable Class responseType, @Nullable Map parameters, @Nullable Locale locale ); /** * Conditional way to tell {@link RestFacadeAdapter} to continue with remote call. */ class ProceedWithRemoteCall extends RuntimeException { private static final long serialVersionUID = 2512251444836265184L; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy