2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.core.model.types;
23 import com.datastax.driver.mapping.annotations.ClusteringColumn;
24 import com.datastax.driver.mapping.annotations.Column;
25 import com.datastax.driver.mapping.annotations.Frozen;
26 import com.datastax.driver.mapping.annotations.PartitionKey;
27 import com.datastax.driver.mapping.annotations.Table;
28 import com.google.common.io.ByteStreams;
29 import org.openecomp.sdc.datatypes.error.ErrorLevel;
30 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
31 import org.openecomp.sdc.logging.types.LoggerConstants;
32 import org.openecomp.sdc.logging.types.LoggerErrorCode;
33 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
34 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
35 import org.openecomp.sdc.versioning.dao.types.Version;
37 import java.io.IOException;
38 import java.nio.ByteBuffer;
40 @Table(keyspace = "dox", name = "vsp_service_template")
41 public class ServiceTemplateEntity implements ServiceElementEntity {
43 private static final String ENTITY_TYPE;
46 ENTITY_TYPE = "Vendor Software Product Service model";
50 @Column(name = "vsp_id")
53 @PartitionKey(value = 1)
55 public Version version;
58 @Column(name = "name")
61 @Column(name = "content_data")
62 public ByteBuffer contentData;
64 @Column(name = "base_name")
65 private String baseName;
67 public ServiceTemplateEntity() {
71 * Instantiates a new Service template entity.
73 * @param entity the entity
75 public ServiceTemplateEntity(ServiceTemplate entity) {
76 this.id = entity.getVspId();
77 this.version = entity.getVersion();
78 this.name = entity.getName();
79 this.setBaseName(entity.getBaseName());
81 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
82 } catch (IOException ioException) {
83 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
84 LoggerTragetServiceName.CREATE_SERVICE_TEMPLATE, ErrorLevel.ERROR.name(),
85 LoggerErrorCode.DATA_ERROR.getErrorCode(),
86 LoggerErrorDescription.CREATE_SERVICE_TEMPLATE);
87 throw new RuntimeException(ioException);
92 public String getBaseName() {
96 public void setBaseName(String baseName) {
97 this.baseName = baseName;
101 public String getEntityType() {
106 public String getFirstClassCitizenId() {
110 public String getId() {
114 public void setId(String id) {
119 public Version getVersion() {
124 public void setVersion(Version version) {
125 this.version = version;
128 public String getName() {
132 public void setName(String name) {
136 public ByteBuffer getContentData() {
140 public void setContentData(ByteBuffer contentData) {
141 this.contentData = contentData;
146 * Gets service template.
148 * @return the service template
150 public ServiceTemplate getServiceTemplate() {
151 ServiceTemplate serviceTemplate = new ServiceTemplate();
152 serviceTemplate.setName(this.getName());
153 serviceTemplate.setVersion(this.getVersion());
154 serviceTemplate.setContentData(this.getContentData().array());
155 serviceTemplate.setVspId(this.getId());
156 serviceTemplate.setBaseName(this.getBaseName());
157 return serviceTemplate;