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.datatypes.error.ErrorLevel;
27 import org.openecomp.sdc.logging.types.LoggerConstants;
28 import org.openecomp.sdc.logging.types.LoggerErrorCode;
29 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
30 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
31 import org.openecomp.sdc.versioning.dao.types.Version;
33 import java.io.IOException;
34 import java.nio.ByteBuffer;
36 @Table(keyspace = "dox", name = "vsp_service_template")
37 public class ServiceTemplateEntity implements ServiceElementEntity {
39 private static final String ENTITY_TYPE;
42 ENTITY_TYPE = "Vendor Software Product Service model";
46 @Column(name = "vsp_id")
49 @PartitionKey(value = 1)
51 public Version version;
54 @Column(name = "name")
57 @Column(name = "content_data")
58 public ByteBuffer contentData;
60 @Column(name = "base_name")
61 private String baseName;
64 * Every entity class must have a default constructor according to
65 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
66 * Definition of mapped classes</a>.
68 public ServiceTemplateEntity() {
69 // Don't delete! Default constructor is required by DataStax driver
73 * Instantiates a new Service template entity.
75 * @param entity the entity
77 public ServiceTemplateEntity(ServiceTemplate entity) {
78 this.id = entity.getVspId();
79 this.version = entity.getVersion();
80 this.name = entity.getName();
81 this.setBaseName(entity.getBaseName());
83 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
84 } catch (IOException ioException) {
85 throw new SdcRuntimeException(ioException);
90 public String getBaseName() {
94 public void setBaseName(String baseName) {
95 this.baseName = baseName;
99 public String getEntityType() {
104 public String getFirstClassCitizenId() {
109 public String getId() {
114 public void setId(String id) {
119 public Version getVersion() {
124 public void setVersion(Version version) {
125 this.version = version;
129 public String getName() {
133 public void setName(String name) {
138 public ByteBuffer getContentData() {
142 public void setContentData(ByteBuffer contentData) {
143 this.contentData = contentData;
146 public ServiceTemplate getServiceTemplate() {
147 ServiceTemplate serviceTemplate = new ServiceTemplate();
148 serviceTemplate.setName(getName());
149 serviceTemplate.setVersion(getVersion());
150 serviceTemplate.setContentData(getContentData().array());
151 serviceTemplate.setVspId(getId());
152 serviceTemplate.setBaseName(getBaseName());
153 return serviceTemplate;