Search in sources :

Example 1 with AlResponse

use of com.applozic.mobicomkit.feed.AlResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method createChannel_withError.

@Test
public void createChannel_withError() {
    ChannelInfo channelInfo = new ChannelInfo();
    try {
        ChannelFeedApiResponse apiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(MockConstants.channelErrorResponse, ChannelFeedApiResponse.class);
        when(channelClientService.createChannelWithResponse(channelInfo)).thenReturn(apiResponse);
        AlResponse response = channelService.createChannel(channelInfo);
        assertFalse(response.isSuccess());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ChannelInfo(com.applozic.mobicomkit.api.people.ChannelInfo) AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Test(org.junit.Test)

Example 2 with AlResponse

use of com.applozic.mobicomkit.feed.AlResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelServiceTest method createChannel_withSuccess.

@Test
public void createChannel_withSuccess() {
    ChannelInfo channelInfo = new ChannelInfo();
    try {
        ChannelFeedApiResponse apiResponse = (ChannelFeedApiResponse) GsonUtils.getObjectFromJson(MockConstants.channelSuccessResponse, ChannelFeedApiResponse.class);
        when(channelClientService.createChannelWithResponse(channelInfo)).thenReturn(apiResponse);
        AlResponse response = channelService.createChannel(channelInfo);
        assertTrue(response.isSuccess() && (response.getResponse() instanceof Channel));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) ChannelInfo(com.applozic.mobicomkit.api.people.ChannelInfo) AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse) Test(org.junit.Test)

Example 3 with AlResponse

use of com.applozic.mobicomkit.feed.AlResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelService method createGroupOfTwoWithResponse.

/**
 * Internal. Group-of-two channels are implemented in the UI. You will not need them.
 *
 * <p>Create a {@link Channel.GroupType#GROUPOFTWO} channel.</p>
 *
 * <p>A group-of-two type channel is implemented in the UI to look like a 1-to-1 chat.
 * It is meant to have two members only.</p>
 *
 * @param channelInfo the channel info that will be used to create the channel
 * @return the {@link AlResponse} from the server
 */
public AlResponse createGroupOfTwoWithResponse(ChannelInfo channelInfo) {
    if (channelInfo == null) {
        return null;
    }
    AlResponse alResponse = new AlResponse();
    if (!TextUtils.isEmpty(channelInfo.getClientGroupId())) {
        Channel channel = channelDatabaseService.getChannelByClientGroupId(channelInfo.getClientGroupId());
        if (channel != null) {
            alResponse.setStatus(AlResponse.SUCCESS);
            alResponse.setResponse(channel);
        } else {
            ChannelFeedApiResponse channelFeedApiResponse = channelClientService.createChannelWithResponse(channelInfo);
            if (channelFeedApiResponse == null) {
                alResponse.setStatus(AlResponse.ERROR);
            } else {
                if (channelFeedApiResponse.isSuccess()) {
                    ChannelFeed channelFeed = channelFeedApiResponse.getResponse();
                    if (channelFeed != null) {
                        ChannelFeed[] channelFeeds = new ChannelFeed[1];
                        channelFeeds[0] = channelFeed;
                        processChannelFeedList(channelFeeds, true);
                        alResponse.setStatus(AlResponse.SUCCESS);
                        alResponse.setResponse(getChannel(channelFeed));
                    }
                } else {
                    ChannelFeed channelFeed = channelClientService.getChannelInfo(channelInfo.getClientGroupId());
                    if (channelFeed != null) {
                        ChannelFeed[] channelFeeds = new ChannelFeed[1];
                        channelFeeds[0] = channelFeed;
                        processChannelFeedList(channelFeeds, false);
                        alResponse.setStatus(AlResponse.SUCCESS);
                        alResponse.setResponse(getChannel(channelFeed));
                    }
                }
            }
        }
    }
    return alResponse;
}
Also used : Channel(com.applozic.mobicommons.people.channel.Channel) AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Example 4 with AlResponse

use of com.applozic.mobicomkit.feed.AlResponse in project Applozic-Android-SDK by AppLozic.

the class ChannelService method createChannel.

/**
 * @deprecated {@link AlResponse} is not longer used. It will be replaced by {@link ApiResponse}.
 *
 * Use {@link ChannelService#createChannelWithResponse(ChannelInfo)} instead.
 */
@Deprecated
public synchronized AlResponse createChannel(final ChannelInfo channelInfo) {
    if (channelInfo == null) {
        return null;
    }
    AlResponse alResponse = new AlResponse();
    ChannelFeedApiResponse channelFeedResponse = null;
    try {
        channelFeedResponse = channelClientService.createChannelWithResponse(channelInfo);
        if (channelFeedResponse == null) {
            return null;
        }
        if (channelFeedResponse.isSuccess()) {
            alResponse.setStatus(AlResponse.SUCCESS);
            ChannelFeed channelFeed = channelFeedResponse.getResponse();
            if (channelFeed != null) {
                ChannelFeed[] channelFeeds = new ChannelFeed[1];
                channelFeeds[0] = channelFeed;
                processChannelFeedList(channelFeeds, true);
                alResponse.setResponse(getChannel(channelFeed));
            }
        } else {
            alResponse.setStatus(AlResponse.ERROR);
            alResponse.setResponse(channelFeedResponse.getErrorResponse());
        }
    } catch (Exception e) {
        alResponse.setStatus(AlResponse.ERROR);
        alResponse.setException(e);
    }
    return alResponse;
}
Also used : AlResponse(com.applozic.mobicomkit.feed.AlResponse) ChannelFeed(com.applozic.mobicomkit.feed.ChannelFeed) SyncChannelFeed(com.applozic.mobicomkit.sync.SyncChannelFeed) ChannelFeedApiResponse(com.applozic.mobicomkit.feed.ChannelFeedApiResponse)

Example 5 with AlResponse

use of com.applozic.mobicomkit.feed.AlResponse in project Applozic-Android-SDK by AppLozic.

the class ApplozicChannelCreateTask method doInBackground.

@Override
protected Boolean doInBackground() {
    try {
        if (!TextUtils.isEmpty(groupName) && groupName.trim().length() != 0 && groupMemberList != null && groupMemberList.size() > 0) {
            channelInfo = new ChannelInfo(groupName.trim(), groupMemberList, groupImageLink);
            if (!TextUtils.isEmpty(clientGroupId)) {
                channelInfo.setClientGroupId(clientGroupId);
            }
            channelInfo.setType(type);
            AlResponse alResponse = channelService.createChannel(channelInfo);
            channel = (Channel) channelService.createChannel(channelInfo).getResponse();
            return channel != null;
        }
        return false;
    } catch (Exception e) {
        e.printStackTrace();
        exception = e;
        return false;
    }
}
Also used : ChannelInfo(com.applozic.mobicomkit.api.people.ChannelInfo) AlResponse(com.applozic.mobicomkit.feed.AlResponse)

Aggregations

AlResponse (com.applozic.mobicomkit.feed.AlResponse)5 ChannelFeedApiResponse (com.applozic.mobicomkit.feed.ChannelFeedApiResponse)4 ChannelInfo (com.applozic.mobicomkit.api.people.ChannelInfo)3 ChannelFeed (com.applozic.mobicomkit.feed.ChannelFeed)2 SyncChannelFeed (com.applozic.mobicomkit.sync.SyncChannelFeed)2 Channel (com.applozic.mobicommons.people.channel.Channel)2 Test (org.junit.Test)2