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