2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 package org.openecomp.sdc.action.types;
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.List;
24 import java.util.Objects;
27 import org.openecomp.sdc.action.ActionConstants;
28 import org.openecomp.sdc.action.dao.types.ActionEntity;
29 import org.openecomp.sdc.versioning.dao.types.Version;
31 public class Action implements Comparable {
32 private String actionUuId;
33 private String actionInvariantUuId;
34 private String version;
35 private ActionStatus status;
37 private String displayName;
38 private List<String> vendorList;
39 private List<String> categoryList;
40 private Date timestamp;
42 private List<Map<String, String>> supportedModels;
43 private List<Map<String, String>> supportedComponents;
44 //private List<HashMap<String,String>> artifacts;
45 private List<ActionArtifact> artifacts;
52 * Instantiates a new Action.
54 * @param action the action
56 public Action(Action action) {
57 this.actionUuId = action.getActionUuId();
58 this.actionInvariantUuId = action.getActionInvariantUuId();
59 this.name = action.getName();
60 this.setDisplayName(action.getDisplayName());
61 this.setVendorList(action.getVendorList());
62 this.setCategoryList(action.getCategoryList());
63 this.setTimestamp(action.getTimestamp());
64 this.setUser(action.getUser());
65 this.version = action.getVersion();
66 this.status = action.getStatus();
67 this.data = action.getData();
68 this.supportedComponents = action.getSupportedComponents();
69 this.supportedModels = action.getSupportedModels();
70 this.artifacts = action.getArtifacts();
73 public String getActionUuId() {
77 public void setActionUuId(String actionUuId) {
78 this.actionUuId = actionUuId;
81 public String getActionInvariantUuId() {
82 return actionInvariantUuId;
85 public void setActionInvariantUuId(String actionInvariantUuId) {
86 this.actionInvariantUuId = actionInvariantUuId;
89 public String getVersion() {
93 public void setVersion(String version) {
94 this.version = version;
97 public ActionStatus getStatus() {
101 public void setStatus(ActionStatus status) {
102 this.status = status;
105 public String getName() {
109 public void setName(String name) {
113 public String getDisplayName() {
117 public void setDisplayName(String displayName) {
118 this.displayName = displayName;
121 public List<String> getVendorList() {
125 public void setVendorList(List<String> vendorList) {
126 this.vendorList = vendorList;
129 public List<String> getCategoryList() {
133 public void setCategoryList(List<String> categoryList) {
134 this.categoryList = categoryList;
137 public Date getTimestamp() {
141 public void setTimestamp(Date timestamp) {
142 this.timestamp = timestamp;
145 public String getUser() {
149 public void setUser(String user) {
153 public List<Map<String, String>> getSupportedModels() {
154 return supportedModels;
157 public void setSupportedModels(List<Map<String, String>> supportedModels) {
158 this.supportedModels = supportedModels;
161 public List<Map<String, String>> getSupportedComponents() {
162 return supportedComponents;
165 public void setSupportedComponents(List<Map<String, String>> supportedComponents) {
166 this.supportedComponents = supportedComponents;
170 public List<ActionArtifact> getArtifacts() {
174 public void setArtifacts(List<ActionArtifact> artifacts) {
175 this.artifacts = artifacts;
178 public String getData() {
182 public void setData(String data) {
187 * To entity action entity.
189 * @return the action entity
191 public ActionEntity toEntity() {
192 ActionEntity destination = new ActionEntity();
195 .setActionUuId(this.getActionUuId() != null ? this.getActionUuId().toUpperCase() : null);
196 destination.setActionInvariantUuId(
197 this.getActionInvariantUuId() != null ? this.getActionInvariantUuId().toUpperCase() : null);
198 destination.setName(this.getName() != null ? this.getName().toLowerCase() : null);
199 if (Objects.nonNull(this.getVendorList())) {
200 destination.setVendorList(new HashSet<>(this.getVendorList()));
202 if (Objects.nonNull(this.getCategoryList())) {
203 destination.setCategoryList(new HashSet<>(this.getCategoryList()));
205 destination.setTimestamp(this.getTimestamp());
206 destination.setUser(this.getUser());
207 destination.setVersion(Version.valueOf(this.getVersion()));
208 if (this.getStatus() != null) {
209 destination.setStatus(this.getStatus().name());
211 destination.setSupportedComponents(getIdFromMap(this.getSupportedComponents(),
212 ActionConstants.SUPPORTED_COMPONENTS_ID));
213 destination.setSupportedModels(
214 getIdFromMap(this.getSupportedModels(), ActionConstants.SUPPORTED_MODELS_VERSION_ID));
215 destination.setData(this.getData());
219 private Set<String> getIdFromMap(List<Map<String, String>> map, String idName) {
220 Set<String> list = new HashSet<>();
221 if (map != null && !map.isEmpty()) {
222 for (Map<String, String> entry : map) {
223 if (entry.containsKey(idName)) {
224 list.add(entry.get(idName) != null ? entry.get(idName).toLowerCase() : null);
233 public int compareTo(Object object) {
234 Action obj = (Action) object;
235 Version thisVersion = Version.valueOf(this.version);
236 Version objVersion = Version.valueOf(obj.getVersion());
237 if (obj.getName().compareTo(this.getName()) == 0) {
238 return compareVersions(objVersion, thisVersion);
240 return obj.getName().compareTo(this.getName());
243 private int compareVersions(Version objVersion, Version thisVersion) {
244 if (objVersion.getMajor() == thisVersion.getMajor()) {
245 return Integer.compare(objVersion.getMinor(), thisVersion.getMinor());
247 return Integer.compare(objVersion.getMajor(), thisVersion.getMajor());
251 public boolean equals(Object o) {
255 if (o == null || getClass() != o.getClass()) {
259 Action action = (Action) o;
261 if (!version.equals(action.version)) {
264 if (!name.equals(action.name)) {
272 public int hashCode() {
273 int result = version.hashCode();
274 result = 31 * result + name.hashCode();