use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class UserDataSyncTest method test_add_birthdate.
@Test
public void test_add_birthdate() throws Exception {
UserData userData = new UserData();
Calendar calendar = Calendar.getInstance();
calendar.set(2000, 1, 1);
userData.setBirthdate(new Date(calendar.getTimeInMillis()));
mobileMessaging.syncUserData(userData);
verify(mobileApiData, after(1000).times(1)).reportUserData(anyString(), reportCaptor.capture());
UserDataReport report = reportCaptor.getValue();
assertEquals(userData.getBirthdate(), DateTimeUtil.DateFromYMDString((String) report.getPredefinedUserData().get("birthdate")));
}
use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class UserDataReporter method sync.
public void sync(final MobileMessaging.ResultListener listener, final UserData userData) {
if (userData == null) {
return;
}
mobileMessagingCore.saveUnreportedUserData(userData);
new MRetryableTask<UserData, UserData>() {
@Override
public UserData run(UserData[] userData) {
if (StringUtils.isBlank(mobileMessagingCore.getPushRegistrationId())) {
MobileMessagingLogger.w("Can't report system data without valid registration");
throw InternalSdkError.NO_VALID_REGISTRATION.getException();
}
UserDataReport request = UserDataMapper.toUserDataReport(userData[0].getPredefinedUserData(), userData[0].getCustomUserData());
MobileMessagingLogger.v("USER DATA >>>", request);
UserDataReport response = mobileApiData.reportUserData(userData[0].getExternalUserId(), request);
MobileMessagingLogger.v("USER DATA <<<", response);
return UserDataMapper.fromUserDataReport(userData[0].getExternalUserId(), response.getPredefinedUserData(), response.getCustomUserData());
}
@Override
public void after(UserData userData) {
mobileMessagingCore.setUserDataReported(userData);
broadcaster.userDataReported(userData);
if (listener != null) {
listener.onResult(userData);
}
}
@Override
public void error(Throwable error) {
MobileMessagingLogger.e("MobileMessaging API returned error (user data)! ", error);
mobileMessagingCore.setLastHttpException(error);
stats.reportError(MobileMessagingStatsError.USER_DATA_SYNC_ERROR);
if (error instanceof BackendBaseExceptionWithContent) {
BackendBaseExceptionWithContent errorWithContent = (BackendBaseExceptionWithContent) error;
mobileMessagingCore.setUserDataReported(errorWithContent.getContent(UserData.class));
if (listener != null) {
listener.onError(MobileMessagingError.createFrom(error));
}
} else if (error instanceof BackendInvalidParameterException) {
mobileMessagingCore.setUserDataReportedWithError();
if (listener != null) {
listener.onError(MobileMessagingError.createFrom(error));
}
} else {
MobileMessagingLogger.v("User data synchronization will be postponed to a later time due to communication error");
if (listener != null) {
listener.onResult(UserData.merge(mobileMessagingCore.getUserData(), userData));
}
}
broadcaster.error(MobileMessagingError.createFrom(error));
}
}.retryWith(retryPolicy(listener)).execute(executor, userData);
}
use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class UserDataSyncTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
reportCaptor = forClass(UserDataReport.class);
dataCaptor = forClass(UserData.class);
given(mobileApiData.reportUserData(anyString(), any(UserDataReport.class))).willReturn(new UserDataReport());
}
use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class UserDataSyncTest method test_remove_custom_element.
@Test
public void test_remove_custom_element() throws Exception {
UserData userData = new UserData();
userData.setCustomUserDataElement("myKey1", new CustomUserDataValue("Some string"));
userData.setCustomUserDataElement("myKey2", new CustomUserDataValue(12345));
userData.setCustomUserDataElement("myKey2", new CustomUserDataValue(new Date()));
userData.removeCustomUserDataElement("myKey1");
userData.removeCustomUserDataElement("myKey2");
userData.removeCustomUserDataElement("myKey3");
mobileMessaging.syncUserData(userData);
verify(mobileApiData, after(1000).times(1)).reportUserData(anyString(), reportCaptor.capture());
UserDataReport report = reportCaptor.getValue();
assertEquals(null, report.getCustomUserData().get("myKey1"));
assertEquals(null, report.getCustomUserData().get("myKey2"));
assertEquals(null, report.getCustomUserData().get("myKey3"));
}
use of org.infobip.mobile.messaging.api.data.UserDataReport in project mobile-messaging-sdk-android by infobip.
the class UserDataStoreTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
captor = ArgumentCaptor.forClass(UserData.class);
given(mobileApiData.reportUserData(anyString(), any(UserDataReport.class))).willReturn(new UserDataReport());
}
Aggregations