3df6137454645908f6976e1f5bc2f0a83cc2ad66
[ccsdk/cds.git] /
1 /*
2  * Copyright (C) 2019 Bell Canada.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
17
18 import org.springframework.data.jpa.repository.JpaRepository
19 import org.springframework.data.jpa.repository.Query
20 import org.springframework.data.repository.query.Param
21 import org.springframework.stereotype.Repository
22 import javax.transaction.Transactional
23
24 @Repository
25 interface TemplateResolutionRepository : JpaRepository<TemplateResolution, String> {
26
27     fun findByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
28         resourceId: String,
29         resourceType: String,
30         blueprintName: String?,
31         blueprintVersion: String?,
32         artifactName: String,
33         occurrence: Int
34     ): TemplateResolution?
35
36     fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
37         key: String,
38         blueprintName: String?,
39         blueprintVersion: String?,
40         artifactName: String,
41         occurrence: Int
42     ): TemplateResolution?
43
44     @Query(
45         "select tr.resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.artifactName = :artifactName and tr.occurrence = :occurrence"
46     )
47     fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
48         @Param("blueprintName") blueprintName: String?,
49         @Param("blueprintVersion") blueprintVersion: String?,
50         @Param("artifactName") artifactName: String,
51         @Param("occurrence") occurrence: Int
52     ): List<String>?
53
54     @Query(
55         "select tr.artifactName as artifactName, tr.resolutionKey as resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.occurrence = :occurrence"
56     )
57     fun findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersionAndOccurrence(
58         @Param("blueprintName") blueprintName: String?,
59         @Param("blueprintVersion") blueprintVersion: String?,
60         @Param("occurrence") occurrence: Int
61     ): List<TemplateResolutionSelector>?
62
63     @Transactional
64     fun deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
65         resourceId: String,
66         resourceType: String,
67         blueprintName: String?,
68         blueprintVersion: String?,
69         artifactName: String,
70         occurrence: Int
71     )
72
73     @Transactional
74     fun deleteByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
75         key: String,
76         blueprintName: String?,
77         blueprintVersion: String?,
78         artifactName: String,
79         occurrence: Int
80     )
81 }