use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class ContactSyncEngineTest method testCancelSync.
/**
* Tests the sync is cancelled in case we remove user data.
*/
@Suppress
public // Breaks tests.
void testCancelSync() {
Log.i(LOG_TAG, "**** testNativeSync_newEngineInstantiation() begin ****");
final ArrayList<ProcessorLog> processorLogs = new ArrayList<ProcessorLog>();
final UiEventCall uiEventCall = new UiEventCall();
final ProcessorLog processorLog = new ProcessorLog();
final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {
@Override
public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
uiEventCall.event = event.ordinal();
uiEventCall.request = request;
uiEventCall.status = status;
uiEventCall.data = data;
}
};
final ProcessorFactory factory = new ProcessorFactory() {
@Override
public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
Log.i(LOG_TAG, "create(), type=" + type);
ProcessorLog log = new ProcessorLog();
log.type = type;
log.time = System.currentTimeMillis();
processorLogs.add(log);
return new BaseSyncProcessor(mContactSyncEngine, null) {
@Override
protected void doCancel() {
// cancel the job
processorLog.type = 1;
}
@Override
protected void doStart() {
// set a "timeout" to be called back immediately
setTimeout(0);
processorLog.type = 2;
}
@Override
public void onTimeoutEvent() {
// set the job as completed
Log.i(LOG_TAG, "onTimeoutEvent()");
complete(ServiceStatus.SUCCESS);
processorLog.type = 3;
}
@Override
public void processCommsResponse(DecodedResponse resp) {
// we don't need this case in this test
processorLog.type = 4;
}
};
}
};
minimalEngineSetup(engineEventCallback, factory);
// set the connection to be fine
NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
long nextRuntime = mContactSyncEngine.getNextRunTime();
// should be equal to -1 because first time sync has not been yet
// started
assertEquals(-1, nextRuntime);
// force a first time sync
mContactSyncEngine.addUiStartFullSync();
processorLog.type = 0;
// start performing the sync
mContactSyncEngine.run();
// the first processor should have started
assertTrue(processorLog.type == 2);
// this will cancel any sync
mContactSyncEngine.onReset();
// get the engine to perform a cancel on the current processor
mContactSyncEngine.run();
assertTrue(processorLog.type == 1);
// check that the engine cancelled the sync
assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
assertEquals(uiEventCall.status, ServiceStatus.USER_CANCELLED.ordinal());
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method updateStatus.
/**
* The utility method to save the status text change to the database...
* @param dbHelper DatabaseHelper - database
* @param statusText String - status text
* @return ContactDetail - the modified or created ContactDetail with key
* ContactDetail.DetailKeys.PRESENCE_TEXT
*/
public static ContactDetail updateStatus(final DatabaseHelper dbHelper, final String statusText) {
Contact meContact = new Contact();
if (fetchMeProfile(dbHelper, meContact) == ServiceStatus.SUCCESS) {
// try to modify an existing detail
for (ContactDetail detail : meContact.details) {
if (detail.key == ContactDetail.DetailKeys.PRESENCE_TEXT) {
detail.value = statusText;
// Currently it's only possible to post a status on
// Vodafone sns
detail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
if (ServiceStatus.SUCCESS == dbHelper.modifyContactDetail(detail)) {
return detail;
}
}
}
// create a new detail instead
ContactDetail contactDetail = new ContactDetail();
contactDetail.setValue(statusText, ContactDetail.DetailKeys.PRESENCE_TEXT, null);
contactDetail.alt = ThirdPartyAccount.SNS_TYPE_VODAFONE;
contactDetail.localContactID = meContact.localContactID;
if (ServiceStatus.SUCCESS == dbHelper.addContactDetail(contactDetail)) {
return contactDetail;
}
}
return null;
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method setMeProfile.
/**
* This method create a Me Profile contact in the database.
* @param dbHelper DatabaseHelper - the database.
* @param meProfile Contact - the Me Profile contact
* @return ServiceStatus - ServiceStatus.SUCCESS when the new contact is
* successfully created.
*/
public static ServiceStatus setMeProfile(final DatabaseHelper dbHelper, Contact meProfile) {
ServiceStatus status = ServiceStatus.ERROR_DATABASE_CORRUPT;
// the contact didn't exist before
if (sMeProfileLocalContactId == null) {
List<Contact> contactList = new ArrayList<Contact>();
contactList.add(meProfile);
status = dbHelper.syncAddContactList(contactList, false, false);
if (ServiceStatus.SUCCESS == status) {
sMeProfileLocalContactId = meProfile.localContactID;
status = StateTable.modifyMeProfileID(sMeProfileLocalContactId, dbHelper.getWritableDatabase());
PresenceDbUtils.resetMeProfileIds();
if (ServiceStatus.SUCCESS != status) {
List<ContactsTable.ContactIdInfo> idList = new ArrayList<ContactsTable.ContactIdInfo>();
ContactsTable.ContactIdInfo contactIdInfo = new ContactsTable.ContactIdInfo();
contactIdInfo.localId = meProfile.localContactID;
contactIdInfo.serverId = meProfile.contactID;
contactIdInfo.nativeId = meProfile.nativeContactId;
idList.add(contactIdInfo);
dbHelper.syncDeleteContactList(idList, false, false);
}
}
}
return status;
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method populateWithDeletedContactDetails.
/**
* This method adds the deleted details to the detail list sent to server...
* @param dbHelper DatabaseHelper - database
* @param contactDetails List<ContactDetail> - the deleted details list
* @param contactId Long - Me Profile local contact id.
*/
private static void populateWithDeletedContactDetails(final DatabaseHelper dbHelper, final List<ContactDetail> contactDetails, final Long contactId) {
List<ContactChangeInfo> deletedDetails = new ArrayList<ContactChangeInfo>();
if (!ContactChangeLogTable.fetchMeProfileChangeLog(deletedDetails, ContactChangeType.DELETE_DETAIL, dbHelper.getReadableDatabase(), contactId)) {
LogUtils.logE("UploadServerContacts populateWithDeletedContactDetails -" + " Unable to fetch contact changes from database");
return;
}
for (int i = 0; i < deletedDetails.size(); i++) {
ContactChangeInfo info = deletedDetails.get(i);
final ContactDetail detail = new ContactDetail();
detail.localDetailID = info.mLocalDetailId;
detail.key = info.mServerDetailKey;
detail.unique_id = info.mServerDetailId;
detail.deleted = true;
contactDetails.add(detail);
}
dbHelper.deleteContactChanges(deletedDetails);
}
use of com.vodafone360.people.database.DatabaseHelper in project 360-Engine-for-Android by 360.
the class SyncMeDbUtils method processMyContactDetailsChanges.
/**
* This method stores the getMyChanges() response to database - details part.
* @param dbHelper DatabaseHelper - database.
* @param currentMeProfile Contact - me profile contact.
* @param profileChanges UserProfile - the contact changes.
* @return ServiceStatus - SUCCESS if the contact changes have been successfully processed stored.
*/
private static String processMyContactDetailsChanges(final DatabaseHelper dbHelper, final Contact currentMeProfile, final UserProfile profileChanges) {
String ret = null;
final ArrayList<ContactDetail> modifiedDetailList = new ArrayList<ContactDetail>();
final ArrayList<ContactDetail> addedDetailList = new ArrayList<ContactDetail>();
final ArrayList<ContactDetail> deletedDetailList = new ArrayList<ContactDetail>();
for (ContactDetail newDetail : profileChanges.details) {
boolean found = false;
for (int i = 0; i < currentMeProfile.details.size(); i++) {
ContactDetail oldDetail = currentMeProfile.details.get(i);
if (DatabaseHelper.doDetailsMatch(newDetail, oldDetail)) {
found = true;
if (newDetail.deleted != null && newDetail.deleted.booleanValue()) {
deletedDetailList.add(oldDetail);
} else if (DatabaseHelper.hasDetailChanged(oldDetail, newDetail)) {
newDetail.localDetailID = oldDetail.localDetailID;
newDetail.localContactID = oldDetail.localContactID;
newDetail.nativeContactId = oldDetail.nativeContactId;
newDetail.nativeDetailId = oldDetail.nativeDetailId;
modifiedDetailList.add(newDetail);
if (newDetail.key == DetailKeys.PHOTO) {
dbHelper.markMeProfileAvatarChanged();
ret = newDetail.value;
}
}
break;
}
}
// in the response or the deleted flag was false we have to add the new detail to the list
if ((!found) && ((null == newDetail.deleted) || (!newDetail.deleted.booleanValue()))) {
newDetail.localContactID = currentMeProfile.localContactID;
newDetail.nativeContactId = currentMeProfile.nativeContactId;
if (newDetail.key == DetailKeys.PHOTO) {
dbHelper.markMeProfileAvatarChanged();
ret = newDetail.value;
}
addedDetailList.add(newDetail);
}
}
if (!addedDetailList.isEmpty()) {
dbHelper.syncAddContactDetailList(addedDetailList, false, false);
}
if (!modifiedDetailList.isEmpty()) {
dbHelper.syncModifyContactDetailList(modifiedDetailList, false, false);
}
if (!deletedDetailList.isEmpty()) {
dbHelper.syncDeleteContactDetailList(deletedDetailList, false, false);
}
return ret;
}
Aggregations