590fca602e2f84f73d51f6097be4a0da776cc5d4
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.Getter;
25 import lombok.NoArgsConstructor;
26 import lombok.Setter;
27 import org.openecomp.core.utilities.json.JsonUtil;
28 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityId;
29 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.CompositionEntityType;
30 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.ComputeData;
31 import org.openecomp.sdc.versioning.dao.types.Version;
32
33 @Getter
34 @Setter
35 @NoArgsConstructor
36 @Table(keyspace = "dox", name = "vsp_component_compute")
37 public class ComputeEntity implements CompositionEntity {
38   public static final String ENTITY_TYPE = "Vendor Software Product Component Compute Flavor";
39
40   @PartitionKey
41   @Column(name = "vsp_id")
42   private String vspId;
43   @PartitionKey(value = 1)
44   @Frozen
45   private Version version;
46   @ClusteringColumn
47   @Column(name = "component_id")
48   private String componentId;
49   @ClusteringColumn(value = 1)
50   @Column(name = "compute_id")
51   private String id;
52   @Column(name = "composition_data")
53   private String compositionData;
54   @Column(name = "questionnaire_data")
55   private String questionnaireData;
56
57   public ComputeEntity(String vspId, Version version, String componentId, String id) {
58     this.vspId = vspId;
59     this.version = version;
60     this.componentId = componentId;
61     this.id = id;
62   }
63
64   @Override
65   public String getEntityType() {
66     return ENTITY_TYPE;
67   }
68
69   @Override
70   public String getFirstClassCitizenId() {
71     return getVspId();
72   }
73
74   @Override
75   public CompositionEntityType getType() {
76     return CompositionEntityType.compute;
77   }
78
79   @Override
80   public CompositionEntityId getCompositionEntityId() {
81     return new CompositionEntityId(getId(),
82         new CompositionEntityId(getComponentId(), new CompositionEntityId(getVspId(), null)));
83   }
84
85   public ComputeData getComputeCompositionData() {
86     return compositionData == null ? null
87         : JsonUtil.json2Object(compositionData, ComputeData.class);
88   }
89
90   public void setComputeCompositionData(ComputeData computeData){
91     this.compositionData = computeData == null ? null : JsonUtil.object2Json(computeData);
92   }
93
94
95 }