Merge "Adding changes for catalog edit and create"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / repository / ModelTypeReactRepository.kt
1 /*
2  *  Copyright © 2019 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.blueprintsprocessor.designer.api.repository
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.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 // TODO("Convert into coroutines")
26 /**
27  * ModelTypeReactRepository.
28  *
29  * @author Brinda Santh
30  */
31 @Service
32 open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) {
33
34     fun save(modelType: ModelType): Mono<ModelType> {
35         return Mono.justOrEmpty(modelTypeRepository.save(modelType))
36     }
37
38     fun findByModelName(modelName: String): Mono<ModelType> {
39         return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName))
40     }
41
42     fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> {
43         return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames))
44             .subscribeOn(Schedulers.elastic())
45     }
46
47     fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> {
48         return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom))
49             .subscribeOn(Schedulers.elastic())
50     }
51
52     fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> {
53         return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms))
54             .subscribeOn(Schedulers.elastic())
55     }
56
57     fun findByDefinitionType(definitionType: String): Flux<ModelType> {
58         return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType))
59             .subscribeOn(Schedulers.elastic())
60     }
61
62     fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> {
63         return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes))
64             .subscribeOn(Schedulers.elastic())
65     }
66
67     fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> {
68         return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags))
69             .subscribeOn(Schedulers.elastic())
70     }
71
72     fun deleteByModelName(modelName: String): Mono<Void> {
73         modelTypeRepository.deleteByModelName(modelName)
74         return Mono.empty()
75     }
76 }