Migrate ccsdk/apps to ccsdk/cds
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / service / repository / BluePrintsReactRepository.kt
1 /*
2  *  Copyright © 2018 IBM.
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.controllerblueprints.service.repository
18
19 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType
20 import org.springframework.stereotype.Service
21 import reactor.core.publisher.Flux
22 import reactor.core.publisher.Mono
23 import reactor.core.scheduler.Schedulers
24
25 /**
26  * ModelTypeReactRepository.
27  *
28  * @author Brinda Santh
29  */
30 @Service
31 open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) {
32
33     fun save(modelType: ModelType): Mono<ModelType> {
34         return Mono.justOrEmpty(modelTypeRepository.save(modelType))
35     }
36
37     fun findByModelName(modelName: String): Mono<ModelType> {
38         return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName))
39     }
40
41     fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> {
42         return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames))
43                 .subscribeOn(Schedulers.elastic())
44     }
45
46     fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> {
47         return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom))
48                 .subscribeOn(Schedulers.elastic())
49     }
50
51     fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> {
52         return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms))
53                 .subscribeOn(Schedulers.elastic())
54     }
55
56     fun findByDefinitionType(definitionType: String): Flux<ModelType> {
57         return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType))
58                 .subscribeOn(Schedulers.elastic())
59     }
60
61     fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> {
62         return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes))
63                 .subscribeOn(Schedulers.elastic())
64     }
65
66     fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> {
67         return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags))
68                 .subscribeOn(Schedulers.elastic())
69     }
70
71     fun deleteByModelName(modelName: String): Mono<Void> {
72         modelTypeRepository.deleteByModelName(modelName)
73         return Mono.empty()
74     }
75
76 }