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.datatypes.error.ErrorLevel;
26 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
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_enriched_service_template")
37 public class EnrichedServiceTemplateEntity 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 * Instantiates a new Enriched service template entity.
66 * @param entity the entity
68 public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
69 this.id = entity.getVspId();
70 this.version = entity.getVersion();
71 this.name = entity.getName();
72 this.setBaseName(entity.getBaseName());
74 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
75 } catch (IOException ioException) {
76 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
77 LoggerTragetServiceName.CREATE_ENRICH_SERVICE_TEMPLATE, ErrorLevel.ERROR.name(),
78 LoggerErrorCode.DATA_ERROR.getErrorCode(),
79 LoggerErrorDescription.CREATE_ENRICH_SERVICE_TEMPLATE);
80 throw new RuntimeException(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;
142 * Gets service template.
144 * @return the service template
146 public ServiceTemplate getServiceTemplate() {
147 ServiceTemplate serviceTemplate = new ServiceTemplate();
148 serviceTemplate.setName(this.getName());
149 serviceTemplate.setVersion(this.getVersion());
150 serviceTemplate.setContentData(this.getContentData().array());
151 serviceTemplate.setVspId(this.getId());
152 serviceTemplate.setBaseName(this.getBaseName());
153 return serviceTemplate;