Skip to content

Commit 28adbb5

Browse files
committed
Deactivate twingraph endpoints
- Add usage of useGraphModule in twingraph modules - Change error message returned when useGraphModule is activated
1 parent 72d9211 commit 28adbb5

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

dataset/src/main/kotlin/com/cosmotech/dataset/service/DatasetServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class DatasetServiceImpl(
135135
@Value("\${csm.platform.twincache.useGraphModule}") private var useGraphModule: Boolean = true
136136

137137
private val notImplementedExceptionMessage =
138-
"The API is not configured to use Graph functionnalities. " +
138+
"The API is not configured to use Graph functionalities. " +
139139
"This endpoint is deactivated. " +
140-
"To change that, set the API configuration entry 'csm.platform.twincache.useGraphModule' to true"
140+
"To activate that, set the API configuration correctly."
141141

142142
override fun findAllDatasets(organizationId: String, page: Int?, size: Int?): List<Dataset> {
143143
organizationService.getVerifiedOrganization(organizationId)

twingraph/src/integrationTest/resources/application-twingraph-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ csm:
143143
host: "localhost"
144144
port: "6379"
145145
username: "default"
146+
useGraphModule: true
146147
# Leave it as blank as there's no auth with test container
147148
password:
148149
solution:

twingraph/src/main/kotlin/com/cosmotech/twingraph/api/TwingraphServiceImpl.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import kotlinx.coroutines.launch
3535
import org.apache.commons.compress.archivers.ArchiveStreamFactory
3636
import org.apache.commons.csv.CSVFormat
3737
import org.apache.commons.csv.CSVRecord
38+
import org.apache.commons.lang3.NotImplementedException
39+
import org.springframework.beans.factory.annotation.Value
3840
import org.springframework.core.io.ByteArrayResource
3941
import org.springframework.core.io.Resource
4042
import org.springframework.http.ContentDisposition
@@ -65,7 +67,15 @@ class TwingraphServiceImpl(
6567
private val resourceScanner: ResourceScanner
6668
) : CsmPhoenixService(), TwingraphApiServiceInterface {
6769

70+
@Value("\${csm.platform.twincache.useGraphModule}") private var useGraphModule: Boolean = true
71+
72+
private val notImplementedExceptionMessage =
73+
"The API is not configured to use Graph functionalities. " +
74+
"This endpoint is deactivated. " +
75+
"To activate that, set the API configuration correctly."
76+
6877
override fun createGraph(organizationId: String, graphId: String, body: Resource?) {
78+
checkIfGraphFunctionalityIsAvailable()
6979
val graphList = mutableListOf<String>()
7080
findAllTwingraphs(organizationId).forEach { graphList.add(it.split(":").first()) }
7181
if (graphList.contains(graphId))
@@ -107,6 +117,7 @@ class TwingraphServiceImpl(
107117
}
108118

109119
override fun jobStatus(organizationId: String, jobId: String): String {
120+
checkIfGraphFunctionalityIsAvailable()
110121
val twingraphImportJobInfoRequest = TwingraphImportJobInfoRequest(this, jobId, organizationId)
111122
this.eventPublisher.publishEvent(twingraphImportJobInfoRequest)
112123
logger.debug("TwingraphImportEventResponse={}", twingraphImportJobInfoRequest.response)
@@ -115,12 +126,14 @@ class TwingraphServiceImpl(
115126

116127
@Suppress("SpreadOperator")
117128
override fun delete(organizationId: String, graphId: String) {
129+
checkIfGraphFunctionalityIsAvailable()
118130
organizationService.getVerifiedOrganization(organizationId, PERMISSION_DELETE)
119131
val versions = getRedisKeyList("$graphId:*")
120132
versions.forEach { unifiedJedis.graphDelete(it) }
121133
}
122134

123135
override fun findAllTwingraphs(organizationId: String): List<String> {
136+
checkIfGraphFunctionalityIsAvailable()
124137
organizationService.getVerifiedOrganization(organizationId)
125138
return getRedisKeyList("*")
126139
}
@@ -137,6 +150,7 @@ class TwingraphServiceImpl(
137150
}
138151

139152
override fun getGraphMetaData(organizationId: String, graphId: String): Map<String, String> {
153+
checkIfGraphFunctionalityIsAvailable()
140154
if (unifiedJedis.exists(graphId.toRedisMetaDataKey())) {
141155
return unifiedJedis.hgetAll(graphId.toRedisMetaDataKey())
142156
}
@@ -173,6 +187,7 @@ class TwingraphServiceImpl(
173187
graphId: String,
174188
twinGraphQuery: TwinGraphQuery
175189
): String {
190+
checkIfGraphFunctionalityIsAvailable()
176191
checkTwinGraphPrerequisites(organizationId, graphId, twinGraphQuery, true)
177192
val resultSet =
178193
unifiedJedis.graphQuery(
@@ -187,6 +202,7 @@ class TwingraphServiceImpl(
187202
graphId: String,
188203
requestBody: Map<String, String>
189204
): Any {
205+
checkIfGraphFunctionalityIsAvailable()
190206
organizationService.getVerifiedOrganization(organizationId)
191207

192208
val graphRotation = requestBody[GRAPH_ROTATION]?.toInt()
@@ -208,6 +224,7 @@ class TwingraphServiceImpl(
208224
graphId: String,
209225
twinGraphQuery: TwinGraphQuery
210226
): TwinGraphHash {
227+
checkIfGraphFunctionalityIsAvailable()
211228
checkTwinGraphPrerequisites(organizationId, graphId, twinGraphQuery, true)
212229
val redisGraphKey = redisGraphKey(graphId, twinGraphQuery.version!!)
213230
val bulkQueryKey = bulkQueryKey(graphId, twinGraphQuery.query, twinGraphQuery.version!!)
@@ -233,6 +250,7 @@ class TwingraphServiceImpl(
233250
twinGraphQuery: TwinGraphQuery,
234251
body: Resource
235252
): TwinGraphBatchResult {
253+
checkIfGraphFunctionalityIsAvailable()
236254
checkTwinGraphPrerequisites(organizationId, graphId, twinGraphQuery, false)
237255
resourceScanner.scanMimeTypes(body, listOf("text/csv", "text/plain"))
238256

@@ -275,6 +293,7 @@ class TwingraphServiceImpl(
275293
) = readCSV(inputStream, result) { actionLambda(twinGraphQuery.query.formatQuery(it)) }
276294

277295
override fun downloadGraph(organizationId: String, hash: String): Resource {
296+
checkIfGraphFunctionalityIsAvailable()
278297
organizationService.getVerifiedOrganization(organizationId)
279298

280299
val bulkQueryId = bulkQueryKey(hash)
@@ -301,6 +320,7 @@ class TwingraphServiceImpl(
301320
type: String,
302321
graphProperties: List<GraphProperties>
303322
): String {
323+
checkIfGraphFunctionalityIsAvailable()
304324
var result = ""
305325
updateGraphMetaData(organizationId, graphId, mapOf("lastModifiedDate" to getLocalDateNow()))
306326
when (type) {
@@ -334,6 +354,7 @@ class TwingraphServiceImpl(
334354
type: String,
335355
ids: List<String>
336356
): String {
357+
checkIfGraphFunctionalityIsAvailable()
337358
var result = ""
338359
updateGraphMetaData(organizationId, graphId, mapOf("lastModifiedDate" to getLocalDateNow()))
339360
when (type) {
@@ -366,6 +387,7 @@ class TwingraphServiceImpl(
366387
type: String,
367388
graphProperties: List<GraphProperties>
368389
): String {
390+
checkIfGraphFunctionalityIsAvailable()
369391
var result = ""
370392
updateGraphMetaData(organizationId, graphId, mapOf("lastModifiedDate" to getLocalDateNow()))
371393
when (type) {
@@ -398,6 +420,7 @@ class TwingraphServiceImpl(
398420
type: String,
399421
ids: List<String>
400422
) {
423+
checkIfGraphFunctionalityIsAvailable()
401424
updateGraphMetaData(organizationId, graphId, mapOf("lastModifiedDate" to getLocalDateNow()))
402425
return when (type) {
403426
TYPE_NODE ->
@@ -419,4 +442,10 @@ class TwingraphServiceImpl(
419442
val graphMetadata = getGraphMetaData(organizationId, graphId)
420443
return graphId + ":" + graphMetadata["lastVersion"].toString()
421444
}
445+
446+
private fun checkIfGraphFunctionalityIsAvailable() {
447+
if (!useGraphModule) {
448+
throw NotImplementedException(notImplementedExceptionMessage)
449+
}
450+
}
422451
}

0 commit comments

Comments
 (0)