summaryrefslogtreecommitdiffstats
path: root/ms/controllerblueprints/modules/service/src/main
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2018-09-09 22:00:59 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2018-09-09 22:00:59 -0400
commitf191f4bbfeb8802ed2b223ad13149aa0f31242b6 (patch)
tree077c10216ad99b46ceea94f8e50cd1bccd3b48f8 /ms/controllerblueprints/modules/service/src/main
parent41c2e50bad504a7f81978598f39ebe409a2df808 (diff)
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 <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/controllerblueprints/modules/service/src/main')
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java88
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java10
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt76
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt8
4 files changed, 113 insertions, 69 deletions
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<ModelType> 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<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> searchModelTypes(String tags) throws BluePrintException {
- if (tags != null) {
- return modelTypeRepository.findByTagsContainingIgnoreCase(tags);
- } else {
- throw new BluePrintException("No Search Information provide");
- }
+ public List<ModelType> 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<ModelType> 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<ModelType>
- * @throws BluePrintException
- */
- public List<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> getModelTypeByDefinitionType(String definitionType) throws BluePrintException {
- if (StringUtils.isNotBlank(definitionType)) {
- return modelTypeRepository.findByDefinitionType(definitionType);
- } else {
- throw new BluePrintException("Model definitionType Information is missing.");
- }
+ public List<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException {
- if (StringUtils.isNotBlank(derivedFrom)) {
- return modelTypeRepository.findByDerivedFrom(derivedFrom);
- } else {
- throw new BluePrintException("Model derivedFrom Information is missing.");
- }
+ public List<ModelType> 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<ResourceDict
/**
* This is a findByName method
*
- * @param name
+ * @param name name
* @return Optional<ResourceMapping>
*/
Optional<ResourceDictionary> findByName(String name);
@@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a findByNameIn method
*
- * @param names
+ * @param names names
* @return Optional<ResourceMapping>
*/
List<ResourceDictionary> findByNameIn(List<String> names);
@@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a findByTagsContainingIgnoreCase method
*
- * @param tags
+ * @param tags tags
* @return Optional<ModelType>
*/
List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags);
@@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a deleteByName method
*
- * @param name
+ * @param name name
*/
- ResourceDictionary deleteByName(String name);
+ void deleteByName(String name);
}
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt
new file mode 100644
index 000000000..141ba92c6
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.apps.controllerblueprints.service.repository
+
+import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType
+import org.springframework.stereotype.Service
+import reactor.core.publisher.Flux
+import reactor.core.publisher.Mono
+import reactor.core.scheduler.Schedulers
+
+/**
+ * ModelTypeReactRepository.
+ *
+ * @author Brinda Santh
+ */
+@Service
+open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) {
+
+ fun save(modelType: ModelType): Mono<ModelType> {
+ return Mono.justOrEmpty(modelTypeRepository.save(modelType))
+ }
+
+ fun findByModelName(modelName: String): Mono<ModelType> {
+ return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName))
+ }
+
+ fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun findByDefinitionType(definitionType: String): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> {
+ return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags))
+ .subscribeOn(Schedulers.elastic())
+ }
+
+ fun deleteByModelName(modelName: String): Mono<Void> {
+ 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<ResourceDictionary> {
- return Mono.fromCallable {
- resourceDictionaryRepository.deleteByName(name)
- }
+ fun deleteByName(name: String): Mono<Void> {
+ resourceDictionaryRepository.deleteByName(name)
+ return Mono.empty()
}
} \ No newline at end of file