mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-28 00:48:50 +00:00 
			
		
		
		
	Fix shares parsing
This commit is contained in:
		
							parent
							
								
									27b18c33a9
								
							
						
					
					
						commit
						45fb12df0e
					
				| @ -70,7 +70,7 @@ class CreateRemoteShareOperation( | ||||
|     private val shareType: ShareType, | ||||
|     private val shareWith: String, | ||||
|     private val permissions: Int | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
| ) : RemoteOperation<ShareResponse>() { | ||||
|     var name = "" // Name to set for the public link | ||||
| 
 | ||||
|     var password: String = "" // Password to set for the public link | ||||
| @ -81,8 +81,8 @@ class CreateRemoteShareOperation( | ||||
| 
 | ||||
|     var retrieveShareDetails = false // To retrieve more info about the just created share | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> { | ||||
|         var result: RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|         try { | ||||
|             val formBodyBuilder = FormBody.Builder() | ||||
| @ -142,7 +142,7 @@ class CreateRemoteShareOperation( | ||||
|                     val remoteOperationResult = getShares.execute(client) | ||||
| 
 | ||||
|                     result = RemoteOperationResult(remoteOperationResult) | ||||
|                     result.data = ShareParserResult(remoteOperationResult.data.toRemoteShare()) | ||||
|                     result.data = remoteOperationResult.data | ||||
|                 } | ||||
| 
 | ||||
|             } else { | ||||
|  | ||||
| @ -30,7 +30,7 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperation | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.resources.CommonOcsResponse | ||||
| import com.owncloud.android.lib.resources.shares.responses.ShareResponse | ||||
| import com.owncloud.android.lib.resources.shares.responses.ShareItem | ||||
| import com.squareup.moshi.JsonAdapter | ||||
| import com.squareup.moshi.Moshi | ||||
| import com.squareup.moshi.Types | ||||
| @ -49,9 +49,14 @@ class GetRemoteShareOperation(private val remoteId: String) : RemoteOperation<Sh | ||||
| 
 | ||||
|     private fun parseResponse(response: String): ShareResponse? { | ||||
|         val moshi = Moshi.Builder().build() | ||||
|         val type: Type = Types.newParameterizedType(CommonOcsResponse::class.java, ShareResponse::class.java) | ||||
|         val adapter: JsonAdapter<CommonOcsResponse<ShareResponse>> = moshi.adapter(type) | ||||
|         return adapter.fromJson(response)!!.ocs.data | ||||
|         val listOfShareItemType: Type = Types.newParameterizedType(List::class.java, ShareItem::class.java) | ||||
|         val commonOcsType: Type = Types.newParameterizedType(CommonOcsResponse::class.java, listOfShareItemType) | ||||
|         val adapter: JsonAdapter<CommonOcsResponse<List<ShareItem>>> = moshi.adapter(commonOcsType) | ||||
|         return adapter.fromJson(response)?.ocs?.data?.let { listOfShareItems -> | ||||
|             ShareResponse(listOfShareItems.map { shareItem -> | ||||
|                 shareItem.toRemoteShare() | ||||
|             }) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private fun onResultUnsuccessful( | ||||
|  | ||||
| @ -59,10 +59,10 @@ class GetRemoteSharesForFileOperation( | ||||
|     private val remoteFilePath: String, | ||||
|     private val reshares: Boolean, | ||||
|     private val subfiles: Boolean | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
| ) : RemoteOperation<ShareResponse>() { | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> { | ||||
|         var result: RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
|  | ||||
| @ -48,10 +48,10 @@ import java.net.URL | ||||
|  * | ||||
|  * @param remoteShareId Share ID | ||||
|  */ | ||||
| class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOperation<ShareParserResult>() { | ||||
| class RemoveRemoteShareOperation(private val remoteShareId: String) : RemoteOperation<ShareResponse>() { | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> { | ||||
|         var result: RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|         try { | ||||
|             val requestUri = client.baseUri | ||||
|  | ||||
| @ -25,4 +25,4 @@ | ||||
| 
 | ||||
| package com.owncloud.android.lib.resources.shares | ||||
| 
 | ||||
| class ShareParserResult(val shares: List<RemoteShare>) | ||||
| data class ShareResponse(val shares: List<RemoteShare>) | ||||
| @ -41,12 +41,12 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar | ||||
|     var ownCloudVersion: OwnCloudVersion? = null | ||||
|     var serverBaseUri: Uri? = null | ||||
| 
 | ||||
|     fun parse(serverResponse: String?): RemoteOperationResult<ShareParserResult> { | ||||
|     fun parse(serverResponse: String?): RemoteOperationResult<ShareResponse> { | ||||
|         if (serverResponse.isNullOrEmpty()) { | ||||
|             return RemoteOperationResult(RemoteOperationResult.ResultCode.WRONG_SERVER_RESPONSE) | ||||
|         } | ||||
| 
 | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|         var result: RemoteOperationResult<ShareResponse> | ||||
|         val resultData: List<RemoteShare>? | ||||
| 
 | ||||
|         try { | ||||
| @ -82,7 +82,7 @@ class ShareToRemoteOperationResultParser(private var shareXmlParser: ShareXMLPar | ||||
|                         } | ||||
| 
 | ||||
|                         if (resultData != null) { | ||||
|                             result.setData(ShareParserResult(ArrayList(resultData.toMutableList()))) | ||||
|                             result.setData(ShareResponse(ArrayList(resultData.toMutableList()))) | ||||
|                         } | ||||
| 
 | ||||
|                     } else { | ||||
|  | ||||
| @ -57,7 +57,7 @@ class UpdateRemoteShareOperation | ||||
|      */ | ||||
|     private val remoteId: String | ||||
| 
 | ||||
| ) : RemoteOperation<ShareParserResult>() { | ||||
| ) : RemoteOperation<ShareResponse>() { | ||||
|     /** | ||||
|      * Name to update in Share resource. Ignored by servers previous to version 10.0.0 | ||||
|      * | ||||
| @ -99,8 +99,8 @@ class UpdateRemoteShareOperation | ||||
| 
 | ||||
|     var retrieveShareDetails = false // To retrieve more info about the just updated share | ||||
| 
 | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareParserResult> { | ||||
|         var result: RemoteOperationResult<ShareParserResult> | ||||
|     override fun run(client: OwnCloudClient): RemoteOperationResult<ShareResponse> { | ||||
|         var result: RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|         try { | ||||
|             val formBodyBuilder = FormBody.Builder() | ||||
| @ -169,10 +169,7 @@ class UpdateRemoteShareOperation | ||||
|                 val getShares = GetRemoteShareOperation( | ||||
|                     emptyShare.id | ||||
|                 ) | ||||
|                 val remoteOperationResult = getShares.execute(client) | ||||
| 
 | ||||
|                 result = RemoteOperationResult(remoteOperationResult) | ||||
|                 result.data = ShareParserResult(remoteOperationResult.data.toRemoteShare()) | ||||
|                 result = getShares.execute(client) | ||||
|             } | ||||
| 
 | ||||
|         } catch (e: Exception) { | ||||
|  | ||||
| @ -31,30 +31,6 @@ import com.owncloud.android.lib.resources.shares.ShareType | ||||
| import com.squareup.moshi.JsonClass | ||||
| import java.io.File | ||||
| 
 | ||||
| 
 | ||||
| @JsonClass(generateAdapter = true) | ||||
| data class ShareResponse( | ||||
|     val shares: List<ShareItem> | ||||
| ) { | ||||
|     fun toRemoteShare() = this.shares.map { shareItem -> | ||||
|         RemoteShare( | ||||
|             id = shareItem.id ?: "0", | ||||
|             shareWith = shareItem.shareWith.orEmpty(), | ||||
|             path = shareItem.path.orEmpty(), | ||||
|             token = shareItem.token.orEmpty(), | ||||
|             sharedWithDisplayName = shareItem.sharedWithDisplayName.orEmpty(), | ||||
|             sharedWithAdditionalInfo = shareItem.sharedWithAdditionalInfo.orEmpty(), | ||||
|             name = shareItem.name.orEmpty(), | ||||
|             shareLink = shareItem.shareLink.orEmpty(), | ||||
|             shareType = ShareType.values().firstOrNull { it.value == shareItem.shareType } ?: ShareType.UNKNOWN, | ||||
|             permissions = shareItem.permissions ?: DEFAULT_PERMISSION, | ||||
|             sharedDate = shareItem.sharedDate ?: INIT_SHARED_DATE, | ||||
|             expirationDate = shareItem.expirationDate ?: INIT_EXPIRATION_DATE_IN_MILLIS, | ||||
|             isFolder = shareItem.path?.endsWith(File.separator) ?: false | ||||
|         ) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @JsonClass(generateAdapter = true) | ||||
| data class ShareItem( | ||||
|     val id: String? = null, | ||||
| @ -69,4 +45,20 @@ data class ShareItem( | ||||
|     val permissions: Int? = null, | ||||
|     val sharedDate: Long? = null, | ||||
|     val expirationDate: Long? = null, | ||||
| ) | ||||
| ) { | ||||
|     fun toRemoteShare() = RemoteShare( | ||||
|         id = id ?: "0", | ||||
|         shareWith = shareWith.orEmpty(), | ||||
|         path = path.orEmpty(), | ||||
|         token = token.orEmpty(), | ||||
|         sharedWithDisplayName = sharedWithDisplayName.orEmpty(), | ||||
|         sharedWithAdditionalInfo = sharedWithAdditionalInfo.orEmpty(), | ||||
|         name = name.orEmpty(), | ||||
|         shareLink = shareLink.orEmpty(), | ||||
|         shareType = ShareType.values().firstOrNull { it.value == shareType } ?: ShareType.UNKNOWN, | ||||
|         permissions = permissions ?: DEFAULT_PERMISSION, | ||||
|         sharedDate = sharedDate ?: INIT_SHARED_DATE, | ||||
|         expirationDate = expirationDate ?: INIT_EXPIRATION_DATE_IN_MILLIS, | ||||
|         isFolder = path?.endsWith(File.separator) ?: false | ||||
|     ) | ||||
| } | ||||
| @ -22,7 +22,7 @@ package com.owncloud.android.lib.resources.shares.services | ||||
| 
 | ||||
| import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.resources.Service | ||||
| import com.owncloud.android.lib.resources.shares.ShareParserResult | ||||
| import com.owncloud.android.lib.resources.shares.ShareResponse | ||||
| import com.owncloud.android.lib.resources.shares.ShareType | ||||
| 
 | ||||
| interface ShareService : Service { | ||||
| @ -30,7 +30,7 @@ interface ShareService : Service { | ||||
|         remoteFilePath: String, | ||||
|         reshares: Boolean, | ||||
|         subfiles: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> | ||||
|     ): RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|     fun insertShare( | ||||
|         remoteFilePath: String, | ||||
| @ -41,7 +41,7 @@ interface ShareService : Service { | ||||
|         password: String, | ||||
|         expirationDate: Long, | ||||
|         publicUpload: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> | ||||
|     ): RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|     fun updateShare( | ||||
|         remoteId: String, | ||||
| @ -50,7 +50,7 @@ interface ShareService : Service { | ||||
|         expirationDate: Long, | ||||
|         permissions: Int, | ||||
|         publicUpload: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> | ||||
|     ): RemoteOperationResult<ShareResponse> | ||||
| 
 | ||||
|     fun deleteShare(remoteId: String): RemoteOperationResult<ShareParserResult> | ||||
|     fun deleteShare(remoteId: String): RemoteOperationResult<ShareResponse> | ||||
| } | ||||
|  | ||||
| @ -25,7 +25,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult | ||||
| import com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation | ||||
| import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation | ||||
| import com.owncloud.android.lib.resources.shares.RemoveRemoteShareOperation | ||||
| import com.owncloud.android.lib.resources.shares.ShareParserResult | ||||
| import com.owncloud.android.lib.resources.shares.ShareResponse | ||||
| import com.owncloud.android.lib.resources.shares.ShareType | ||||
| import com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation | ||||
| import com.owncloud.android.lib.resources.shares.services.ShareService | ||||
| @ -36,7 +36,7 @@ class OCShareService(override val client: OwnCloudClient) : | ||||
|         remoteFilePath: String, | ||||
|         reshares: Boolean, | ||||
|         subfiles: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> = GetRemoteSharesForFileOperation( | ||||
|     ): RemoteOperationResult<ShareResponse> = GetRemoteSharesForFileOperation( | ||||
|         remoteFilePath, | ||||
|         reshares, | ||||
|         subfiles | ||||
| @ -51,7 +51,7 @@ class OCShareService(override val client: OwnCloudClient) : | ||||
|         password: String, | ||||
|         expirationDate: Long, | ||||
|         publicUpload: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> = | ||||
|     ): RemoteOperationResult<ShareResponse> = | ||||
|         CreateRemoteShareOperation( | ||||
|             remoteFilePath, | ||||
|             shareType, | ||||
| @ -72,7 +72,7 @@ class OCShareService(override val client: OwnCloudClient) : | ||||
|         expirationDate: Long, | ||||
|         permissions: Int, | ||||
|         publicUpload: Boolean | ||||
|     ): RemoteOperationResult<ShareParserResult> = | ||||
|     ): RemoteOperationResult<ShareResponse> = | ||||
|         UpdateRemoteShareOperation( | ||||
|             remoteId | ||||
|         ).apply { | ||||
| @ -84,7 +84,7 @@ class OCShareService(override val client: OwnCloudClient) : | ||||
|             this.retrieveShareDetails = true | ||||
|         }.execute(client) | ||||
| 
 | ||||
|     override fun deleteShare(remoteId: String): RemoteOperationResult<ShareParserResult> = | ||||
|     override fun deleteShare(remoteId: String): RemoteOperationResult<ShareResponse> = | ||||
|         RemoveRemoteShareOperation( | ||||
|             remoteId | ||||
|         ).execute(client) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user