2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository
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
25 // TODO("Convert into coroutines")
27 * ModelTypeReactRepository.
29 * @author Brinda Santh
32 open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) {
34 fun save(modelType: ModelType): Mono<ModelType> {
35 return Mono.justOrEmpty(modelTypeRepository.save(modelType))
38 fun findByModelName(modelName: String): Mono<ModelType> {
39 return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName))
42 fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> {
43 return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames))
44 .subscribeOn(Schedulers.elastic())
47 fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> {
48 return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom))
49 .subscribeOn(Schedulers.elastic())
52 fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> {
53 return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms))
54 .subscribeOn(Schedulers.elastic())
57 fun findByDefinitionType(definitionType: String): Flux<ModelType> {
58 return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType))
59 .subscribeOn(Schedulers.elastic())
62 fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> {
63 return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes))
64 .subscribeOn(Schedulers.elastic())
67 fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> {
68 return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags))
69 .subscribeOn(Schedulers.elastic())
72 fun deleteByModelName(modelName: String): Mono<Void> {
73 modelTypeRepository.deleteByModelName(modelName)