d84d5605575777ecde7c862752b615cef1fa8e4f
[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 lombok.Getter;
29 import lombok.NoArgsConstructor;
30 import lombok.Setter;
31 import org.openecomp.core.utilities.json.JsonUtil;
32 import org.openecomp.sdc.action.types.Action;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34
35 @Getter
36 @Setter
37 @NoArgsConstructor
38 @Table(keyspace = "dox", name = "Action")
39 public class ActionEntity {
40
41   @Column(name = "actionUuId")
42   private String actionUuId;
43   @PartitionKey(value = 0)
44   @Column(name = "actionInvariantUuId")
45   private String actionInvariantUuId;
46   @PartitionKey(value = 1)
47   @Frozen
48   @Column(name = "version")
49   private Version version;
50   @Column(name = "status")
51   private String status;
52   @Column(name = "name")
53   private String name;
54   @Column(name = "vendor_list")
55   private Set<String> vendorList;
56   @Column(name = "category_list")
57   private Set<String> categoryList;
58   @Column(name = "timestamp")
59   private Date timestamp;
60   @Column(name = "user")
61   private String user;
62   @Column(name = "supportedModels")
63   private Set<String> supportedModels;
64   @Column(name = "supportedComponents")
65   private Set<String> supportedComponents;
66   @Column(name = "data")
67   private String data;
68
69   public ActionEntity(String actionInvariantUuId, Version version) {
70     this.actionInvariantUuId = actionInvariantUuId;
71     this.version = version;
72   }
73
74   /**
75    * Sets vendor list.
76    *
77    * @param vendorList the vendor list
78    */
79   public void setVendorList(Set<String> vendorList) {
80     this.vendorList = vendorList != null && !vendorList.isEmpty() ?
81                               vendorList.stream().map(String::toLowerCase).collect(Collectors.toSet()) : vendorList;
82   }
83
84   /**
85    * Sets category list.
86    *
87    * @param categoryList the category list
88    */
89   public void setCategoryList(Set<String> categoryList) {
90     this.categoryList = categoryList != null && !categoryList.isEmpty() ?
91                                 categoryList.stream().map(String::toLowerCase).collect(Collectors.toSet()) :
92                                 categoryList;
93   }
94
95   /**
96    * To dto action.
97    *
98    * @return the action
99    */
100   public Action toDto() {
101     Action destination = JsonUtil.json2Object(this.getData(), Action.class);
102     destination.setData(this.getData());
103     destination.setTimestamp(this.getTimestamp());
104     destination.setUser(this.getUser());
105     destination.setData(this.getData());
106     return destination;
107   }
108
109 }