Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ buildscript {
classpath 'com.android.tools.build:gradle:9.2.1'
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.5.9'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8"
classpath "org.jacoco:org.jacoco.core:$jacoco_version"
classpath "org.jacoco:org.jacoco.report:$jacoco_version"
Expand All @@ -35,6 +36,7 @@ plugins {
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'org.jetbrains.kotlin.plugin.serialization'
apply from: "$rootProject.projectDir/jacoco.gradle"
apply plugin: "com.github.spotbugs"
apply plugin: 'io.gitlab.arturbosch.detekt'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.EntityLabels
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.OcsKotlinResponse
import com.owncloud.android.lib.ocs.SEPARATOR
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class GetAllSelectableLabelsRemoteOperation(
private val entityType: String,
private val entityId: Long
) : OCSRemoteOperation<EntityLabels>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<EntityLabels> {
val getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId + AVAILABLE + JSON_FORMAT,
true
)
return try {
val status = client.execute(getMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, getMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<EntityLabels>>(
getMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<EntityLabels>(true, getMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
getMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<EntityLabels> =
RemoteOperationResult<EntityLabels>(e).also {
Log_OC.e(TAG, "Get all selectable labels failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = GetAllSelectableLabelsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
private const val AVAILABLE = "/available"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.HoldLabelInfo
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.OcsKotlinResponse
import com.owncloud.android.lib.ocs.SEPARATOR
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class GetAvailableHoldLabelsRemoteOperation(
private val entityType: String,
private val entityId: Long
) : OCSRemoteOperation<List<HoldLabelInfo>>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<List<HoldLabelInfo>> {
val getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId +
HOLD_AVAILABLE + JSON_FORMAT,
true
)
return try {
val status = client.execute(getMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, getMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<List<HoldLabelInfo>>>(
getMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<List<HoldLabelInfo>>(true, getMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
getMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<List<HoldLabelInfo>> =
RemoteOperationResult<List<HoldLabelInfo>>(e).also {
Log_OC.e(TAG, "Get available hold labels failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = GetAvailableHoldLabelsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
private const val HOLD_AVAILABLE = "/hold/available"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.RetentionLabelInfo
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.OcsKotlinResponse
import com.owncloud.android.lib.ocs.SEPARATOR
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class GetAvailableRetentionLabelsRemoteOperation(
Comment thread
alperozturk96 marked this conversation as resolved.
private val entityType: String,
private val entityId: Long
) : OCSRemoteOperation<List<RetentionLabelInfo>>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<List<RetentionLabelInfo>> {
val getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId +
RETENTION_AVAILABLE + JSON_FORMAT,
true
)
return try {
val status = client.execute(getMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, getMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<List<RetentionLabelInfo>>>(
getMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<List<RetentionLabelInfo>>(true, getMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
getMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<List<RetentionLabelInfo>> =
RemoteOperationResult<List<RetentionLabelInfo>>(e).also {
Log_OC.e(TAG, "Get available retention labels failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = GetAvailableRetentionLabelsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
private const val RETENTION_AVAILABLE = "/retention/available"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.SensitivityLabelInfo
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.OcsKotlinResponse
import com.owncloud.android.lib.ocs.SEPARATOR
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class GetAvailableSensitivityLabelsRemoteOperation(
Comment thread
alperozturk96 marked this conversation as resolved.
private val entityType: String,
private val entityId: Long
) : OCSRemoteOperation<List<SensitivityLabelInfo>>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<List<SensitivityLabelInfo>> {
val getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId +
SENSITIVITY_AVAILABLE + JSON_FORMAT,
true
)
return try {
val status = client.execute(getMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, getMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<List<SensitivityLabelInfo>>>(
getMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<List<SensitivityLabelInfo>>(true, getMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
getMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<List<SensitivityLabelInfo>> =
RemoteOperationResult<List<SensitivityLabelInfo>>(e).also {
Log_OC.e(TAG, "Get available sensitivity labels failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = GetAvailableSensitivityLabelsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
private const val SENSITIVITY_AVAILABLE = "/sensitivity/available"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.EntityLabels
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.OcsKotlinResponse
import com.owncloud.android.lib.ocs.SEPARATOR
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class GetEntityLabelsRemoteOperation(
Comment thread
alperozturk96 marked this conversation as resolved.
private val entityType: String,
private val entityId: String
) : OCSRemoteOperation<EntityLabels>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<EntityLabels> {
val getMethod =
GetMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId + JSON_FORMAT,
true
)
return try {
val status = client.execute(getMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, getMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<EntityLabels>>(
getMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<EntityLabels>(true, getMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
getMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<EntityLabels> =
RemoteOperationResult<EntityLabels>(e).also {
Log_OC.e(TAG, "Get entity labels failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = GetEntityLabelsRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: MIT
*/

package com.nextcloud.android.lib.resources.governance

import com.nextcloud.android.lib.resources.governance.model.GovernanceLabelResponse
import com.nextcloud.android.lib.resources.governance.model.LabelType
import com.nextcloud.common.NextcloudClient
import com.nextcloud.operations.DeleteMethod
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.ocs.OcsKotlinResponse
import com.owncloud.android.lib.ocs.ocsJson
import com.owncloud.android.lib.resources.OCSRemoteOperation
import org.apache.commons.httpclient.HttpStatus

class RemoveLabelRemoteOperation(
Comment thread
alperozturk96 marked this conversation as resolved.
private val entityType: String,
private val entityId: Long,
private val labelType: LabelType,
private val labelId: String
) : OCSRemoteOperation<GovernanceLabelResponse>() {
@Suppress("TooGenericExceptionCaught")
override fun run(client: NextcloudClient): RemoteOperationResult<GovernanceLabelResponse> {
val deleteMethod =
DeleteMethod(
client.baseUri.toString() + ENDPOINT + entityType + SEPARATOR + entityId + SEPARATOR +
labelType.value + SEPARATOR + labelId + JSON_FORMAT,
true
)
return try {
val status = client.execute(deleteMethod)
if (status != HttpStatus.SC_OK) {
return RemoteOperationResult(false, deleteMethod)
}
val response =
ocsJson.decodeFromString<OcsKotlinResponse<GovernanceLabelResponse>>(
deleteMethod.getResponseBodyAsString()
)
val data = response.ocs.data
RemoteOperationResult<GovernanceLabelResponse>(true, deleteMethod).apply { resultData = data }
} catch (e: Exception) {
failure(e)
} finally {
deleteMethod.releaseConnection()
}
}

@Suppress("DEPRECATION")
private fun failure(e: Exception): RemoteOperationResult<GovernanceLabelResponse> =
RemoteOperationResult<GovernanceLabelResponse>(e).also {
Log_OC.e(TAG, "Remove label from entity failed: " + it.logMessage, it.exception)
}

companion object {
private val TAG = RemoveLabelRemoteOperation::class.java.simpleName
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
private const val SEPARATOR = "/"
}
}
Loading
Loading