Search in sources :

Example 56 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class PresenceTable method getUserPresenceByLocalContactId.

/**
 * This method returns user/me profile presence state.
 *
 * @param localContactId - me profile localContactId
 * @param readableDatabase - the database to read from
 * @return user/me profile presence state wrapped in "User" wrapper class,
 *         or NULL if the specified localContactId doesn't exist
 * @throws SQLException if the database layer throws this exception.
 * @throws NullPointerException if the passed in database instance is null.
 * @return user - User object filled with presence information.
 */
public static User getUserPresenceByLocalContactId(long localContactId, SQLiteDatabase readableDatabase) throws SQLException, NullPointerException {
    if (readableDatabase == null) {
        throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
    }
    User user = null;
    if (localContactId < 0) {
        LogUtils.logE("PresenceTable.getUserPresenceByLocalContactId(): " + "#localContactId# parameter is -1 ");
        return user;
    }
    Cursor c = null;
    try {
        c = readableDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Field.LOCAL_CONTACT_ID + "=" + localContactId, null);
        ArrayList<NetworkPresence> networkPresence = new ArrayList<NetworkPresence>();
        user = new User();
        // i.e. 0
        int onlineStatus = OnlineStatus.OFFLINE.ordinal();
        while (c.moveToNext()) {
            user.setLocalContactId(c.getLong(LOCAL_CONTACT_ID));
            String userId = c.getString(USER_ID);
            int networkId = c.getInt(NETWORK_ID);
            int statusId = c.getInt(NETWORK_STATUS);
            if (statusId > onlineStatus) {
                onlineStatus = statusId;
            }
            networkPresence.add(new NetworkPresence(userId, networkId, statusId));
        }
        if (!networkPresence.isEmpty()) {
            user.setOverallOnline(onlineStatus);
            user.setPayload(networkPresence);
        }
    } finally {
        CloseUtils.close(c);
        c = null;
    }
    return user;
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) User(com.vodafone360.people.engine.presence.User) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 57 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class PresenceTable method getUserPresence.

/**
 * This method fills the provided user object with presence information.
 *
 * @param user User - the user with a localContactId != -1
 * @param readableDatabase - the database to read from
 * @return user/me profile presence state wrapped in "User" wrapper class,
 *         or NULL if the specified localContactId doesn't exist
 * @throws SQLException if the database layer throws this exception.
 * @throws NullPointerException if the passed in database instance is null.
 */
public static void getUserPresence(User user, SQLiteDatabase readableDatabase) throws SQLException, NullPointerException {
    if (readableDatabase == null) {
        throw new NullPointerException(DEFAULT_ERROR_MESSAGE);
    }
    if (user.getLocalContactId() < 0) {
        LogUtils.logE("PresenceTable.getUserPresenceByLocalContactId(): " + "#localContactId# parameter is -1 ");
        return;
    }
    Cursor c = null;
    try {
        c = readableDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Field.LOCAL_CONTACT_ID + "=" + user.getLocalContactId(), null);
        if (c != null) {
            // i.e. 0
            int onlineStatus = OnlineStatus.OFFLINE.ordinal();
            ArrayList<NetworkPresence> payload = user.getPayload();
            payload.clear();
            while (c.moveToNext()) {
                String userId = c.getString(USER_ID);
                int networkId = c.getInt(NETWORK_ID);
                int statusId = c.getInt(NETWORK_STATUS);
                if (statusId > onlineStatus) {
                    onlineStatus = statusId;
                }
                payload.add(new NetworkPresence(userId, networkId, statusId));
            }
            user.setOverallOnline(onlineStatus);
        }
    } finally {
        CloseUtils.close(c);
        c = null;
    }
}
Also used : NetworkPresence(com.vodafone360.people.engine.presence.NetworkPresence) Cursor(android.database.Cursor)

Example 58 with User

use of com.vodafone360.people.engine.presence.User in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method setFirstTimeNativeSyncComplete.

/**
 * Helper function to update the database when the state of the
 * {@link #mFirstTimeNativeSyncComplete} flag changes.
 *
 * @param value New value to the flag. True indicates that the native fetch
 *            part of the first time sync has been completed. The flag is
 *            never set to false again by the engine, it will be only set to
 *            false when a remove user data is done (and the database is
 *            deleted).
 * @return SUCCESS or a suitable error code if the database could not be
 *         updated.
 */
private ServiceStatus setFirstTimeNativeSyncComplete(boolean value) {
    if (mFirstTimeSyncComplete == value) {
        return ServiceStatus.SUCCESS;
    }
    PersistSettings setting = new PersistSettings();
    setting.putFirstTimeNativeSyncComplete(value);
    ServiceStatus status = mDb.setOption(setting);
    if (ServiceStatus.SUCCESS == status) {
        mFirstTimeNativeSyncComplete = value;
    }
    return status;
}
Also used : PersistSettings(com.vodafone360.people.service.PersistSettings) ServiceStatus(com.vodafone360.people.service.ServiceStatus)

Aggregations

ServiceStatus (com.vodafone360.people.service.ServiceStatus)22 Contact (com.vodafone360.people.datatypes.Contact)12 ArrayList (java.util.ArrayList)12 User (com.vodafone360.people.engine.presence.User)11 Hashtable (java.util.Hashtable)9 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)7 Request (com.vodafone360.people.service.io.Request)7 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 PersistSettings (com.vodafone360.people.service.PersistSettings)6 QueueManager (com.vodafone360.people.service.io.QueueManager)6 SmallTest (android.test.suitebuilder.annotation.SmallTest)4 Identity (com.vodafone360.people.datatypes.Identity)4 ServerIdInfo (com.vodafone360.people.database.DatabaseHelper.ServerIdInfo)3 RegistrationDetails (com.vodafone360.people.datatypes.RegistrationDetails)3 NetworkPresence (com.vodafone360.people.engine.presence.NetworkPresence)3 Cursor (android.database.Cursor)2 SQLiteStatement (android.database.sqlite.SQLiteStatement)2 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)2 AuthSessionHolder (com.vodafone360.people.datatypes.AuthSessionHolder)2 ContactChanges (com.vodafone360.people.datatypes.ContactChanges)2