push addional code
[sdc.git] / openecomp-be / lib / openecomp-sdc-model-lib / openecomp-sdc-model-api / src / main / java / org / openecomp / core / model / types / EnrichedServiceTemplateEntity.java
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.core.model.types;
22
23 import com.google.common.io.ByteStreams;
24
25 import com.datastax.driver.mapping.annotations.ClusteringColumn;
26 import com.datastax.driver.mapping.annotations.Column;
27 import com.datastax.driver.mapping.annotations.Frozen;
28 import com.datastax.driver.mapping.annotations.PartitionKey;
29 import com.datastax.driver.mapping.annotations.Table;
30 import org.openecomp.sdc.versioning.dao.types.Version;
31
32 import java.io.IOException;
33 import java.nio.ByteBuffer;
34
35 @Table(keyspace = "dox", name = "vsp_enriched_service_template")
36 public class EnrichedServiceTemplateEntity implements ServiceElementEntity {
37
38   private static final String ENTITY_TYPE;
39
40   static {
41     ENTITY_TYPE = "Vendor Software Product Service model";
42   }
43
44   @PartitionKey
45   @Column(name = "vsp_id")
46   public String id;
47
48   @PartitionKey(value = 1)
49   @Frozen
50   public Version version;
51
52   @ClusteringColumn
53   @Column(name = "name")
54   public String name;
55
56   @Column(name = "content_data")
57   public ByteBuffer contentData;
58
59
60   @Column(name = "base_name")
61   private String baseName;
62
63   public EnrichedServiceTemplateEntity() {
64   }
65
66   /**
67    * Instantiates a new Enriched service template entity.
68    *
69    * @param entity the entity
70    */
71   public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
72     this.id = entity.getVspId();
73     this.version = entity.getVersion();
74     this.name = entity.getName();
75     this.setBaseName(entity.getBaseName());
76     try {
77       this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
78     } catch (IOException ioException) {
79       throw new RuntimeException(ioException);
80     }
81
82   }
83
84
85   public String getBaseName() {
86     return baseName;
87   }
88
89   public void setBaseName(String baseName) {
90     this.baseName = baseName;
91   }
92
93
94   @Override
95   public String getEntityType() {
96     return ENTITY_TYPE;
97   }
98
99   @Override
100   public String getFirstClassCitizenId() {
101     return getId();
102   }
103
104   public String getId() {
105     return id;
106   }
107
108   public void setId(String id) {
109     this.id = id;
110   }
111
112   @Override
113   public Version getVersion() {
114     return version;
115   }
116
117   @Override
118   public void setVersion(Version version) {
119     this.version = version;
120   }
121
122   public String getName() {
123     return name;
124   }
125
126   public void setName(String name) {
127     this.name = name;
128   }
129
130   public ByteBuffer getContentData() {
131     return contentData;
132   }
133
134   public void setContentData(ByteBuffer contentData) {
135     this.contentData = contentData;
136   }
137
138
139   /**
140    * Gets service template.
141    *
142    * @return the service template
143    */
144   public ServiceTemplate getServiceTemplate() {
145     ServiceTemplate serviceTemplate = new ServiceTemplate();
146     serviceTemplate.setName(this.getName());
147     serviceTemplate.setVersion(this.getVersion());
148     serviceTemplate.setContentData(this.getContentData().array());
149     serviceTemplate.setVspId(this.getId());
150     serviceTemplate.setBaseName(this.getBaseName());
151     return serviceTemplate;
152
153   }
154 }