From fa536ca8bd901dc51833cfe906f7b22846674d2f Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Mon, 16 May 2022 11:09:06 -0400 Subject: Enable deleting resources by lastN occurrences Also enable deletion using resource-type and resource-id. Issue-ID: CCSDK-3735 Signed-off-by: Jozsef Csongvai Signed-off-by: kuldipr Change-Id: Id1b487fce97f582bd3781dfd5bcff61a8df08c5c --- .../resource/api/DeleteResponse.kt | 19 ++++++++++++ .../resource/api/ResourceController.kt | 36 +++++++++++++++++----- 2 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/DeleteResponse.kt (limited to 'ms/blueprintsprocessor/modules/inbounds/resource-api') diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/DeleteResponse.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/DeleteResponse.kt new file mode 100644 index 000000000..0ad5b5e17 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/DeleteResponse.kt @@ -0,0 +1,19 @@ +/* + * Copyright © 2022 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.resource.api + +data class DeleteResponse(val deletedEntries: Int) diff --git a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt index d2b7ac368..dbfc69738 100644 --- a/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt +++ b/ms/blueprintsprocessor/modules/inbounds/resource-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/resource/api/ResourceController.kt @@ -173,25 +173,45 @@ open class ResourceController(private var resourceResolutionDBService: ResourceR notes = "Delete all the resources associated to a resolution-key using blueprint metadata, artifact name and the resolution-key." ) @PreAuthorize("hasRole('USER')") - fun deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey( + suspend fun deleteResolutions( @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 + @RequestParam(value = "artifactName", required = true, defaultValue = "") artifactName: String, + @ApiParam(value = "Resolution Key associated with the resolution", required = false) + @RequestParam(value = "resolutionKey", required = false) resolutionKey: String?, + @ApiParam(value = "resourceType associated with the resolution, must be used with resourceId", required = false) + @RequestParam(value = "resourceType", required = false) resourceType: String?, + @ApiParam(value = "Resolution Key associated with the resolution, must be used with resourceType", required = false) + @RequestParam(value = "resourceId", required = false) resourceId: String?, + @ApiParam(value = "Only delete last N occurrences", required = false) + @RequestParam(value = "lastN", required = false) lastN: Int? ) = runBlocking { - ResponseEntity.ok() - .body( - resourceResolutionDBService.deleteByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKey( + when { + resolutionKey?.isNotEmpty() == true -> resourceResolutionDBService.deleteResources( + bpName, + bpVersion, + artifactName, + resolutionKey, + lastN + ) + resourceId?.isNotEmpty() == true && resourceType?.isNotEmpty() == true -> + resourceResolutionDBService.deleteResources( bpName, bpVersion, artifactName, - resolutionKey + resourceType, + resourceId, + lastN ) + else -> throw httpProcessorException( + ErrorCatalogCodes.REQUEST_NOT_FOUND, + ResourceApiDomains.RESOURCE_API, + "Either use resolutionKey or resourceType + resourceId. Values cannot be blank" ) + }.let { ResponseEntity.ok().body(DeleteResponse(it)) } } @RequestMapping( -- cgit 1.2.3-korg