18c4d949aba758f4b8133132b7de20a9bc73fe54
[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.vendorsoftwareproduct.dao.type;
22
23 import com.datastax.driver.mapping.annotations.*;
24 import lombok.EqualsAndHashCode;
25 import lombok.Getter;
26 import lombok.NoArgsConstructor;
27 import lombok.Setter;
28 import org.openecomp.core.utilities.json.JsonUtil;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComponentData;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33
34 import java.util.ArrayList;
35 import java.util.List;
36
37 @EqualsAndHashCode
38 @Getter
39 @Setter
40 @NoArgsConstructor
41 @Table(keyspace = "dox", name = "vsp_component")
42 public class ComponentEntity implements CompositionEntity {
43   public static final String ENTITY_TYPE = "Vendor Software Product Component";
44
45   @PartitionKey
46   @Column(name = "vsp_id")
47   private String vspId;
48   @PartitionKey(value = 1)
49   @Frozen
50   private Version version;
51   @ClusteringColumn
52   @Column(name = "component_id")
53   private String id;
54   @Column(name = "composition_data")
55   private String compositionData;
56   @Column(name = "questionnaire_data")
57   private String questionnaireData;
58   @Transient
59   private List<NicEntity> nics = new ArrayList<>();
60
61   /**
62    * Instantiates a new Component entity.
63    *
64    * @param vspId   the vsp id
65    * @param version the version
66    * @param id      the id
67    */
68   public ComponentEntity(String vspId, Version version, String id) {
69     this.vspId = vspId;
70     this.version = version;
71     this.id = id;
72   }
73
74   @Override
75   public CompositionEntityType getType() {
76     return CompositionEntityType.component;
77   }
78
79   @Override
80   public CompositionEntityId getCompositionEntityId() {
81     return new CompositionEntityId(getId(), new CompositionEntityId(getVspId(), null));
82   }
83
84   @Override
85   public String getEntityType() {
86     return ENTITY_TYPE;
87   }
88
89   @Override
90   public String getFirstClassCitizenId() {
91     return getVspId();
92   }
93
94   public ComponentData getComponentCompositionData() {
95     return compositionData == null ? null
96         : JsonUtil.json2Object(compositionData, ComponentData.class);
97   }
98
99   public void setComponentCompositionData(ComponentData component) {
100     this.compositionData = component == null ? null : JsonUtil.object2Json(component);
101   }
102 }