2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service;
\r
19 import org.apache.commons.lang3.StringUtils;
\r
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
\r
22 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository;
\r
23 import org.onap.ccsdk.apps.controllerblueprints.service.validator.ModelTypeValidator;
\r
24 import org.springframework.stereotype.Service;
\r
25 import org.springframework.transaction.annotation.Transactional;
\r
27 import java.util.List;
\r
28 import java.util.Optional;
\r
31 * ModelTypeService.java Purpose: Provide ModelTypeService Service ModelTypeService
\r
33 * @author Brinda Santh
\r
39 public class ModelTypeService {
\r
41 private ModelTypeRepository modelTypeRepository;
\r
44 * This is a ModelTypeService, used to save and get the model types stored in database
\r
46 * @param modelTypeRepository
\r
48 public ModelTypeService(ModelTypeRepository modelTypeRepository) {
\r
49 this.modelTypeRepository = modelTypeRepository;
\r
54 * This is a getModelTypeByName service
\r
56 * @param modelTypeName
\r
58 * @throws BluePrintException
\r
60 public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException {
\r
61 ModelType modelType = null;
\r
62 if (StringUtils.isNotBlank(modelTypeName)) {
\r
63 Optional<ModelType> modelTypeOption = modelTypeRepository.findByModelName(modelTypeName);
\r
64 if (modelTypeOption.isPresent()) {
\r
65 modelType = modelTypeOption.get();
\r
68 throw new BluePrintException("Model Name Information is missing.");
\r
75 * This is a searchModelTypes service
\r
78 * @return List<ModelType>
\r
79 * @throws BluePrintException
\r
81 public List<ModelType> searchModelTypes(String tags) throws BluePrintException {
\r
83 return modelTypeRepository.findByTagsContainingIgnoreCase(tags);
\r
85 throw new BluePrintException("No Search Information provide");
\r
90 * This is a saveModel service
\r
94 * @throws BluePrintException
\r
96 public ModelType saveModel(ModelType modelType) throws BluePrintException {
\r
98 ModelTypeValidator.validateModelType(modelType);
\r
100 Optional<ModelType> dbModelType = modelTypeRepository.findByModelName(modelType.getModelName());
\r
101 if (dbModelType.isPresent()) {
\r
102 ModelType dbModel = dbModelType.get();
\r
103 dbModel.setDescription(modelType.getDescription());
\r
104 dbModel.setDefinition(modelType.getDefinition());
\r
105 dbModel.setDefinitionType(modelType.getDefinitionType());
\r
106 dbModel.setDerivedFrom(modelType.getDerivedFrom());
\r
107 dbModel.setTags(modelType.getTags());
\r
108 dbModel.setVersion(modelType.getVersion());
\r
109 dbModel.setUpdatedBy(modelType.getUpdatedBy());
\r
110 modelType = modelTypeRepository.save(dbModel);
\r
112 modelType = modelTypeRepository.save(modelType);
\r
119 * This is a deleteByModelName service
\r
122 * @throws BluePrintException
\r
124 public void deleteByModelName(String modelName) throws BluePrintException {
\r
125 if (modelName != null) {
\r
126 modelTypeRepository.deleteByModelName(modelName);
\r
128 throw new BluePrintException("Model Name Information is missing.");
\r
133 * This is a getModelTypeByTags service
\r
136 * @return List<ModelType>
\r
137 * @throws BluePrintException
\r
139 public List<ModelType> getModelTypeByTags(String tags) throws BluePrintException {
\r
140 if (StringUtils.isNotBlank(tags)) {
\r
141 return modelTypeRepository.findByTagsContainingIgnoreCase(tags);
\r
143 throw new BluePrintException("Model Tag Information is missing.");
\r
148 * This is a getModelTypeByDefinitionType service
\r
150 * @param definitionType
\r
151 * @return List<ModelType>
\r
152 * @throws BluePrintException
\r
154 public List<ModelType> getModelTypeByDefinitionType(String definitionType) throws BluePrintException {
\r
155 if (StringUtils.isNotBlank(definitionType)) {
\r
156 return modelTypeRepository.findByDefinitionType(definitionType);
\r
158 throw new BluePrintException("Model definitionType Information is missing.");
\r
163 * This is a getModelTypeByDerivedFrom service
\r
165 * @param derivedFrom
\r
166 * @return List<ModelType>
\r
167 * @throws BluePrintException
\r
169 public List<ModelType> getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException {
\r
170 if (StringUtils.isNotBlank(derivedFrom)) {
\r
171 return modelTypeRepository.findByDerivedFrom(derivedFrom);
\r
173 throw new BluePrintException("Model derivedFrom Information is missing.");
\r