From 9230937a4421dc12da05fa70e6ed101ae0e19da2 Mon Sep 17 00:00:00 2001 From: davigonz Date: Mon, 30 Sep 2019 15:27:17 +0200 Subject: [PATCH] Keep decoupling shares and capabilities, start to use mappers --- owncloudComLibrary/build.gradle | 2 + .../android/lib/common/OwnCloudAccount.java | 1 - .../shares/CreateRemoteShareOperation.kt | 1 + .../lib/resources/shares/RemoteShare.kt | 1 + .../lib/resources/shares/RemoteShareMapper.kt | 51 +++++++++++++++ .../ShareToRemoteOperationResultParser.kt | 1 + .../android/lib/resources/shares/ShareType.kt | 63 ------------------ .../lib/resources/shares/ShareXMLParser.kt | 1 + .../resources/status/CapabilityBooleanType.kt | 65 ------------------- .../status/GetRemoteCapabilitiesOperation.kt | 1 + .../lib/resources/status/RemoteCapability.kt | 2 + 11 files changed, 60 insertions(+), 129 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt delete mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt diff --git a/owncloudComLibrary/build.gradle b/owncloudComLibrary/build.gradle index 384dacf3..971d400e 100644 --- a/owncloudComLibrary/build.gradle +++ b/owncloudComLibrary/build.gradle @@ -4,6 +4,8 @@ apply plugin: 'kotlin-kapt' apply plugin: 'kotlin-allopen' dependencies { + implementation project(':owncloudDomain') + api 'com.squareup.okhttp3:okhttp:3.12.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion" api 'com.gitlab.ownclouders:dav4android:oc_support_1.0.1' diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java index ba03b545..222eb366 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudAccount.java @@ -149,5 +149,4 @@ public class OwnCloudAccount { return null; } } - } \ No newline at end of file diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt index b7080c4d..cfec6248 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/CreateRemoteShareOperation.kt @@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.shares +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.PostMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt index 04b61b97..2d75b125 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShare.kt @@ -26,6 +26,7 @@ package com.owncloud.android.lib.resources.shares import android.os.Parcel import android.os.Parcelable +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.FileUtils import java.io.Serializable diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt new file mode 100644 index 00000000..81229fa9 --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/RemoteShareMapper.kt @@ -0,0 +1,51 @@ +/** + * ownCloud Android client application + * + * @author David González Verdugo + * Copyright (C) 2019 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * 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 . + */ + +package com.owncloud.android.lib.resources.shares + +import com.owncloud.android.domain.mapper.RemoteMapper +import com.owncloud.android.domain.sharing.shares.model.OCShare + +class RemoteShareMapper : RemoteMapper { + override fun toModel(remote: RemoteShare?): OCShare? = + remote?.let { + OCShare( + fileSource = remote.fileSource, + itemSource = remote.itemSource, + shareType = remote.shareType!!, + shareWith = remote.shareWith, + path = remote.path, + permissions = remote.permissions, + sharedDate = remote.sharedDate, + expirationDate = remote.expirationDate, + token = remote.token, + sharedWithDisplayName = remote.sharedWithDisplayName, + sharedWithAdditionalInfo = remote.sharedWithAdditionalInfo, + isFolder = remote.isFolder, + userId = remote.userId, + remoteId = remote.id, + name = remote.name, + shareLink = remote.shareLink + ) + } + + override fun toRemote(model: OCShare?): RemoteShare? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt index 09fc03ab..775e35d8 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareToRemoteOperationResultParser.kt @@ -28,6 +28,7 @@ package com.owncloud.android.lib.resources.shares import android.net.Uri +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.status.OwnCloudVersion diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt deleted file mode 100644 index 8825ffdc..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareType.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -package com.owncloud.android.lib.resources.shares - -/** - * Enum for Share Type, with values: - * -1 - No shared - * 0 - Shared by user - * 1 - Shared by group - * 3 - Shared by public link - * 4 - Shared by e-mail - * 5 - Shared by contact - * 6 - Federated - * - * @author masensio - */ - -enum class ShareType constructor(val value: Int) { - NO_SHARED(-1), - USER(0), - GROUP(1), - PUBLIC_LINK(3), - EMAIL(4), - CONTACT(5), - FEDERATED(6); - - companion object { - fun fromValue(value: Int): ShareType? { - return when (value) { - -1 -> NO_SHARED - 0 -> USER - 1 -> GROUP - 3 -> PUBLIC_LINK - 4 -> EMAIL - 5 -> CONTACT - 6 -> FEDERATED - else -> null - } - } - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt index df634321..95b60982 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/ShareXMLParser.kt @@ -25,6 +25,7 @@ package com.owncloud.android.lib.resources.shares import android.util.Xml +import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.network.WebdavUtils import com.owncloud.android.lib.resources.files.FileUtils diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt deleted file mode 100644 index 7d3d51e7..00000000 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/CapabilityBooleanType.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. - * @author masensio - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -package com.owncloud.android.lib.resources.status - -/** - * Enum for Boolean Type in RemoteCapability parameters, with values: - * -1 - Unknown - * 0 - False - * 1 - True - */ -enum class CapabilityBooleanType private constructor(val value: Int) { - UNKNOWN(-1), - FALSE(0), - TRUE(1); - - val isUnknown: Boolean - get() = value == -1 - - val isFalse: Boolean - get() = value == 0 - - val isTrue: Boolean - get() = value == 1 - - companion object { - fun fromValue(value: Int): CapabilityBooleanType? { - return when (value) { - -1 -> UNKNOWN - 0 -> FALSE - 1 -> TRUE - else -> null - } - } - - fun fromBooleanValue(boolValue: Boolean): CapabilityBooleanType { - return if (boolValue) { - TRUE - } else { - FALSE - } - } - } -} diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt index d5ab846d..2dc62568 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/GetRemoteCapabilitiesOperation.kt @@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.status +import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.http.HttpConstants import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt index c1337119..2de02389 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/status/RemoteCapability.kt @@ -26,6 +26,8 @@ */ package com.owncloud.android.lib.resources.status +import com.owncloud.android.domain.capabilities.model.CapabilityBooleanType + /** * Contains data of the Capabilities for an account, from the Capabilities API */