Skip to content
This repository has been archived by the owner on Aug 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into 'release/1.2.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#   rest/build.gradle
  • Loading branch information
Stannieman committed Feb 10, 2018
2 parents db551ac + e26faf2 commit ff4b96f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:2.2.3'
}
}

Expand Down
10 changes: 5 additions & 5 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
12 changes: 6 additions & 6 deletions rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
minSdkVersion 16
Expand All @@ -18,9 +18,9 @@ android {
}

dependencies {
compile 'be.stannieman:commonservices:1.0.2.0'
compile 'com.android.volley:volley:1.1.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.4'
compile 'be.stannieman:commonservices:1.0.1.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.7'
}

task createJavaDoc(type: Javadoc) {
Expand All @@ -44,7 +44,7 @@ publishing {
aar(MavenPublication) {
groupId 'be.stannieman'
artifactId 'rest'
version '1.2.0'
version '1.0.1'
artifact "$buildDir\\outputs\\aar\\signed-${project.getName()}-release.aar"
artifact createJavaDocJar
artifact createSourcesJar
Expand Down
53 changes: 26 additions & 27 deletions rest/src/main/java/stannieman/rest/RestClientBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.concurrent.TimeoutException;

import stannieman.commonservices.helpers.ResultCodeHelper;
import stannieman.commonservices.models.DataServiceResult;
import stannieman.commonservices.models.GeneralResultCodes;
import stannieman.commonservices.models.IHasDataAndSuccessState;
import stannieman.commonservices.models.ServiceResult;
Expand Down Expand Up @@ -70,26 +69,26 @@ protected <SuccessResponseDataType, ErrorResponseDataType extends ErrorResponseD
if (!uriResult.isSuccess()) {
RestClientResultCodes resultCode = ResultCodeHelper.GetResultCodeOrNull(uriResult, RestClientResultCodes.class);
return resultCode != null
? new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.CANNOT_CREATE_URI);
? new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.CANNOT_CREATE_URI);
}
String uriString = uriResult.getData();

IHasDataAndSuccessState<String> bodyStringResult = getBodyString(requestProperties.getBody());
if (!bodyStringResult.isSuccess()) {
RestClientResultCodes resultCode = ResultCodeHelper.GetResultCodeOrNull(uriResult, RestClientResultCodes.class);
return resultCode != null
? new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.CANNOT_CREATE_JSON_STRING_FROM_OBJECT);
? new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.CANNOT_CREATE_JSON_STRING_FROM_OBJECT);
}
String bodyString = bodyStringResult.getData();

IHasDataAndSuccessState<NetworkResponse> networkResponseResult = getNetworkResponse(method, uriString, headers, bodyString);
if (!networkResponseResult.isSuccess()) {
RestClientResultCodes resultCode = ResultCodeHelper.GetResultCodeOrNull(uriResult, RestClientResultCodes.class);
return resultCode != null
? new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new DataServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.REQUEST_FAILED);
? new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(resultCode)
: new ServiceResult<RestResult<SuccessResponseDataType, ErrorResponseDataType>, RestClientResultCodes>(RestClientResultCodes.REQUEST_FAILED);
}
NetworkResponse networkResponse = networkResponseResult.getData();

Expand All @@ -102,21 +101,21 @@ private IHasDataAndSuccessState<String> getUriString(String subPath, String[] su
try {
String uriString = new URI(scheme, null, host, port, absoluteEndpointPath + parametrizedSubPath, null, null).toString();
String queryString = QueryParamsHelper.getQueryString(queryParameters, ENCODING);
return new DataServiceResult<>(uriString + queryString, GeneralResultCodes.OK);
return new ServiceResult<>(uriString + queryString, GeneralResultCodes.OK);
} catch (Exception e) {
return new DataServiceResult<>(CANNOT_CREATE_URI);
return new ServiceResult<>(CANNOT_CREATE_URI);
}
}

private IHasDataAndSuccessState<String> getBodyString(Object body) {
if (body != null) {
try {
return new DataServiceResult<>(objectMapper.writeValueAsString(body), GeneralResultCodes.OK);
return new ServiceResult<>(objectMapper.writeValueAsString(body), GeneralResultCodes.OK);
} catch (Exception e) {
return new DataServiceResult<>(RestClientResultCodes.CANNOT_CREATE_JSON_STRING_FROM_OBJECT);
return new ServiceResult<>(RestClientResultCodes.CANNOT_CREATE_JSON_STRING_FROM_OBJECT);
}
}
return new DataServiceResult<>();
return new ServiceResult<>();
}

private IHasDataAndSuccessState<NetworkResponse> getNetworkResponse(int method, String uriString, Map<String, String> headers, String bodyString) {
Expand All @@ -128,58 +127,58 @@ private IHasDataAndSuccessState<NetworkResponse> getNetworkResponse(int method,
response = future.get(timeout, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e) {
return new DataServiceResult<>(RestClientResultCodes.REQUEST_INTERRUPTED);
return new ServiceResult<>(RestClientResultCodes.REQUEST_INTERRUPTED);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (!(cause instanceof VolleyError)) {
return new DataServiceResult<>(RestClientResultCodes.REQUEST_FAILED);
return new ServiceResult<>(RestClientResultCodes.REQUEST_FAILED);
}
VolleyError error = (VolleyError) cause;
if (error.networkResponse == null) {
return new DataServiceResult<>(RestClientResultCodes.REQUEST_FAILED);
return new ServiceResult<>(RestClientResultCodes.REQUEST_FAILED);
}
response = error.networkResponse;
} catch (TimeoutException e) {
return new DataServiceResult<>(RestClientResultCodes.REQUEST_TIMED_OUT);
return new ServiceResult<>(RestClientResultCodes.REQUEST_TIMED_OUT);
}

return new DataServiceResult<>(response, GeneralResultCodes.OK);
return new ServiceResult<>(response, GeneralResultCodes.OK);
}

private <SuccessResponseDataType, ErrorResponseDataType extends ErrorResponseDataBase> IHasDataAndSuccessState<RestResult<SuccessResponseDataType, ErrorResponseDataType>> createRestResultFromNetworkResponse(Class<SuccessResponseDataType> successResponseDataType, Class<ErrorResponseDataType> errorResponseDataType, NetworkResponse networkResponse, Integer[] successStatusCodes) {
String jsonString = NetworkResponseRequest.parseToString(networkResponse);

if (isStatusCodeOk(networkResponse.statusCode, successStatusCodes)) {
if (successResponseDataType == null) {
return new DataServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode), GeneralResultCodes.OK);
return new ServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode), GeneralResultCodes.OK);
}
else {
try {
SuccessResponseDataType successObject = objectMapper.readValue(jsonString, successResponseDataType);
return new DataServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode, successObject), GeneralResultCodes.OK);
return new ServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode, successObject), GeneralResultCodes.OK);
} catch (JsonMappingException e) {
return new DataServiceResult<>(RestClientResultCodes.JSON_RESPONSE_DATA_TYPE_MISMATCH);
return new ServiceResult<>(RestClientResultCodes.JSON_RESPONSE_DATA_TYPE_MISMATCH);
} catch (JsonParseException e) {
return new DataServiceResult<>(RestClientResultCodes.RESPONSE_IS_NOT_VALID_JSON);
return new ServiceResult<>(RestClientResultCodes.RESPONSE_IS_NOT_VALID_JSON);
} catch (IOException e) {
return new DataServiceResult<>(RestClientResultCodes.CANNOT_CREATE_OBJECT_FROM_SUCCESS_RESPONSE);
return new ServiceResult<>(RestClientResultCodes.CANNOT_CREATE_OBJECT_FROM_SUCCESS_RESPONSE);
}
}
}

if (errorResponseDataType == null) {
return new DataServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(false, networkResponse.statusCode));
return new ServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(false, networkResponse.statusCode));
}
else {
try {
ErrorResponseDataType errorObject = objectMapper.readValue(jsonString, errorResponseDataType);
return new DataServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode, errorObject), GeneralResultCodes.OK);
return new ServiceResult<>(new RestResult<SuccessResponseDataType, ErrorResponseDataType>(networkResponse.statusCode, errorObject), GeneralResultCodes.OK);
} catch (JsonMappingException e) {
return new DataServiceResult<>(RestClientResultCodes.JSON_ERROR_DATA_TYPE_MISMATCH);
return new ServiceResult<>(RestClientResultCodes.JSON_ERROR_DATA_TYPE_MISMATCH);
} catch (JsonParseException e) {
return new DataServiceResult<>(RestClientResultCodes.RESPONSE_IS_NOT_VALID_JSON);
return new ServiceResult<>(RestClientResultCodes.RESPONSE_IS_NOT_VALID_JSON);
} catch (IOException e) {
return new DataServiceResult<>(RestClientResultCodes.CANNOT_CREATE_OBJECT_FROM_ERROR_RESPONSE);
return new ServiceResult<>(RestClientResultCodes.CANNOT_CREATE_OBJECT_FROM_ERROR_RESPONSE);
}
}
}
Expand Down

0 comments on commit ff4b96f

Please sign in to comment.