a7e5389583803a178a3871c744866298e1ff2b96
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / onap / so / bpmn / core / domain / VnfResource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.bpmn.core.domain;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.UUID;
26
27 import com.fasterxml.jackson.annotation.JsonIgnore;
28 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29 import com.fasterxml.jackson.annotation.JsonProperty;
30 import com.fasterxml.jackson.annotation.JsonRootName;
31
32 /**
33  * Encapsulates VNF resource data set
34  *
35  */
36 @JsonRootName("vnfResource")
37 public class VnfResource extends Resource {
38
39         private static final long serialVersionUID = 1L;
40
41         /*
42          * set resourceType for this object
43          */
44         public VnfResource(){
45                 resourceType = ResourceType.VNF;
46                 setResourceId(UUID.randomUUID().toString());
47         }
48
49         /*
50          * fields specific to VNF resource type
51          */
52         @JsonProperty("vfModules")
53         private List <ModuleResource>  vfModules;
54         private String vnfHostname;
55         private String vnfType;
56         private String nfFunction;
57         private String nfType;
58         private String nfRole;
59         private String nfNamingCode;
60         private String multiStageDesign;
61         private String orchestrationStatus;
62
63         @JsonIgnore
64         private String resourceInput;
65
66         /*
67          * GET and SET
68          */
69         public List<ModuleResource> getVfModules() {
70                 return vfModules;
71         }
72         public void setModules(List<ModuleResource> moduleResources) {
73                 this.vfModules = moduleResources;
74         }
75         public String getVnfHostname() {
76                 return vnfHostname;
77         }
78         public void setVnfHostname(String vnfHostname) {
79                 this.vnfHostname = vnfHostname;
80         }
81         @Deprecated
82         public void setVnfType(String vnfType) {
83                 this.vnfType = vnfType;
84         }
85         public String getVnfType() {
86                 return vnfType;
87         }
88         public String getNfFunction() {
89                 return nfFunction;
90         }
91         public void setNfFunction(String nfFunction) {
92                 this.nfFunction = nfFunction;
93         }
94         public String getNfType() {
95                 return nfType;
96         }
97         public void setNfType(String nfType) {
98                 this.nfType = nfType;
99         }
100         public String getNfRole() {
101                 return nfRole;
102         }
103         public void setNfRole(String nfRole) {
104                 this.nfRole = nfRole;
105         }
106         public String getNfNamingCode() {
107                 return nfNamingCode;
108         }
109         public void setNfNamingCode(String nfNamingCode) {
110                 this.nfNamingCode = nfNamingCode;
111         }
112         public String getMultiStageDesign() {
113                 return multiStageDesign;
114         }
115         public void setMultiStageDesign(String multiStageDesign) {
116                 this.multiStageDesign = multiStageDesign;
117         }
118         /*
119          * GET accessors per design requirements
120          */
121
122
123         public String getOrchestrationStatus(){
124                 return orchestrationStatus;
125         }
126
127         public void setOrchestrationStatus(String orchestrationStatus){
128                 this.orchestrationStatus = orchestrationStatus;
129         }
130
131         public String getResourceInput() {
132                 return resourceInput;
133         }
134
135         public void setResourceInput(String resourceInput) {
136                 this.resourceInput = resourceInput;
137         }
138
139         /**
140          * Returns a list of all VfModule objects.
141          * Base module is first entry in the list
142          * @return ordered list of ModuleResources objects
143          */
144         @JsonIgnore
145         public List<ModuleResource> getAllVfModuleObjects(){
146                 if (vfModules == null) {
147                         return null;
148                 }
149
150                 for (int i = 0; i < vfModules.size(); i++) {
151                         ModuleResource moduleResource = vfModules.get(i);
152                         if (moduleResource.getIsBase()){
153                                 vfModules.remove(moduleResource);
154                                 vfModules.add(0,moduleResource);
155                         }
156                 }
157                 return vfModules;
158         }
159
160         /**
161          *
162          * @return Returns JSON list of all VfModule structures.
163          */
164         @JsonIgnore
165         public String getAllVfModulesJson(){
166
167                 return listToJson(vfModules);
168         }
169
170         // methods to add to the list
171         public void addVfModule(ModuleResource moduleResource) {
172                 if (vfModules == null){
173                         vfModules = new ArrayList<>();
174                 }
175                 this.vfModules.add(moduleResource);
176         }
177
178
179         /**
180          * Utility method to allow construction of the filed in the form of
181          * <serviceResources.modelInfo.modelName>/<serviceVnfs.modelInfo.modelInstanceName>
182          *
183          * default setter for this field deprecated
184          * @param modelName << serviceResources.modelInfo.modelName
185          */
186         public void constructVnfType(String modelName) {
187                 this.vnfType = modelName.concat("/").concat(this.modelInfo.getModelInstanceName());
188         }
189 }