Update VID SO API call generation - include PNF instanceName parameter in SO API...
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / serviceInstantiation / ServiceInstantiation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 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.vid.model.serviceInstantiation;
22
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.stream.Collectors;
30 import java.util.stream.Stream;
31 import org.apache.commons.lang3.ObjectUtils;
32 import org.onap.vid.job.JobAdapter;
33 import org.onap.vid.job.JobType;
34 import org.onap.vid.model.VidNotions;
35 import org.onap.vid.mso.model.ModelInfo;
36 import org.onap.vid.utils.jackson.BooleanAsStringSerializer;
37
38 public class ServiceInstantiation extends BaseResource implements JobAdapter.AsyncJobRequest {
39
40     private final String owningEntityId;
41
42     private final String owningEntityName;
43
44     private final String projectName;
45
46     private final String subscriberName;
47
48     private final String globalSubscriberId;
49
50     private final String productFamilyId;
51
52     private final String subscriptionServiceType;
53
54     private final String tenantName;
55
56     private final String aicZoneId;
57
58     private final String aicZoneName;
59
60     private final Map<String, Vnf> vnfs;
61
62     private final Map<String, Pnf> pnfs;
63
64     private final Map<String, Network> networks;
65
66     private final Map<String, InstanceGroup> vnfGroups;
67
68     private final boolean isPause;
69
70     private int bulkSize;
71
72     private final String testApi;
73
74     private final boolean isALaCarte;
75
76     private final VidNotions vidNotions;
77     private Map<String, VrfEntry> vrfs;
78
79     public ServiceInstantiation(@JsonProperty("modelInfo") ModelInfo modelInfo,
80                                 @JsonProperty("owningEntityId") String owningEntityId,
81                                 @JsonProperty("owningEntityName") String owningEntityName,
82                                 @JsonProperty("projectName") String projectName,
83                                 @JsonProperty("globalSubscriberId") String globalSubscriberId,
84                                 @JsonProperty("subscriberName") String subscriberName,
85                                 @JsonProperty("productFamilyId") String productFamilyId,
86                                 @JsonProperty("instanceName") String instanceName,
87                                 @JsonProperty("subscriptionServiceType") String subscriptionServiceType,
88                                 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
89                                 @JsonProperty("legacyRegion") String legacyRegion,
90                                 @JsonProperty("tenantId") String tenantId,
91                                 @JsonProperty("tenantName") String tenantName,
92                                 @JsonProperty("aicZoneId") String aicZoneId,
93                                 @JsonProperty("aicZoneName") String aicZoneName,
94                                 @JsonProperty("vnfs") Map<String, Vnf> vnfs,
95                                 @JsonProperty("pnfs") Map<String, Pnf> pnfs,
96                                 @JsonProperty("networks") Map<String, Network> networks,
97                                 @JsonProperty("vnfGroups") Map<String, InstanceGroup> vnfGroups,
98                                 @JsonProperty("vrfs") Map<String, VrfEntry> vrfs,
99                                 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
100                                 @JsonProperty("pause") boolean isPause,
101                                 @JsonProperty("bulkSize") int bulkSize,
102                                 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
103                                 @JsonProperty("isALaCarte") boolean isALaCarte,
104                                 @JsonProperty("testApi") String testApi,
105                                 @JsonProperty("instanceId") String instanceId,
106                                 @JsonProperty("action") String action,
107                                 @JsonProperty("trackById") String trackById,
108                                 @JsonProperty("isFailed") Boolean isFailed,
109                                 @JsonProperty("statusMessage") String statusMessage,
110                                 @JsonProperty("vidNotions") VidNotions vidNotions,
111                                 @JsonProperty("originalName") String originalName) {
112         super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId, trackById, isFailed, statusMessage,
113             null, null, originalName);
114         this.owningEntityId = owningEntityId;
115         this.owningEntityName = owningEntityName;
116         this.projectName = projectName;
117         this.globalSubscriberId = globalSubscriberId;
118         this.subscriberName = subscriberName;
119         this.productFamilyId = productFamilyId;
120         this.subscriptionServiceType = subscriptionServiceType;
121         this.tenantName = tenantName;
122         this.aicZoneId = aicZoneId;
123         this.aicZoneName = aicZoneName;
124         this.vnfs = vnfs;
125         this.pnfs = pnfs;
126         this.networks = networks;
127         this.vnfGroups = vnfGroups;
128         this.vrfs = vrfs;
129         this.isPause = isPause;
130         this.bulkSize = bulkSize;
131         this.isALaCarte = isALaCarte;
132         this.testApi = isALaCarte ? testApi : null;
133         this.vidNotions = vidNotions;
134     }
135
136     @Override
137     @JsonSerialize(using=BooleanAsStringSerializer.class)
138     public boolean isRollbackOnFailure() {
139         // this override is for the BooleanAsStringSerializer annotation,
140         // but for Service-Instance level only
141         return super.isRollbackOnFailure();
142     }
143
144     public String getOwningEntityId() {
145         return owningEntityId;
146     }
147
148     public String getOwningEntityName() {
149         return owningEntityName;
150     }
151
152     public String getProjectName() {
153         return projectName;
154     }
155
156     public String getGlobalSubscriberId() {
157         return globalSubscriberId;
158     }
159
160     public String getSubscriberName() {
161         return subscriberName;
162     }
163
164     public String getProductFamilyId() {
165         return productFamilyId;
166     }
167
168     public String getSubscriptionServiceType() {
169         return subscriptionServiceType;
170     }
171
172     public String getTenantName() {
173         return tenantName;
174     }
175
176     public String getAicZoneId() {
177         return aicZoneId;
178     }
179
180     public String getAicZoneName() {
181         return aicZoneName;
182     }
183
184     public Map<String, Vnf> getVnfs() {
185         return emptyMapIfNull(vnfs);
186     }
187
188     public Map<String, Pnf> getPnfs() {
189         return emptyMapIfNull(pnfs);
190     }
191
192     public Map<String, Network> getNetworks() {
193         return emptyMapIfNull(networks);
194     }
195
196     public Map<String, InstanceGroup> getVnfGroups() {
197         return emptyMapIfNull(vnfGroups);
198     }
199
200     public Map<String, VrfEntry> getVrfs() {
201         return emptyMapIfNull(vrfs);
202     }
203
204     public boolean isPause() {
205         return isPause;
206     }
207
208     public int getBulkSize() { return bulkSize; }
209
210     public void setBulkSize(int bulkSize) {
211         this.bulkSize = bulkSize;
212     }
213
214     public VidNotions getVidNotions() {
215         return vidNotions;
216     }
217
218     @Override
219     protected String getModelType() {
220         return "service";
221     }
222
223     @Override
224     public Collection<BaseResource> getChildren() {
225         return Stream.of(getNetworks().values(), getVnfs().values(), getVnfGroups().values()).flatMap(Collection::stream).collect(Collectors.toList());
226     }
227
228     @JsonProperty("isALaCarte")
229     public boolean isALaCarte() {
230         return isALaCarte;
231     }
232
233     public String getTestApi() {
234         return this.testApi;
235     }
236
237     @Override
238     public JobType getJobType() {
239         return JobType.ALaCarteService;
240     }
241
242     private <T> Map<String, T> emptyMapIfNull(Map<String, T> map) {
243         return ObjectUtils.defaultIfNull(map, Collections.emptyMap());
244     }
245
246 }