Skip to content

Commit bb924d7

Browse files
Add remote operations for governance.
Assisted-by: ClaudeCode:claude-sonnet-4-6 Assisted-by: Copilot:claude-sonnet-4-6 Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 5621965 commit bb924d7

22 files changed

Lines changed: 899 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
data class EntityLabels(
11+
val sensitivity: List<SensitivityLabelInfo>,
12+
val retention: List<RetentionLabelInfo>,
13+
val hold: List<HoldLabelInfo>
14+
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
class GetAllSelectableLabelsRemoteOperation(
20+
private val entityType: String,
21+
private val entityId: Long
22+
) : OCSRemoteOperation<EntityLabels>() {
23+
@Suppress("TooGenericExceptionCaught")
24+
override fun run(client: NextcloudClient): RemoteOperationResult<EntityLabels> {
25+
var result: RemoteOperationResult<EntityLabels>
26+
var getMethod: GetMethod? = null
27+
try {
28+
getMethod =
29+
GetMethod(
30+
client.baseUri.toString() + ENDPOINT + entityType + "/" + entityId + AVAILABLE + JSON_FORMAT,
31+
true
32+
)
33+
val status = client.execute(getMethod)
34+
if (status == HttpStatus.SC_OK) {
35+
val labels =
36+
getServerResponse(
37+
getMethod,
38+
object : TypeToken<ServerResponse<EntityLabels>>() {}
39+
)?.ocs?.data
40+
41+
if (labels != null) {
42+
result = RemoteOperationResult(true, getMethod)
43+
result.setResultData(labels)
44+
} else {
45+
result = RemoteOperationResult(false, getMethod)
46+
}
47+
} else {
48+
result = RemoteOperationResult(false, getMethod)
49+
}
50+
} catch (e: Exception) {
51+
result = RemoteOperationResult(e)
52+
Log_OC.e(TAG, "Get all selectable labels failed: " + result.logMessage, result.exception)
53+
} finally {
54+
getMethod?.releaseConnection()
55+
}
56+
return result
57+
}
58+
59+
companion object {
60+
private val TAG = GetAllSelectableLabelsRemoteOperation::class.java.simpleName
61+
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
62+
private const val AVAILABLE = "/available"
63+
}
64+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
/**
20+
* Get the hold labels the user may apply to an entity
21+
*/
22+
class GetAvailableHoldLabelsRemoteOperation(
23+
private val entityType: String,
24+
private val entityId: Long
25+
) : OCSRemoteOperation<List<HoldLabelInfo>>() {
26+
@Suppress("TooGenericExceptionCaught")
27+
override fun run(client: NextcloudClient): RemoteOperationResult<List<HoldLabelInfo>> {
28+
var result: RemoteOperationResult<List<HoldLabelInfo>>
29+
var getMethod: GetMethod? = null
30+
try {
31+
getMethod =
32+
GetMethod(
33+
client.baseUri.toString() + ENDPOINT + entityType + "/" + entityId +
34+
HOLD_AVAILABLE + JSON_FORMAT,
35+
true
36+
)
37+
val status = client.execute(getMethod)
38+
if (status == HttpStatus.SC_OK) {
39+
val labels =
40+
getServerResponse(
41+
getMethod,
42+
object : TypeToken<ServerResponse<List<HoldLabelInfo>>>() {}
43+
)?.ocs?.data
44+
45+
if (labels != null) {
46+
result = RemoteOperationResult(true, getMethod)
47+
result.setResultData(labels)
48+
} else {
49+
result = RemoteOperationResult(false, getMethod)
50+
}
51+
} else {
52+
result = RemoteOperationResult(false, getMethod)
53+
}
54+
} catch (e: Exception) {
55+
result = RemoteOperationResult(e)
56+
Log_OC.e(
57+
TAG,
58+
"Get available hold labels failed: " + result.logMessage,
59+
result.exception
60+
)
61+
} finally {
62+
getMethod?.releaseConnection()
63+
}
64+
return result
65+
}
66+
67+
companion object {
68+
private val TAG = GetAvailableHoldLabelsRemoteOperation::class.java.simpleName
69+
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
70+
private const val HOLD_AVAILABLE = "/hold/available"
71+
}
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
/**
20+
* Get the retention labels the user may apply to an entity
21+
*/
22+
class GetAvailableRetentionLabelsRemoteOperation(
23+
private val entityType: String,
24+
private val entityId: Long
25+
) : OCSRemoteOperation<List<RetentionLabelInfo>>() {
26+
@Suppress("TooGenericExceptionCaught")
27+
override fun run(client: NextcloudClient): RemoteOperationResult<List<RetentionLabelInfo>> {
28+
var result: RemoteOperationResult<List<RetentionLabelInfo>>
29+
var getMethod: GetMethod? = null
30+
try {
31+
getMethod =
32+
GetMethod(
33+
client.baseUri.toString() + ENDPOINT + entityType + "/" + entityId +
34+
RETENTION_AVAILABLE + JSON_FORMAT,
35+
true
36+
)
37+
val status = client.execute(getMethod)
38+
if (status == HttpStatus.SC_OK) {
39+
val labels =
40+
getServerResponse(
41+
getMethod,
42+
object : TypeToken<ServerResponse<List<RetentionLabelInfo>>>() {}
43+
)?.ocs?.data
44+
45+
if (labels != null) {
46+
result = RemoteOperationResult(true, getMethod)
47+
result.setResultData(labels)
48+
} else {
49+
result = RemoteOperationResult(false, getMethod)
50+
}
51+
} else {
52+
result = RemoteOperationResult(false, getMethod)
53+
}
54+
} catch (e: Exception) {
55+
result = RemoteOperationResult(e)
56+
Log_OC.e(
57+
TAG,
58+
"Get available retention labels failed: " + result.logMessage,
59+
result.exception
60+
)
61+
} finally {
62+
getMethod?.releaseConnection()
63+
}
64+
return result
65+
}
66+
67+
companion object {
68+
private val TAG = GetAvailableRetentionLabelsRemoteOperation::class.java.simpleName
69+
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
70+
private const val RETENTION_AVAILABLE = "/retention/available"
71+
}
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
/**
20+
* Get the sensitivity labels the user may apply to an entity
21+
*/
22+
class GetAvailableSensitivityLabelsRemoteOperation(
23+
private val entityType: String,
24+
private val entityId: Long
25+
) : OCSRemoteOperation<List<SensitivityLabelInfo>>() {
26+
@Suppress("TooGenericExceptionCaught")
27+
override fun run(client: NextcloudClient): RemoteOperationResult<List<SensitivityLabelInfo>> {
28+
var result: RemoteOperationResult<List<SensitivityLabelInfo>>
29+
var getMethod: GetMethod? = null
30+
try {
31+
getMethod =
32+
GetMethod(
33+
client.baseUri.toString() + ENDPOINT + entityType + "/" + entityId +
34+
SENSITIVITY_AVAILABLE + JSON_FORMAT,
35+
true
36+
)
37+
val status = client.execute(getMethod)
38+
if (status == HttpStatus.SC_OK) {
39+
val labels =
40+
getServerResponse(
41+
getMethod,
42+
object : TypeToken<ServerResponse<List<SensitivityLabelInfo>>>() {}
43+
)?.ocs?.data
44+
45+
if (labels != null) {
46+
result = RemoteOperationResult(true, getMethod)
47+
result.setResultData(labels)
48+
} else {
49+
result = RemoteOperationResult(false, getMethod)
50+
}
51+
} else {
52+
result = RemoteOperationResult(false, getMethod)
53+
}
54+
} catch (e: Exception) {
55+
result = RemoteOperationResult(e)
56+
Log_OC.e(
57+
TAG,
58+
"Get available sensitivity labels failed: " + result.logMessage,
59+
result.exception
60+
)
61+
} finally {
62+
getMethod?.releaseConnection()
63+
}
64+
return result
65+
}
66+
67+
companion object {
68+
private val TAG = GetAvailableSensitivityLabelsRemoteOperation::class.java.simpleName
69+
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
70+
private const val SENSITIVITY_AVAILABLE = "/sensitivity/available"
71+
}
72+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
import com.google.gson.reflect.TypeToken
11+
import com.nextcloud.common.NextcloudClient
12+
import com.nextcloud.operations.GetMethod
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import com.owncloud.android.lib.ocs.ServerResponse
16+
import com.owncloud.android.lib.resources.OCSRemoteOperation
17+
import org.apache.commons.httpclient.HttpStatus
18+
19+
/**
20+
* Get all labels applied to an entity, grouped by type, filtered to those visible to the calling user
21+
*/
22+
class GetEntityLabelsRemoteOperation(
23+
private val entityType: String,
24+
private val entityId: String
25+
) : OCSRemoteOperation<EntityLabels>() {
26+
@Suppress("TooGenericExceptionCaught")
27+
override fun run(client: NextcloudClient): RemoteOperationResult<EntityLabels> {
28+
var result: RemoteOperationResult<EntityLabels>
29+
var getMethod: GetMethod? = null
30+
try {
31+
getMethod =
32+
GetMethod(
33+
client.baseUri.toString() + ENDPOINT + entityType + "/" + entityId + JSON_FORMAT,
34+
true
35+
)
36+
val status = client.execute(getMethod)
37+
if (status == HttpStatus.SC_OK) {
38+
val entityLabels =
39+
getServerResponse(
40+
getMethod,
41+
object : TypeToken<ServerResponse<EntityLabels>>() {}
42+
)?.ocs?.data
43+
44+
if (entityLabels != null) {
45+
result = RemoteOperationResult(true, getMethod)
46+
result.setResultData(entityLabels)
47+
} else {
48+
result = RemoteOperationResult(false, getMethod)
49+
}
50+
} else {
51+
result = RemoteOperationResult(false, getMethod)
52+
}
53+
} catch (e: Exception) {
54+
result = RemoteOperationResult(e)
55+
Log_OC.e(
56+
TAG,
57+
"Get entity labels failed: " + result.logMessage,
58+
result.exception
59+
)
60+
} finally {
61+
getMethod?.releaseConnection()
62+
}
63+
return result
64+
}
65+
66+
companion object {
67+
private val TAG = GetEntityLabelsRemoteOperation::class.java.simpleName
68+
private const val ENDPOINT = "/ocs/v2.php/apps/governance/v1/labels/"
69+
}
70+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.nextcloud.android.lib.resources.governance
9+
10+
data class GovernanceLabelResponse(
11+
val message: String
12+
)

0 commit comments

Comments
 (0)