use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class ContactDetailsTable method getContactChanges.
/**
* Gets an array of ContactChange from the contact's local id.
*
* @see ContactChange
*
* @param localId the local id of the contact to get
* @return an array of ContactChange
*/
public static ContactChange[] getContactChanges(long localId, boolean nativeSyncableOnly, SQLiteDatabase readableDb) {
final String[] SELECTION = { String.valueOf(localId) };
final String QUERY_STRING = nativeSyncableOnly ? QUERY_NATIVE_SYNCABLE_CONTACT_DETAILS_BY_LOCAL_ID : QUERY_CONTACT_DETAILS_BY_LOCAL_ID;
Cursor cursor = null;
try {
cursor = readableDb.rawQuery(QUERY_STRING, SELECTION);
if (cursor.getCount() > 0) {
final ContactChange[] changes = new ContactChange[cursor.getCount()];
int index = 0;
while (cursor.moveToNext()) {
// fill the ContactChange class with contact detail data if not empty
// StringVal=7
String value = cursor.getString(7);
// prevent null pointer (however should the detail be even stored in People DB if null?)
if (value == null)
value = "";
// Key=6
final int key = cursor.isNull(6) ? ContactChange.KEY_UNKNOWN : mapInternalKeyToContactChangeKey(cursor.getInt(6));
// Type=4, OrderNo=5
final int flags = mapInternalTypeAndOrderToContactChangeFlag(cursor.isNull(4) ? 0 : cursor.getInt(4), cursor.getInt(5));
// create the change
final ContactChange change = new ContactChange(key, value, flags);
changes[index++] = change;
// LocalContactId=0
change.setInternalContactId(cursor.isNull(0) ? ContactChange.INVALID_ID : cursor.getLong(0));
// DetailLocalId=1
change.setInternalDetailId(cursor.isNull(1) ? ContactChange.INVALID_ID : cursor.getInt(1));
// NativeDetailId=2
change.setNabDetailId(cursor.isNull(2) ? ContactChange.INVALID_ID : cursor.getLong(2));
// NativeContactIdDup=3
change.setNabContactId(cursor.isNull(3) ? ContactChange.INVALID_ID : cursor.getLong(3));
// DetailServerId=8
change.setBackendDetailId(cursor.isNull(8) ? ContactChange.INVALID_ID : cursor.getLong(8));
if (nativeSyncableOnly) {
// in this mode, we have to tell if the detail is new or updated
if (change.getNabDetailId() == ContactChange.INVALID_ID) {
change.setType(ContactChange.TYPE_ADD_DETAIL);
} else {
change.setType(ContactChange.TYPE_UPDATE_DETAIL);
}
}
}
if (index == changes.length) {
return changes;
} else if (index > 0) {
// there were some empty details, need to trim the array
final ContactChange[] trimmed = new ContactChange[index];
System.arraycopy(changes, 0, trimmed, 0, index);
return trimmed;
}
}
} catch (Exception e) {
// what else can we do?
LogUtils.logE("ContactDetailsTable.getContactChanges(): " + e);
} finally {
CursorUtils.closeCursor(cursor);
}
return null;
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class ContactSyncEngineTest method testUiRequestCompleteEvent_fullSync.
/**
* Verifies that events are fired after UI requests.
*/
@Suppress
public // Breaks tests.
void testUiRequestCompleteEvent_fullSync() {
Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() begin ****");
final UiEventCall uiEventCall = new UiEventCall();
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);
return new DummySyncProcessor(mContactSyncEngine, null);
}
};
minimalEngineSetup(engineEventCallback, factory);
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);
// set the connection to be fine
NetworkAgent.setAgentState(AgentState.CONNECTED);
// ask for a full sync
mContactSyncEngine.addUiStartFullSync();
nextRuntime = mContactSyncEngine.getNextRunTime();
assertEquals(0, nextRuntime);
mContactSyncEngine.run();
// check that first time sync is completed
assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() end ****");
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class DefaultProcessorFactoryTest method testUnexpectedProcessorType.
/**
* Checks that the unexpected type of processor creation is handled.
*/
public void testUnexpectedProcessorType() {
DefaultProcessorFactory factory = new DefaultProcessorFactory();
Exception exception = null;
try {
// with type=-12, an IllegalArgumentException shall be thrown
factory.create(-12, null, null);
} catch (IllegalArgumentException e) {
exception = e;
}
// check the exception type
assertTrue(exception instanceof IllegalArgumentException);
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class DefaultProcessorFactoryTest method testProcessorTypeCreation.
/**
* Tests the type of the created processor depending on the requested type.
*/
@Suppress
public void testProcessorTypeCreation() {
DefaultProcessorFactory factory = new DefaultProcessorFactory();
BaseSyncProcessor processor;
processor = factory.create(ProcessorFactory.DOWNLOAD_SERVER_CONTACTS, null, null);
assertTrue(processor instanceof DownloadServerContacts);
processor = factory.create(ProcessorFactory.FETCH_NATIVE_CONTACTS, null, null);
assertTrue(processor instanceof FetchNativeContacts);
processor = factory.create(ProcessorFactory.UPDATE_NATIVE_CONTACTS, null, null);
assertTrue(processor instanceof UpdateNativeContacts);
processor = factory.create(ProcessorFactory.UPLOAD_SERVER_CONTACTS, null, null);
assertTrue(processor instanceof UploadServerContacts);
}
use of com.vodafone360.people.service.io.Request.Type in project 360-Engine-for-Android by 360.
the class ContactChangeTest method testConstructors.
@SmallTest
public void testConstructors() {
String value = new String("value");
int type = ContactChange.TYPE_ADD_CONTACT;
long nabContactId = 100;
long internalContactId = 200;
long backendContactId = 300;
//----------------------------------------
ContactChange cc = new ContactChange(ContactChange.KEY_VCARD_PHONE, value, ContactChange.FLAG_HOME);
assertEquals(ContactChange.KEY_VCARD_PHONE, cc.getKey());
assertEquals("vcard.phone", cc.getKeyToString());
assertEquals(value, cc.getValue());
assertEquals(ContactChange.FLAG_HOME, cc.getFlags());
assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
assertEquals(-1L, cc.getBackendContactId());
assertEquals(-1L, cc.getBackendDetailId());
assertEquals(-1L, cc.getInternalContactId());
assertEquals(-1L, cc.getInternalDetailId());
assertEquals(-1L, cc.getNabContactId());
assertEquals(-1L, cc.getNabDetailId());
//----------------------------------------
cc = new ContactChange(type);
assertEquals(type, cc.getType());
assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
assertEquals(-1L, cc.getBackendContactId());
assertEquals(-1L, cc.getBackendDetailId());
assertEquals(-1L, cc.getInternalContactId());
assertEquals(-1L, cc.getInternalDetailId());
assertEquals(-1L, cc.getNabContactId());
assertEquals(-1L, cc.getNabDetailId());
assertEquals(null, cc.getValue());
assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
//----------------------------------------
cc = new ContactChange(Long.MAX_VALUE);
assertEquals(Long.MAX_VALUE, cc.getNabContactId());
assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
assertEquals(-1L, cc.getBackendContactId());
assertEquals(-1L, cc.getBackendDetailId());
assertEquals(-1L, cc.getInternalContactId());
assertEquals(-1L, cc.getInternalDetailId());
assertEquals(-1L, cc.getNabDetailId());
assertEquals(null, cc.getValue());
assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
//----------------------------------------
cc = new ContactChange(Long.MAX_VALUE, Long.MIN_VALUE);
assertEquals(Long.MAX_VALUE, cc.getNabContactId());
assertEquals(Long.MIN_VALUE, cc.getNabDetailId());
assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
assertEquals(ContactChange.TYPE_UNKNOWN, cc.getType());
assertEquals(-1L, cc.getBackendContactId());
assertEquals(-1L, cc.getBackendDetailId());
assertEquals(-1L, cc.getInternalContactId());
assertEquals(-1L, cc.getInternalDetailId());
assertEquals(null, cc.getValue());
assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
//----------------------------------------
ContactChange original = new ContactChange();
original.setNabContactId(nabContactId);
original.setBackendContactId(backendContactId);
original.setInternalContactId(internalContactId);
cc = ContactChange.createIdsChange(original, type);
assertEquals(nabContactId, cc.getNabContactId());
assertEquals(backendContactId, cc.getBackendContactId());
assertEquals(internalContactId, cc.getInternalContactId());
assertEquals(type, cc.getType());
assertEquals(ContactChange.FLAG_NONE, cc.getFlags());
assertEquals(-1L, cc.getBackendDetailId());
assertEquals(-1L, cc.getInternalDetailId());
assertEquals(-1L, cc.getNabDetailId());
assertEquals(null, cc.getValue());
assertEquals(ContactChange.KEY_UNKNOWN, cc.getKey());
}
Aggregations