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.
17 package org.openecomp.core.model.types;
19 import com.datastax.driver.mapping.annotations.*;
20 import com.google.common.io.ByteStreams;
21 import org.openecomp.sdc.common.errors.SdcRuntimeException;
22 import org.openecomp.sdc.versioning.dao.types.Version;
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
27 @Table(keyspace = "dox", name = "vsp_enriched_service_template")
28 public class EnrichedServiceTemplateEntity implements ServiceElementEntity {
30 private static final String ENTITY_TYPE;
33 ENTITY_TYPE = "Vendor Software Product Service model";
37 @Column(name = "vsp_id")
40 @PartitionKey(value = 1)
42 public Version version;
45 @Column(name = "name")
48 @Column(name = "content_data")
49 public ByteBuffer contentData;
51 @Column(name = "base_name")
52 private String baseName;
55 * Every entity class must have a default constructor according to
56 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
57 * Definition of mapped classes</a>.
59 public EnrichedServiceTemplateEntity() {
60 // Don't delete! Default constructor is required by DataStax driver
64 * Instantiates a new Enriched service template entity.
66 * @param entity the entity
68 public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
69 this.id = entity.getVspId();
70 this.version = entity.getVersion();
71 this.name = entity.getName();
72 this.setBaseName(entity.getBaseName());
74 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
75 } catch (IOException ioException) {
76 throw new SdcRuntimeException(ioException);
81 public String getBaseName() {
85 public void setBaseName(String baseName) {
86 this.baseName = baseName;
90 public String getEntityType() {
95 public String getFirstClassCitizenId() {
100 public String getId() {
105 public void setId(String id) {
110 public Version getVersion() {
115 public void setVersion(Version version) {
116 this.version = version;
120 public String getName() {
124 public void setName(String name) {
129 public ByteBuffer getContentData() {
133 public void setContentData(ByteBuffer contentData) {
134 this.contentData = contentData;
137 public ServiceTemplate getServiceTemplate() {
138 ServiceTemplate serviceTemplate = new ServiceTemplate();
139 serviceTemplate.setName(getName());
140 serviceTemplate.setVersion(getVersion());
141 serviceTemplate.setContentData(getContentData().array());
142 serviceTemplate.setVspId(getId());
143 serviceTemplate.setBaseName(getBaseName());
144 return serviceTemplate;