add a rest endpoint to remove resources 67/103067/4
authorJulien Fontaine <julien.fontaine@bell.ca>
Wed, 4 Mar 2020 21:09:26 +0000 (16:09 -0500)
committerKAPIL SINGAL <ks220y@att.com>
Mon, 9 Mar 2020 14:15:44 +0000 (14:15 +0000)
Issue-ID: CCSDK-2159
Signed-off-by: Julien Fontaine <julien.fontaine@bell.ca>
Change-Id: I504fa0aad6f4e7105a53e793d08d08d92bbb8df4

ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBServiceTest.kt
ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt

index f8bf7bd..dc15537 100644 (file)
@@ -198,4 +198,27 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
             throw BluePrintException("Failed to store resource resolution result.", ex)
         }
     }
+
+    /**
+     * This is a deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey method to delete resources
+     * associated to a specific resolution-key
+     *
+     * @param blueprintName name of the CBA
+     * @param blueprintVersion version of the CBA
+     * @param artifactName name of the artifact
+     * @param resolutionKey value of the resolution-key
+     */
+    suspend fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+        blueprintName: String,
+        blueprintVersion: String,
+        artifactName: String,
+        resolutionKey: String
+    ) {
+        resourceResolutionRepository.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+                blueprintName,
+                blueprintVersion,
+                artifactName,
+                resolutionKey
+        )
+    }
 }
index a2a3a75..c2d630e 100644 (file)
@@ -17,6 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
 
 import org.springframework.data.jpa.repository.JpaRepository
 import org.springframework.stereotype.Repository
+import javax.transaction.Transactional
 
 @Repository
 interface ResourceResolutionRepository : JpaRepository<ResourceResolution, String> {
@@ -59,4 +60,12 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
         resourceType: String,
         occurrence: Int
     ): List<ResourceResolution>
+
+    @Transactional
+    fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+        blueprintName: String?,
+        blueprintVersion: String?,
+        artifactName: String,
+        resolutionKey: String
+    )
 }
index 4f864a4..e667cd1 100644 (file)
@@ -223,4 +223,16 @@ open class ResourceResolutionDBServiceTest {
             assertEquals(resourceResolution, res)
         }
     }
+
+    @Test
+    fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyTest() {
+        every {
+            resourceResolutionRepository.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(any(), any(), any(), any())
+        } returns Unit
+        runBlocking {
+            val res = resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+                    blueprintName, blueprintVersion, artifactPrefix, resolutionKey)
+            assertEquals(Unit, res)
+        }
+    }
 }
index b49ca68..264cd23 100644 (file)
@@ -102,6 +102,28 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR
         }
     }
 
+    @RequestMapping(
+            path = [""],
+            method = [RequestMethod.DELETE], produces = [MediaType.APPLICATION_JSON_VALUE]
+    )
+    @ApiOperation(value = "Delete resources using resolution key",
+            notes = "Delete all the resources associated to a resolution-key using blueprint metadata, artifact name and the resolution-key.",
+            produces = MediaType.APPLICATION_JSON_VALUE)
+    @PreAuthorize("hasRole('USER')")
+    fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(
+        @ApiParam(value = "Name of the CBA.", required = true)
+        @RequestParam(value = "bpName", required = true) bpName: String,
+        @ApiParam(value = "Version of the CBA.", required = true)
+        @RequestParam(value = "bpVersion", required = true) bpVersion: String,
+        @ApiParam(value = "Artifact name for which to retrieve a resolved resource.", required = true)
+        @RequestParam(value = "artifactName", required = false, defaultValue = "") artifactName: String,
+        @ApiParam(value = "Resolution Key associated with the resolution.", required = true)
+        @RequestParam(value = "resolutionKey", required = true) resolutionKey: String
+    ) = runBlocking {
+        ResponseEntity.ok()
+                .body(resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey(bpName, bpVersion, artifactName, resolutionKey))
+    }
+
     @RequestMapping(
         path = ["/resource"],
         method = [RequestMethod.GET],