@@ -35,6 +35,8 @@ import kotlinx.coroutines.launch
3535import org.apache.commons.compress.archivers.ArchiveStreamFactory
3636import org.apache.commons.csv.CSVFormat
3737import org.apache.commons.csv.CSVRecord
38+ import org.apache.commons.lang3.NotImplementedException
39+ import org.springframework.beans.factory.annotation.Value
3840import org.springframework.core.io.ByteArrayResource
3941import org.springframework.core.io.Resource
4042import 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