Add Semicolon at the end
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / serviceInstantiation / BaseResource.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.JsonIgnore;
24 import com.fasterxml.jackson.annotation.JsonProperty;
25 import com.google.common.collect.ImmutableMap;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.vid.job.JobAdapter;
28 import org.onap.vid.job.JobType;
29 import org.onap.vid.model.Action;
30 import org.onap.vid.mso.model.ModelInfo;
31
32 import java.util.Collection;
33 import java.util.Collections;
34 import java.util.List;
35 import java.util.Map;
36
37 public abstract class BaseResource implements JobAdapter.AsyncJobRequest {
38
39         protected String instanceId;
40
41         protected ModelInfo modelInfo;
42
43         protected String instanceName;
44
45         protected Action action;
46
47         protected String lcpCloudRegionId;
48
49         protected String tenantId;
50
51         protected List<Map<String, String>> instanceParams;
52
53         protected boolean rollbackOnFailure;
54
55         protected String trackById;
56
57         protected Boolean isFailed;
58
59         protected String statusMessage;
60
61         private static final Map<String, Action> actionStingToEnumMap = ImmutableMap.<String, Action>builder()
62                         .put("Delete", Action.Delete)
63                         .put("Create", Action.Create)
64                         .put("None", Action.None)
65                         .put("Update_Delete", Action.Delete)
66                         .put("None_Delete", Action.Delete)
67                         .put("Resume", Action.Resume)
68                         .put("Replace", Action.Replace)
69                         .build();
70
71
72         protected BaseResource(@JsonProperty("modelInfo") ModelInfo modelInfo,
73                                                    @JsonProperty("instanceName") String instanceName,
74                                                    @JsonProperty("action") String action,
75                                                    @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
76                                                    @JsonProperty("legacyRegion") String legacyRegion,
77                                                    @JsonProperty("tenantId") String tenantId,
78                                                    @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
79                                                    @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
80                                                    @JsonProperty("instanceId") String instanceId,
81                                                    @JsonProperty("trackById") String trackById,
82                                                    @JsonProperty("isFailed") Boolean isFailed,
83                                                    @JsonProperty("statusMessage") String statusMessage) {
84                 this.modelInfo = modelInfo;
85                 this.modelInfo.setModelType(getModelType());
86                 this.rollbackOnFailure = rollbackOnFailure;
87                 this.instanceName = StringUtils.defaultString(instanceName, "");
88                 this.action = actionStringToEnum(action);
89                 this.lcpCloudRegionId = StringUtils.isNotEmpty(legacyRegion) ? legacyRegion : lcpCloudRegionId;
90                 this.tenantId = tenantId;
91                 this.instanceParams = instanceParams;
92                 this.instanceId = instanceId;
93                 this.trackById = trackById;
94                 this.isFailed = isFailed!= null ? isFailed: false;
95                 this.statusMessage = statusMessage;
96         }
97
98         private Action actionStringToEnum(String actionAsString) {
99                 return actionStingToEnumMap.get(actionAsString);
100         }
101
102         public ModelInfo getModelInfo() {
103                 return modelInfo;
104         }
105
106         public String getInstanceName() {
107                 return instanceName;
108         }
109
110         public Action getAction() {
111                 return (action == null ? Action.Create : action);
112         }
113
114         public String getLcpCloudRegionId() {
115                 return lcpCloudRegionId;
116         }
117
118         public String getTenantId() {
119                 return tenantId;
120         }
121
122         public List<Map<String, String>> getInstanceParams() {
123                 return instanceParams == null ? Collections.emptyList() : instanceParams;
124         }
125
126         public boolean isRollbackOnFailure() { return rollbackOnFailure; }
127
128         public String getInstanceId() {
129                 return instanceId;
130         }
131
132         protected abstract String getModelType();
133
134         public String getTrackById() {
135                 return trackById;
136         }
137
138         public void setTrackById(String trackById) {
139                 this.trackById = trackById;
140         }
141
142         public Boolean getIsFailed() {
143                 return isFailed;
144         }
145
146         public void setIsFailed(Boolean isFailed) {
147                 this.isFailed = isFailed;
148         }
149
150         public void setInstanceId(String instanceId) {
151                 this.instanceId = instanceId;
152         }
153
154         public void setAction(Action action) {
155                 this.action = action;
156         }
157
158         public String getStatusMessage() {
159                 return statusMessage;
160         }
161
162         public void setStatusMessage(String statusMessage) {
163                 this.statusMessage = statusMessage;
164         }
165
166         @JsonIgnore
167         public abstract Collection<? extends BaseResource> getChildren();
168
169         @JsonIgnore
170         public abstract JobType getJobType();
171 }