66ef6a93401a103eb8151a8d6088f544d4a87c42
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2018 IBM Intellectual Property.
3  * Modifications Copyright © 2018 IBM.
4  *
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 package org.onap.ccsdk.apps.controllerblueprints.service;
18
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;
24
25 import java.util.List;
26 import java.util.Optional;
27
28 /**
29  * CBAContentService.java Purpose: Provide CBAContent Template Service processing
30  * CBAContentService
31  *
32  * @author Ruben Chang
33  * @version 1.0
34  */
35
36 @Service
37 public class CBAContentService {
38
39     private static EELFLogger log = EELFManager.getInstance().getLogger(CBAContentService.class);
40
41     private CBAContentRepository cbaContentRepository;
42
43     /**
44      * Constructor of the class
45      * @param cbaContentRepository CRUD methods for entity CBAContentRepository
46      */
47     public CBAContentService(CBAContentRepository cbaContentRepository) {
48         this.cbaContentRepository = cbaContentRepository;
49         log.info("CBAContentRepository sucessfully instantiated");
50     }
51
52     /**
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
60      */
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);
69         return cbaContent;
70     }
71
72     /**
73      * Get the list of Controller Blueprint archives
74      * @return List<CbaContent> list with the controller blueprint archives
75      */
76     public List<CbaContent> getList(){
77         return cbaContentRepository.findAll();
78     }
79
80     /**
81      * Get a single Controller Blueprint archive by uuID
82      * @param uuID the userID controller blueprint identifier
83      * @return Optional<CbaContent>
84      */
85     public Optional<CbaContent> findByUUID(String uuID) {
86         return cbaContentRepository.findById(uuID);
87     }
88
89     /**
90      * Method deleteCBAById: Delete a CBA in data base with it associated Blueprint Model
91      * @param uuid the uuid that identify the CBA
92      */
93     public void deleteCBAById(String uuid) {
94         cbaContentRepository.deleteById(uuid);
95     }
96
97 }