Formatting Code base with ktlint
[ccsdk/cds.git] / ms / blueprintsprocessor / functions / message-prioritizaion / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / functions / message / prioritization / db / PrioritizationMessageRepository.kt
1 /*
2  * Copyright © 2018-2019 AT&T Intellectual Property.
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
17 package org.onap.ccsdk.cds.blueprintsprocessor.functions.message.prioritization.db
18
19 import org.springframework.data.domain.Pageable
20 import org.springframework.data.jpa.repository.JpaRepository
21 import org.springframework.data.jpa.repository.Modifying
22 import org.springframework.data.jpa.repository.Query
23 import org.springframework.stereotype.Repository
24 import org.springframework.transaction.annotation.Transactional
25 import java.util.Date
26
27 @Repository
28 @Transactional(readOnly = true)
29 interface PrioritizationMessageRepository : JpaRepository<MessagePrioritization, String> {
30
31     @Query("FROM MessagePrioritization pm WHERE pm.group = :group ORDER BY pm.createdDate asc")
32     fun findByGroup(group: String, count: Pageable): List<MessagePrioritization>?
33
34     @Query(
35         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
36                 "ORDER BY pm.createdDate asc"
37     )
38     fun findByGroupAndStateIn(group: String, states: List<String>, count: Pageable): List<MessagePrioritization>?
39
40     @Query(
41         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
42                 "ORDER BY pm.updatedDate asc"
43     )
44     fun findByGroupAndStateInOrderByUpdatedDate(group: String, states: List<String>, count: Pageable):
45             List<MessagePrioritization>?
46
47     @Query(
48         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
49                 "AND pm.expiryDate > :expiryCheckDate ORDER BY pm.createdDate asc"
50     )
51     fun findByGroupAndStateInAndNotExpiredDate(
52         group: String,
53         states: List<String>,
54         expiryCheckDate: Date,
55         count: Pageable
56     ): List<MessagePrioritization>?
57
58     @Query(
59         "FROM MessagePrioritization pm WHERE pm.state in :states " +
60                 "AND pm.expiryDate < :expiryCheckDate ORDER BY pm.createdDate asc"
61     )
62     fun findByStateInAndExpiredDate(
63         states: List<String>,
64         expiryCheckDate: Date,
65         count: Pageable
66     ): List<MessagePrioritization>?
67
68     @Query(
69         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
70                 "AND pm.expiryDate < :expiryCheckDate ORDER BY pm.createdDate asc"
71     )
72     fun findByGroupAndStateInAndExpiredDate(
73         group: String,
74         states: List<String>,
75         expiryCheckDate: Date,
76         count: Pageable
77     ): List<MessagePrioritization>?
78
79     @Query(
80         "FROM MessagePrioritization pm WHERE pm.group = :group " +
81                 "AND pm.expiryDate < :expiryCheckDate ORDER BY pm.createdDate asc"
82     )
83     fun findByByGroupAndExpiredDate(group: String, expiryCheckDate: Date, count: Pageable): List<MessagePrioritization>?
84
85     @Query(
86         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
87                 "AND pm.correlationId = :correlationId ORDER BY pm.createdDate asc"
88     )
89     fun findByGroupAndCorrelationId(group: String, states: List<String>, correlationId: String):
90             List<MessagePrioritization>?
91
92     @Query(
93         "FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state in :states " +
94                 "AND pm.type in :types AND pm.correlationId = :correlationId ORDER BY pm.createdDate asc"
95     )
96     fun findByGroupAndTypesAndCorrelationId(
97         group: String,
98         states: List<String>,
99         types: List<String>,
100         correlationId: String
101     ): List<MessagePrioritization>?
102
103     @Modifying
104     @Transactional
105     @Query(
106         "UPDATE MessagePrioritization SET state = :state, updatedDate = :currentDate " +
107                 "WHERE id = :id"
108     )
109     fun setStateForMessageId(id: String, state: String, currentDate: Date): Int
110
111     @Modifying
112     @Transactional
113     @Query(
114         "UPDATE MessagePrioritization SET priority = :priority, updatedDate = :currentDate " +
115                 "WHERE id = :id"
116     )
117     fun setPriorityForMessageId(id: String, priority: String, currentDate: Date): Int
118
119     @Modifying
120     @Transactional
121     @Query(
122         "UPDATE MessagePrioritization SET state = :state, updatedDate = :currentDate " +
123                 "WHERE id IN :ids"
124     )
125     fun setStateForMessageIds(ids: List<String>, state: String, currentDate: Date): Int
126
127     @Modifying
128     @Transactional
129     @Query(
130         "UPDATE MessagePrioritization SET priority = :priority, updatedDate = :currentDate " +
131                 "WHERE id IN :ids"
132     )
133     fun setPriorityForMessageIds(ids: List<String>, priority: String, currentDate: Date): Int
134
135     @Modifying
136     @Transactional
137     @Query(
138         "UPDATE MessagePrioritization SET state = :state, error = :error, updatedDate = :currentDate " +
139                 "WHERE id = :id"
140     )
141     fun setStateAndErrorForMessageId(id: String, state: String, error: String, currentDate: Date): Int
142
143     @Modifying
144     @Transactional
145     @Query(
146         "UPDATE MessagePrioritization SET state = :state, " +
147                 "aggregatedMessageIds = :aggregatedMessageIds, updatedDate = :currentDate WHERE id = :id"
148     )
149     fun setStateAndAggregatedMessageIds(id: String, state: String, aggregatedMessageIds: String, currentDate: Date): Int
150
151     @Modifying
152     @Transactional
153     @Query("DELETE FROM MessagePrioritization pm WHERE pm.group = :group")
154     fun deleteGroup(group: String)
155
156     @Modifying
157     @Transactional
158     @Query("DELETE FROM MessagePrioritization pm WHERE pm.group = :group AND pm.state IN :states")
159     fun deleteGroupAndStateIn(group: String, states: List<String>)
160 }