2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.sdc.action.types;
23 import org.openecomp.sdc.action.ActionConstants;
24 import org.openecomp.sdc.action.dao.types.ActionEntity;
25 import org.openecomp.sdc.versioning.dao.types.Version;
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.List;
32 public class Action implements Comparable {
33 private String actionUuId;
34 private String actionInvariantUuId;
35 private String version;
36 private ActionStatus status;
38 private String displayName;
39 private String endpointUri;
40 private List<String> vendorList;
41 private List<String> categoryList;
42 private Date timestamp;
44 private List<HashMap<String, String>> supportedModels;
45 private List<HashMap<String, String>> supportedComponents;
46 //private List<HashMap<String,String>> artifacts;
47 private List<ActionArtifact> artifacts;
54 * Instantiates a new Action.
56 * @param action the action
58 public Action(Action action) {
59 this.actionUuId = action.getActionUuId();
60 this.actionInvariantUuId = action.getActionInvariantUuId();
61 this.name = action.getName();
62 this.setDisplayName(action.getDisplayName());
63 this.setVendorList(action.getVendorList());
64 this.setCategoryList(action.getCategoryList());
65 this.setTimestamp(action.getTimestamp());
66 this.setUser(action.getUser());
67 this.version = action.getVersion();
68 this.status = action.getStatus();
69 this.data = action.getData();
70 this.supportedComponents = action.getSupportedComponents();
71 this.supportedModels = action.getSupportedModels();
72 this.artifacts = action.getArtifacts();
75 public String getActionUuId() {
79 public void setActionUuId(String actionUuId) {
80 this.actionUuId = actionUuId;
83 public String getActionInvariantUuId() {
84 return actionInvariantUuId;
87 public void setActionInvariantUuId(String actionInvariantUuId) {
88 this.actionInvariantUuId = actionInvariantUuId;
91 public String getVersion() {
95 public void setVersion(String version) {
96 this.version = version;
99 public ActionStatus getStatus() {
103 public void setStatus(ActionStatus status) {
104 this.status = status;
107 public String getName() {
111 public void setName(String name) {
115 public String getDisplayName() {
119 public void setDisplayName(String displayName) {
120 this.displayName = displayName;
123 public String getEndpointUri() {
127 public void setEndpointUri(String endpointUri) {
128 this.endpointUri = endpointUri;
131 public List<String> getVendorList() {
135 public void setVendorList(List<String> vendorList) {
136 this.vendorList = vendorList;
139 public List<String> getCategoryList() {
143 public void setCategoryList(List<String> categoryList) {
144 this.categoryList = categoryList;
147 public Date getTimestamp() {
151 public void setTimestamp(Date timestamp) {
152 this.timestamp = timestamp;
155 public String getUser() {
159 public void setUser(String user) {
163 public List<HashMap<String, String>> getSupportedModels() {
164 return supportedModels;
167 public void setSupportedModels(List<HashMap<String, String>> supportedModels) {
168 this.supportedModels = supportedModels;
171 public List<HashMap<String, String>> getSupportedComponents() {
172 return supportedComponents;
175 public void setSupportedComponents(List<HashMap<String, String>> supportedComponents) {
176 this.supportedComponents = supportedComponents;
179 public List<ActionArtifact> getArtifacts() {
183 public void setArtifacts(List<ActionArtifact> artifacts) {
184 this.artifacts = artifacts;
187 public String getData() {
191 public void setData(String data) {
196 * To entity action entity.
198 * @return the action entity
200 public ActionEntity toEntity() {
201 ActionEntity destination = new ActionEntity();
204 .setActionUuId(this.getActionUuId() != null ? this.getActionUuId().toUpperCase() : null);
205 destination.setActionInvariantUuId(
206 this.getActionInvariantUuId() != null ? this.getActionInvariantUuId().toUpperCase() : null);
207 destination.setName(this.getName() != null ? this.getName().toLowerCase() : null);
208 destination.setVendorList(this.getVendorList());
209 destination.setCategoryList(this.getCategoryList());
210 destination.setTimestamp(this.getTimestamp());
211 destination.setUser(this.getUser());
212 destination.setVersion(Version.valueOf(this.getVersion()));
213 if (this.getStatus() != null) {
214 destination.setStatus(this.getStatus().name());
216 destination.setSupportedComponents(
217 getIdFromMap(this.getSupportedComponents(), ActionConstants.SUPPORTED_COMPONENTS_ID));
218 destination.setSupportedModels(
219 getIdFromMap(this.getSupportedModels(), ActionConstants.SUPPORTED_MODELS_VERSION_ID));
220 destination.setData(this.getData());
224 private List<String> getIdFromMap(List<HashMap<String, String>> map, String idName) {
225 List<String> list = new ArrayList<>();
226 if (map != null && !map.isEmpty()) {
227 map.forEach(entry -> {
228 if (entry.containsKey(idName)) {
229 list.add(entry.get(idName) != null ? entry.get(idName).toLowerCase() : null);
238 public int compareTo(Object object) {
239 Action obj = (Action) object;
240 Version thisVersion = Version.valueOf(this.version);
241 Version objVersion = Version.valueOf(obj.getVersion());
242 if (obj.getName().compareTo(this.getName()) == 0) {
243 return compareVersions(objVersion, thisVersion);
245 return obj.getName().compareTo(this.getName());
248 private int compareVersions(Version objVersion, Version thisVersion) {
249 if (objVersion.getMajor() == thisVersion.getMajor()) {
250 return Integer.compare(objVersion.getMinor(), thisVersion.getMinor());
252 return Integer.compare(objVersion.getMajor(), thisVersion.getMajor());