From 9f8a6b5ba125f707143cac7ecb2f9945672c2128 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Fri, 16 Feb 2018 10:13:52 +0100 Subject: [PATCH 01/18] expose config for modules init --- COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java b/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java index 9c00d48..a42d01d 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java +++ b/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java @@ -58,7 +58,7 @@ public abstract class BaseConfig> { * * @return Comapi ApiSpace identifier. */ - String getApiSpaceId() { + public String getApiSpaceId() { return apiSpaceId; } @@ -67,7 +67,7 @@ String getApiSpaceId() { * * @return Comapi logging configuration. */ - LogConfig getLogConfig() { + public LogConfig getLogConfig() { return logConfig; } From 40c83bafbbfaa94ff7978c43054e2c6a7e72ace9 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Tue, 8 May 2018 17:32:57 +0200 Subject: [PATCH 02/18] added message sender avatar uri, non null session from client api --- COMAPI/foundation/build.gradle | 4 +-- .../src/main/java/com/comapi/BaseClient.java | 2 +- .../src/main/java/com/comapi/BaseConfig.java | 2 +- .../src/main/java/com/comapi/Session.java | 4 +++ .../comapi/internal/ListenerListAdapter.java | 2 -- .../comapi/internal/helpers/APIHelper.java | 15 ++++++---- .../comapi/internal/network/ApiWrapper.java | 2 +- .../internal/network/SessionController.java | 28 ++++++++----------- .../network/model/messaging/Sender.java | 7 +++++ .../java/com/comapi/ComapiClientTest.java | 2 +- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index 41a597d..2551f59 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -58,8 +58,8 @@ dependencies { compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' /*FCM*/ - compile 'com.google.android.gms:play-services-base:11.6.2' - compile 'com.google.firebase:firebase-messaging:11.6.2' + compile 'com.google.android.gms:play-services-base:12.0.0' + compile 'com.google.firebase:firebase-messaging:12.0.0' /*Sockets*/ compile 'com.neovisionaries:nv-websocket-client:2.3' } diff --git a/COMAPI/foundation/src/main/java/com/comapi/BaseClient.java b/COMAPI/foundation/src/main/java/com/comapi/BaseClient.java index 54f27da..67e8c1f 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/BaseClient.java +++ b/COMAPI/foundation/src/main/java/com/comapi/BaseClient.java @@ -274,7 +274,7 @@ public int getState() { */ @Override public Session getSession() { - return state.get() > GlobalState.INITIALISING ? new Session(dataMgr.getSessionDAO().session()) : null; + return state.get() > GlobalState.INITIALISING ? new Session(dataMgr.getSessionDAO().session()) : new Session(); } abstract public T service(); diff --git a/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java b/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java index a42d01d..cb3d767 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java +++ b/COMAPI/foundation/src/main/java/com/comapi/BaseConfig.java @@ -130,7 +130,7 @@ PushTokenProvider getPushTokenProvider() { * * @return True if Firebase Cloud Messaging is configured and initialised */ - boolean isFcmEnabled() { + public boolean isFcmEnabled() { return fcmEnabled; } diff --git a/COMAPI/foundation/src/main/java/com/comapi/Session.java b/COMAPI/foundation/src/main/java/com/comapi/Session.java index 576924a..c6d126e 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/Session.java +++ b/COMAPI/foundation/src/main/java/com/comapi/Session.java @@ -36,6 +36,10 @@ public class Session { private boolean hasRequiredFields; + public Session() { + hasRequiredFields = false; + } + public Session(SessionData data) { if (data != null) { this.hasRequiredFields = !TextUtils.isEmpty(data.getProfileId()) && data.getExpiresOn() > 0 && !TextUtils.isEmpty(data.getAccessToken()) && !TextUtils.isEmpty(data.getSessionId()); diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/ListenerListAdapter.java b/COMAPI/foundation/src/main/java/com/comapi/internal/ListenerListAdapter.java index 62070ef..5d03707 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/ListenerListAdapter.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/ListenerListAdapter.java @@ -136,7 +136,6 @@ public void onSocketConnected() { log.d("TEST listener onSocketConnected triggered"); for (IStateListener listener : stateListeners) { try { - log.d("TEST listener onSocketConnected listener found"); listener.onSocketConnected(); } catch (Exception e) { logError(e, "socket connected"); @@ -148,7 +147,6 @@ public void onSocketDisconnected() { log.d("TEST listener onSocketDisconnected triggered"); for (IStateListener listener : stateListeners) { try { - log.d("TEST listener onSocketDisconnected listener found"); listener.onSocketDisconnected(); } catch (Exception e) { logError(e, "socket disconnected"); diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/helpers/APIHelper.java b/COMAPI/foundation/src/main/java/com/comapi/internal/helpers/APIHelper.java index db7c1a6..2222f1a 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/helpers/APIHelper.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/helpers/APIHelper.java @@ -22,6 +22,7 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.text.TextUtils; import com.comapi.internal.network.model.messaging.MessageToSend; import com.comapi.internal.network.model.messaging.Part; @@ -48,14 +49,18 @@ public class APIHelper { */ public static MessageToSend createMessage(@NonNull String conversationId, @NonNull String body, @Nullable String title) { - Part bodyPart = Part.builder().setData(body).setName("body").setSize(body.length()).setType("text/plain").build(); - Map fcm = new HashMap<>(); - fcm.put("notification", new Notification(title != null ? title : conversationId, body, conversationId)); + String fcmMsg = !TextUtils.isEmpty(body) ? body : "attachments"; + fcm.put("notification", new Notification(title != null ? title : conversationId, fcmMsg, conversationId)); Map apns = new HashMap<>(); - apns.put("alert", body); + apns.put("alert", fcmMsg); - return MessageToSend.builder().addPart(bodyPart).setAlert(fcm, apns).build(); + MessageToSend.Builder builder = MessageToSend.builder(); + if (!TextUtils.isEmpty(body)) { + Part bodyPart = Part.builder().setData(body).setName("body").setSize(body.length()).setType("text/plain").build(); + builder.addPart(bodyPart); + } + return builder.setAlert(fcm, apns).build(); } /** diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ApiWrapper.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ApiWrapper.java index f27ae43..fd0f8d1 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ApiWrapper.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ApiWrapper.java @@ -95,6 +95,6 @@ private void log(@NonNull Logger log, @NonNull ComapiResult r, String msg) { * @param msg Message with which the log should start with. */ private void log(@NonNull Logger log, @NonNull Throwable t, String msg) { - log.e(msg + ". Error calling services. " + t.getLocalizedMessage()); + log.f(msg + ". Error calling services. " + t.getLocalizedMessage(), t); } } \ No newline at end of file diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java index cb79879..e7d3a75 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java @@ -52,7 +52,6 @@ import retrofit2.Response; import rx.Observable; import rx.exceptions.Exceptions; -import rx.functions.Func1; import rx.schedulers.Schedulers; /** @@ -259,22 +258,17 @@ private Observable doStartSessionServiceCalls(@NonNull fi return new ChallengeOptions(startResponse.getNonce()); }) .takeWhile(challengeOptions -> challengeOptions != null) - .concatMap(new Func1>() { - @Override - public Observable call(ChallengeOptions challengeOptions) { - return getAuthToken(challengeOptions) - .timeout(auth.timeoutSeconds(), TimeUnit.SECONDS) - .retryWhen(errors -> errors.zipWith(Observable.range(1, 3), (n, i) -> { - if (i >= 3) { - //noinspection ThrowableResultOfMethodCallIgnored - Exceptions.propagate(n); - } - return i; - })) - .subscribeOn(Schedulers.io()) - .observeOn(Schedulers.io()); - } - }) + .concatMap(challengeOptions -> getAuthToken(challengeOptions) + .timeout(auth.timeoutSeconds(), TimeUnit.SECONDS) + .retryWhen(errors -> errors.zipWith(Observable.range(1, 3), (n, i) -> { + if (i >= 3) { + //noinspection ThrowableResultOfMethodCallIgnored + Exceptions.propagate(n); + } + return i; + })) + .subscribeOn(Schedulers.io()) + .observeOn(Schedulers.io())) .doOnNext(token -> log.d("Received 3rd party auth token: " + token)) .map(token -> getSessionCreateRequest(token, sessionCreateManager.getSessionAuthId(), deviceId)) .concatMap(sessionCreateRequest -> service.createSession(apiSpaceId, sessionCreateRequest) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/messaging/Sender.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/messaging/Sender.java index fd3369e..83eb295 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/messaging/Sender.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/messaging/Sender.java @@ -36,6 +36,9 @@ public class Sender { @SerializedName("name") protected String name; + @SerializedName("avatarUrl") + protected String avatarUrl; + /** * Recommended constructor. * @@ -64,4 +67,8 @@ public String getId() { public String getName() { return name; } + + public String getAvatarUrl() { + return avatarUrl; + } } diff --git a/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java b/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java index 9a9a521..8f344a0 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java @@ -657,7 +657,7 @@ public void wrongStates() throws NoSuchFieldException, IllegalAccessException { File merged = pc.copyLogs(file0).toBlocking().first(); assertNull(merged); - assertNull(pc.getSession()); + assertFalse(pc.getSession().isSuccessfullyCreated()); assertNull(pc.getLogs().toBlocking().first()); } From 7cd4f3e9969ac1deaae5eb25f7dcd9c02936f10c Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Tue, 3 Jul 2018 15:38:29 +0200 Subject: [PATCH 03/18] removed allowBackup --- COMAPI/foundation/src/main/AndroidManifest.xml | 2 +- .../com/comapi/internal/network/ServiceTest.java | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/COMAPI/foundation/src/main/AndroidManifest.xml b/COMAPI/foundation/src/main/AndroidManifest.xml index 5741f89..2eabb20 100644 --- a/COMAPI/foundation/src/main/AndroidManifest.xml +++ b/COMAPI/foundation/src/main/AndroidManifest.xml @@ -32,7 +32,7 @@ - + Date: Thu, 19 Jul 2018 17:17:15 +0200 Subject: [PATCH 04/18] dependency update --- COMAPI/build.gradle | 11 +++-- COMAPI/foundation/build.gradle | 47 ++++++++++--------- .../main/java/com/comapi/ComapiClient.java | 3 ++ .../main/java/com/comapi/RxComapiClient.java | 3 ++ .../java/com/comapi/ComapiCallbackTest.java | 2 +- .../java/com/comapi/ComapiClientTest.java | 2 +- .../lifecycle/LifecycleObserverTest.java | 2 +- .../internal/network/sockets/SocketTest.java | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- 9 files changed, 44 insertions(+), 32 deletions(-) diff --git a/COMAPI/build.gradle b/COMAPI/build.gradle index a58f6aa..5013a47 100644 --- a/COMAPI/build.gradle +++ b/COMAPI/build.gradle @@ -4,12 +4,16 @@ buildscript { repositories { jcenter() mavenCentral() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.1.3' - classpath 'com.google.gms:google-services:3.1.1' + classpath 'com.google.gms:google-services:4.0.1' // For test coverage classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3" @@ -27,7 +31,8 @@ allprojects { url 'http://clojars.org/repo' } maven { - url 'https://maven.google.com' + url 'https://maven.google.com/' + name 'Google' } } } diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index 2551f59..e161c14 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -3,12 +3,12 @@ apply from: 'version.gradle' apply from: 'code_coverage.gradle' android { - compileSdkVersion 26 - buildToolsVersion '26.0.2' + compileSdkVersion 28 + buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 16 - targetSdkVersion 26 + targetSdkVersion 28 versionCode 3 versionName foundationVersion testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' @@ -37,31 +37,32 @@ android { } dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - /* Android */ - compile 'com.android.support:appcompat-v7:26.1.0' + implementation fileTree(include: ['*.jar'], dir: 'libs') + /* testing */ - testCompile 'junit:junit:4.12' - androidTestCompile 'junit:junit:4.12' - testCompile 'org.robolectric:robolectric:3.2.2' - testCompile 'org.robolectric:shadows-play-services:3.2.2' - testCompile 'org.robolectric:shadows-support-v4:3.2.2' - androidTestCompile 'com.android.support.test:runner:1.0.1' - androidTestCompile 'com.android.support.test:rules:1.0.1' - testCompile 'com.squareup.okhttp3:mockwebserver:3.9.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'junit:junit:4.12' + testImplementation 'org.robolectric:robolectric:3.4.2' + testImplementation 'org.robolectric:shadows-play-services:3.3.2' + testImplementation 'org.robolectric:shadows-support-v4:3.3.2' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test:rules:1.0.2' + testImplementation 'com.squareup.okhttp3:mockwebserver:3.9.0' /* Rx */ - compile 'io.reactivex:rxjava:1.3.3' - compile 'io.reactivex:rxandroid:1.2.1' - compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0' + implementation 'io.reactivex:rxjava:1.3.3' + implementation 'io.reactivex:rxandroid:1.2.1' + implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0' /* Network */ - compile 'com.squareup.retrofit2:retrofit:2.3.0' - compile 'com.squareup.retrofit2:converter-gson:2.3.0' - compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' + implementation 'com.squareup.retrofit2:retrofit:2.3.0' + implementation 'com.squareup.retrofit2:converter-gson:2.3.0' + implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0' + /*FCM*/ - compile 'com.google.android.gms:play-services-base:12.0.0' - compile 'com.google.firebase:firebase-messaging:12.0.0' + //noinspection GradleCompatible warning disabled (seems to be caused by internal firebase-messaging dependencies versioning) + implementation 'com.google.firebase:firebase-messaging:17.1.0' + /*Sockets*/ - compile 'com.neovisionaries:nv-websocket-client:2.3' + implementation 'com.neovisionaries:nv-websocket-client:2.3' } /* diff --git a/COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java b/COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java index 282adbf..77008df 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java +++ b/COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java @@ -88,7 +88,10 @@ public ServiceAccessor service() { /** * Gets the content of internal log files. + * + * @deprecated Use safer version - {@link this#copyLogs(File)} instead. */ + @Deprecated public void getLogs(Callback callback) { adapter.adapt(super.getLogs(), callback); } diff --git a/COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java b/COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java index aaf69f2..cb41e31 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java +++ b/COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java @@ -92,8 +92,11 @@ public RxServiceAccessor service() { /** * Gets the content of internal log files. + * + * @deprecated Use safer version - {@link this#copyLogs(File)} instead. */ @Override + @Deprecated public Observable getLogs() { return super.getLogs(); } diff --git a/COMAPI/foundation/src/test/java/com/comapi/ComapiCallbackTest.java b/COMAPI/foundation/src/test/java/com/comapi/ComapiCallbackTest.java index e3be7aa..6f7562a 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/ComapiCallbackTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/ComapiCallbackTest.java @@ -54,7 +54,7 @@ import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowBluetoothAdapter; -import org.robolectric.util.ActivityController; +import org.robolectric.android.controller.ActivityController; import java.io.IOException; import java.lang.reflect.InvocationTargetException; diff --git a/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java b/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java index 8f344a0..41e8e70 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/ComapiClientTest.java @@ -61,7 +61,7 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowApplication; import org.robolectric.shadows.ShadowBluetoothAdapter; -import org.robolectric.util.ActivityController; +import org.robolectric.android.controller.ActivityController; import java.io.File; import java.io.FileNotFoundException; diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/lifecycle/LifecycleObserverTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/lifecycle/LifecycleObserverTest.java index c9e2c3a..d6f3207 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/lifecycle/LifecycleObserverTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/lifecycle/LifecycleObserverTest.java @@ -35,7 +35,7 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; -import org.robolectric.util.ActivityController; +import org.robolectric.android.controller.ActivityController; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/network/sockets/SocketTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/network/sockets/SocketTest.java index f05f84e..5562c72 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/network/sockets/SocketTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/network/sockets/SocketTest.java @@ -46,7 +46,7 @@ import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; -import org.robolectric.util.ActivityController; +import org.robolectric.android.controller.ActivityController; import java.lang.ref.WeakReference; import java.net.URI; diff --git a/COMAPI/gradle/wrapper/gradle-wrapper.properties b/COMAPI/gradle/wrapper/gradle-wrapper.properties index 13512eb..c257936 100644 --- a/COMAPI/gradle/wrapper/gradle-wrapper.properties +++ b/COMAPI/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Nov 13 11:24:04 CET 2017 +#Wed Jul 18 17:37:03 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip From a0880c2eb9fe97e65d017c1272179e46de86c715 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Tue, 7 Aug 2018 10:31:37 +0200 Subject: [PATCH 05/18] update retrolambda, turn off javadoc error --- COMAPI/build.gradle | 7 +------ COMAPI/foundation/build.gradle | 5 +++++ COMAPI/foundation/code_coverage.gradle | 15 +++++++++------ .../java/com/comapi/internal/CallbackAdapter.java | 2 +- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/COMAPI/build.gradle b/COMAPI/build.gradle index 5013a47..f094f8e 100644 --- a/COMAPI/build.gradle +++ b/COMAPI/build.gradle @@ -19,7 +19,7 @@ buildscript { classpath "org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3" classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1' - classpath 'me.tatarka:gradle-retrolambda:3.2.4' + classpath 'me.tatarka:gradle-retrolambda:3.7.0' } } @@ -39,9 +39,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} - -// Running 'gradle wrapper' will generate gradlew -task wrapper(type: Wrapper) { - gradleVersion = '3.4.1' } \ No newline at end of file diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index e161c14..bc4d7ca 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -84,6 +84,11 @@ def localReleaseDest = "${buildDir}/release/${version}" task androidJavadocs(type: Javadoc, overwrite: true) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.links("http://docs.oracle.com/javase/7/docs/api/") + options.linksOffline "http://d.android.com/reference","${android.sdkDirectory}/docs/reference" + exclude '**/BuildConfig.java' + exclude '**/R.java' + failOnError = false } task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { diff --git a/COMAPI/foundation/code_coverage.gradle b/COMAPI/foundation/code_coverage.gradle index 38f8166..a273089 100644 --- a/COMAPI/foundation/code_coverage.gradle +++ b/COMAPI/foundation/code_coverage.gradle @@ -69,12 +69,15 @@ task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") { classesPath = 'foundation/build/intermediates/classes/debug' } - new File(classesPath).eachFileRecurse { file -> - if (file.name.contains('$$')) { - def oldPath = file.path - def newPath = oldPath.replace('$$', '$') - file.renameTo(newPath) - renamedFilesMap[newPath] = oldPath + File dir = new File(classesPath) + if (dir.exists()) { + dir.eachFileRecurse { file -> + if (file.name.contains('$$')) { + def oldPath = file.path + def newPath = oldPath.replace('$$', '$') + file.renameTo(newPath) + renamedFilesMap[newPath] = oldPath + } } } } diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/CallbackAdapter.java b/COMAPI/foundation/src/main/java/com/comapi/internal/CallbackAdapter.java index 61512ec..f8647e8 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/CallbackAdapter.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/CallbackAdapter.java @@ -32,7 +32,7 @@ /** * Adapter to change observables into callbacks. By default it subscribes on io thread and notifies on the main thread. - * To change that behaviour ovveride CallbackAdapter#adapt(Observable, Callback) method and pass to SDK initialisation method. + * To change that behaviour override CallbackAdapter#adapt(Observable, Callback) method and pass to SDK initialisation method. * * @author Marcin Swierczek * @since 1.0.0 From fec0f02db42ed88a25d2c363eb93a7610e7452cb Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 9 Aug 2018 10:35:45 +0200 Subject: [PATCH 06/18] file logging fix --- .../com/comapi/internal/log/AppenderFile.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java b/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java index 7dde3d9..5dd8c90 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java @@ -27,12 +27,11 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.io.Writer; import java.lang.ref.WeakReference; -import java.nio.charset.Charset; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -80,11 +79,6 @@ class AppenderFile extends Appender { */ private final FormatterFileLog formatter; - /** - * File output stream to save Donky SDK logs. - */ - private FileOutputStream outputStream; - /** * File input stream to load Donky SDK logs. */ @@ -97,8 +91,7 @@ class AppenderFile extends Appender { /** * Recommended constructor. - * - * @param appContext Application Context. + * @param appContext Application Context. * @param logLevel Logging level that should be used for console output. Messages with higher * level won't be displayed in logcat. * @param formatter Message formatter. Defines the format of the output. @@ -108,7 +101,7 @@ class AppenderFile extends Appender { super(logLevel); this.appContextRef = new WeakReference<>(appContext); this.formatter = formatter; - executor = Executors.newSingleThreadExecutor(); + this.executor = Executors.newSingleThreadExecutor(); if (logSizeLimit >= MIN_LOG_SIZE) { this.fileSizeLimitKb = logSizeLimit; } else { @@ -131,10 +124,13 @@ public void appendLog(final String tag, final int logLevel, final String msg, fi rollOverFiles(); - outputStream = context.openFileOutput(name(1), Context.MODE_APPEND); - - if (outputStream != null) { - outputStream.write(formatter.formatMessage(logLevel, tag, msg, exception).getBytes(Charset.forName("UTF-8"))); + File mainFile = new File(context.getFilesDir(), name(1)); + if (!mainFile.exists()) { + mainFile.createNewFile(); + } + if (mainFile.exists() && mainFile.canWrite()) { + Writer outputStream = new BufferedWriter(new FileWriter(mainFile, true), 1024); + outputStream.write(formatter.formatMessage(logLevel, tag, msg, exception)); outputStream.flush(); outputStream.close(); } @@ -174,7 +170,7 @@ private void rollOverFiles() { if (mainFile.exists()) { - float fileSize = new File(dir, name(1)).length(); + float fileSize = mainFile.length(); fileSize = fileSize / 1024.0f; //In kilobytes if (fileSize > fileSizeLimitKb) { From 22ddbf03d7959067baa12b28808712a140ad9d9c Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 16 Aug 2018 15:18:10 +0200 Subject: [PATCH 07/18] update version number --- COMAPI/foundation/src/main/java/com/comapi/BaseComapi.java | 2 +- COMAPI/foundation/version.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/BaseComapi.java b/COMAPI/foundation/src/main/java/com/comapi/BaseComapi.java index 98a3f02..59ce75b 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/BaseComapi.java +++ b/COMAPI/foundation/src/main/java/com/comapi/BaseComapi.java @@ -38,7 +38,7 @@ class BaseComapi { /** * Version of the ComapiImpl SDK MAJOR.MINOR.PATCH.BUILD */ - private final static String SDK_VERSION = "1.2.0"; + private final static String SDK_VERSION = "1.3.0"; private static final Set apiSpaces = Collections.synchronizedSet(new HashSet()); diff --git a/COMAPI/foundation/version.gradle b/COMAPI/foundation/version.gradle index 9053d72..1b06f6c 100644 --- a/COMAPI/foundation/version.gradle +++ b/COMAPI/foundation/version.gradle @@ -4,7 +4,7 @@ */ -ext.foundationVersion = '1.2.0' +ext.foundationVersion = '1.3.0' def isFoundationRelease = System.getenv("isparagonrelease") ext.isReleaseVersion = isFoundationRelease != null ? isFoundationRelease : false From 6bdf28977f8a5a19975bfb82037aeb09101fe438 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 16 Aug 2018 15:21:30 +0200 Subject: [PATCH 08/18] Version update, removed unused scripts --- COMAPI/instrumentation_test.cmd | 30 ------------------------------ COMAPI/instrumentation_test.sh | 27 --------------------------- README.md | 4 ++-- 3 files changed, 2 insertions(+), 59 deletions(-) delete mode 100755 COMAPI/instrumentation_test.cmd delete mode 100755 COMAPI/instrumentation_test.sh diff --git a/COMAPI/instrumentation_test.cmd b/COMAPI/instrumentation_test.cmd deleted file mode 100755 index 66a3048..0000000 --- a/COMAPI/instrumentation_test.cmd +++ /dev/null @@ -1,30 +0,0 @@ -@echo off - -SET "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_74" -start cmd /c call adb devices -l | find "device product:" >nul -if errorlevel 1 ( - echo No connected devices - start cmd /c call emulator -avd Nexus4_23 -wipe-data -no-skin -no-audio -no-window -) else ( - echo Found connected device -) - -:loop -echo checking if device ready... - -cmd /c call adb wait-for-device shell getprop init.svc.bootanim > tmpFile -set /p var= < tmpFile -del tmpFile - -ECHO var=%var% -if NOT "%var%"=="stopped" ( - echo waiting ... - ping 127.0.0.1 -n 3 > nul - goto loop -) else ( - ECHO emulator is ready - call PUSHD ".\COMAPI" - call .\gradlew.bat connectedAndroidTest -i -) - -exit 0 \ No newline at end of file diff --git a/COMAPI/instrumentation_test.sh b/COMAPI/instrumentation_test.sh deleted file mode 100755 index ba0c679..0000000 --- a/COMAPI/instrumentation_test.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# Starts Nexus5_API23 emulator and performs instrumentation tests - -#Start the emulator -emulator -avd Nexus5_API23 -wipe-data & EMULATOR_PID=$! - -# Wait for Android to finish booting -WAIT_CMD="adb wait-for-device shell getprop init.svc.bootanim" -until $WAIT_CMD | grep -m 1 stopped; do - echo "Waiting..." - sleep 1 -done - -# Unlock the Lock Screen -#adb shell input keyevent 82 - -# Clear and capture logcat -adb logcat -c -adb logcat > build/logcat.log & LOGCAT_PID=$! - -# Run the tests -./gradlew connectedAndroidTest -i - -# Stop the background processes -kill $LOGCAT_PID -kill $EMULATOR_PID \ No newline at end of file diff --git a/README.md b/README.md index f89fbc4..6700d6d 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ Via Maven com.comapi foundation - 1.2.0 + 1.3.0 ``` or Gradle ``` -compile 'com.comapi:foundation:1.2.0' +compile 'com.comapi:foundation:1.3.0' ``` For more information about the integration please visit [the website](http://docs.comapi.com/reference#one-sdk-android-overview). From d0223dd48f3ad8a2d4e481bd40d988a6b8754d4e Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 16 Aug 2018 15:27:20 +0200 Subject: [PATCH 09/18] remove unnecessary project files --- COMAPI/foundation/src/build.gradle | 198 --------------------- COMAPI/foundation/src/code_coverage.gradle | 180 ------------------- COMAPI/foundation/src/proguard-rules.pro | 17 -- COMAPI/foundation/src/version.gradle | 38 ---- 4 files changed, 433 deletions(-) delete mode 100644 COMAPI/foundation/src/build.gradle delete mode 100644 COMAPI/foundation/src/code_coverage.gradle delete mode 100644 COMAPI/foundation/src/proguard-rules.pro delete mode 100644 COMAPI/foundation/src/version.gradle diff --git a/COMAPI/foundation/src/build.gradle b/COMAPI/foundation/src/build.gradle deleted file mode 100644 index d756a73..0000000 --- a/COMAPI/foundation/src/build.gradle +++ /dev/null @@ -1,198 +0,0 @@ -apply plugin: 'com.android.library' -apply from: 'version.gradle' -apply from: 'code_coverage.gradle' - -android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' - - defaultConfig { - minSdkVersion 16 - targetSdkVersion 25 - versionCode 2 - versionName foundationVersion - testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - testCoverageEnabled = false - } - debug { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - testCoverageEnabled = false - } - } - lintOptions { - disable 'InvalidPackage' - disable 'AppLinksAutoVerifyError' - abortOnError false - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } -} - -dependencies { - compile fileTree(include: ['*.jar'], dir: 'libs') - /* Android */ - compile 'com.android.support:appcompat-v7:25.3.0' - - /* testing */ - testCompile 'junit:junit:4.12' - androidTestCompile 'junit:junit:4.12' - testCompile 'org.robolectric:robolectric:3.1.2' - testCompile "org.robolectric:shadows-play-services:3.1.2" - testCompile "org.robolectric:shadows-support-v4:3.1.2" - androidTestCompile 'com.android.support.test:runner:0.5' - androidTestCompile 'com.android.support.test:rules:0.5' - testCompile 'com.squareup.okhttp3:mockwebserver:3.6.0' - - /* Network */ - compile 'com.squareup.retrofit2:retrofit:2.2.0' - compile 'com.squareup.retrofit2:converter-gson:2.2.0' - compile 'com.squareup.okhttp3:logging-interceptor:3.6.0' - compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0' - - /* RxJava */ - compile 'io.reactivex:rxjava:1.2.7' - compile 'io.reactivex:rxandroid:1.2.1' - - /*FCM*/ - compile 'com.google.android.gms:play-services-base:10.2.0' - compile 'com.google.firebase:firebase-messaging:10.2.0' - - /*Sockets*/ - compile 'com.neovisionaries:nv-websocket-client:1.31' -} - -/* - - Generate Maven release files - ./gradlew clean build generateRelease - -*/ - -apply plugin: 'signing' -apply plugin: 'maven' - -def groupId = 'com.comapi' -def artifactId = 'foundation' -def version = foundationVersion -def comapiUrl = 'http://www.comapi.com/' -def localReleaseDest = "${buildDir}/release/${version}" - -task androidJavadocs(type: Javadoc, overwrite: true) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) -} - -task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { - classifier = 'javadoc' - from androidJavadocs.destinationDir -} - -task androidSourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.srcDirs -} - -uploadArchives { - - repositories.mavenDeployer { - - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = groupId - pom.artifactId = artifactId - pom.version = version - pom.project { - - packaging 'aar' - - licenses { - license { - name 'MIT License' - url 'http://www.opensource.org/licenses/mit-license.php' - distribution 'repo' - } - } - name 'Comapi' - description 'Provides the basics of any Comapi integration into your apps. The Comapi Foundation SDK is responsible for handling: registration, control of User and Device registration details, sending and receiving content & data.' - url comapiUrl - - developers { - developer { - id 'marcinswierczek' - name 'Marcin Swierczek'; - email 'sdk@comapi.com'; - } - } - - scm { - url 'https://github.com/comapi/comapi-sdk-android' - connection 'scm:git:https://github.com/comapi/comapi-sdk-android.git' - developerConnection 'scm:git:https://github.com/comapi/comapi-sdk-android.git' - } - } - - // Add other pom properties here if you want (developer details / licenses) - repository(url: "file://${localReleaseDest}") - } -} - -/** - * To avoid conflict with Jcentre autogenerated files - */ -task removeMavenMetatdata(type: Delete) { - delete fileTree(dir: "${localReleaseDest}/com/comapi/foundation", exclude: "${version}") -} - -task zipRelease(type: Zip) { - from "${localReleaseDest}" - destinationDir buildDir - archiveName "${artifactId}-${version}.zip" -} - -task generateRelease << { - println "Release ${version} can be found at ${localReleaseDest}/" - println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip" -} - -signing { - required { isReleaseVersion || hasProperty("teamcity") } - sign configurations.archives -} - -if (hasProperty("teamcity")) { - gradle.taskGraph.whenReady { taskGraph -> - if (taskGraph.allTasks.any { it instanceof Sign }) { - - def id = System.getenv("keyid") - def file = System.getenv("secretkeyringfile") - def password = System.getenv("donkypassword") - - allprojects { ext."signing.keyId" = id } - allprojects { ext."signing.secretKeyRingFile" = file } - allprojects { ext."signing.password" = password } - - } - } -} - -generateRelease.dependsOn(uploadArchives) -zipRelease.dependsOn(removeMavenMetatdata) -generateRelease.dependsOn(zipRelease) - -artifacts { - archives androidSourcesJar - archives androidJavadocsJar -} - -apply plugin: 'me.tatarka.retrolambda' -retrolambda { - javaVersion JavaVersion.VERSION_1_7 -} \ No newline at end of file diff --git a/COMAPI/foundation/src/code_coverage.gradle b/COMAPI/foundation/src/code_coverage.gradle deleted file mode 100644 index 2f6b588..0000000 --- a/COMAPI/foundation/src/code_coverage.gradle +++ /dev/null @@ -1,180 +0,0 @@ -/* - - Code coverage result - -*/ - -apply plugin: 'jacoco' -apply plugin: "com.github.kt3k.coveralls" - -ext { - limits = [ - 'instruction': 85, - 'branch' : 70, - 'line' : 85, - 'complexity' : 70, - 'method' : 84, - 'class' : 85 - ] -} - -jacoco { - toolVersion = "0.7.2.201409121644" -} - -def coverageSourceDirs = [ - '../foundation/src/main/java' -] - -task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") { - - group = "Reporting" - - description = "Generate Jacoco coverage reports" - - classDirectories = fileTree( - dir: '../foundation/build/intermediates/classes/debug', - excludes: ['**/R.class', - '**/R$*.class', - '**/*$ViewInjector*.*', - '**/BuildConfig.*', - '**/Manifest*.*', - '**/LogLevel.class', - '**/IDService.class', - '**/PushService.class', - '**/PushBroadcastReceiver.class' - ] - ) - - additionalSourceDirs = files(coverageSourceDirs) - sourceDirectories = files(coverageSourceDirs) - executionData = files('../foundation/build/jacoco/testDebugUnitTest.exec') - - reports { - xml.enabled = true - html.enabled = true - } - - def renamedFilesMap = [:] - - // Hacky fix for issue: https://code.google.com/p/android/issues/detail?id=69174. - // Rename files with '$$' before generating report, and then rename back after - doFirst { - - def classesPath - - if (project.hasProperty("teamcity")) { - classesPath = 'COMAPI/foundation/build/intermediates/classes/debug' - } else { - classesPath = 'foundation/build/intermediates/classes/debug' - } - - new File(classesPath).eachFileRecurse { file -> - if (file.name.contains('$$')) { - def oldPath = file.path - def newPath = oldPath.replace('$$', '$') - file.renameTo(newPath) - renamedFilesMap[newPath] = oldPath - } - } - } - - /** - * Solution to jacoco test coverage report parsing found here https://github.com/springfox/springfox/blob/fb780ee1f14627b239fba95730a69900b9b2313a/gradle/coverage.gradle - */ - doLast { - - renamedFilesMap.each() { - def newPath, def oldPath -> - new File(newPath as String).renameTo(oldPath as String) - } - - def report = file("build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml") - logger.lifecycle("Checking coverage results: ${report}") - - def parser = new XmlParser() - parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); - parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false) - def results = parser.parse(report) - - def percentage = { - if (it != null) { - def covered = it.'@covered' as Double - def missed = it.'@missed' as Double - ((covered / (covered + missed)) * 100).round(2) - } else { - 100 - } - } - - def counters = results.counter - - def countersL = counters.find { it.'@type'.equals('LINE') } - def countersM = counters.find { it.'@type'.equals('METHOD') } - def countersC = counters.find { it.'@type'.equals('CLASS') } - - def teamcityLogMethodsCoverage = { - if (it != null) { - def covered = it.'@covered' as Double - def missed = it.'@missed' as Double - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsMCovered' value='" + covered + "']") - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsMTotal' value='" + (covered + missed) + "']") - } - } - - def teamcityLogLinesCoverage = { - if (it != null) { - def covered = it.'@covered' as Double - def missed = it.'@missed' as Double - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsLCovered' value='" + covered + "']") - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsLTotal' value='" + (covered + missed) + "']") - } - } - - def teamcityLogClassCoverage = { - if (it != null) { - def covered = it.'@covered' as Double - def missed = it.'@missed' as Double - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsCCovered' value='" + covered + "']") - logger.lifecycle("##teamcity[buildStatisticValue key='CodeCoverageAbsCTotal' value='" + (covered + missed) + "']") - } - } - - logger.lifecycle("##teamcity[blockOpened name='Code Coverage Summary']") - teamcityLogLinesCoverage(countersL) - teamcityLogMethodsCoverage(countersM) - teamcityLogClassCoverage(countersC) - logger.lifecycle("##teamcity[blockClosed name='Code Coverage Summary']") - - def metrics = [:] - metrics << [ - 'instruction': percentage(counters.find { it.'@type'.equals('INSTRUCTION') }), - 'branch' : percentage(counters.find { it.'@type'.equals('BRANCH') }), - 'line' : percentage(countersL), - 'complexity' : percentage(counters.find { it.'@type'.equals('COMPLEXITY') }), - 'method' : percentage(countersM), - 'class' : percentage(countersC) - ] - - def failures = [] - metrics.each { - def limit = limits[it.key as String] - if (it.value < limit) { - failures.add("- ${it.key} coverage rate is: ${it.value}%, minimum is ${limit}%") - } - } - - if (failures) { - logger.quiet("------------------ Code Coverage Failed -----------------------") - failures.each { - logger.quiet(it) - } - logger.quiet("---------------------------------------------------------------") - throw new GradleException("Code coverage failed") - } else { - logger.quiet("Passed Code Coverage Checks") - } - } -} - -check.dependsOn jacocoTestReport \ No newline at end of file diff --git a/COMAPI/foundation/src/proguard-rules.pro b/COMAPI/foundation/src/proguard-rules.pro deleted file mode 100644 index ab03c62..0000000 --- a/COMAPI/foundation/src/proguard-rules.pro +++ /dev/null @@ -1,17 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/marcin/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/COMAPI/foundation/src/version.gradle b/COMAPI/foundation/src/version.gradle deleted file mode 100644 index e0b95dd..0000000 --- a/COMAPI/foundation/src/version.gradle +++ /dev/null @@ -1,38 +0,0 @@ -/* - - Defines version and build number - -*/ - -ext.foundationVersion = '1.0.1' - -def isFoundationRelease = System.getenv("isparagonrelease") -ext.isReleaseVersion = isFoundationRelease != null ? isFoundationRelease : false - -if (!isReleaseVersion) { - foundationVersion = foundationVersion + '-SNAPSHOT' -} - -if (project.hasProperty("teamcity")) { - ext.foundationBuildNumber = teamcity['build.number'] -} else { - ext.foundationBuildNumber = getDate() -} - -def getDate() { - def date = new Date() - def formattedDate = date.format('yyyyMMddHHmmss') - return formattedDate -} - -task printFoundationVersion << { - logger.lifecycle("Version number is " + foundationVersion) - println foundationVersion -} - -task printBuildNumber << { - logger.lifecycle("Build number is " + foundationBuildNumber) - println foundationBuildNumber -} - -//logger.lifecycle("##teamcity[buildNumber '"+foundationBuildNumber+"']") \ No newline at end of file From 8f274b9d42b4b4f558f2aad7687977f60b2187dd Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 13 Sep 2018 17:26:37 +0200 Subject: [PATCH 10/18] State controller for UI elements, state aware fab, logging event added to event bus. --- COMAPI/foundation/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index bc4d7ca..4b424e3 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -60,6 +60,7 @@ dependencies { /*FCM*/ //noinspection GradleCompatible warning disabled (seems to be caused by internal firebase-messaging dependencies versioning) implementation 'com.google.firebase:firebase-messaging:17.1.0' + implementation 'com.google.android.gms:play-services-base:15.0.1' /*Sockets*/ implementation 'com.neovisionaries:nv-websocket-client:2.3' From 34775d4e3d1357c93386a7706f1fa223f2440f55 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 4 Oct 2018 14:52:15 +0200 Subject: [PATCH 11/18] profile APIs with defaults --- .../java/com/comapi/RxServiceAccessor.java | 60 +++++++ .../main/java/com/comapi/ServiceAccessor.java | 70 +++++++- .../comapi/internal/network/ComapiResult.java | 2 - .../internal/network/InternalService.java | 149 +++++++++++++++- .../network/model/profile/ComapiProfile.java | 161 ++++++++++++++++++ .../comapi/internal/network/ServiceTest.java | 150 ++++++++++++++++ .../src/test/resources/rest_profile_get.json | 12 +- .../test/resources/rest_profile_patch.json | 10 +- .../test/resources/rest_profile_query.json | 11 ++ .../test/resources/rest_profile_update.json | 10 +- 10 files changed, 624 insertions(+), 11 deletions(-) create mode 100644 COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java diff --git a/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java b/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java index cd7db16..26c941b 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java +++ b/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java @@ -39,6 +39,7 @@ import com.comapi.internal.network.model.messaging.MessageToSend; import com.comapi.internal.network.model.messaging.MessagesQueryResponse; import com.comapi.internal.network.model.messaging.UploadContentResponse; +import com.comapi.internal.network.model.profile.ComapiProfile; import java.util.List; import java.util.Map; @@ -82,6 +83,15 @@ public ProfileService profile() { return service; } + /** + * Access COMAPI Service profile APIs. + * + * @return COMAPI Service profile APIs. + */ + public RxServiceAccessor.ProfileServiceWithDefaults profileWithDefaults() { + return service.getProfileServiceWithDefaults(); + } + /** * Access COMAPI Service session management APIs. * @@ -174,6 +184,56 @@ public interface ProfileService { Observable>> patchMyProfile(@NonNull final Map profileDetails, final String eTag); } + /** + * Public interface to access ComapiImpl services limited to user profiles functionality. + * + * @author Marcin Swierczek + * @since 1.0.0 + * Copyright (C) Donky Networks Ltd. All rights reserved. + */ + public interface ProfileServiceWithDefaults { + + /** + * Get profile details from the service. + * + * @param profileId Profile Id of the user. + * @return Profile details from the service. + */ + Observable> getProfile(@NonNull final String profileId); + + /** + * Query user profiles on the services. + * + * @param queryString Query string. See https://www.npmjs.com/package/mongo-querystring for query syntax. You can use {@link QueryBuilder} helper class to construct valid query string. + * @return Profiles detail from the service. + */ + Observable>> queryProfiles(@NonNull final String queryString); + + /** + * Updates profile for an active session. + * + * @param profileDetails Profile details. + * @return Observable with to perform update profile for current session. + */ + Observable> updateProfile(@NonNull final ComapiProfile profileDetails, final String eTag); + + /** + * Applies given profile patch if required permission is granted. + * + * @param profileDetails Profile details. + * @return Observable with to perform patch profile for current session. + */ + Observable> patchProfile(@NonNull String profileId, @NonNull final ComapiProfile profileDetails, final String eTag); + + /** + * Applies profile patch for an active session. + * + * @param profileDetails Profile details. + * @return Observable with to perform patch profile for current session. + */ + Observable> patchMyProfile(@NonNull final ComapiProfile profileDetails, final String eTag); + } + /** * Public interface to access ComapiImpl services limited to messaging functionality. * diff --git a/COMAPI/foundation/src/main/java/com/comapi/ServiceAccessor.java b/COMAPI/foundation/src/main/java/com/comapi/ServiceAccessor.java index b122b9b..73dd2ac 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/ServiceAccessor.java +++ b/COMAPI/foundation/src/main/java/com/comapi/ServiceAccessor.java @@ -24,12 +24,12 @@ import android.support.annotation.Nullable; import com.comapi.internal.network.ComapiResult; -import com.comapi.internal.network.InternalService; import com.comapi.internal.network.ContentData; +import com.comapi.internal.network.InternalService; +import com.comapi.internal.network.model.conversation.Conversation; import com.comapi.internal.network.model.conversation.ConversationCreate; import com.comapi.internal.network.model.conversation.ConversationDetails; import com.comapi.internal.network.model.conversation.ConversationUpdate; -import com.comapi.internal.network.model.conversation.Conversation; import com.comapi.internal.network.model.conversation.Participant; import com.comapi.internal.network.model.conversation.Scope; import com.comapi.internal.network.model.messaging.ConversationEventsResponse; @@ -39,12 +39,11 @@ import com.comapi.internal.network.model.messaging.MessageToSend; import com.comapi.internal.network.model.messaging.MessagesQueryResponse; import com.comapi.internal.network.model.messaging.UploadContentResponse; +import com.comapi.internal.network.model.profile.ComapiProfile; import java.util.List; import java.util.Map; -import rx.Observable; - /** * Separates access to subsets of service APIs. * @@ -75,6 +74,8 @@ public MessagingService messaging() { /** * Access COMAPI Service profile APIs. + * This APIs version operates with the raw map of profile key-value pairs. + * @see this#profileWithDefaults * * @return COMAPI Service profile APIs. */ @@ -82,6 +83,16 @@ public ProfileService profile() { return service; } + /** + * Access COMAPI Service profile APIs. + * This APIs version wraps the raw map of profile key-value pairs in ComapiProfile objects that introduces default keys that can be understood by the Comapi Portal. + * + * @return COMAPI Service profile APIs. + */ + public ProfileServiceWithDefaults profileWithDefaults() { + return service.getProfileServiceWithDefaultsAndCallbacks(); + } + /** * Access COMAPI Service session management APIs. * @@ -166,6 +177,57 @@ public interface ProfileService { void patchMyProfile(@NonNull final Map profileDetails, final String eTag, @Nullable Callback>> callback); } + /** + * Public interface to access ComapiImpl services limited to user profiles functionality. + * + * @author Marcin Swierczek + * @since 1.0.0 + * Copyright (C) Donky Networks Ltd. All rights reserved. + */ + public interface ProfileServiceWithDefaults { + + /** + * Get profile details from the service. + * + * @param profileId Profile Id of the user. + * @param callback Callback with the result. + */ + void getProfile(@NonNull final String profileId, @Nullable Callback> callback); + + /** + * Query user profiles on the services. + * + * @param queryString Query string. See https://www.npmjs.com/package/mongo-querystring for query syntax. You can use {@link QueryBuilder} helper class to construct valid query string. + * @param callback Callback with the result. + */ + void queryProfiles(@NonNull final String queryString, @Nullable Callback>> callback); + + /** + * Updates profile for an active session. + * + * @param profileDetails Profile details. + * @param callback Callback with the result. + */ + void updateProfile(@NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback); + + /** + * Applies given profile patch if required permission is granted. + * + * @param profileId Id of an profile to patch. + * @param profileDetails Profile details. + * @param callback Callback with the result. + */ + void patchProfile(@NonNull final String profileId, @NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback); + + /** + * Applies profile patch for an active session. + * + * @param profileDetails Profile details. + * @param callback Callback with the result. + */ + void patchMyProfile(@NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback); + } + /** * Public interface to access ComapiImpl services limited to messaging functionality. * diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java index c462d7a..c1e046f 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java @@ -20,8 +20,6 @@ package com.comapi.internal.network; -import java.io.IOException; - import retrofit2.Response; /** diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/InternalService.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/InternalService.java index b411e70..a3ecb1a 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/InternalService.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/InternalService.java @@ -30,6 +30,8 @@ import com.comapi.Callback; import com.comapi.ComapiAuthenticator; import com.comapi.QueryBuilder; +import com.comapi.RxServiceAccessor; +import com.comapi.ServiceAccessor; import com.comapi.Session; import com.comapi.internal.CallbackAdapter; import com.comapi.internal.ComapiException; @@ -56,6 +58,7 @@ import com.comapi.internal.network.model.messaging.MessageToSend; import com.comapi.internal.network.model.messaging.MessagesQueryResponse; import com.comapi.internal.network.model.messaging.UploadContentResponse; +import com.comapi.internal.network.model.profile.ComapiProfile; import com.comapi.internal.network.sockets.SocketController; import com.comapi.internal.push.PushManager; @@ -66,7 +69,6 @@ import rx.Observable; - /** * Manages all service calls checking session state and redirecting to appropriate controllers. * @@ -1013,4 +1015,149 @@ public Observable> createFbOptInState() { return doCreateFbOptInState(token); } } + + public RxProfileServiceWithDefaultsImpl getProfileServiceWithDefaults() { + return new RxProfileServiceWithDefaultsImpl(); + } + + public ProfileServiceWithDefaultsImpl getProfileServiceWithDefaultsAndCallbacks() { + return new ProfileServiceWithDefaultsImpl(new RxProfileServiceWithDefaultsImpl(), adapter); + } + + /** + * Adding default keys to profile APIs. + */ + public class RxProfileServiceWithDefaultsImpl implements RxServiceAccessor.ProfileServiceWithDefaults { + + private RxProfileServiceWithDefaultsImpl() { + } + + /** + * Get profile details from the service. + * + * @param profileId Profile Id of the user. + * @return Observable emitting profile details from the service. + */ + public Observable> getProfile(@NonNull final String profileId) { + return InternalService.this.getProfile(profileId).map(result -> new ComapiResult<>(result, new ComapiProfile(result.getResult()))); + } + + /** + * Query user profiles on the services. + * + * @param queryString Query string. See https://www.npmjs.com/package/mongo-querystring for query syntax. You can use {@link QueryBuilder} helper class to construct valid query string. + * @return Observable emitting profiles detail from the service. + */ + public Observable>> queryProfiles(@NonNull final String queryString) { + return InternalService.this.queryProfiles(queryString).map(result -> { + List list = new ArrayList<>(); + if (result.isSuccessful() && result.getResult() != null) { + for (Map map : result.getResult()) { + list.add(new ComapiProfile(map)); + } + } + return new ComapiResult<>(result, list); + }); + } + + /** + * Updates profile for an active session. + * + * @param profileDetails Profile details. + * @return Observable to perform update profile for current session. + */ + public Observable> updateProfile(@NonNull final ComapiProfile profileDetails, final String eTag) { + return InternalService.this.updateProfile(profileDetails.asMap(), eTag).map(result -> new ComapiResult<>(result, new ComapiProfile(result.getResult()))); + } + + /** + * Applies given profile patch if required permission is granted. + * + * @param profileId Profile unique identifier. + * @param profileDetails Profile details. + * @return Observable to perform patch profile for current session. + */ + public Observable> patchProfile(@NonNull String profileId, @NonNull final ComapiProfile profileDetails, final String eTag) { + return InternalService.this.patchProfile(profileId, profileDetails.asMap(), eTag).map(result -> new ComapiResult<>(result, new ComapiProfile(result.getResult()))); + } + + /** + * Applies profile patch for an active session. + * + * @param profileDetails Profile details. + * @param eTag Identifier assigned by a web server to a specific version of a resource found at a URL. Use it to validate if you modify latest version of the profile data. + * @return Observable to perform patch profile for current session. + */ + public Observable> patchMyProfile(@NonNull final ComapiProfile profileDetails, final String eTag) { + return InternalService.this.patchMyProfile(profileDetails.asMap(), eTag).map(result -> new ComapiResult<>(result, new ComapiProfile(result.getResult()))); + } + } + + /** + * Adding default keys to profile APIs. + */ + public static class ProfileServiceWithDefaultsImpl implements ServiceAccessor.ProfileServiceWithDefaults { + + private final CallbackAdapter adapter; + private final RxProfileServiceWithDefaultsImpl service; + + private ProfileServiceWithDefaultsImpl(@NonNull RxProfileServiceWithDefaultsImpl service, @NonNull CallbackAdapter adapter) { + this.service = service; + this.adapter = adapter; + } + + /** + * Get profile details from the service. + * + * @param profileId Profile Id of the user. + * @param callback Profile details from the service. + */ + public void getProfile(@NonNull final String profileId, @Nullable Callback> callback) { + adapter.adapt(service.getProfile(profileId), callback); + } + + /** + * Query user profiles on the services. + * + * @param queryString Query string. See https://www.npmjs.com/package/mongo-querystring for query syntax. You can use {@link QueryBuilder} helper class to construct valid query string. + * @param callback Profiles detail from the service. + */ + public void queryProfiles(@NonNull final String queryString, @Nullable Callback>> callback) { + adapter.adapt(service.queryProfiles(queryString), callback); + } + + /** + * Updates profile for an active session. + * + * @param profileDetails New profile details. + * @param eTag Identifier assigned by a web server to a specific version of a resource found at a URL. Use it to validate if you modify latest version of the profile data. + * @param callback Observable with to perform update profile for current session. + */ + public void updateProfile(@NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback) { + adapter.adapt(service.updateProfile(profileDetails, eTag), callback); + } + + /** + * Applies given profile patch if required permission is granted. + * + * @param profileId Profile unique identifier. + * @param profileDetails New addition to profile details. + * @param eTag Identifier assigned by a web server to a specific version of a resource found at a URL. Use it to validate if you modify latest version of the profile data. + * @param callback Observable with to perform patch profile for current session. + */ + public void patchProfile(@NonNull String profileId, @NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback) { + adapter.adapt(service.patchProfile(profileId, profileDetails, eTag), callback); + } + + /** + * Applies profile patch for an active session. + * + * @param profileDetails New addition to profile details. + * @param eTag Identifier assigned by a web server to a specific version of a resource found at a URL. Use it to validate if you modify latest version of the profile data. + * @param callback Observable with to perform patch profile for current session. + */ + public void patchMyProfile(@NonNull final ComapiProfile profileDetails, final String eTag, @Nullable Callback> callback) { + adapter.adapt(service.patchMyProfile(profileDetails, eTag), callback); + } + } } \ No newline at end of file diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java new file mode 100644 index 0000000..e460199 --- /dev/null +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java @@ -0,0 +1,161 @@ +package com.comapi.internal.network.model.profile; + +import java.util.HashMap; +import java.util.Map; + +/** + * Wraps the raw map of profile properties into object with defaults, e.g. first name, last name etc. This properties cna be recognised e.g. by the Comapi Portal. + * + * @author Marcin Swierczek + * @since 1.3.0 + */ +public class ComapiProfile { + + private static final String keyId = "id"; + private static final String keyFirstName = "firstName"; + private static final String keyLastName = "lastName"; + private static final String keyEmail = "email"; + private static final String keyGender = "gender"; + private static final String keyPhoneNumber = "phoneNumber"; + private static final String keyCountryCode = "phoneNumberCountryCode"; + private static final String keyProfilePicture = "profilePicture"; + + private Map defaultProperties = new HashMap<>(); + + private Map customProperties = new HashMap<>(); + + public ComapiProfile() { + } + + public ComapiProfile(Map properties) { + + for (String key : properties.keySet()) { + if (key.equals(keyId)) { + defaultProperties.put(key, (String) properties.get(key)); + } + if (key.equals(keyFirstName)) { + setFirstName((String) properties.get(key)); + } else if (key.equals(keyLastName)) { + setLastName((String) properties.get(key)); + } else if (key.equals(keyEmail)) { + setEmail((String) properties.get(key)); + } else if (key.equals(keyPhoneNumber)) { + setPhoneNumber((String) properties.get(key)); + } else if (key.equals(keyCountryCode)) { + setPhoneNumberCountryCode((String) properties.get(key)); + } else if (key.equals(keyGender)) { + setGender((String) properties.get(key)); + } else if (key.equals(keyProfilePicture)) { + setProfilePicture((String) properties.get(key)); + } else if (!key.startsWith("_")) { + add(key, properties.get(key)); + } + } + } + + /** + * Internal profile id. + */ + public String getId() { + return defaultProperties.get(keyId); + } + + public String getFirstName() { + return defaultProperties.get(keyFirstName); + } + + public ComapiProfile setFirstName(String value) { + defaultProperties.put(keyFirstName, value); + return this; + } + + public String getLastName() { + return defaultProperties.get(keyLastName); + } + + public ComapiProfile setLastName(String value) { + defaultProperties.put(keyLastName, value); + return this; + } + + public String getEmail() { + return defaultProperties.get(keyEmail); + } + + public ComapiProfile setEmail(String value) { + defaultProperties.put(keyEmail, value); + return this; + } + + public String getGender() { + return defaultProperties.get(keyGender); + } + + public ComapiProfile setGender(String value) { + defaultProperties.put(keyGender, value); + return this; + } + + public String getPhoneNumber() { + return defaultProperties.get(keyPhoneNumber); + } + + public ComapiProfile setPhoneNumber(String value) { + defaultProperties.put(keyPhoneNumber, value); + return this; + } + + public String getPhoneNumberCountryCode() { + return defaultProperties.get(keyCountryCode); + } + + public ComapiProfile setPhoneNumberCountryCode(String value) { + defaultProperties.put(keyCountryCode, value); + return this; + } + + public String getProfilePicture() { + return defaultProperties.get(keyProfilePicture); + } + + public ComapiProfile setProfilePicture(String value) { + defaultProperties.put(keyProfilePicture, value); + return this; + } + + /** + * Add custom key-value pair + * + * @param key Profile property key + * avoid default keys : "id", "firstName", "lastName", "email", "gender", "phoneNumber", "phoneNumberCountryCode", "profilePicture"; + * @param value Profile property value. + */ + public void add(String key, Object value) { + customProperties.put(key, value); + } + + /** + * Remove custom key-value pair + * + * @param key Profile property key + * + * @return Removed profile property value or null. + */ + public Object remove(String key) { + return customProperties.remove(key); + } + + public Object get(String key) { + return customProperties.get(key); + } + + /** + * Merge all profile properties to a single map. + */ + public Map asMap() { + Map map = new HashMap<>(); + map.putAll(defaultProperties); + map.putAll(customProperties); + return map; + } +} \ No newline at end of file diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java index 0f42bb2..1422e95 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java @@ -49,6 +49,7 @@ import com.comapi.internal.network.model.messaging.MessageToSend; import com.comapi.internal.network.model.messaging.OrphanedEvent; import com.comapi.internal.network.model.messaging.Part; +import com.comapi.internal.network.model.profile.ComapiProfile; import com.comapi.internal.network.sockets.SocketController; import com.comapi.internal.push.PushManager; import com.comapi.mock.MockAuthenticator; @@ -82,6 +83,7 @@ import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.fail; import static org.robolectric.RuntimeEnvironment.application; /** @@ -218,6 +220,27 @@ public void getProfile() throws Exception { } + @Test + public void getProfileWithDefaults() throws Exception { + + server.enqueue(ResponseTestHelper.createMockResponse(this, "rest_profile_get.json", 200).addHeader("ETag", "eTag")); + + service.getProfileServiceWithDefaults().getProfile("profileId").toBlocking().forEach(response -> { + assertEquals(true, response.isSuccessful()); + assertEquals(200, response.getCode()); + assertEquals("id", response.getResult().get("id")); + assertEquals("firstName", response.getResult().getFirstName()); + assertEquals("lastName", response.getResult().getLastName()); + assertEquals("email", response.getResult().getEmail()); + assertEquals("gender", response.getResult().getGender()); + assertEquals("phoneNumber", response.getResult().getPhoneNumber()); + assertEquals("phoneNumberCountryCode", response.getResult().getPhoneNumberCountryCode()); + assertEquals("profilePicture", response.getResult().getProfilePicture()); + assertEquals("custom", response.getResult().get("custom")); + assertNotNull(response.getETag()); + }); + } + @Test public void getProfile_sessionCreateInProgress() throws Exception { @@ -330,6 +353,60 @@ public void queryProfile() throws Exception { }); } + @Test + public void queryProfileWithDefaults() throws Exception { + + server.enqueue(ResponseTestHelper.createMockResponse(this, "rest_profile_query.json", 200).addHeader("ETag", "eTag")); + + List list = new ArrayList<>(); + list.add(""); + + String query = new QueryBuilder() + .addContains("", "") + .addEndsWith("", "") + .addEqual("", "") + .addExists("") + .addGreaterOrEqualThan("", "") + .addLessOrEqualThan("", "") + .addLessThan("", "") + .addGreaterThan("", "") + .addNotExists("") + .addStartsWith("", "") + .addUnequal("", "") + .inArray("", list) + .notInArray("", list) + .build(); + + assertNotNull(query); + + service.getProfileServiceWithDefaults().queryProfiles(query).toBlocking().forEach(response -> { + assertEquals(true, response.isSuccessful()); + assertEquals(200, response.getCode()); + + ComapiProfile profile = null; + for (ComapiProfile p : response.getResult()) { + if (p.getId().equals("id")) { + profile = p; + break; + } + } + + if (profile != null) { + assertEquals("firstName", profile.getFirstName()); + assertEquals("lastName", profile.getLastName()); + assertEquals("email", profile.getEmail()); + assertEquals("gender", profile.getGender()); + assertEquals("phoneNumber", profile.getPhoneNumber()); + assertEquals("phoneNumberCountryCode", profile.getPhoneNumberCountryCode()); + assertEquals("profilePicture", profile.getProfilePicture()); + assertEquals("custom", profile.get("custom")); + assertNotNull(response.getETag()); + } else { + fail("no profile with id = id"); + } + }); + } + @Test public void queryProfile_sessionCreateInProgress() throws Exception { isCreateSessionInProgress.set(true); @@ -383,6 +460,30 @@ public void updateProfile() throws Exception { }); } + @Test + public void updateProfileWithDefaults() throws Exception { + + server.enqueue(ResponseTestHelper.createMockResponse(this, "rest_profile_update.json", 200).addHeader("ETag", "eTag")); + + Map map = new HashMap<>(); + map.put("key", "value"); + map.put("key2", 312); + + service.getProfileServiceWithDefaults().updateProfile(new ComapiProfile(map), "eTag").toBlocking().forEach(response -> { + assertEquals(true, response.isSuccessful()); + assertEquals(200, response.getCode()); + assertEquals("firstName", response.getResult().getFirstName()); + assertEquals("lastName", response.getResult().getLastName()); + assertEquals("email", response.getResult().getEmail()); + assertEquals("gender", response.getResult().getGender()); + assertEquals("phoneNumber", response.getResult().getPhoneNumber()); + assertEquals("phoneNumberCountryCode", response.getResult().getPhoneNumberCountryCode()); + assertEquals("profilePicture", response.getResult().getProfilePicture()); + assertEquals("custom", response.getResult().get("custom")); + assertNotNull(response.getETag()); + }); + } + @Test public void updateProfile_sessionCreateInProgress() throws Exception { isCreateSessionInProgress.set(true); @@ -423,6 +524,30 @@ public void patchProfile() throws Exception { }); } + @Test + public void patchProfileWithDefaults() throws Exception { + + server.enqueue(ResponseTestHelper.createMockResponse(this, "rest_profile_patch.json", 200).addHeader("ETag", "eTag")); + + Map map = new HashMap<>(); + map.put("key", "value"); + map.put("key2", 312); + + service.getProfileServiceWithDefaults().patchMyProfile(new ComapiProfile(map), "eTag").toBlocking().forEach(response -> { + assertEquals(true, response.isSuccessful()); + assertEquals(200, response.getCode()); + assertEquals("firstName", response.getResult().getFirstName()); + assertEquals("lastName", response.getResult().getLastName()); + assertEquals("email", response.getResult().getEmail()); + assertEquals("gender", response.getResult().getGender()); + assertEquals("phoneNumber", response.getResult().getPhoneNumber()); + assertEquals("phoneNumberCountryCode", response.getResult().getPhoneNumberCountryCode()); + assertEquals("profilePicture", response.getResult().getProfilePicture()); + assertEquals("custom", response.getResult().get("custom")); + assertNotNull(response.getETag()); + }); + } + @Test public void patchProfile2() throws Exception { @@ -440,6 +565,31 @@ public void patchProfile2() throws Exception { }); } + @Test + public void patchProfileWithDefaults2() throws Exception { + + server.enqueue(ResponseTestHelper.createMockResponse(this, "rest_profile_patch.json", 200).addHeader("ETag", "eTag")); + + Map map = new HashMap<>(); + map.put("key", "value"); + map.put("key2", 312); + + service.getProfileServiceWithDefaults().patchProfile("someId", new ComapiProfile(map), null).toBlocking().forEach(response -> { + assertEquals(true, response.isSuccessful()); + assertEquals(200, response.getCode()); + assertNotNull(response.getResult().get("id")); + assertEquals("firstName", response.getResult().getFirstName()); + assertEquals("lastName", response.getResult().getLastName()); + assertEquals("email", response.getResult().getEmail()); + assertEquals("gender", response.getResult().getGender()); + assertEquals("phoneNumber", response.getResult().getPhoneNumber()); + assertEquals("phoneNumberCountryCode", response.getResult().getPhoneNumberCountryCode()); + assertEquals("profilePicture", response.getResult().getProfilePicture()); + assertEquals("custom", response.getResult().get("custom")); + assertNotNull(response.getETag()); + }); + } + @Test public void patchProfile_sessionCreateInProgress() throws Exception { isCreateSessionInProgress.set(true); diff --git a/COMAPI/foundation/src/test/resources/rest_profile_get.json b/COMAPI/foundation/src/test/resources/rest_profile_get.json index 398ba6c..6adf212 100644 --- a/COMAPI/foundation/src/test/resources/rest_profile_get.json +++ b/COMAPI/foundation/src/test/resources/rest_profile_get.json @@ -1,3 +1,11 @@ { - "id": "someProfileId" -} \ No newline at end of file + "id" : "id", + "firstName" : "firstName", + "lastName" : "lastName", + "email" : "email", + "gender" : "gender", + "phoneNumber" : "phoneNumber", + "phoneNumberCountryCode" : "phoneNumberCountryCode", + "profilePicture" : "profilePicture", + "custom" : "custom" +} diff --git a/COMAPI/foundation/src/test/resources/rest_profile_patch.json b/COMAPI/foundation/src/test/resources/rest_profile_patch.json index ed54f8e..cdf3f4a 100644 --- a/COMAPI/foundation/src/test/resources/rest_profile_patch.json +++ b/COMAPI/foundation/src/test/resources/rest_profile_patch.json @@ -1,4 +1,12 @@ { "id": "p1", - "key": "value" + "key": "value", + "firstName" : "firstName", + "lastName" : "lastName", + "email" : "email", + "gender" : "gender", + "phoneNumber" : "phoneNumber", + "phoneNumberCountryCode" : "phoneNumberCountryCode", + "profilePicture" : "profilePicture", + "custom" : "custom" } \ No newline at end of file diff --git a/COMAPI/foundation/src/test/resources/rest_profile_query.json b/COMAPI/foundation/src/test/resources/rest_profile_query.json index 72e4892..1079c7a 100644 --- a/COMAPI/foundation/src/test/resources/rest_profile_query.json +++ b/COMAPI/foundation/src/test/resources/rest_profile_query.json @@ -8,5 +8,16 @@ { "id": "p3", "key": "value" + }, + { + "id" : "id", + "firstName" : "firstName", + "lastName" : "lastName", + "email" : "email", + "gender" : "gender", + "phoneNumber" : "phoneNumber", + "phoneNumberCountryCode" : "phoneNumberCountryCode", + "profilePicture" : "profilePicture", + "custom" : "custom" } ] \ No newline at end of file diff --git a/COMAPI/foundation/src/test/resources/rest_profile_update.json b/COMAPI/foundation/src/test/resources/rest_profile_update.json index 2146ae1..1d4d231 100644 --- a/COMAPI/foundation/src/test/resources/rest_profile_update.json +++ b/COMAPI/foundation/src/test/resources/rest_profile_update.json @@ -1,3 +1,11 @@ { - "id": "p1" + "id": "p1", + "firstName" : "firstName", + "lastName" : "lastName", + "email" : "email", + "gender" : "gender", + "phoneNumber" : "phoneNumber", + "phoneNumberCountryCode" : "phoneNumberCountryCode", + "profilePicture" : "profilePicture", + "custom" : "custom" } \ No newline at end of file From b2330a016e4a04270ac9773fd4087c7fbbcf5309 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Thu, 4 Oct 2018 15:16:52 +0200 Subject: [PATCH 12/18] missing comment --- .../foundation/src/main/java/com/comapi/RxServiceAccessor.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java b/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java index 26c941b..4bbed9d 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java +++ b/COMAPI/foundation/src/main/java/com/comapi/RxServiceAccessor.java @@ -76,6 +76,8 @@ public MessagingService messaging() { /** * Access COMAPI Service profile APIs. + * This APIs version operates with the raw map of profile key-value pairs. + * @see this#profileWithDefaults * * @return COMAPI Service profile APIs. */ @@ -85,6 +87,7 @@ public ProfileService profile() { /** * Access COMAPI Service profile APIs. + * This APIs version wraps the raw map of profile key-value pairs in ComapiProfile objects that introduces default keys that can be understood by the Comapi Portal. * * @return COMAPI Service profile APIs. */ From 5133360b6db7312728f4ca2816934755b5206b50 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Wed, 10 Oct 2018 10:31:52 +0200 Subject: [PATCH 13/18] parsing validation failures, get CoampiProfile from event --- .../comapi/internal/network/ComapiResult.java | 66 ++++++++++++++++++- .../model/events/ProfileUpdateEvent.java | 12 +++- .../network/model/profile/ComapiProfile.java | 42 ++++++------ .../comapi/internal/network/ServiceTest.java | 13 ++-- 4 files changed, 106 insertions(+), 27 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java index c1e046f..333e0cb 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/ComapiResult.java @@ -20,6 +20,13 @@ package com.comapi.internal.network; +import android.support.annotation.Nullable; + +import com.comapi.internal.Parser; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + import retrofit2.Response; /** @@ -155,4 +162,61 @@ public String getMessage() { public String getErrorBody() { return errorBody; } -} + + /** + * Get API call validation failures details. + * + * @return List of validation failures returned from services. Can be null. + */ + public @Nullable + List getValidationFailures() { + if (errorBody != null && !errorBody.isEmpty()) { + ComapiValidationFailures failures = null; + try { + failures = new Parser().parse(errorBody, ComapiValidationFailures.class); + } catch (Exception e) { + return null; + } + return failures.validationFailures; + } + + return null; + } + + class ComapiValidationFailures { + + @SerializedName("validationFailures") + private List validationFailures; + + public List getValidationFailures() { + return validationFailures; + } + } + + public class ComapiValidationFailure { + + @SerializedName("paramName") + private String paramName; + + @SerializedName("message") + private String message; + + /** + * Name of the JSON parameter that failed the check on the server side. + * + * @return Name of the JSON parameter. + */ + public String getParamName() { + return paramName; + } + + /** + * Cause of API call validation failure returned from the services. + * + * @return Cause of API call validation failure. + */ + public String getMessage() { + return message; + } + } +} \ No newline at end of file diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/events/ProfileUpdateEvent.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/events/ProfileUpdateEvent.java index 52b1568..9ba7e9d 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/events/ProfileUpdateEvent.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/events/ProfileUpdateEvent.java @@ -20,6 +20,7 @@ package com.comapi.internal.network.model.events; +import com.comapi.internal.network.model.profile.ComapiProfile; import com.google.gson.annotations.SerializedName; import java.util.Map; @@ -92,7 +93,7 @@ public String getCreatedBy() { } /** - * Gets profile update details. + * Gets row map of profile update details. * * @return Profile update details. */ @@ -100,6 +101,15 @@ public Map getPayload() { return payload; } + /** + * Gets profile update details. + * + * @return Profile update details. + */ + public ComapiProfile getProfileDetails() { + return new ComapiProfile(payload); + } + /** * Gets API Space in which profile exist. * diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java index e460199..2cb97ad 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java @@ -29,26 +29,28 @@ public ComapiProfile() { public ComapiProfile(Map properties) { - for (String key : properties.keySet()) { - if (key.equals(keyId)) { - defaultProperties.put(key, (String) properties.get(key)); - } - if (key.equals(keyFirstName)) { - setFirstName((String) properties.get(key)); - } else if (key.equals(keyLastName)) { - setLastName((String) properties.get(key)); - } else if (key.equals(keyEmail)) { - setEmail((String) properties.get(key)); - } else if (key.equals(keyPhoneNumber)) { - setPhoneNumber((String) properties.get(key)); - } else if (key.equals(keyCountryCode)) { - setPhoneNumberCountryCode((String) properties.get(key)); - } else if (key.equals(keyGender)) { - setGender((String) properties.get(key)); - } else if (key.equals(keyProfilePicture)) { - setProfilePicture((String) properties.get(key)); - } else if (!key.startsWith("_")) { - add(key, properties.get(key)); + if (properties != null && !properties.isEmpty()) { + for (String key : properties.keySet()) { + if (key.equals(keyId)) { + defaultProperties.put(key, (String) properties.get(key)); + } + if (key.equals(keyFirstName)) { + setFirstName((String) properties.get(key)); + } else if (key.equals(keyLastName)) { + setLastName((String) properties.get(key)); + } else if (key.equals(keyEmail)) { + setEmail((String) properties.get(key)); + } else if (key.equals(keyPhoneNumber)) { + setPhoneNumber((String) properties.get(key)); + } else if (key.equals(keyCountryCode)) { + setPhoneNumberCountryCode((String) properties.get(key)); + } else if (key.equals(keyGender)) { + setGender((String) properties.get(key)); + } else if (key.equals(keyProfilePicture)) { + setProfilePicture((String) properties.get(key)); + } else if (!key.startsWith("_")) { + add(key, properties.get(key)); + } } } } diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java index 1422e95..f6d8b0d 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java @@ -427,11 +427,9 @@ public void queryProfile_noSession_shouldFail() throws Exception { public void queryProfile_serverError() throws Exception { MockResponse response = new MockResponse(); - response.setResponseCode(500); - response.setHttp2ErrorCode(500); - response.setBody("{\n" + - " \"key\": \"value\"\n" + - "}"); + response.setResponseCode(400); + response.setHttp2ErrorCode(400); + response.setBody("{\"validationFailures\":[{\"paramName\":\"someParameter\",\"message\":\"details\"}]}"); server.enqueue(response); String query = new QueryBuilder() @@ -440,6 +438,11 @@ public void queryProfile_serverError() throws Exception { service.queryProfiles(query).toBlocking().forEach(result -> { assertEquals(false, result.isSuccessful()); assertNotNull(result.getErrorBody()); + List>>.ComapiValidationFailure> failures = result.getValidationFailures(); + assertNotNull(failures); + assertEquals(1, failures.size()); + assertEquals("details", failures.get(0).getMessage()); + assertEquals("someParameter", failures.get(0).getParamName()); }); } From d3eb647347d6a87f22ce3865681ec7629478e720 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Fri, 12 Oct 2018 11:31:11 +0200 Subject: [PATCH 14/18] profile data toString --- .../network/model/profile/ComapiProfile.java | 19 ++++++++++++++++ .../comapi/internal/network/ServiceTest.java | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java index 2cb97ad..933edcb 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/model/profile/ComapiProfile.java @@ -160,4 +160,23 @@ public Map asMap() { map.putAll(customProperties); return map; } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + Map combined = asMap(); + if (!combined.isEmpty()) { + for (String key : combined.keySet()) { + sb.append(key).append(" = ").append(combined.get(key).toString()).append(" "); + if (sb.length() > 1000) { + sb.append("..."); + break; + } + } + } else { + sb.append(""); + } + return sb.toString().trim(); + } } \ No newline at end of file diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java index f6d8b0d..2c677e3 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/network/ServiceTest.java @@ -80,6 +80,7 @@ import static com.comapi.helpers.DataTestHelper.API_SPACE_ID; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.assertTrue; @@ -237,10 +238,31 @@ public void getProfileWithDefaults() throws Exception { assertEquals("phoneNumberCountryCode", response.getResult().getPhoneNumberCountryCode()); assertEquals("profilePicture", response.getResult().getProfilePicture()); assertEquals("custom", response.getResult().get("custom")); + assertNotNull(response.getResult().toString()); assertNotNull(response.getETag()); }); } + @Test + public void profileToString() { + + ComapiProfile profile = new ComapiProfile(); + for (int i=0; i<100; i++) { + profile.add(String.valueOf(i), "x"); + } + + assertNotNull(profile.toString()); + assertFalse(profile.toString().endsWith("...")); + + for (int i=100; i<10000; i++) { + profile.add(String.valueOf(i), "x"); + } + + assertNotNull(profile.toString()); + assertTrue(profile.toString().length() < 1010); + assertTrue(profile.toString().endsWith("...")); + } + @Test public void getProfile_sessionCreateInProgress() throws Exception { From 8ac9321fb1a686729894531b340e303469a6629b Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Tue, 16 Oct 2018 16:13:41 +0200 Subject: [PATCH 15/18] dependency update --- COMAPI/build.gradle | 2 +- COMAPI/foundation/build.gradle | 11 +++-------- COMAPI/gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/COMAPI/build.gradle b/COMAPI/build.gradle index f094f8e..446bac9 100644 --- a/COMAPI/build.gradle +++ b/COMAPI/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.google.gms:google-services:4.0.1' diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index 4b424e3..253cc63 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -4,7 +4,7 @@ apply from: 'code_coverage.gradle' android { compileSdkVersion 28 - buildToolsVersion '27.0.3' + buildToolsVersion '28.0.3' defaultConfig { minSdkVersion 16 @@ -59,8 +59,8 @@ dependencies { /*FCM*/ //noinspection GradleCompatible warning disabled (seems to be caused by internal firebase-messaging dependencies versioning) - implementation 'com.google.firebase:firebase-messaging:17.1.0' - implementation 'com.google.android.gms:play-services-base:15.0.1' + implementation 'com.google.firebase:firebase-messaging:17.3.3' + implementation 'com.google.android.gms:play-services-base:16.0.1' /*Sockets*/ implementation 'com.neovisionaries:nv-websocket-client:2.3' @@ -192,9 +192,4 @@ generateRelease.dependsOn(zipRelease) artifacts { archives androidSourcesJar archives androidJavadocsJar -} - -apply plugin: 'me.tatarka.retrolambda' -retrolambda { - javaVersion JavaVersion.VERSION_1_7 } \ No newline at end of file diff --git a/COMAPI/gradle/wrapper/gradle-wrapper.properties b/COMAPI/gradle/wrapper/gradle-wrapper.properties index c257936..1f99c5f 100644 --- a/COMAPI/gradle/wrapper/gradle-wrapper.properties +++ b/COMAPI/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip From 84182b3f5f05c25d7b3e42108bc815ea942ad1b5 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Wed, 17 Oct 2018 16:12:03 +0200 Subject: [PATCH 16/18] cleanup --- .../com/comapi/internal/log/AppenderFile.java | 5 ++-- .../com/comapi/internal/log/LoggingTest.java | 28 ++++--------------- COMAPI/foundation/version.gradle | 4 --- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java b/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java index 5dd8c90..6822d67 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/log/AppenderFile.java @@ -91,7 +91,8 @@ class AppenderFile extends Appender { /** * Recommended constructor. - * @param appContext Application Context. + * + * @param appContext Application Context. * @param logLevel Logging level that should be used for console output. Messages with higher * level won't be displayed in logcat. * @param formatter Message formatter. Defines the format of the output. @@ -321,4 +322,4 @@ private void mergeFiles(@NonNull File mergedFile) throws IOException { bw.close(); } } -} +} \ No newline at end of file diff --git a/COMAPI/foundation/src/test/java/com/comapi/internal/log/LoggingTest.java b/COMAPI/foundation/src/test/java/com/comapi/internal/log/LoggingTest.java index 3f66a0b..93022a1 100644 --- a/COMAPI/foundation/src/test/java/com/comapi/internal/log/LoggingTest.java +++ b/COMAPI/foundation/src/test/java/com/comapi/internal/log/LoggingTest.java @@ -26,6 +26,7 @@ import com.comapi.BuildConfig; import com.comapi.helpers.FileHelper; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,16 +35,11 @@ import org.robolectric.annotation.Config; import org.robolectric.shadows.ShadowLog; -import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStreamReader; import java.io.PrintStream; import java.util.UUID; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -70,8 +66,6 @@ public class LoggingTest { private static ByteArrayOutputStream baos; private static PrintStream ps; - private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private final Object obj = new Object(); @Before @@ -168,6 +162,9 @@ public void offLogLevel() throws InterruptedException { @Test public void testRollOver() throws InterruptedException { + // having some troubles with file writing mocks on windows and probably renameTo method + Assume.assumeFalse(isWindows()); + // Remove shadow consoleLevel stream to avoid out of memory exception in test ShadowLog.stream = null; @@ -308,20 +305,7 @@ private void assertLogged(int level, String id, String logs) { } } - private String loadLogs(File file) throws IOException { - - StringBuilder sb = new StringBuilder(); - String line; - - if (file.exists()) { - FileInputStream inputStream = new FileInputStream(file); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - while ((line = reader.readLine()) != null) { - sb.append(line).append('\n'); - } - reader.close(); - } - - return sb.toString(); + public boolean isWindows() { + return System.getProperty( "os.name" ).startsWith( "Windows" ); } } \ No newline at end of file diff --git a/COMAPI/foundation/version.gradle b/COMAPI/foundation/version.gradle index 1b06f6c..647ec2c 100644 --- a/COMAPI/foundation/version.gradle +++ b/COMAPI/foundation/version.gradle @@ -9,10 +9,6 @@ ext.foundationVersion = '1.3.0' def isFoundationRelease = System.getenv("isparagonrelease") ext.isReleaseVersion = isFoundationRelease != null ? isFoundationRelease : false -if (!isReleaseVersion) { - foundationVersion = foundationVersion + '-SNAPSHOT' -} - if (project.hasProperty("teamcity")) { ext.foundationBuildNumber = teamcity['build.number'] } else { From 2c53ebc815b0c740336ff48fd1653b00f9bcab0e Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Wed, 23 Jan 2019 11:48:43 +0100 Subject: [PATCH 17/18] fix initialisation when no google services instaled --- .../comapi/internal/network/SessionController.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java b/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java index e7d3a75..d8f5ac1 100644 --- a/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java +++ b/COMAPI/foundation/src/main/java/com/comapi/internal/network/SessionController.java @@ -210,7 +210,9 @@ Observable startSession() { if (isFcmEnabled) { return updatePushToken(session) .doOnNext(pushUpdateResult -> { - if (!pushUpdateResult.second.isSuccessful()) { + if (pushUpdateResult.second == null) { + log.e("Failed to update push token on the server."); + } else if (!pushUpdateResult.second.isSuccessful()) { log.e("Failed to update push token on the server. " + pushUpdateResult.second.message()); } else { log.i("Push token updated on the server."); @@ -334,7 +336,12 @@ private Observable>> updatePushToken(SessionDat return Observable.create((Observable.OnSubscribe) sub -> { String token = dataMgr.getDeviceDAO().device().getPushToken(); if (TextUtils.isEmpty(token)) { - token = pushMgr.getPushToken(); + try { + token = pushMgr.getPushToken(); + } catch (Exception e) { + log.e("Error obtaining FCM token. No Google Services on the phone?"); + } + if (!TextUtils.isEmpty(token)) { dataMgr.getDeviceDAO().setPushToken(token); } From 1d12d6bfc4952e07019ee2588e8903ec496dae62 Mon Sep 17 00:00:00 2001 From: MarcinSwierczek Date: Wed, 30 Jan 2019 09:23:16 +0100 Subject: [PATCH 18/18] dependency update --- COMAPI/foundation/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/COMAPI/foundation/build.gradle b/COMAPI/foundation/build.gradle index 253cc63..3cd3987 100644 --- a/COMAPI/foundation/build.gradle +++ b/COMAPI/foundation/build.gradle @@ -59,8 +59,8 @@ dependencies { /*FCM*/ //noinspection GradleCompatible warning disabled (seems to be caused by internal firebase-messaging dependencies versioning) - implementation 'com.google.firebase:firebase-messaging:17.3.3' - implementation 'com.google.android.gms:play-services-base:16.0.1' + implementation 'com.google.firebase:firebase-messaging:17.3.4' + implementation 'com.google.android.gms:play-services-base:16.1.0' /*Sockets*/ implementation 'com.neovisionaries:nv-websocket-client:2.3'