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.google.common.io.ByteStreams;
21 import com.datastax.driver.mapping.annotations.ClusteringColumn;
22 import com.datastax.driver.mapping.annotations.Column;
23 import com.datastax.driver.mapping.annotations.Frozen;
24 import com.datastax.driver.mapping.annotations.PartitionKey;
25 import com.datastax.driver.mapping.annotations.Table;
27 import org.openecomp.sdc.datatypes.error.ErrorLevel;
28 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
29 import org.openecomp.sdc.logging.types.LoggerConstants;
30 import org.openecomp.sdc.logging.types.LoggerErrorCode;
31 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
32 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
33 import org.openecomp.sdc.versioning.dao.types.Version;
35 import java.io.IOException;
36 import java.nio.ByteBuffer;
38 @Table(keyspace = "dox", name = "vsp_enriched_service_template")
39 public class EnrichedServiceTemplateEntity implements ServiceElementEntity {
41 private static final String ENTITY_TYPE;
44 ENTITY_TYPE = "Vendor Software Product Service model";
48 @Column(name = "vsp_id")
51 @PartitionKey(value = 1)
53 public Version version;
56 @Column(name = "name")
59 @Column(name = "content_data")
60 public ByteBuffer contentData;
62 @Column(name = "base_name")
63 private String baseName;
66 * Instantiates a new Enriched service template entity.
68 * @param entity the entity
70 public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
71 this.id = entity.getVspId();
72 this.version = entity.getVersion();
73 this.name = entity.getName();
74 this.setBaseName(entity.getBaseName());
76 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
77 } catch (IOException ioException) {
78 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
79 LoggerTragetServiceName.CREATE_ENRICH_SERVICE_TEMPLATE, ErrorLevel.ERROR.name(),
80 LoggerErrorCode.DATA_ERROR.getErrorCode(),
81 LoggerErrorDescription.CREATE_ENRICH_SERVICE_TEMPLATE);
82 throw new RuntimeException(ioException);
87 public String getBaseName() {
91 public void setBaseName(String baseName) {
92 this.baseName = baseName;
96 public String getEntityType() {
101 public String getFirstClassCitizenId() {
106 public String getId() {
111 public void setId(String id) {
116 public Version getVersion() {
121 public void setVersion(Version version) {
122 this.version = version;
126 public String getName() {
130 public void setName(String name) {
135 public ByteBuffer getContentData() {
139 public void setContentData(ByteBuffer contentData) {
140 this.contentData = contentData;
144 * Gets service template.
146 * @return the service template
148 public ServiceTemplate getServiceTemplate() {
149 ServiceTemplate serviceTemplate = new ServiceTemplate();
150 serviceTemplate.setName(this.getName());
151 serviceTemplate.setVersion(this.getVersion());
152 serviceTemplate.setContentData(this.getContentData().array());
153 serviceTemplate.setVspId(this.getId());
154 serviceTemplate.setBaseName(this.getBaseName());
155 return serviceTemplate;