Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / main / java / org / onap / vid / mso / model / BaseResourceInstantiationRequestDetails.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.mso.model;
22
23 import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
24 import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
25
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.fasterxml.jackson.annotation.JsonTypeInfo;
29 import com.fasterxml.jackson.annotation.JsonTypeName;
30 import java.util.List;
31
32 @JsonInclude(NON_NULL)
33 public class BaseResourceInstantiationRequestDetails {
34
35     @JsonProperty("modelInfo")
36     protected ModelInfo modelInfo;
37
38     @JsonProperty("cloudConfiguration")
39     protected CloudConfiguration cloudConfiguration;
40
41     @JsonProperty("requestInfo")
42     protected RequestInfo requestInfo;
43
44     @JsonProperty("platform")
45     protected Platform platform;
46
47     @JsonProperty("lineOfBusiness")
48     protected LineOfBusiness lineOfBusiness;
49
50     @JsonProperty("relatedInstanceList")
51     protected List<RelatedInstance> relatedInstanceList;
52
53     @JsonProperty("requestParameters")
54     protected RequestParameters requestParameters;
55
56     public BaseResourceInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo,
57                                                    @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration,
58                                                    @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo,
59                                                    @JsonProperty(value = "platform", required = true) Platform platform,
60                                                    @JsonProperty(value = "lineOfBusiness", required = true) LineOfBusiness lineOfBusiness,
61                                                    @JsonProperty(value = "relatedInstanceList", required = true) List<RelatedInstance> relatedInstanceList,
62                                                    @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters)
63     {
64         this.modelInfo = modelInfo;
65         this.cloudConfiguration = cloudConfiguration;
66         this.requestInfo = requestInfo;
67         this.platform = platform;
68         this.lineOfBusiness = lineOfBusiness;
69         this.relatedInstanceList = relatedInstanceList;
70         this.requestParameters = requestParameters;
71     }
72
73     public BaseResourceInstantiationRequestDetails(@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo,
74                                                    @JsonProperty(value = "cloudConfiguration", required = true) CloudConfiguration cloudConfiguration,
75                                                    @JsonProperty(value = "requestInfo", required = true) RequestInfo requestInfo,
76                                                    @JsonProperty(value = "relatedInstanceList", required = true) List<RelatedInstance> relatedInstanceList,
77                                                    @JsonProperty(value = "requestParameters", required = true) RequestParameters requestParameters)
78     {
79         this.modelInfo = modelInfo;
80         this.cloudConfiguration = cloudConfiguration;
81         this.requestInfo = requestInfo;
82         this.relatedInstanceList = relatedInstanceList;
83         this.requestParameters = requestParameters;
84     }
85
86     public static class RequestInfo {
87
88         @JsonInclude(NON_EMPTY) public final String instanceName;
89         @JsonInclude(NON_EMPTY) public final String productFamilyId;
90         public final String source;
91         @JsonInclude(NON_NULL) public final Boolean suppressRollback;
92         public final String requestorId;
93
94         public RequestInfo(String instanceName, String productFamilyId, String source, Boolean rollbackOnFailure, String requestorId) {
95             this.instanceName = instanceName;
96             this.productFamilyId = productFamilyId;
97             this.source = source;
98             this.requestorId = requestorId;
99             // in the FE we are asking for "RollbackOnFailure" but to MSO we are passing the negative value "suppressRollback"
100             this.suppressRollback = rollbackOnFailure != null ? (!rollbackOnFailure) : null;
101         }
102     }
103
104     public static class Project{
105         public final String projectName;
106
107         public Project(String projectName) {
108             this.projectName = projectName;
109         }
110     }
111
112     public static class Platform{
113         public final String platformName;
114
115         public Platform(String platformName) {
116             this.platformName = platformName;
117         }
118     }
119
120     public static class LineOfBusiness{
121         public final String lineOfBusinessName;
122
123         private LineOfBusiness(String lineOfBusiness) {
124             this.lineOfBusinessName = lineOfBusiness;
125         }
126
127         public static LineOfBusiness of(String lineOfBusiness) {
128             return lineOfBusiness==null ? null : new LineOfBusiness(lineOfBusiness);
129         }
130     }
131
132     @JsonTypeName("relatedInstance")
133     @JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
134     public static class RelatedInstance{
135         public ModelInfo modelInfo;
136         @JsonInclude(NON_NULL) public String instanceId; //TODO ask Eylon - is this needed, and if yes, for other fields as well?
137         @JsonInclude(NON_NULL) public String instanceName;
138
139         public RelatedInstance (@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo,
140                                 @JsonProperty (value = "instanceId", required = true) String instanceId){
141             this.modelInfo = modelInfo;
142             this.instanceId = instanceId;
143         }
144
145         public RelatedInstance (@JsonProperty(value = "modelInfo", required = true) ModelInfo modelInfo,
146                                 @JsonProperty (value = "instanceId", required = true) String instanceId,
147                                 @JsonProperty (value = "instanceName", required = true) String instanceName){
148             this.modelInfo = modelInfo;
149             this.instanceId = instanceId;
150             this.instanceName = instanceName;
151         }
152     }
153
154     public static class RequestParameters {
155         public final List<? extends UserParamTypes> userParams;
156
157         @JsonInclude(NON_NULL) public final String testApi;
158         public RequestParameters(List<? extends UserParamTypes> userParams, String testApi) {
159             this.userParams = userParams;
160             this.testApi = testApi;
161         }
162
163         public List<? extends UserParamTypes> getUserParams() {
164             return userParams;
165         }
166         public String getTestApi() {
167             return testApi;
168         }
169     }
170 }
171