2 * Copyright © 2016-2017 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openecomp.core.model.types;
18 import com.datastax.driver.mapping.annotations.ClusteringColumn;
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 import com.google.common.io.ByteStreams;
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
26 import org.openecomp.sdc.common.errors.SdcRuntimeException;
27 import org.openecomp.sdc.versioning.dao.types.Version;
29 @Table(keyspace = "dox", name = "vsp_enriched_service_template")
30 public class EnrichedServiceTemplateEntity implements ServiceElementEntity {
32 private static final String ENTITY_TYPE;
35 ENTITY_TYPE = "Vendor Software Product Service model";
39 @Column(name = "vsp_id")
41 @PartitionKey(value = 1)
43 public Version version;
45 @Column(name = "name")
47 @Column(name = "content_data")
48 public ByteBuffer contentData;
49 @Column(name = "base_name")
50 private String baseName;
53 * Every entity class must have a default constructor according to
54 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
55 * Definition of mapped classes</a>.
57 public EnrichedServiceTemplateEntity() {
58 // Don't delete! Default constructor is required by DataStax driver
62 * Instantiates a new Enriched service template entity.
64 * @param entity the entity
66 public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
67 this.id = entity.getVspId();
68 this.version = entity.getVersion();
69 this.name = entity.getName();
70 this.setBaseName(entity.getBaseName());
72 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
73 } catch (IOException ioException) {
74 throw new SdcRuntimeException(ioException);
78 public String getBaseName() {
82 public void setBaseName(String baseName) {
83 this.baseName = baseName;
87 public String getEntityType() {
92 public String getFirstClassCitizenId() {
97 public String getId() {
102 public void setId(String id) {
107 public Version getVersion() {
112 public void setVersion(Version version) {
113 this.version = version;
117 public String getName() {
121 public void setName(String name) {
126 public ByteBuffer getContentData() {
130 public void setContentData(ByteBuffer contentData) {
131 this.contentData = contentData;
134 public ServiceTemplate getServiceTemplate() {
135 ServiceTemplate serviceTemplate = new ServiceTemplate();
136 serviceTemplate.setName(getName());
137 serviceTemplate.setVersion(getVersion());
138 serviceTemplate.setContentData(getContentData().array());
139 serviceTemplate.setVspId(getId());
140 serviceTemplate.setBaseName(getBaseName());
141 return serviceTemplate;