2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.pnfsimulator.template;
23 import java.util.List;
24 import java.util.Optional;
26 import com.google.gson.JsonObject;
27 import org.onap.pnfsimulator.db.Storage;
28 import org.onap.pnfsimulator.template.search.TemplateSearchHelper;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.context.annotation.Primary;
31 import org.springframework.stereotype.Service;
35 public class TemplateService implements Storage<Template> {
37 private final TemplateRepository templateRepository;
38 private TemplateSearchHelper searchHelper;
42 public TemplateService(TemplateRepository templateRepository, TemplateSearchHelper searchHelper) {
43 this.templateRepository = templateRepository;
44 this.searchHelper = searchHelper;
48 public List<Template> getAll() {
49 return templateRepository.findAll();
53 public Optional<Template> get(String name) {
54 return templateRepository.findById(name);
58 public void persist(Template template) {
59 templateRepository.save(template);
63 public boolean tryPersistOrOverwrite(Template template, boolean overwrite) {
64 if (templateRepository.existsById(template.getId()) && !overwrite) {
67 templateRepository.save(template);
72 public void delete(String templateName) {
73 templateRepository.deleteById(templateName);
77 public List<String> getIdsByContentCriteria(JsonObject stringQueryJson) {
78 return searchHelper.getIdsOfDocumentMatchingCriteria(stringQueryJson);