add arbitrary storage business layer

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-06-29 15:03:36 +02:00
parent ad223155d7
commit 12f793567e
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
6 changed files with 61 additions and 6 deletions

View File

@ -0,0 +1,39 @@
/*
* Nextcloud Talk application
*
* @author Andy Scherzinger
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.arbitrarystorage
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository
import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import io.reactivex.Maybe
class ArbitraryStorageManager(private val arbitraryStoragesRepository: ArbitraryStoragesRepository) {
fun storeStorageSetting(accountIdentifier: Long, key: String?, value: String?, objectString: String?) {
arbitraryStoragesRepository.saveArbitraryStorage(ArbitraryStorage(accountIdentifier, key, objectString, value))
}
fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): Maybe<ArbitraryStorage> {
return arbitraryStoragesRepository.getStorageSetting(accountIdentifier, key, objectString)
}
suspend fun deleteAllEntriesForAccountIdentifier(accountIdentifier: Long) {
return arbitraryStoragesRepository.deleteArbitraryStorage(accountIdentifier)
}
}

View File

@ -25,6 +25,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity import com.nextcloud.talk.data.storage.model.ArbitraryStorageEntity
import io.reactivex.Maybe
@Dao @Dao
abstract class ArbitraryStoragesDao { abstract class ArbitraryStoragesDao {
@ -34,7 +35,11 @@ abstract class ArbitraryStoragesDao {
"\"key\" = :key AND " + "\"key\" = :key AND " +
"object = :objectString" "object = :objectString"
) )
abstract fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorageEntity abstract fun getStorageSetting(
accountIdentifier: Long,
key: String,
objectString: String
): Maybe<ArbitraryStorageEntity>
@Query("DELETE FROM ArbitraryStorage WHERE accountIdentifier = :accountIdentifier") @Query("DELETE FROM ArbitraryStorage WHERE accountIdentifier = :accountIdentifier")
abstract suspend fun deleteArbitraryStorage(accountIdentifier: Long) abstract suspend fun deleteArbitraryStorage(accountIdentifier: Long)

View File

@ -21,9 +21,10 @@
package com.nextcloud.talk.data.storage package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorage import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import io.reactivex.Maybe
interface ArbitraryStoragesRepository { interface ArbitraryStoragesRepository {
fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): ArbitraryStorage fun getStorageSetting(accountIdentifier: Long, key: String, objectString: String): Maybe<ArbitraryStorage>
suspend fun deleteArbitraryStorage(accountIdentifier: Long) suspend fun deleteArbitraryStorage(accountIdentifier: Long)
fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long fun saveArbitraryStorage(arbitraryStorage: ArbitraryStorage): Long
} }

View File

@ -21,6 +21,7 @@
package com.nextcloud.talk.data.storage package com.nextcloud.talk.data.storage
import com.nextcloud.talk.data.storage.model.ArbitraryStorage import com.nextcloud.talk.data.storage.model.ArbitraryStorage
import io.reactivex.Maybe
class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) : class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: ArbitraryStoragesDao) :
ArbitraryStoragesRepository { ArbitraryStoragesRepository {
@ -28,10 +29,10 @@ class ArbitraryStoragesRepositoryImpl(private val arbitraryStoragesDao: Arbitrar
accountIdentifier: Long, accountIdentifier: Long,
key: String, key: String,
objectString: String objectString: String
): ArbitraryStorage { ): Maybe<ArbitraryStorage> {
return ArbitraryStorageMapper.toModel( return arbitraryStoragesDao
arbitraryStoragesDao.getStorageSetting(accountIdentifier, key, objectString) .getStorageSetting(accountIdentifier, key, objectString)
)!! .map { ArbitraryStorageMapper.toModel(it) }
} }
override suspend fun deleteArbitraryStorage(accountIdentifier: Long) { override suspend fun deleteArbitraryStorage(accountIdentifier: Long) {

View File

@ -21,7 +21,10 @@ package com.nextcloud.talk.utils.database.arbitrarystorage;
import autodagger.AutoInjector; import autodagger.AutoInjector;
import com.nextcloud.talk.application.NextcloudTalkApplication; import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.arbitrarystorage.ArbitraryStorageManager;
import com.nextcloud.talk.dagger.modules.DatabaseModule; import com.nextcloud.talk.dagger.modules.DatabaseModule;
import com.nextcloud.talk.data.storage.ArbitraryStoragesRepository;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import io.requery.Persistable; import io.requery.Persistable;
@ -41,4 +44,9 @@ public class ArbitraryStorageModule {
public ArbitraryStorageUtils provideArbitraryStorageUtils(ReactiveEntityStore<Persistable> dataStore) { public ArbitraryStorageUtils provideArbitraryStorageUtils(ReactiveEntityStore<Persistable> dataStore) {
return new ArbitraryStorageUtils(dataStore); return new ArbitraryStorageUtils(dataStore);
} }
@Provides
public ArbitraryStorageManager provideArbitraryStorageManager(ArbitraryStoragesRepository repository) {
return new ArbitraryStorageManager(repository);
}
} }

View File

@ -29,6 +29,7 @@ import io.requery.query.Result;
import io.requery.reactivex.ReactiveEntityStore; import io.requery.reactivex.ReactiveEntityStore;
import io.requery.reactivex.ReactiveScalar; import io.requery.reactivex.ReactiveScalar;
@Deprecated
public class ArbitraryStorageUtils { public class ArbitraryStorageUtils {
private ReactiveEntityStore<Persistable> dataStore; private ReactiveEntityStore<Persistable> dataStore;