@Override public Observable<List<MessageEntity>> fetchByType(MessageEntity.Type type) { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataSource .fetchMessageByType(mMessageDataMapper.map(type)) .map((messageList -> mMessageDataMapper.map(messageList))); }
@Override public Observable<List<MessageEntity>> fetchByStatus(MessageEntity.Status status) { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataSource .fetchMessageByStatus(mMessageDataMapper.map(status)) .map((messageList -> mMessageDataMapper.map(messageList))); }
@Override public Observable<List<MessageEntity>> fetchPending() { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataSource .fetchPending() .map((messageList -> mMessageDataMapper.map(messageList))); }
@Override public Observable<List<MessageEntity>> importMessage() { return Observable.defer( () -> { ProcessSms processSms = mPostMessage.getProcessSms(); List<SmsMessage> smsMessages = processSms.importMessages(); List<Message> messages = new ArrayList<>(); for (SmsMessage smsMessage : smsMessages) { messages.add(mPostMessage.map(smsMessage)); } return Observable.just(mMessageDataMapper.map(messages)); }); }
@Override public Observable<Long> updateEntity(MessageEntity messageEntity) { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataSource.put(mMessageDataMapper.map(messageEntity)); }
@Override public Observable<MessageEntity> getEntity(Long id) { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataSource.getMessage(id).map(message -> mMessageDataMapper.map(message)); }
@Override public List<MessageEntity> syncFetchPending() { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataMapper.map(mMessageDataSource.syncFetchPending()); }
@Override public MessageEntity syncFetchByUuid(String uuid) { mMessageDataSource = mMessageDataSourceFactory.createMessageDatabaseSource(); return mMessageDataMapper.map(mMessageDataSource.fetchMessageByUuid(uuid)); }