91a25783b5a991c226872642c83dd146277baef9
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.tosca.datatypes;
22
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Optional;
27
28 import org.apache.commons.collections.MapUtils;
29 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
30 import org.openecomp.core.utilities.file.FileContentHandler;
31 import org.openecomp.sdc.datatypes.model.AsdcModel;
32 import org.openecomp.sdc.tosca.services.DataModelUtil;
33
34 /**
35  * Tosca service model.
36  */
37 public class ToscaServiceModel implements AsdcModel {
38
39     private FileContentHandler artifactFiles;
40     private Map<String, ServiceTemplate> serviceTemplates;
41     private String entryDefinitionServiceTemplate;
42
43     public ToscaServiceModel() {
44     }
45
46     /**
47      * Instantiates a new Tosca service model.
48      *
49      * @param artifactFiles                  the artifact files
50      * @param serviceTemplates               the service templates
51      * @param entryDefinitionServiceTemplate the entry definition service template
52      */
53     public ToscaServiceModel(FileContentHandler artifactFiles,
54                              Map<String, ServiceTemplate> serviceTemplates,
55                              String entryDefinitionServiceTemplate) {
56         this.artifactFiles = artifactFiles;
57         this.serviceTemplates = serviceTemplates;
58         this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
59     }
60
61     /**
62      * Gets artifact files.
63      *
64      * @return the artifact files
65      */
66     public FileContentHandler getArtifactFiles() {
67         return artifactFiles;
68     }
69
70     public void setArtifactFiles(FileContentHandler artifactFiles) {
71         this.artifactFiles = artifactFiles;
72     }
73
74     /**
75      * Gets service templates.
76      *
77      * @return the service templates
78      */
79     public Map<String, ServiceTemplate> getServiceTemplates() {
80         return Collections.unmodifiableMap(serviceTemplates);
81     }
82
83     public Optional<ServiceTemplate> getServiceTemplate(String serviceTemplateName) {
84         return MapUtils.isEmpty(this.serviceTemplates) ? Optional.empty()
85                 : Optional.of(this.serviceTemplates.get(serviceTemplateName));
86     }
87
88     public void addServiceTemplate(String serviceTemplateName,
89                                    ServiceTemplate serviceTemplate) {
90         if (MapUtils.isEmpty(serviceTemplates)) {
91             serviceTemplates = new HashMap<>();
92         }
93
94         serviceTemplates.put(serviceTemplateName, serviceTemplate);
95     }
96
97     /**
98      * Sets service templates.
99      *
100      * @param serviceTemplates the service templates
101      */
102     public void setServiceTemplates(Map<String, ServiceTemplate> serviceTemplates) {
103         this.serviceTemplates = serviceTemplates;
104     }
105
106     /**
107      * Gets entry definition service template.
108      *
109      * @return the entry definition service template
110      */
111     public String getEntryDefinitionServiceTemplate() {
112         return entryDefinitionServiceTemplate;
113     }
114
115     /**
116      * Sets entry definition service template.
117      *
118      * @param entryDefinitionServiceTemplate the entry definition service template
119      */
120     public void setEntryDefinitionServiceTemplate(String entryDefinitionServiceTemplate) {
121         this.entryDefinitionServiceTemplate = entryDefinitionServiceTemplate;
122     }
123
124     /**
125      * Gets cloned service model.
126      *
127      * @param toscaServiceModel the tosca service model
128      * @return the cloned service model
129      */
130     public static ToscaServiceModel getClonedServiceModel(ToscaServiceModel toscaServiceModel) {
131         return ToscaServiceModel.class.cast(DataModelUtil.getClonedObject(toscaServiceModel));
132     }
133 }