9d0f3d830d402b032618674ce5e17d1dea04cddc
[sdc.git] /
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.dao.types;
22
23 import com.datastax.driver.mapping.annotations.Column;
24 import com.datastax.driver.mapping.annotations.Frozen;
25 import com.datastax.driver.mapping.annotations.PartitionKey;
26 import com.datastax.driver.mapping.annotations.Table;
27 import org.openecomp.core.utilities.json.JsonUtil;
28 import org.openecomp.sdc.action.types.Action;
29 import org.openecomp.sdc.versioning.dao.types.Version;
30
31 import java.util.ArrayList;
32 import java.util.Date;
33 import java.util.List;
34 import java.util.stream.Collectors;
35
36
37 @Table(keyspace = "dox", name = "Action")
38 public class ActionEntity {
39
40   @Column(name = "actionUuId")
41   private String actionUuId;
42   @PartitionKey(value = 0)
43   @Column(name = "actionInvariantUuId")
44   private String actionInvariantUuId;
45   @PartitionKey(value = 1)
46   @Frozen
47   @Column(name = "version")
48   private Version version;
49   @Column(name = "status")
50   private String status;
51   @Column(name = "name")
52   private String name;
53   @Column(name = "vendor_list")
54   private List<String> vendorList;
55   @Column(name = "category_list")
56   private List<String> categoryList;
57   @Column(name = "timestamp")
58   private Date timestamp;
59   @Column(name = "user")
60   private String user;
61   @Column(name = "supportedModels")
62   private List<String> supportedModels;
63   @Column(name = "supportedComponents")
64   private List<String> supportedComponents;
65   @Column(name = "data")
66   private String data;
67
68   /**
69    * Every entity class must have a default constructor according to
70    * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
71    * Definition of mapped classes</a>.
72    */
73   public ActionEntity() {
74     // Don't delete! Default constructor is required by DataStax driver
75   }
76
77   public ActionEntity(String actionInvariantUuId, Version version) {
78     this.actionInvariantUuId = actionInvariantUuId;
79     this.version = version;
80   }
81
82   public String getActionUuId() {
83     return actionUuId;
84   }
85
86   public void setActionUuId(String actionUuId) {
87     this.actionUuId = actionUuId;
88   }
89
90   public String getActionInvariantUuId() {
91     return actionInvariantUuId;
92   }
93
94   public void setActionInvariantUuId(String actionInvariantUuId) {
95     this.actionInvariantUuId = actionInvariantUuId;
96   }
97
98   public Version getVersion() {
99     return version;
100   }
101
102   public void setVersion(Version version) {
103     this.version = version;
104   }
105
106   public String getStatus() {
107     return status;
108   }
109
110   public void setStatus(String status) {
111     this.status = status;
112   }
113
114   public String getName() {
115     return name;
116   }
117
118   public void setName(String name) {
119     this.name = name;
120   }
121
122   public List<String> getVendorList() {
123     return vendorList;
124   }
125
126   /**
127    * Sets vendor list.
128    *
129    * @param vendorList the vendor list
130    */
131   public void setVendorList(List<String> vendorList) {
132     if (vendorList != null && !vendorList.isEmpty()) {
133       List<String> lowerCaseVendorList = new ArrayList<>();
134       lowerCaseVendorList
135           .addAll(vendorList.stream().map(String::toLowerCase).collect(Collectors.toList()));
136       this.vendorList = lowerCaseVendorList;
137     } else {
138       this.vendorList = vendorList;
139     }
140   }
141
142   public List<String> getCategoryList() {
143     return categoryList;
144   }
145
146   /**
147    * Sets category list.
148    *
149    * @param categoryList the category list
150    */
151   public void setCategoryList(List<String> categoryList) {
152     if (categoryList != null && !categoryList.isEmpty()) {
153       List<String> lowerCaseCategoryList = new ArrayList<>();
154       lowerCaseCategoryList
155           .addAll(categoryList.stream().map(String::toLowerCase).collect(Collectors.toList()));
156       this.categoryList = lowerCaseCategoryList;
157     } else {
158       this.categoryList = categoryList;
159     }
160   }
161
162   public Date getTimestamp() {
163     return timestamp;
164   }
165
166   public void setTimestamp(Date timestamp) {
167     this.timestamp = timestamp;
168   }
169
170   public String getUser() {
171     return user;
172   }
173
174   public void setUser(String user) {
175     this.user = user;
176   }
177
178   public List<String> getSupportedModels() {
179     return supportedModels;
180   }
181
182   public void setSupportedModels(List<String> supportedModels) {
183     this.supportedModels = supportedModels;
184   }
185
186   public List<String> getSupportedComponents() {
187     return supportedComponents;
188   }
189
190   public void setSupportedComponents(List<String> supportedComponents) {
191     this.supportedComponents = supportedComponents;
192   }
193
194   public String getData() {
195     return data;
196   }
197
198   public void setData(String data) {
199     this.data = data;
200   }
201
202   /**
203    * To dto action.
204    *
205    * @return the action
206    */
207   public Action toDto() {
208     Action destination = JsonUtil.json2Object(this.getData(), Action.class);
209     destination.setData(this.getData());
210     destination.setTimestamp(this.getTimestamp());
211     destination.setUser(this.getUser());
212     destination.setData(this.getData());
213     return destination;
214   }
215
216 }