Search in sources :

Example 6 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem in project 360-Engine-for-Android by 360.

the class NowPlusDatatypesTests method testGroupItem.

public void testGroupItem() {
    int groupType = 1;
    boolean isReadOnly = true;
    boolean requiresLocalisation = true;
    boolean isSystemGroup = true;
    boolean isSmartGroup = true;
    long id = 3;
    long userId = 4;
    String name = "foo";
    GroupItem input = new GroupItem();
    input.mGroupType = (Integer) groupType;
    input.mIsReadOnly = (Boolean) isReadOnly;
    input.mRequiresLocalisation = (Boolean) requiresLocalisation;
    input.mIsSystemGroup = (Boolean) isSystemGroup;
    input.mIsSmartGroup = (Boolean) isSmartGroup;
    input.mId = (Long) id;
    input.mUserId = (Long) userId;
    input.mName = name;
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put("grouptype", groupType);
    hash.put("isreadonly", isReadOnly);
    hash.put("requireslocalisation", requiresLocalisation);
    hash.put("issystemgroup", isSystemGroup);
    hash.put("issmartgroup", isSmartGroup);
    hash.put("id", id);
    hash.put("userid", userId);
    hash.put("name", name);
    GroupItem helper = new GroupItem();
    GroupItem output = helper.createFromHashtable(hash);
    assertEquals(input.getType(), output.getType());
    assertEquals(input.toString(), output.toString());
    assertEquals(input.mGroupType, output.mGroupType);
    assertEquals(input.mIsReadOnly, output.mIsReadOnly);
    assertEquals(input.mRequiresLocalisation, output.mRequiresLocalisation);
    assertEquals(input.mIsSystemGroup, output.mIsSystemGroup);
    assertEquals(input.mIsSmartGroup, output.mIsSmartGroup);
    assertEquals(input.mId, output.mId);
    assertEquals(input.mUserId, output.mUserId);
    assertEquals(input.mName, output.mName);
}
Also used : Hashtable(java.util.Hashtable) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 7 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem in project 360-Engine-for-Android by 360.

the class GroupPrivacy method addContactGroupRelations.

/**
 * Implementation of groupprivacy/addcontactgrouprelations API. Parameters
 * are; [auth], List<Long> contactidlist, List<Group> grouplist
 *
 * @param engine handle to ContactSyncEngine
 * @param contactidlist List of contacts ids associated with this request.
 * @param grouplist List of groups associated with this request.
 * @return request id generated for this request
 */
public static int addContactGroupRelations(BaseEngine engine, List<Long> contactidlist, List<GroupItem> grouplist) {
    if (LoginEngine.getSession() == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() Invalid session, return -1");
        return -1;
    }
    if (contactidlist == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() contactidlist cannot be NULL");
        return -1;
    }
    if (grouplist == null) {
        LogUtils.logE("GroupPrivacy.addContactGroupRelations() grouplist cannot be NULL");
        return -1;
    }
    Request request = new Request(FUNCTION_ADD_CONTACT_GROUP_RELATIONS, Request.Type.CONTACT_GROUP_RELATIONS, engine.engineId(), false, Settings.API_REQUESTS_TIMEOUT_GROUP_PRIVACY);
    request.addData("contactidlist", new Vector<Object>(contactidlist));
    request.addData("grouplist", ApiUtils.createVectorOfGroup(grouplist));
    QueueManager queue = QueueManager.getInstance();
    int requestId = queue.addRequest(request);
    queue.fireQueueStateChanged();
    return requestId;
}
Also used : Request(com.vodafone360.people.service.io.Request) QueueManager(com.vodafone360.people.service.io.QueueManager)

Example 8 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem in project 360-Engine-for-Android by 360.

the class GroupsTableTest method testAddingFetchingDeletingGroups.

/**
 * Test for adding, fetching and deleting items in the Groups Table.
 */
public final void testAddingFetchingDeletingGroups() {
    createTable();
    ArrayList<GroupItem> workingGroupItemList = new ArrayList<GroupItem>();
    assertEquals("Unable to fetch groups from table", ServiceStatus.SUCCESS, GroupsTable.fetchGroupList(workingGroupItemList, mTestDatabase.getWritableDatabase()));
    assertEquals("Fetched data from newly created table does not have " + "exactly 3 system groups. Size[" + workingGroupItemList.size() + "]", 3, workingGroupItemList.size());
    List<GroupItem> cachedGroupItemList = new ArrayList<GroupItem>(workingGroupItemList);
    cachedGroupItemList.addAll(generateGroupItemList());
    if (GroupsTable.addGroupList(generateGroupItemList(), mTestDatabase.getWritableDatabase()) != ServiceStatus.SUCCESS) {
        fail("Unable to add groups into table");
    }
    workingGroupItemList.clear();
    if (GroupsTable.fetchGroupList(workingGroupItemList, mTestDatabase.getWritableDatabase()) != ServiceStatus.SUCCESS) {
        fail("Unable to fetch groups from table");
    }
    // comparing in and out list
    if (cachedGroupItemList.size() != workingGroupItemList.size()) {
        fail("In and out list have different sizes");
    }
    for (int i = 0; i < cachedGroupItemList.size(); i++) {
        if (!doGroupItemsMatch(cachedGroupItemList.get(i), workingGroupItemList.get(i))) {
            fail("Element (" + i + ") is not the same in IN and OUT list");
        }
    }
    /**
     * Test for cursor functions. *
     */
    Cursor cursor = GroupsTable.getGroupCursor(mTestDatabase.getReadableDatabase());
    ArrayList<GroupItem> cursorList = new ArrayList<GroupItem>();
    if (cursor.moveToFirst()) {
        cursorList.add(GroupsTable.getQueryData(cursor));
        while (cursor.moveToNext()) {
            cursorList.add(GroupsTable.getQueryData(cursor));
        }
    }
    assertEquals("In and cursorList list have different sizes", cachedGroupItemList.size(), cursorList.size());
    for (int i = 0; i < cachedGroupItemList.size(); i++) {
        if (!doGroupItemsMatch(cachedGroupItemList.get(i), cursorList.get(i))) {
            fail("Element (" + i + ") is not the same in IN and " + "cursorList list");
        }
    }
    if (GroupsTable.deleteAllGroups(mTestDatabase.getWritableDatabase()) != ServiceStatus.SUCCESS) {
        fail("Unable to delete groups from table");
    }
    workingGroupItemList.clear();
    if (GroupsTable.fetchGroupList(workingGroupItemList, mTestDatabase.getWritableDatabase()) != ServiceStatus.SUCCESS) {
        fail("Unable to fetch groups from table");
    }
    if (workingGroupItemList.size() > 0) {
        fail("There are still rows in table that should be now empty");
    }
    Log.i(LOG_TAG, "testAddingFetchingDeletingGroups PASS");
}
Also used : ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem) Cursor(android.database.Cursor)

Example 9 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem in project 360-Engine-for-Android by 360.

the class UploadServerContacts method sendNextAddGroupRelationsPage.

/**
 * Sends next add contact/group relation request to the server. Many
 * contacts can be added by a single request.
 */
private void sendNextAddGroupRelationsPage() {
    ContactChangeInfo info = null;
    mActiveGroupId = null;
    mContactIdList.clear();
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> groupInfoList = new ArrayList<ContactChangeInfo>();
    long startTime = System.nanoTime();
    if (!ContactChangeLogTable.fetchContactChangeLog(groupInfoList, ContactChangeType.ADD_GROUP_REL, 0, MAX_UP_PAGE_SIZE, mDb.getReadableDatabase())) {
        LogUtils.logE("UploadServerContacts." + "sendNextAddGroupRelationsPage() Unable to fetch add " + "group relations from database");
        complete(ServiceStatus.ERROR_DATABASE_CORRUPT);
        return;
    }
    mDbSyncTime += (System.nanoTime() - startTime);
    if (groupInfoList.size() == 0) {
        moveToNextState();
        return;
    }
    mContactChangeInfoList.clear();
    List<ContactChangeInfo> deleteInfoList = new ArrayList<ContactChangeInfo>();
    for (int i = 0; i < groupInfoList.size(); i++) {
        info = groupInfoList.get(i);
        if (info.mServerContactId == null) {
            info.mServerContactId = mDb.fetchServerId(info.mLocalContactId);
        }
        if (info.mServerContactId != null && info.mGroupOrRelId != null) {
            if (mActiveGroupId == null) {
                mActiveGroupId = info.mGroupOrRelId;
            }
            if (info.mGroupOrRelId.equals(mActiveGroupId)) {
                mContactIdList.add(info.mServerContactId);
                mContactChangeInfoList.add(info);
            }
            continue;
        }
        LogUtils.logE("UploadServerContact.sendNextAddGroupRelationsPage() " + "Invalid add group change: SID = " + info.mServerContactId + ", gid=" + info.mGroupOrRelId);
        deleteInfoList.add(info);
    }
    mDb.deleteContactChanges(deleteInfoList);
    if (mActiveGroupId == null) {
        moveToNextState();
        return;
    }
    mGroupList.clear();
    GroupItem group = new GroupItem();
    group.mId = mActiveGroupId;
    mGroupList.add(group);
    if (NetworkAgent.getAgentState() != NetworkAgent.AgentState.CONNECTED) {
        complete(NetworkAgent.getServiceStatusfromDisconnectReason());
        return;
    }
    mNoOfItemsSent = mGroupList.size();
    setReqId(GroupPrivacy.addContactGroupRelations(getEngine(), mContactIdList, mGroupList));
}
Also used : ContactChangeInfo(com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo) ArrayList(java.util.ArrayList) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Example 10 with GroupItem

use of com.vodafone360.people.datatypes.GroupItem in project 360-Engine-for-Android by 360.

the class GroupsTable method addGroupList.

/**
 * Adds list of groups to the table
 *
 * @param groupList The list to add
 * @param writableDb Writable SQLite database
 * @return SUCCESS or a suitable error code
 */
public static ServiceStatus addGroupList(List<GroupItem> groupList, SQLiteDatabase writableDb) {
    try {
        writableDb.beginTransaction();
        for (GroupItem mGroupItem : groupList) {
            if (Settings.ENABLED_DATABASE_TRACE) {
                DatabaseHelper.trace(true, "GroupsTable.addGroupList() mName[" + mGroupItem.mName + "]");
            }
            mGroupItem.mLocalGroupId = writableDb.insertOrThrow(TABLE_NAME, null, fillUpdateData(mGroupItem));
            if (mGroupItem.mLocalGroupId < 0) {
                LogUtils.logE("GroupsTable.addGroupList() Unable to add group - mName[" + mGroupItem.mName + "");
                writableDb.endTransaction();
                return ServiceStatus.ERROR_DATABASE_CORRUPT;
            }
        }
        writableDb.setTransactionSuccessful();
    } catch (SQLException e) {
        LogUtils.logE("GroupsTable.addGroupList() SQLException - Unable to add group", e);
        return ServiceStatus.ERROR_DATABASE_CORRUPT;
    } finally {
        if (writableDb != null) {
            writableDb.endTransaction();
        }
    }
    return ServiceStatus.SUCCESS;
}
Also used : SQLException(android.database.SQLException) GroupItem(com.vodafone360.people.datatypes.GroupItem)

Aggregations

GroupItem (com.vodafone360.people.datatypes.GroupItem)9 ArrayList (java.util.ArrayList)6 ItemList (com.vodafone360.people.datatypes.ItemList)3 ServiceStatus (com.vodafone360.people.service.ServiceStatus)2 Hashtable (java.util.Hashtable)2 Cursor (android.database.Cursor)1 SQLException (android.database.SQLException)1 ContactChangeInfo (com.vodafone360.people.database.tables.ContactChangeLogTable.ContactChangeInfo)1 Contact (com.vodafone360.people.datatypes.Contact)1 QueueManager (com.vodafone360.people.service.io.QueueManager)1 Request (com.vodafone360.people.service.io.Request)1 Vector (java.util.Vector)1