2 * Copyright © 2018 IBM Intellectual Property.
3 * Modifications Copyright © 2018 IBM.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.service;
19 import com.att.eelf.configuration.EELFLogger;
20 import com.att.eelf.configuration.EELFManager;
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.CbaContent;
22 import org.onap.ccsdk.apps.controllerblueprints.service.repository.CBAContentRepository;
23 import org.springframework.stereotype.Service;
25 import java.util.List;
26 import java.util.Optional;
29 * CBAContentService.java Purpose: Provide CBAContent Template Service processing
37 public class CBAContentService {
39 private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class);
41 private CBAContentRepository cbaContentRepository;
44 * Constructor of the class
45 * @param cbaContentRepository CRUD methods for entity CBAContentRepository
47 public CBAContentService(CBAContentRepository cbaContentRepository) {
48 this.cbaContentRepository = cbaContentRepository;
49 log.info("CBAContentRepository sucessfully instantiated");
53 * Save the CBAContent into the CBA_CONTENT table
54 * @param cbaName The name of the file
55 * @param cbaVersion version number of the CBA archive
56 * @param cbaState int that would represent the state. Refer to the CbaStateEnum
57 * @param cbaDescription Brief description that would help to identify and recognize the CBA archive
58 * @param file the file
59 * @return CbaContent the record saved into the table CBA_CONTENT
61 public CbaContent saveCBAContent(String cbaName, String cbaVersion, int cbaState, String cbaDescription, byte[] file){
62 CbaContent cbaContent = new CbaContent();
63 cbaContent.setCbaName(cbaName);
64 cbaContent.setCbaVersion(cbaVersion);
65 cbaContent.setCbaState(cbaState);
66 cbaContent.setCbaDescription(cbaDescription);
67 cbaContent.setCbaFile(file);
68 cbaContentRepository.saveAndFlush(cbaContent);
73 * Get the list of Controller Blueprint archives
74 * @return List<CbaContent> list with the controller blueprint archives
76 public List<CbaContent> getList(){
77 return cbaContentRepository.findAll();
81 * Get a single Controller Blueprint archive by uuID
82 * @param uuID the userID controller blueprint identifier
83 * @return Optional<CbaContent>
85 public Optional<CbaContent> findByUUID(String uuID) {
86 return cbaContentRepository.findById(uuID);
90 * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model
91 * @param uuid the uuid that identify the CBA
93 public void deleteCBAById(String uuid) {
94 cbaContentRepository.deleteById(uuid);