20903c07175a369da672627808f25db5adb5a454
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / domain / VnfResource.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.mso.bpmn.core.domain;\r
22 \r
23 import java.util.ArrayList;\r
24 import java.util.List;\r
25 import java.util.UUID;\r
26 \r
27 import com.fasterxml.jackson.annotation.JsonIgnore;\r
28 import com.fasterxml.jackson.annotation.JsonProperty;\r
29 import com.fasterxml.jackson.annotation.JsonRootName;\r
30 \r
31 /**\r
32  * Encapsulates VNF resource data set\r
33  *\r
34  */\r
35 @JsonRootName("vnfResource")\r
36 public class VnfResource extends Resource {\r
37 \r
38         private static final long serialVersionUID = 1L;\r
39 \r
40         /*\r
41          * set resourceType for this object\r
42          */\r
43         public VnfResource(){\r
44                 resourceType = ResourceType.VNF;\r
45                 setResourceId(UUID.randomUUID().toString());\r
46         }\r
47         \r
48         /*\r
49          * fields specific to VNF resource type\r
50          */\r
51         @JsonProperty("vfModules")\r
52         private List <ModuleResource>  vfModules;\r
53         private String vnfType;\r
54         private String nfFunction;\r
55         private String nfType;\r
56         private String nfRole;\r
57         private String nfNamingCode;\r
58 \r
59         /*\r
60          * GET and SET\r
61          */\r
62         public List<ModuleResource> getVfModules() {\r
63                 return vfModules;\r
64         }\r
65         public void setModules(List<ModuleResource> moduleResources) {\r
66                 this.vfModules = moduleResources;\r
67         }\r
68         @Deprecated\r
69         public void setVnfType(String vnfType) {\r
70                 this.vnfType = vnfType;\r
71         }\r
72         public String getVnfType() {\r
73                 return vnfType;\r
74         }\r
75         public String getNfFunction() {\r
76                 return nfFunction;\r
77         }\r
78         public void setNfFunction(String nfFunction) {\r
79                 this.nfFunction = nfFunction;\r
80         }\r
81         public String getNfType() {\r
82                 return nfType;\r
83         }\r
84         public void setNfType(String nfType) {\r
85                 this.nfType = nfType;\r
86         }\r
87         public String getNfRole() {\r
88                 return nfRole;\r
89         }\r
90         public void setNfRole(String nfRole) {\r
91                 this.nfRole = nfRole;\r
92         }\r
93         public String getNfNamingCode() {\r
94                 return nfNamingCode;\r
95         }\r
96         public void setNfNamingCode(String nfNamingCode) {\r
97                 this.nfNamingCode = nfNamingCode;\r
98         }\r
99         /*\r
100          * GET accessors per design requirements\r
101          */\r
102         \r
103         /**\r
104          * Returns a list of all VfModule objects.\r
105          * Base module is first entry in the list\r
106          * @return ordered list of ModuleResources objects\r
107          */\r
108         @JsonIgnore\r
109         public List<ModuleResource> getAllVfModuleObjects(){\r
110                 if (vfModules == null) {\r
111                         return null;\r
112                 }\r
113                 \r
114                 for (int i = 0; i < vfModules.size(); i++) {\r
115                         ModuleResource moduleResource = vfModules.get(i);\r
116                         if (moduleResource.getIsBase()){\r
117                                 vfModules.remove(moduleResource);\r
118                                 vfModules.add(0,moduleResource);\r
119                         }\r
120                 }\r
121                 return vfModules;\r
122         }\r
123         \r
124         /**\r
125          * \r
126          * @return Returns JSON list of all VfModule structures.\r
127          */\r
128         @JsonIgnore\r
129         public String getAllVfModulesJson(){\r
130                 \r
131                 return listToJson(vfModules);\r
132         }\r
133         \r
134         // methods to add to the list\r
135         public void addVfModule(ModuleResource moduleResource) {\r
136                 if (vfModules == null){\r
137                         vfModules = new ArrayList<>();\r
138                 }\r
139                 this.vfModules.add(moduleResource);\r
140         }\r
141         \r
142 \r
143         /**\r
144          * Utility method to allow construction of the filed in the form of \r
145          * <serviceResources.modelInfo.modelName>/<serviceVnfs.modelInfo.modelInstanceName>\r
146          * \r
147          * default setter for this field deprecated\r
148          * @param modelName << serviceResources.modelInfo.modelName\r
149          */\r
150         public void constructVnfType(String modelName) {\r
151                 this.vnfType = modelName.concat("/").concat(this.modelInfo.getModelInstanceName());\r
152         }\r
153 }