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.
16 package org.openecomp.sdc.action.types;
18 import java.util.Date;
19 import java.util.HashSet;
20 import java.util.List;
22 import java.util.Objects;
24 import org.openecomp.sdc.action.ActionConstants;
25 import org.openecomp.sdc.action.dao.types.ActionEntity;
26 import org.openecomp.sdc.versioning.dao.types.Version;
28 public class Action implements Comparable {
30 private String actionUuId;
31 private String actionInvariantUuId;
32 private String version;
33 private ActionStatus status;
35 private String displayName;
36 private List<String> vendorList;
37 private List<String> categoryList;
38 private Date timestamp;
40 private List<Map<String, String>> supportedModels;
41 private List<Map<String, String>> supportedComponents;
42 //private List<HashMap<String,String>> artifacts;
43 private List<ActionArtifact> artifacts;
50 * Instantiates a new Action.
52 * @param action the action
54 public Action(Action action) {
55 this.actionUuId = action.getActionUuId();
56 this.actionInvariantUuId = action.getActionInvariantUuId();
57 this.name = action.getName();
58 this.setDisplayName(action.getDisplayName());
59 this.setVendorList(action.getVendorList());
60 this.setCategoryList(action.getCategoryList());
61 this.setTimestamp(action.getTimestamp());
62 this.setUser(action.getUser());
63 this.version = action.getVersion();
64 this.status = action.getStatus();
65 this.data = action.getData();
66 this.supportedComponents = action.getSupportedComponents();
67 this.supportedModels = action.getSupportedModels();
68 this.artifacts = action.getArtifacts();
71 public String getActionUuId() {
75 public void setActionUuId(String actionUuId) {
76 this.actionUuId = actionUuId;
79 public String getActionInvariantUuId() {
80 return actionInvariantUuId;
83 public void setActionInvariantUuId(String actionInvariantUuId) {
84 this.actionInvariantUuId = actionInvariantUuId;
87 public String getVersion() {
91 public void setVersion(String version) {
92 this.version = version;
95 public ActionStatus getStatus() {
99 public void setStatus(ActionStatus status) {
100 this.status = status;
103 public String getName() {
107 public void setName(String name) {
111 public String getDisplayName() {
115 public void setDisplayName(String displayName) {
116 this.displayName = displayName;
119 public List<String> getVendorList() {
123 public void setVendorList(List<String> vendorList) {
124 this.vendorList = vendorList;
127 public List<String> getCategoryList() {
131 public void setCategoryList(List<String> categoryList) {
132 this.categoryList = categoryList;
135 public Date getTimestamp() {
139 public void setTimestamp(Date timestamp) {
140 this.timestamp = timestamp;
143 public String getUser() {
147 public void setUser(String user) {
151 public List<Map<String, String>> getSupportedModels() {
152 return supportedModels;
155 public void setSupportedModels(List<Map<String, String>> supportedModels) {
156 this.supportedModels = supportedModels;
159 public List<Map<String, String>> getSupportedComponents() {
160 return supportedComponents;
163 public void setSupportedComponents(List<Map<String, String>> supportedComponents) {
164 this.supportedComponents = supportedComponents;
167 public List<ActionArtifact> getArtifacts() {
171 public void setArtifacts(List<ActionArtifact> artifacts) {
172 this.artifacts = artifacts;
175 public String getData() {
179 public void setData(String data) {
184 * To entity action entity.
186 * @return the action entity
188 public ActionEntity toEntity() {
189 ActionEntity destination = new ActionEntity();
190 destination.setActionUuId(this.getActionUuId() != null ? this.getActionUuId().toUpperCase() : null);
191 destination.setActionInvariantUuId(this.getActionInvariantUuId() != null ? this.getActionInvariantUuId().toUpperCase() : null);
192 destination.setName(this.getName() != null ? this.getName().toLowerCase() : null);
193 if (Objects.nonNull(this.getVendorList())) {
194 destination.setVendorList(new HashSet<>(this.getVendorList()));
196 if (Objects.nonNull(this.getCategoryList())) {
197 destination.setCategoryList(new HashSet<>(this.getCategoryList()));
199 destination.setTimestamp(this.getTimestamp());
200 destination.setUser(this.getUser());
201 destination.setVersion(Version.valueOf(this.getVersion()));
202 if (this.getStatus() != null) {
203 destination.setStatus(this.getStatus().name());
205 destination.setSupportedComponents(getIdFromMap(this.getSupportedComponents(), ActionConstants.SUPPORTED_COMPONENTS_ID));
206 destination.setSupportedModels(getIdFromMap(this.getSupportedModels(), ActionConstants.SUPPORTED_MODELS_VERSION_ID));
207 destination.setData(this.getData());
211 private Set<String> getIdFromMap(List<Map<String, String>> map, String idName) {
212 Set<String> list = new HashSet<>();
213 if (map != null && !map.isEmpty()) {
214 for (Map<String, String> entry : map) {
215 if (entry.containsKey(idName)) {
216 list.add(entry.get(idName) != null ? entry.get(idName).toLowerCase() : null);
225 public int compareTo(Object object) {
226 Action obj = (Action) object;
227 Version thisVersion = Version.valueOf(this.version);
228 Version objVersion = Version.valueOf(obj.getVersion());
229 if (obj.getName().compareTo(this.getName()) == 0) {
230 return compareVersions(objVersion, thisVersion);
232 return obj.getName().compareTo(this.getName());
235 private int compareVersions(Version objVersion, Version thisVersion) {
236 if (objVersion.getMajor() == thisVersion.getMajor()) {
237 return Integer.compare(objVersion.getMinor(), thisVersion.getMinor());
239 return Integer.compare(objVersion.getMajor(), thisVersion.getMajor());
243 public boolean equals(Object o) {
247 if (o == null || getClass() != o.getClass()) {
250 Action action = (Action) o;
251 if (!Objects.equals(version, action.version)) {
254 return Objects.equals(name, action.name);
258 public int hashCode() {
259 return com.google.common.base.Objects.hashCode(version, name);