From e10032c90bfcf5c56fc3200e89b142b782eac88f Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 28 Aug 2018 22:46:02 -0400 Subject: Controller Blueprints Microservice Add resource assignment json data to input property convertor utlity and their test cases. Change-Id: Ie4557048e85df38c75ac3d31ff62d4fce0662d9f Issue-ID: CCSDK-488 Signed-off-by: Brinda Santh --- .../ResourceDefinitionValidationService.java | 29 ++++++++++ .../service/ResourceDictionaryService.java | 67 +++++++++------------- .../ResourceDictionaryValidationService.java | 31 ---------- 3 files changed, 56 insertions(+), 71 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java (limited to 'ms/controllerblueprints/modules/service') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java new file mode 100644 index 000000000..d3bf42302 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDefinitionValidationService.java @@ -0,0 +1,29 @@ +/* + * 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; + +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDefinitionDefaultValidationService; +import org.springframework.stereotype.Service; + +@Service +public class ResourceDefinitionValidationService extends ResourceDefinitionDefaultValidationService { + + public ResourceDefinitionValidationService(BluePrintRepoService bluePrintRepoService) { + super(bluePrintRepoService); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java index 85e701b41..ccf4ffcc7 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryService.java @@ -18,6 +18,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; import com.google.common.base.Preconditions; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; @@ -43,16 +44,16 @@ public class ResourceDictionaryService { private ResourceDictionaryRepository resourceDictionaryRepository; - private ResourceDictionaryValidationService resourceDictionaryValidationService; + private ResourceDefinitionValidationService resourceDictionaryValidationService; /** * This is a DataDictionaryService, used to save and get the Resource Mapping stored in database * - * @param dataDictionaryRepository - * @param resourceDictionaryValidationService + * @param dataDictionaryRepository dataDictionaryRepository + * @param resourceDictionaryValidationService resourceDictionaryValidationService */ public ResourceDictionaryService(ResourceDictionaryRepository dataDictionaryRepository, - ResourceDictionaryValidationService resourceDictionaryValidationService) { + ResourceDefinitionValidationService resourceDictionaryValidationService) { this.resourceDictionaryRepository = dataDictionaryRepository; this.resourceDictionaryValidationService = resourceDictionaryValidationService; } @@ -60,58 +61,49 @@ public class ResourceDictionaryService { /** * This is a getDataDictionaryByName service * - * @param name + * @param name name * @return DataDictionary - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ResourceDictionary getResourceDictionaryByName(String name) throws BluePrintException { - if (StringUtils.isNotBlank(name)) { - return resourceDictionaryRepository.findByName(name).get(); + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + Optional resourceDictionaryDb = resourceDictionaryRepository.findByName(name); + if (resourceDictionaryDb.isPresent()) { + return resourceDictionaryDb.get(); } else { - throw new BluePrintException("Resource Mapping Name Information is missing."); + throw new BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)); } } /** * This is a searchResourceDictionaryByNames service * - * @param names + * @param names names * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByNames(List names) - throws BluePrintException { - if (names != null && !names.isEmpty()) { - return resourceDictionaryRepository.findByNameIn(names); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByNames(List names) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide"); + return resourceDictionaryRepository.findByNameIn(names); } /** * This is a searchResourceDictionaryByTags service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchResourceDictionaryByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchResourceDictionaryByTags(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide"); + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveDataDictionary service * - * @param resourceDictionary + * @param resourceDictionary resourceDictionary * @return DataDictionary - * @throws BluePrintException */ - public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) - throws BluePrintException { + public ResourceDictionary saveResourceDictionary(ResourceDictionary resourceDictionary) { Preconditions.checkNotNull(resourceDictionary, "Resource Dictionary information is missing"); Preconditions.checkArgument(StringUtils.isNotBlank(resourceDictionary.getDefinition()), "Resource Dictionary definition information is missing"); @@ -130,7 +122,7 @@ public class ResourceDictionaryService { PropertyDefinition propertyDefinition = resourceDefinition.getProperty(); resourceDictionary.setDescription(propertyDefinition.getDescription()); resourceDictionary.setDataType(propertyDefinition.getType()); - if(propertyDefinition.getEntrySchema() != null){ + if (propertyDefinition.getEntrySchema() != null) { resourceDictionary.setEntrySchema(propertyDefinition.getEntrySchema().getType()); } @@ -164,15 +156,10 @@ public class ResourceDictionaryService { /** * This is a deleteResourceDictionary service * - * @param name - * @throws BluePrintException + * @param name name */ - public void deleteResourceDictionary(String name) throws BluePrintException { - if (name != null) { - resourceDictionaryRepository.deleteByName(name); - } else { - throw new BluePrintException("Resource Mapping Id Information is missing."); - } - + public void deleteResourceDictionary(String name) { + Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing."); + resourceDictionaryRepository.deleteByName(name); } } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java deleted file mode 100644 index 7de7fc4c3..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ResourceDictionaryValidationService.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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; - -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRepoService; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceDictionaryDefaultValidationService; -import org.springframework.stereotype.Service; - -@Service -public class ResourceDictionaryValidationService extends ResourceDictionaryDefaultValidationService { - - private BluePrintRepoService bluePrintRepoService; - - public ResourceDictionaryValidationService(BluePrintRepoService bluePrintRepoService) { - super(bluePrintRepoService); - } -} -- cgit 1.2.3-korg