Search in sources :

Example 1 with RequestSearchContact

use of com.fanap.podchat.mainmodel.RequestSearchContact in project pod-chat-android-sdk by FanapSoft.

the class ChatActivity method searchContact.

private void searchContact() {
    RequestSearchContact requestSearchContact = new RequestSearchContact.Builder("0", "20").query("pO").build();
    presenter.searchContact(requestSearchContact);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact)

Example 2 with RequestSearchContact

use of com.fanap.podchat.mainmodel.RequestSearchContact in project pod-chat-android-sdk by FanapSoft.

the class ChatTestIntegration method searchContact.

@Test
@MediumTest
public void searchContact() {
    sleep(3000);
    RequestSearchContact requestSearchContact = new RequestSearchContact.Builder("0", "2").id("1063").build();
    presenter.searchContact(requestSearchContact);
    sleep(3000);
    Mockito.verify(view, Mockito.times(1)).onSearchContact();
}
Also used : RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) MediumTest(android.support.test.filters.MediumTest)

Example 3 with RequestSearchContact

use of com.fanap.podchat.mainmodel.RequestSearchContact in project pod-chat-android-sdk by FanapSoft.

the class ChatTestSandbox method searchContact.

@Test
@MediumTest
public void searchContact() {
    sleep(3000);
    RequestSearchContact requestSearchContact = new RequestSearchContact.Builder("0", "2").id("1063").build();
    presenter.searchContact(requestSearchContact);
    sleep(3000);
    Mockito.verify(view, Mockito.times(1)).onSearchContact();
}
Also used : RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) MediumTest(android.support.test.filters.MediumTest)

Example 4 with RequestSearchContact

use of com.fanap.podchat.mainmodel.RequestSearchContact in project pod-chat-android-sdk by FanapSoft.

the class ChatTest method searchContact.

@Test
@MediumTest
public void searchContact() {
    sleep(3000);
    RequestSearchContact requestSearchContact = new RequestSearchContact.Builder("0", "2").id("1063").build();
    presenter.searchContact(requestSearchContact);
    sleep(3000);
    Mockito.verify(view, Mockito.times(1)).onSearchContact();
}
Also used : RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) FlakyTest(android.support.test.filters.FlakyTest) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test) LargeTest(android.support.test.filters.LargeTest) MediumTest(android.support.test.filters.MediumTest)

Example 5 with RequestSearchContact

use of com.fanap.podchat.mainmodel.RequestSearchContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method searchContacts.

@NonNull
public ChatResponse<ResultContact> searchContacts(RequestSearchContact requestSearchContact, String size, String offset) {
    List<Contact> contacts = new ArrayList<>();
    ChatResponse<ResultContact> chatResponse = new ChatResponse<>();
    chatResponse.setCache(true);
    ResultContact resultContact = new ResultContact();
    resultContact.setContacts(new ArrayList<>(contacts));
    chatResponse.setHasError(false);
    long nextOffset = Long.parseLong(offset) + Long.parseLong(size);
    resultContact.setHasNext(false);
    resultContact.setNextOffset(nextOffset);
    if (requestSearchContact.getId() != null) {
        try {
            CacheContact cacheContact = messageDao.getContactById(Long.parseLong(requestSearchContact.getId()));
            contacts.add(cacheContactToContactMapper(cacheContact));
            resultContact.setContacts(new ArrayList<>(contacts));
            resultContact.setContentCount(1);
        } catch (NumberFormatException e) {
            Log.e(TAG, "Invalid Id");
            chatResponse.setHasError(true);
            chatResponse.setErrorMessage("Invalid Id");
            chatResponse.setErrorCode(ChatConstant.ERROR_CODE_INVALID_CONTACT_ID);
            resultContact.setContentCount(0);
        }
        chatResponse.setResult(resultContact);
        return chatResponse;
    }
    String order = Util.isNullOrEmpty(requestSearchContact.getOrder()) ? "desc" : requestSearchContact.getOrder();
    String orderBy = " order by hasUser " + order + ", lastName is null or lastName='', lastName, firstName is null or firstName='', firstName";
    String query = "select * from CacheContact where";
    if (!Util.isNullOrEmpty(requestSearchContact.getQuery())) {
        query += " (firstName LIKE '%" + requestSearchContact.getQuery() + "%' OR lastName LIKE '%" + requestSearchContact.getQuery() + "%') AND";
    } else if (!Util.isNullOrEmpty(requestSearchContact.getFirstName()) && !Util.isNullOrEmpty(requestSearchContact.getLastName()))
        query += " (firstName LIKE '%" + requestSearchContact.getFirstName() + "%' AND lastName LIKE '%" + requestSearchContact.getLastName() + "%') AND";
    else if (!Util.isNullOrEmpty(requestSearchContact.getFirstName()))
        query += " firstName LIKE '%" + requestSearchContact.getFirstName() + "%' AND";
    else if (!Util.isNullOrEmpty(requestSearchContact.getLastName()))
        query += " lastName LIKE '%" + requestSearchContact.getLastName() + "%' AND";
    if (!Util.isNullOrEmpty(requestSearchContact.getEmail()))
        query += " email LIKE '%" + requestSearchContact.getEmail() + "%' AND";
    if (!Util.isNullOrEmpty(requestSearchContact.getCellphoneNumber()))
        query += " cellphoneNumber LIKE '%" + requestSearchContact.getCellphoneNumber() + "%'";
    if (query.endsWith("AND")) {
        query = query.substring(0, query.lastIndexOf("AND") - 1);
    }
    long contentCount = messageDao.getRawContactsCount(new SimpleSQLiteQuery(query.replaceFirst("select \\* ", "select count(id) ")));
    query += orderBy + " LIMIT " + size + " OFFSET " + offset;
    List<CacheContact> cachedContacts = messageDao.getRawContacts(new SimpleSQLiteQuery(query));
    if (!Util.isNullOrEmpty(cachedContacts)) {
        for (CacheContact cachedContact : cachedContacts) {
            contacts.add(cacheContactToContactMapper(cachedContact));
        }
    }
    resultContact.setContacts(new ArrayList<>(contacts));
    resultContact.setHasNext(Long.parseLong(offset) + contacts.size() < contentCount);
    resultContact.setNextOffset(Long.parseLong(offset) + contacts.size());
    resultContact.setContentCount(contentCount);
    chatResponse.setResult(resultContact);
    return chatResponse;
}
Also used : ArrayList(java.util.ArrayList) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) ResultContact(com.fanap.podchat.model.ResultContact) SimpleSQLiteQuery(android.arch.persistence.db.SimpleSQLiteQuery) ChatResponse(com.fanap.podchat.model.ChatResponse) CacheContact(com.fanap.podchat.cachemodel.CacheContact) NonNull(android.support.annotation.NonNull)

Aggregations

RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)5 FlakyTest (android.support.test.filters.FlakyTest)3 LargeTest (android.support.test.filters.LargeTest)3 MediumTest (android.support.test.filters.MediumTest)3 Test (org.junit.Test)3 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)1 NonNull (android.support.annotation.NonNull)1 CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)1 CacheContact (com.fanap.podchat.cachemodel.CacheContact)1 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)1 Contact (com.fanap.podchat.mainmodel.Contact)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1 ResultContact (com.fanap.podchat.model.ResultContact)1 GsonBuilder (com.google.gson.GsonBuilder)1 ArrayList (java.util.ArrayList)1