2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.model.serviceInstantiation;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24 import com.google.common.collect.ImmutableMap;
25 import org.apache.commons.lang3.StringUtils;
26 import org.onap.vid.job.JobAdapter;
27 import org.onap.vid.model.Action;
28 import org.onap.vid.mso.model.ModelInfo;
30 import java.util.Collections;
31 import java.util.List;
34 public abstract class BaseResource implements JobAdapter.AsyncJobRequest {
36 protected final String instanceId;
37 protected ModelInfo modelInfo;
39 protected String instanceName;
41 protected final Action action;
43 protected String lcpCloudRegionId;
45 protected String tenantId;
47 protected List<Map<String, String>> instanceParams;
49 protected boolean rollbackOnFailure;
51 private static final Map<String, Action> actionStingToEnumMap = ImmutableMap.of(
52 "Delete", Action.Delete,
53 "Create", Action.Create,
55 "Update_Delete", Action.Delete,
56 "None_Delete", Action.Delete
60 protected BaseResource(@JsonProperty("modelInfo") ModelInfo modelInfo,
61 @JsonProperty("instanceName") String instanceName,
62 @JsonProperty("action") String action,
63 @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId,
64 @JsonProperty("legacyRegion") String legacyRegion,
65 @JsonProperty("tenantId") String tenantId,
66 @JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
67 @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
68 @JsonProperty("instanceId") String instanceId) {
69 this.modelInfo = modelInfo;
70 this.modelInfo.setModelType(getModelType());
71 this.rollbackOnFailure = rollbackOnFailure;
72 this.instanceName = StringUtils.defaultString(instanceName, "");;
73 this.action = actionStringToEnum(action);
74 this.lcpCloudRegionId = StringUtils.isNotEmpty(legacyRegion) ? legacyRegion : lcpCloudRegionId;
75 this.tenantId = tenantId;
76 this.instanceParams = instanceParams;
77 this.instanceId = instanceId;
80 private Action actionStringToEnum(String actionAsString) {
81 return actionStingToEnumMap.get(actionAsString);
84 public ModelInfo getModelInfo() {
88 public String getInstanceName() {
92 public Action getAction() {
96 public String getLcpCloudRegionId() {
97 return lcpCloudRegionId;
100 public String getTenantId() {
104 public List<Map<String, String>> getInstanceParams() {
105 return instanceParams == null ? Collections.emptyList() : instanceParams;
108 public boolean isRollbackOnFailure() { return rollbackOnFailure; }
110 public String getInstanceId() {
114 protected abstract String getModelType();