From f191f4bbfeb8802ed2b223ad13149aa0f31242b6 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 9 Sep 2018 22:00:59 -0400 Subject: Controller Blueprints Microservice Add ModelType and Resource Dictionary reactor repository service and junit test cases for reactor repositories. Change-Id: Id358082739f81d18b534c224dc7472355e21f026 Issue-ID: CCSDK-491 Signed-off-by: Brinda Santh --- .../service/ModelTypeService.java | 88 +++++++--------------- .../repository/ResourceDictionaryRepository.java | 10 +-- .../repository/BluePrintsReactRepository.kt | 76 +++++++++++++++++++ .../ResourceDictionaryReactRepository.kt | 8 +- 4 files changed, 113 insertions(+), 69 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt (limited to 'ms/controllerblueprints/modules/service/src/main') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java index 2bc2963b6..925a6c492 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; @@ -43,7 +45,7 @@ public class ModelTypeService { /** * This is a ModelTypeService, used to save and get the model types stored in database * - * @param modelTypeRepository + * @param modelTypeRepository modelTypeRepository */ public ModelTypeService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; @@ -53,19 +55,15 @@ public class ModelTypeService { /** * This is a getModelTypeByName service * - * @param modelTypeName + * @param modelTypeName modelTypeName * @return ModelType - * @throws BluePrintException */ - public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException { + public ModelType getModelTypeByName(String modelTypeName) { ModelType modelType = null; - if (StringUtils.isNotBlank(modelTypeName)) { - Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); - if (modelTypeOption.isPresent()) { - modelType = modelTypeOption.get(); - } - } else { - throw new BluePrintException("Model Name Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing."); + Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); + if (modelTypeOption.isPresent()) { + modelType = modelTypeOption.get(); } return modelType; } @@ -74,27 +72,25 @@ public class ModelTypeService { /** * This is a searchModelTypes service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchModelTypes(String tags) throws BluePrintException { - if (tags != null) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchModelTypes(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide"); + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveModel service * - * @param modelType + * @param modelType modelType * @return ModelType - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ModelType saveModel(ModelType modelType) throws BluePrintException { + Preconditions.checkNotNull(modelType, "Model Type Information is missing."); + ModelTypeValidator.validateModelType(modelType); Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); @@ -118,60 +114,34 @@ public class ModelTypeService { /** * This is a deleteByModelName service * - * @param modelName - * @throws BluePrintException + * @param modelName modelName */ - public void deleteByModelName(String modelName) throws BluePrintException { - if (modelName != null) { - modelTypeRepository.deleteByModelName(modelName); - } else { - throw new BluePrintException("Model Name Information is missing."); - } - } + public void deleteByModelName(String modelName) { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing."); + modelTypeRepository.deleteByModelName(modelName); - /** - * This is a getModelTypeByTags service - * - * @param tags - * @return List - * @throws BluePrintException - */ - public List getModelTypeByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("Model Tag Information is missing."); - } } /** * This is a getModelTypeByDefinitionType service * - * @param definitionType + * @param definitionType definitionType * @return List - * @throws BluePrintException */ - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - if (StringUtils.isNotBlank(definitionType)) { - return modelTypeRepository.findByDefinitionType(definitionType); - } else { - throw new BluePrintException("Model definitionType Information is missing."); - } + public List getModelTypeByDefinitionType(String definitionType) { + Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing."); + return modelTypeRepository.findByDefinitionType(definitionType); } /** * This is a getModelTypeByDerivedFrom service * - * @param derivedFrom + * @param derivedFrom derivedFrom * @return List - * @throws BluePrintException */ - public List getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException { - if (StringUtils.isNotBlank(derivedFrom)) { - return modelTypeRepository.findByDerivedFrom(derivedFrom); - } else { - throw new BluePrintException("Model derivedFrom Information is missing."); - } + public List getModelTypeByDerivedFrom(String derivedFrom) { + Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing."); + return modelTypeRepository.findByDerivedFrom(derivedFrom); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 16031b6e0..c53040e2b 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -37,7 +37,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ Optional findByName(String name); @@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByNameIn(List names); @@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByTagsContainingIgnoreCase(String tags); @@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository { + return Mono.justOrEmpty(modelTypeRepository.save(modelType)) + } + + fun findByModelName(modelName: String): Mono { + return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) + } + + fun findByModelNameIn(modelNames: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFrom(derivedFrom: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFromIn(derivedFroms: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionType(definitionType: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionTypeIn(definitionTypes: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByModelName(modelName: String): Mono { + modelTypeRepository.deleteByModelName(modelName) + return Mono.empty() + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt index 064b5c382..0865b69da 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.repository -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary import org.springframework.stereotype.Service import reactor.core.publisher.Flux @@ -49,10 +48,9 @@ open class ResourceDictionaryReactRepository(private val resourceDictionaryRepos .subscribeOn(Schedulers.elastic()) } - fun deleteByName(name: String): Mono { - return Mono.fromCallable { - resourceDictionaryRepository.deleteByName(name) - } + fun deleteByName(name: String): Mono { + resourceDictionaryRepository.deleteByName(name) + return Mono.empty() } } \ No newline at end of file -- cgit 1.2.3-korg