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