[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / lib / openecomp-sdc-action-lib / openecomp-sdc-action-api / src / main / java / org / openecomp / sdc / action / types / Action.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.action.types;
22
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;
26
27 import java.util.ArrayList;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.List;
31
32 public class Action implements Comparable {
33   private String actionUuId;
34   private String actionInvariantUuId;
35   private String version;
36   private ActionStatus status;
37   private String name;
38   private String displayName;
39   private List<String> vendorList;
40   private List<String> categoryList;
41   private Date timestamp;
42   private String user;
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;
47   private String data;
48
49   public Action() {
50   }
51
52   /**
53    * Instantiates a new Action.
54    *
55    * @param action the action
56    */
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();
72   }
73
74   public String getActionUuId() {
75     return actionUuId;
76   }
77
78   public void setActionUuId(String actionUuId) {
79     this.actionUuId = actionUuId;
80   }
81
82   public String getActionInvariantUuId() {
83     return actionInvariantUuId;
84   }
85
86   public void setActionInvariantUuId(String actionInvariantUuId) {
87     this.actionInvariantUuId = actionInvariantUuId;
88   }
89
90   public String getVersion() {
91     return version;
92   }
93
94   public void setVersion(String version) {
95     this.version = version;
96   }
97
98   public ActionStatus getStatus() {
99     return status;
100   }
101
102   public void setStatus(ActionStatus status) {
103     this.status = status;
104   }
105
106   public String getName() {
107     return name;
108   }
109
110   public void setName(String name) {
111     this.name = name;
112   }
113
114   public String getDisplayName() {
115     return displayName;
116   }
117
118   public void setDisplayName(String displayName) {
119     this.displayName = displayName;
120   }
121
122   public List<String> getVendorList() {
123     return vendorList;
124   }
125
126   public void setVendorList(List<String> vendorList) {
127     this.vendorList = vendorList;
128   }
129
130   public List<String> getCategoryList() {
131     return categoryList;
132   }
133
134   public void setCategoryList(List<String> categoryList) {
135     this.categoryList = categoryList;
136   }
137
138   public Date getTimestamp() {
139     return timestamp;
140   }
141
142   public void setTimestamp(Date timestamp) {
143     this.timestamp = timestamp;
144   }
145
146   public String getUser() {
147     return user;
148   }
149
150   public void setUser(String user) {
151     this.user = user;
152   }
153
154   public List<HashMap<String, String>> getSupportedModels() {
155     return supportedModels;
156   }
157
158   public void setSupportedModels(List<HashMap<String, String>> supportedModels) {
159     this.supportedModels = supportedModels;
160   }
161
162   public List<HashMap<String, String>> getSupportedComponents() {
163     return supportedComponents;
164   }
165
166   public void setSupportedComponents(List<HashMap<String, String>> supportedComponents) {
167     this.supportedComponents = supportedComponents;
168   }
169
170
171   public List<ActionArtifact> getArtifacts() {
172     return artifacts;
173   }
174
175   public void setArtifacts(List<ActionArtifact> artifacts) {
176     this.artifacts = artifacts;
177   }
178
179   public String getData() {
180     return data;
181   }
182
183   public void setData(String data) {
184     this.data = data;
185   }
186
187   /**
188    * To entity action entity.
189    *
190    * @return the action entity
191    */
192   public ActionEntity toEntity() {
193     ActionEntity destination = new ActionEntity();
194
195     destination
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());
207     }
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());
213     return destination;
214   }
215
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);
222         }
223       }
224       return list;
225     }
226     return null;
227   }
228
229   @Override
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);
236     }
237     return obj.getName().compareTo(this.getName());
238   }
239
240   private int compareVersions(Version objVersion, Version thisVersion) {
241     if (objVersion.getMajor() == thisVersion.getMajor()) {
242       return Integer.compare(objVersion.getMinor(), thisVersion.getMinor());
243     }
244     return Integer.compare(objVersion.getMajor(), thisVersion.getMajor());
245   }
246
247 }