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.ClusteringColumn;
20 import com.datastax.driver.mapping.annotations.Column;
21 import com.datastax.driver.mapping.annotations.Frozen;
22 import com.datastax.driver.mapping.annotations.PartitionKey;
23 import com.datastax.driver.mapping.annotations.Table;
24 import com.google.common.io.ByteStreams;
25 import org.openecomp.sdc.common.errors.SdcRuntimeException;
26 import org.openecomp.sdc.versioning.dao.types.Version;
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
31 @Table(keyspace = "dox", name = "vsp_service_template")
32 public class ServiceTemplateEntity implements ServiceElementEntity {
34 private static final String ENTITY_TYPE;
37 ENTITY_TYPE = "Vendor Software Product Service model";
41 @Column(name = "vsp_id")
44 @PartitionKey(value = 1)
46 public Version version;
49 @Column(name = "name")
52 @Column(name = "content_data")
53 public ByteBuffer contentData;
55 @Column(name = "base_name")
56 private String baseName;
59 * Every entity class must have a default constructor according to
60 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
61 * Definition of mapped classes</a>.
63 public ServiceTemplateEntity() {
64 // Don't delete! Default constructor is required by DataStax driver
68 * Instantiates a new Service template entity.
70 * @param entity the entity
72 public ServiceTemplateEntity(ServiceTemplate entity) {
73 this.id = entity.getVspId();
74 this.version = entity.getVersion();
75 this.name = entity.getName();
76 this.setBaseName(entity.getBaseName());
78 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
79 } catch (IOException ioException) {
80 throw new SdcRuntimeException(ioException);
85 public String getBaseName() {
89 public void setBaseName(String baseName) {
90 this.baseName = baseName;
94 public String getEntityType() {
99 public String getFirstClassCitizenId() {
104 public String getId() {
109 public void setId(String id) {
114 public Version getVersion() {
119 public void setVersion(Version version) {
120 this.version = version;
124 public String getName() {
128 public void setName(String name) {
133 public ByteBuffer getContentData() {
137 public void setContentData(ByteBuffer contentData) {
138 this.contentData = contentData;
141 public ServiceTemplate getServiceTemplate() {
142 ServiceTemplate serviceTemplate = new ServiceTemplate();
143 serviceTemplate.setName(getName());
144 serviceTemplate.setVersion(getVersion());
145 serviceTemplate.setContentData(getContentData().array());
146 serviceTemplate.setVspId(getId());
147 serviceTemplate.setBaseName(getBaseName());
148 return serviceTemplate;