Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e399f10c authored by Tobias Kaminsky's avatar Tobias Kaminsky Committed by GitHub
Browse files

Merge pull request #1605 from nextcloud/recommendations

retrieve recommendations
parents 1a8e497c 142588cb
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -111,6 +111,8 @@ services:
      - su www-data -c "php /var/www/html/occ app:enable -f testing"
      - su www-data -c "php /var/www/html/occ app:enable -f testing"
      - su www-data -c "git clone --depth 1 https://github.com/nextcloud/files_downloadlimit.git /var/www/html/apps/files_downloadlimit/"
      - su www-data -c "git clone --depth 1 https://github.com/nextcloud/files_downloadlimit.git /var/www/html/apps/files_downloadlimit/"
      - su www-data -c "php /var/www/html/occ app:enable -f files_downloadlimit"
      - su www-data -c "php /var/www/html/occ app:enable -f files_downloadlimit"
      - su www-data -c "git clone --depth 1 -b master https://github.com/nextcloud/recommendations.git /var/www/html/apps/recommendations/"
      - su www-data -c "php /var/www/html/occ app:enable -f recommendations"
      - /usr/local/bin/run.sh
      - /usr/local/bin/run.sh


trigger:
trigger:
@@ -228,6 +230,8 @@ services:
      - su www-data -c "php /var/www/html/occ app:enable -f testing"
      - su www-data -c "php /var/www/html/occ app:enable -f testing"
      - su www-data -c "git clone --depth 1 -b $SERVER_VERSION https://github.com/nextcloud/files_downloadlimit.git /var/www/html/apps/files_downloadlimit/"
      - su www-data -c "git clone --depth 1 -b $SERVER_VERSION https://github.com/nextcloud/files_downloadlimit.git /var/www/html/apps/files_downloadlimit/"
      - su www-data -c "php /var/www/html/occ app:enable -f files_downloadlimit"
      - su www-data -c "php /var/www/html/occ app:enable -f files_downloadlimit"
      - su www-data -c "git clone --depth 1 -b $SERVER_VERSION https://github.com/nextcloud/recommendations.git /var/www/html/apps/recommendations/"
      - su www-data -c "php /var/www/html/occ app:enable recommendations"
      - /usr/local/bin/run.sh
      - /usr/local/bin/run.sh


trigger:
trigger:
@@ -239,6 +243,6 @@ trigger:
    - pull_request
    - pull_request
---
---
kind: signature
kind: signature
hmac: fe00fcbb3bf41f6aa84193e380345c3b009ef933d295dda86ea3c959a8373381
hmac: f9e2219ba5004d6abb6eb04ede0dedf0b9d5f20d8769228c1e48a09451a54b06


...
...
+27 −0
Original line number Original line Diff line number Diff line
/*
 * Nextcloud Android Library
 *
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2024 Tobias Kaminsky <tobias@kaminsky.me>
 * SPDX-License-Identifier: MIT
 */
package com.nextcloud.android.lib.resources.recommendations

import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
import com.owncloud.android.lib.resources.status.NextcloudVersion
import org.junit.Assert.assertTrue
import org.junit.Test

class GetRecommendationsRemoteOperationIT : AbstractIT() {
    @Test
    fun getRecommendations() {
        testOnlyOnServer(NextcloudVersion.nextcloud_31)
        assertTrue(CreateFolderRemoteOperation("/test/", true).execute(client).isSuccess)

        val result = GetRecommendationsRemoteOperation().execute(nextcloudClient).resultData

        assertTrue(result.enabled)
        assertTrue(result.recommendations.isNotEmpty())
    }
}
+12 −7
Original line number Original line Diff line number Diff line
@@ -9,6 +9,13 @@
 */
 */
package com.owncloud.android;
package com.owncloud.android;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
import com.owncloud.android.lib.resources.status.E2EVersion;
import com.owncloud.android.lib.resources.status.E2EVersion;
@@ -19,13 +26,6 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;


import org.junit.Test;
import org.junit.Test;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

/**
/**
 * Class to test GetRemoteCapabilitiesOperation
 * Class to test GetRemoteCapabilitiesOperation
 */
 */
@@ -154,5 +154,10 @@ public class GetCapabilitiesRemoteOperationIT extends AbstractIT {


        // e2e
        // e2e
        assertNotSame(capability.getEndToEndEncryptionApiVersion(), E2EVersion.UNKNOWN);
        assertNotSame(capability.getEndToEndEncryptionApiVersion(), E2EVersion.UNKNOWN);

        // recommendations
        if (capability.getVersion().isNewerOrEqual(NextcloudVersion.nextcloud_31)) {
            assertTrue(capability.getRecommendations().isTrue());
        }
    }
    }
}
}
+67 −0
Original line number Original line Diff line number Diff line
/*
 * Nextcloud Android Library
 *
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2024 Tobias Kaminsky <tobias@kaminsky.me>
 * SPDX-License-Identifier: MIT
 */
package com.nextcloud.android.lib.resources.recommendations

import com.google.gson.reflect.TypeToken
import com.nextcloud.common.NextcloudClient
import com.nextcloud.operations.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.ServerResponse
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

/**
 * Get recommendation of an user
 */
class GetRecommendationsRemoteOperation : OCSRemoteOperation<RecommendationResponse>() {
    @Suppress("TooGenericExceptionCaught")
    override fun run(client: NextcloudClient): RemoteOperationResult<RecommendationResponse> {
        var result: RemoteOperationResult<RecommendationResponse>
        var getMethod: GetMethod? = null
        try {
            getMethod =
                GetMethod(
                    client.baseUri.toString() + ENDPOINT + JSON_FORMAT,
                    true
                )
            val status = client.execute(getMethod)
            if (status == HttpStatus.SC_OK) {
                val map =
                    getServerResponse(
                        getMethod,
                        object : TypeToken<ServerResponse<RecommendationResponse>>() {}
                    )?.ocs?.data

                if (map != null) {
                    result = RemoteOperationResult(true, getMethod)
                    result.setResultData(map)
                } else {
                    result = RemoteOperationResult(false, getMethod)
                }
            } else {
                result = RemoteOperationResult(false, getMethod)
            }
        } catch (e: Exception) {
            result = RemoteOperationResult(e)
            Log_OC.e(
                TAG,
                "Get recommendations failed: " + result.logMessage,
                result.exception
            )
        } finally {
            getMethod?.releaseConnection()
        }
        return result
    }

    companion object {
        private val TAG = GetRecommendationsRemoteOperation::class.java.simpleName
        private const val ENDPOINT = "/ocs/v2.php/apps/recommendations/api/v1/recommendations"
    }
}
+20 −0
Original line number Original line Diff line number Diff line
/*
 * Nextcloud Android Library
 *
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2024 Tobias Kaminsky <tobias@kaminsky.me>
 * SPDX-License-Identifier: MIT
 */

package com.nextcloud.android.lib.resources.recommendations

data class Recommendation(
    val id: Long,
    val timestamp: Long,
    val name: String,
    val directory: String,
    val extension: String,
    val mimeType: String,
    val hasPreview: Boolean,
    val reason: String
)
Loading