Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
[#13] No point in keeping separate subclasses of ResponseTypeRelatedR…
Browse files Browse the repository at this point in the history
…equestsExecutor
  • Loading branch information
nurkiewicz committed Dec 4, 2014
1 parent 6234752 commit 95eb02d
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor
import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import groovy.transform.TypeChecked
import org.springframework.http.HttpMethod
import org.springframework.http.HttpMethod as SpringHttpMethod
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestOperations

import static org.springframework.http.HttpMethod.DELETE

/**
* Abstraction over {@link RestOperations} that for a {@link ResponseTypeRelatedRequestsExecutor#getHttpMethod()}
* checks whether user passed an URL or a template. Basing on this we create an execute a request.
Expand All @@ -23,20 +26,20 @@ import org.springframework.web.client.RestOperations
* @see RestOperations
*/
@TypeChecked
abstract class ResponseTypeRelatedRequestsExecutor<T> {
public class ResponseTypeRelatedRequestsExecutor<T> {

protected final RestExecutor<T> restExecutor
protected final Map params
private final Class<T> responseType
final HttpMethod httpMethod

ResponseTypeRelatedRequestsExecutor(Map params, RestOperations restOperations, RetryExecutor retryExecutor, Class<T> responseType) {
public ResponseTypeRelatedRequestsExecutor(Map params, RestOperations restOperations, RetryExecutor retryExecutor, Class<T> responseType, HttpMethod httpMethod) {
this.params = params
this.responseType = responseType
this.restExecutor = new RestExecutor(restOperations, retryExecutor)
this.httpMethod = httpMethod
}

protected abstract SpringHttpMethod getHttpMethod()

ResponseEntity<T> exchange() {
return restExecutor.exchange(httpMethod, params, responseType)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.BodylessWithHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersHaving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders
import groovy.transform.TypeChecked
import org.springframework.http.HttpEntity
import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestOperations

import javax.ws.rs.DELETE

import static com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders.NO_PREDEFINED_HEADERS

/**
Expand Down Expand Up @@ -91,8 +95,8 @@ class DeleteMethodBuilder implements DeleteMethod, UrlParameterizableDeleteMetho
return delete().exchangeAsync()
}

private DeleteExecuteForResponseTypeRelated delete() {
return new DeleteExecuteForResponseTypeRelated(params, restOperations, retryExecutor)
private ResponseTypeRelatedRequestsExecutor<Object> delete() {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, Object, HttpMethod.DELETE)
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.BodyContainingWithHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersHaving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.ObjectReceiving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.ResponseEntityReceiving
import groovy.transform.TypeChecked
import org.springframework.http.HttpEntity
import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestOperations

Expand Down Expand Up @@ -87,7 +89,7 @@ class GetMethodBuilder implements GetMethod, UrlParameterizableGetMethod, Respon

@Override
public <T> ListenableFuture<T> ofTypeAsync(Class<T> responseType) {
GetExecuteForResponseTypeRelated<T> get = get(responseType)
ResponseTypeRelatedRequestsExecutor<T> get = get(responseType)
ListenableFuture<ResponseEntity<T>> future = get.exchangeAsync()
return Futures.transform(future, { ResponseEntity input ->
return input?.body
Expand All @@ -111,8 +113,8 @@ class GetMethodBuilder implements GetMethod, UrlParameterizableGetMethod, Respon
}
}

private GetExecuteForResponseTypeRelated get(Class responseType) {
return new GetExecuteForResponseTypeRelated(params, restOperations, retryExecutor, responseType)
private ResponseTypeRelatedRequestsExecutor get(Class responseType) {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, responseType, HttpMethod.GET)
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.BodylessWithHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersHaving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders
import groovy.transform.TypeChecked
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestOperations

Expand Down Expand Up @@ -97,8 +99,8 @@ class HeadMethodBuilder implements HeadMethod, UrlParameterizableHeadMethod, Res
return Futures.transform(future, {ResponseEntity re -> re?.headers} as Function<ResponseEntity, HttpHeaders>)
}

private HeadExecuteForResponseTypeRelated head() {
return new HeadExecuteForResponseTypeRelated(params, restOperations, retryExecutor)
private ResponseTypeRelatedRequestsExecutor<Object> head() {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, Object, HttpMethod.HEAD)
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersHaving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.ObjectReceiving
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders
Expand All @@ -16,6 +17,7 @@ import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestOperations

import static com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.PredefinedHttpHeaders.NO_PREDEFINED_HEADERS
import static org.springframework.http.HttpMethod.OPTIONS

/**
* Implementation of the {@link org.springframework.http.HttpMethod#HEAD method} fluent API
Expand Down Expand Up @@ -117,8 +119,8 @@ class OptionsMethodBuilder implements
}
}

private OptionsExecuteForResponseTypeRelated options(Class responseType) {
return new OptionsExecuteForResponseTypeRelated(params, restOperations, retryExecutor, responseType)
private ResponseTypeRelatedRequestsExecutor options(Class responseType) {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, responseType, OPTIONS)
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.LocationFindingExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.BodyContainingWithHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersSetting
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.ObjectReceiving
Expand Down Expand Up @@ -127,8 +128,8 @@ class PostMethodBuilder extends LocationFindingExecutor implements
}
}

private PostExecuteForResponseTypeRelated post(Class responseType) {
return new PostExecuteForResponseTypeRelated(params, restOperations, retryExecutor, responseType)
private ResponseTypeRelatedRequestsExecutor post(Class responseType) {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, responseType, POST)
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.common.util.concurrent.ListenableFuture
import com.nurkiewicz.asyncretry.RetryExecutor
import com.nurkiewicz.asyncretry.SyncRetryExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.LocationFindingExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.executor.ResponseTypeRelatedRequestsExecutor
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.BodyContainingWithHeaders
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.HeadersSetting
import com.ofg.infrastructure.web.resttemplate.fluent.common.response.receive.ObjectReceiving
Expand Down Expand Up @@ -128,8 +129,8 @@ class PutMethodBuilder extends LocationFindingExecutor implements
}
}

private PutExecuteForResponseTypeRelated put(Class responseType) {
return new PutExecuteForResponseTypeRelated(params, restOperations, retryExecutor, responseType)
private ResponseTypeRelatedRequestsExecutor put(Class responseType) {
return new ResponseTypeRelatedRequestsExecutor(params, restOperations, retryExecutor, responseType, PUT)
}

@Override
Expand Down

0 comments on commit 95eb02d

Please sign in to comment.