Change ServiceInstance's top-level rollbackOnFailure serialization to String
[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, Network> networks;
63
64     private final Map<String, InstanceGroup> vnfGroups;
65
66     private final boolean isPause;
67
68     private int bulkSize;
69
70     private final String testApi;
71
72     private final boolean isALaCarte;
73
74     private final VidNotions vidNotions;
75     private Map<String, VrfEntry> vrfs;
76
77     public ServiceInstantiation(@JsonProperty("modelInfo") ModelInfo modelInfo,
78                                 @JsonProperty("owningEntityId") String owningEntityId,
79                                 @JsonProperty("owningEntityName") String owningEntityName,
80                                 @JsonProperty("projectName") String projectName,
81                                 @JsonProperty("globalSubscriberId") String globalSubscriberId,
82                                 @JsonProperty("subscriberName") String subscriberName,
83                                 @JsonProperty("productFamilyId") String productFamilyId,
84                                 @JsonProperty("instanceName") String instanceName,
85                                 @JsonProperty("subscriptionServiceType") String subscriptionServiceType,
86                                 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
87                                 @JsonProperty("legacyRegion") String legacyRegion,
88                                 @JsonProperty("tenantId") String tenantId,
89                                 @JsonProperty("tenantName") String tenantName,
90                                 @JsonProperty("aicZoneId") String aicZoneId,
91                                 @JsonProperty("aicZoneName") String aicZoneName,
92                                 @JsonProperty("vnfs") Map<String, Vnf> vnfs,
93                                 @JsonProperty("networks") Map<String, Network> networks,
94                                 @JsonProperty("vnfGroups") Map<String, InstanceGroup> vnfGroups,
95                                 @JsonProperty("vrfs") Map<String, VrfEntry> vrfs,
96                                 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
97                                 @JsonProperty("pause") boolean isPause,
98                                 @JsonProperty("bulkSize") int bulkSize,
99                                 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
100                                 @JsonProperty("isALaCarte") boolean isALaCarte,
101                                 @JsonProperty("testApi") String testApi,
102                                 @JsonProperty("instanceId") String instanceId,
103                                 @JsonProperty("action") String action,
104                                 @JsonProperty("trackById") String trackById,
105                                 @JsonProperty("isFailed") Boolean isFailed,
106                                 @JsonProperty("statusMessage") String statusMessage,
107                                 @JsonProperty("vidNotions") VidNotions vidNotions) {
108         super(modelInfo, instanceName, action, lcpCloudRegionId, legacyRegion, tenantId, instanceParams, rollbackOnFailure, instanceId, trackById, isFailed, statusMessage,
109             null);
110         this.owningEntityId = owningEntityId;
111         this.owningEntityName = owningEntityName;
112         this.projectName = projectName;
113         this.globalSubscriberId = globalSubscriberId;
114         this.subscriberName = subscriberName;
115         this.productFamilyId = productFamilyId;
116         this.subscriptionServiceType = subscriptionServiceType;
117         this.tenantName = tenantName;
118         this.aicZoneId = aicZoneId;
119         this.aicZoneName = aicZoneName;
120         this.vnfs = vnfs;
121         this.networks = networks;
122         this.vnfGroups = vnfGroups;
123         this.vrfs = vrfs;
124         this.isPause = isPause;
125         this.bulkSize = bulkSize;
126         this.isALaCarte = isALaCarte;
127         this.testApi = isALaCarte ? testApi : null;
128         this.vidNotions = vidNotions;
129     }
130
131     @Override
132     @JsonSerialize(using=BooleanAsStringSerializer.class)
133     public boolean isRollbackOnFailure() {
134         // this override is for the BooleanAsStringSerializer annotation,
135         // but for Service-Instance level only
136         return super.isRollbackOnFailure();
137     }
138
139     public String getOwningEntityId() {
140         return owningEntityId;
141     }
142
143     public String getOwningEntityName() {
144         return owningEntityName;
145     }
146
147     public String getProjectName() {
148         return projectName;
149     }
150
151     public String getGlobalSubscriberId() {
152         return globalSubscriberId;
153     }
154
155     public String getSubscriberName() {
156         return subscriberName;
157     }
158
159     public String getProductFamilyId() {
160         return productFamilyId;
161     }
162
163     public String getSubscriptionServiceType() {
164         return subscriptionServiceType;
165     }
166
167     public String getTenantName() {
168         return tenantName;
169     }
170
171     public String getAicZoneId() {
172         return aicZoneId;
173     }
174
175     public String getAicZoneName() {
176         return aicZoneName;
177     }
178
179     public Map<String, Vnf> getVnfs() {
180         return emptyMapIfNull(vnfs);
181     }
182
183     public Map<String, Network> getNetworks() {
184         return emptyMapIfNull(networks);
185     }
186
187     public Map<String, InstanceGroup> getVnfGroups() {
188         return emptyMapIfNull(vnfGroups);
189     }
190
191     public Map<String, VrfEntry> getVrfs() {
192         return emptyMapIfNull(vrfs);
193     }
194
195     public boolean isPause() {
196         return isPause;
197     }
198
199     public int getBulkSize() { return bulkSize; }
200
201     public void setBulkSize(int bulkSize) {
202         this.bulkSize = bulkSize;
203     }
204
205     public VidNotions getVidNotions() {
206         return vidNotions;
207     }
208
209     @Override
210     protected String getModelType() {
211         return "service";
212     }
213
214     @Override
215     public Collection<BaseResource> getChildren() {
216         return Stream.of(getNetworks().values(), getVnfs().values(), getVnfGroups().values()).flatMap(Collection::stream).collect(Collectors.toList());
217     }
218
219     @JsonProperty("isALaCarte")
220     public boolean isALaCarte() {
221         return isALaCarte;
222     }
223
224     public String getTestApi() {
225         return this.testApi;
226     }
227
228     @Override
229     public JobType getJobType() {
230         return JobType.ALaCarteService;
231     }
232
233     private <T> Map<String, T> emptyMapIfNull(Map<String, T> map) {
234         return ObjectUtils.defaultIfNull(map, Collections.emptyMap());
235     }
236
237 }