67869d11f148a0deac141a1d53edebe1a58db251
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 Bell Canada.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.repository
19
20 import com.fasterxml.jackson.databind.JsonNode
21 import org.jetbrains.annotations.NotNull
22 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain.BlueprintModel
23 import org.springframework.data.jpa.repository.JpaRepository
24 import org.springframework.data.jpa.repository.Query
25 import org.springframework.data.repository.query.Param
26 import org.springframework.stereotype.Repository
27 import java.util.Optional
28 import javax.transaction.Transactional
29
30 /**
31  * @param <T> Model
32  */
33 @Repository
34 interface BlueprintModelRepository : JpaRepository<BlueprintModel, String> {
35
36     /**
37      * This is a findById method
38      *
39      * @param id id
40      * @return Optional<T>
41      */
42     override fun findById(id: String): Optional<BlueprintModel>
43
44     /**
45      * This is a findByArtifactNameAndArtifactVersion method
46      *
47      * @param artifactName artifactName
48      * @param artifactVersion artifactVersion
49      * @return T?
50      */
51     fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): BlueprintModel?
52
53     /**
54      *  Find the Blueprint UUID (blueprint_model_id) for a given artifactName/Version
55      *
56      * @param artifactName artifactName
57      * @param artifactVersion artifactVersion
58      * @return String?
59      */
60     @Query("SELECT m.id FROM BlueprintModel m WHERE m.artifactName = :artifactName AND m.artifactVersion = :artifactVersion")
61     fun findIdByArtifactNameAndArtifactVersion(@Param("artifactName") artifactName: String, @Param("artifactVersion") artifactVersion: String): String?
62
63     /**
64      * Find the workflows for a given blueprint name/version
65      * @param artifactName artifactName
66      * @param artifactVersion artifactVersion
67      * @return String?
68      */
69     @Query("SELECT m.workflows from BlueprintModel m WHERE m.artifactName = :artifactName AND m.artifactVersion = :artifactVersion")
70     fun findWorkflowsByArtifactNameAndArtifactVersion(@Param("artifactName") artifactName: String, @Param("artifactVersion") artifactVersion: String): JsonNode?
71
72     /**
73      * This is a findTopByArtifactNameOrderByArtifactIdDesc method
74      *
75      * @param artifactName artifactName
76      * @return T?
77      */
78     fun findTopByArtifactNameOrderByArtifactVersionDesc(artifactName: String): BlueprintModel?
79
80     /**
81      * This is a findTopByArtifactName method
82      *
83      * @param artifactName artifactName
84      * @return List<T>
85      */
86     fun findTopByArtifactName(artifactName: String): List<BlueprintModel>
87
88     /**
89      * This is a findByTagsContainingIgnoreCase method
90      *
91      * @param tags tags
92      * @return List<T>
93      */
94     fun findByTagsContainingIgnoreCase(tags: String): List<BlueprintModel>
95
96     /**
97      * This is a deleteByArtifactNameAndArtifactVersion method
98      *
99      * @param artifactName artifactName
100      * @param artifactVersion artifactVersion
101      */
102     @Transactional
103     fun deleteByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String)
104
105     /**
106      * This is a deleteById method
107      *
108      * @param id id
109      */
110     override fun deleteById(@NotNull id: String)
111 }