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;
30 import org.openecomp.sdc.datatypes.error.ErrorLevel;
31 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
32 import org.openecomp.sdc.logging.types.LoggerConstants;
33 import org.openecomp.sdc.logging.types.LoggerErrorCode;
34 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
35 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
36 import org.openecomp.sdc.versioning.dao.types.Version;
38 import java.io.IOException;
39 import java.nio.ByteBuffer;
41 @Table(keyspace = "dox", name = "vsp_service_artifact")
42 public class ServiceArtifactEntity implements ServiceElementEntity {
43 private static final String ENTITY_TYPE;
46 ENTITY_TYPE = "Vendor Software Product Service artifact";
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 public ServiceArtifactEntity() {
68 * Instantiates a new Service artifact entity.
70 * @param entity the entity
72 public ServiceArtifactEntity(ServiceArtifact entity) {
73 this.id = entity.getVspId();
74 this.version = entity.getVersion();
75 this.name = entity.getName();
78 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
79 } catch (IOException ioException) {
80 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
81 LoggerTragetServiceName.CREATE_SERVICE_ARTIFACT, ErrorLevel.ERROR.name(),
82 LoggerErrorCode.DATA_ERROR.getErrorCode(),
83 LoggerErrorDescription.CREATE_SERVICE_ARTIFACT);
84 throw new RuntimeException(ioException);
90 public String getEntityType() {
95 public String getFirstClassCitizenId() {
99 public String getId() {
103 public void setId(String id) {
108 public Version getVersion() {
113 public void setVersion(Version version) {
114 this.version = version;
117 public String getName() {
121 public void setName(String name) {
125 public ByteBuffer getContentData() {
129 public void setContentData(ByteBuffer contentData) {
130 this.contentData = contentData;
134 * Gets service artifact.
136 * @return the service artifact
138 public ServiceArtifact getServiceArtifact() {
139 ServiceArtifact serviceArtifact = new ServiceArtifact();
140 serviceArtifact.setName(this.getName());
141 serviceArtifact.setVersion(this.getVersion());
142 serviceArtifact.setContentData(this.getContentData().array());
143 serviceArtifact.setVspId(this.getId());
144 return serviceArtifact;