59e94ce62a7309c3e2fa22ad7a61eba6edfa4f1d
[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.CompositionEntityId;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Nic;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33
34 @Getter
35 @Setter
36 @EqualsAndHashCode
37 @NoArgsConstructor
38 @Table(keyspace = "dox", name = "vsp_component_nic")
39 public class NicEntity implements CompositionEntity {
40   private static final String ENTITY_TYPE = "Vendor Software Product NIC";
41
42   @PartitionKey
43   @Column(name = "vsp_id")
44   private String vspId;
45   @PartitionKey(value = 1)
46   @Frozen
47   private Version version;
48   @ClusteringColumn
49   @Column(name = "component_id")
50   private String componentId;
51   @ClusteringColumn(value = 1)
52   @Column(name = "nic_id")
53   private String id;
54   @Column(name = "composition_data")
55   private String compositionData;
56   @Column(name = "questionnaire_data")
57   private String questionnaireData;
58
59   /**
60    * Instantiates a new Nic entity.
61    *
62    * @param vspId       the vsp id
63    * @param version     the version
64    * @param componentId the component id
65    * @param id          the id
66    */
67   public NicEntity(String vspId, Version version, String componentId, String id) {
68     this.vspId = vspId;
69     this.version = version;
70     this.componentId = componentId;
71     this.id = id;
72   }
73
74   @Override
75   public CompositionEntityType getType() {
76     return CompositionEntityType.nic;
77   }
78
79   @Override
80   public CompositionEntityId getCompositionEntityId() {
81     return new CompositionEntityId(getId(),
82         new CompositionEntityId(getComponentId(), new CompositionEntityId(getVspId(), null)));
83   }
84
85   @Override
86   public String getEntityType() {
87     return ENTITY_TYPE;
88   }
89
90   @Override
91   public String getFirstClassCitizenId() {
92     return getVspId();
93   }
94
95   public Nic getNicCompositionData() {
96     return compositionData == null ? null : JsonUtil.json2Object(compositionData, Nic.class);
97   }
98
99   public void setNicCompositionData(Nic nic) {
100     this.compositionData = nic == null ? null : JsonUtil.object2Json(nic);
101   }
102 }