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 List<String> vendorList;
40 private List<String> categoryList;
41 private Date timestamp;
43 private List<HashMap<String, String>> supportedModels;
44 private List<HashMap<String, String>> supportedComponents;
45 //private List<HashMap<String,String>> artifacts;
46 private List<ActionArtifact> artifacts;
53 * Instantiates a new Action.
55 * @param action the action
57 public Action(Action action) {
58 this.actionUuId = action.getActionUuId();
59 this.actionInvariantUuId = action.getActionInvariantUuId();
60 this.name = action.getName();
61 this.setDisplayName(action.getDisplayName());
62 this.setVendorList(action.getVendorList());
63 this.setCategoryList(action.getCategoryList());
64 this.setTimestamp(action.getTimestamp());
65 this.setUser(action.getUser());
66 this.version = action.getVersion();
67 this.status = action.getStatus();
68 this.data = action.getData();
69 this.supportedComponents = action.getSupportedComponents();
70 this.supportedModels = action.getSupportedModels();
71 this.artifacts = action.getArtifacts();
74 public String getActionUuId() {
78 public void setActionUuId(String actionUuId) {
79 this.actionUuId = actionUuId;
82 public String getActionInvariantUuId() {
83 return actionInvariantUuId;
86 public void setActionInvariantUuId(String actionInvariantUuId) {
87 this.actionInvariantUuId = actionInvariantUuId;
90 public String getVersion() {
94 public void setVersion(String version) {
95 this.version = version;
98 public ActionStatus getStatus() {
102 public void setStatus(ActionStatus status) {
103 this.status = status;
106 public String getName() {
110 public void setName(String name) {
114 public String getDisplayName() {
118 public void setDisplayName(String displayName) {
119 this.displayName = displayName;
122 public List<String> getVendorList() {
126 public void setVendorList(List<String> vendorList) {
127 this.vendorList = vendorList;
130 public List<String> getCategoryList() {
134 public void setCategoryList(List<String> categoryList) {
135 this.categoryList = categoryList;
138 public Date getTimestamp() {
142 public void setTimestamp(Date timestamp) {
143 this.timestamp = timestamp;
146 public String getUser() {
150 public void setUser(String user) {
154 public List<HashMap<String, String>> getSupportedModels() {
155 return supportedModels;
158 public void setSupportedModels(List<HashMap<String, String>> supportedModels) {
159 this.supportedModels = supportedModels;
162 public List<HashMap<String, String>> getSupportedComponents() {
163 return supportedComponents;
166 public void setSupportedComponents(List<HashMap<String, String>> supportedComponents) {
167 this.supportedComponents = supportedComponents;
171 public List<ActionArtifact> getArtifacts() {
175 public void setArtifacts(List<ActionArtifact> artifacts) {
176 this.artifacts = artifacts;
179 public String getData() {
183 public void setData(String data) {
188 * To entity action entity.
190 * @return the action entity
192 public ActionEntity toEntity() {
193 ActionEntity destination = new ActionEntity();
196 .setActionUuId(this.getActionUuId() != null ? this.getActionUuId().toUpperCase() : null);
197 destination.setActionInvariantUuId(
198 this.getActionInvariantUuId() != null ? this.getActionInvariantUuId().toUpperCase() : null);
199 destination.setName(this.getName() != null ? this.getName().toLowerCase() : null);
200 destination.setVendorList(this.getVendorList());
201 destination.setCategoryList(this.getCategoryList());
202 destination.setTimestamp(this.getTimestamp());
203 destination.setUser(this.getUser());
204 destination.setVersion(Version.valueOf(this.getVersion()));
205 if (this.getStatus() != null) {
206 destination.setStatus(this.getStatus().name());
208 destination.setSupportedComponents(getIdFromMap(this.getSupportedComponents(),
209 ActionConstants.SUPPORTED_COMPONENTS_ID));
210 destination.setSupportedModels(
211 getIdFromMap(this.getSupportedModels(), ActionConstants.SUPPORTED_MODELS_VERSION_ID));
212 destination.setData(this.getData());
216 private List<String> getIdFromMap(List<HashMap<String, String>> map, String idName) {
217 List<String> list = new ArrayList<>();
218 if (map != null && !map.isEmpty()) {
219 for (HashMap<String, String> entry : map) {
220 if (entry.containsKey(idName)) {
221 list.add(entry.get(idName) != null ? entry.get(idName).toLowerCase() : null);
230 public int compareTo(Object object) {
231 Action obj = (Action) object;
232 Version thisVersion = Version.valueOf(this.version);
233 Version objVersion = Version.valueOf(obj.getVersion());
234 if (obj.getName().compareTo(this.getName()) == 0) {
235 return compareVersions(objVersion, thisVersion);
237 return obj.getName().compareTo(this.getName());
240 private int compareVersions(Version objVersion, Version thisVersion) {
241 if (objVersion.getMajor() == thisVersion.getMajor()) {
242 return Integer.compare(objVersion.getMinor(), thisVersion.getMinor());
244 return Integer.compare(objVersion.getMajor(), thisVersion.getMajor());