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.google.common.io.ByteStreams;
25 import com.datastax.driver.mapping.annotations.ClusteringColumn;
26 import com.datastax.driver.mapping.annotations.Column;
27 import com.datastax.driver.mapping.annotations.Frozen;
28 import com.datastax.driver.mapping.annotations.PartitionKey;
29 import com.datastax.driver.mapping.annotations.Table;
31 import org.openecomp.sdc.datatypes.error.ErrorLevel;
32 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
33 import org.openecomp.sdc.logging.types.LoggerConstants;
34 import org.openecomp.sdc.logging.types.LoggerErrorCode;
35 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
36 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
37 import org.openecomp.sdc.versioning.dao.types.Version;
39 import java.io.IOException;
40 import java.nio.ByteBuffer;
42 @Table(keyspace = "dox", name = "vsp_service_template")
43 public class ServiceTemplateEntity implements ServiceElementEntity {
45 private static final String ENTITY_TYPE;
48 ENTITY_TYPE = "Vendor Software Product Service model";
52 @Column(name = "vsp_id")
55 @PartitionKey(value = 1)
57 public Version version;
60 @Column(name = "name")
63 @Column(name = "content_data")
64 public ByteBuffer contentData;
66 @Column(name = "base_name")
67 private String baseName;
69 public ServiceTemplateEntity() {
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 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
86 LoggerTragetServiceName.CREATE_SERVICE_TEMPLATE, ErrorLevel.ERROR.name(),
87 LoggerErrorCode.DATA_ERROR.getErrorCode(),
88 LoggerErrorDescription.CREATE_SERVICE_TEMPLATE);
89 throw new RuntimeException(ioException);
94 public String getBaseName() {
98 public void setBaseName(String baseName) {
99 this.baseName = baseName;
103 public String getEntityType() {
108 public String getFirstClassCitizenId() {
112 public String getId() {
116 public void setId(String id) {
121 public Version getVersion() {
126 public void setVersion(Version version) {
127 this.version = version;
130 public String getName() {
134 public void setName(String name) {
138 public ByteBuffer getContentData() {
142 public void setContentData(ByteBuffer contentData) {
143 this.contentData = contentData;
148 * Gets service template.
150 * @return the service template
152 public ServiceTemplate getServiceTemplate() {
153 ServiceTemplate serviceTemplate = new ServiceTemplate();
154 serviceTemplate.setName(this.getName());
155 serviceTemplate.setVersion(this.getVersion());
156 serviceTemplate.setContentData(this.getContentData().array());
157 serviceTemplate.setVspId(this.getId());
158 serviceTemplate.setBaseName(this.getBaseName());
159 return serviceTemplate;