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;
26 import org.openecomp.sdc.datatypes.error.ErrorLevel;
27 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
28 import org.openecomp.sdc.logging.types.LoggerConstants;
29 import org.openecomp.sdc.logging.types.LoggerErrorCode;
30 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
31 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
32 import org.openecomp.sdc.versioning.dao.types.Version;
34 import java.io.IOException;
35 import java.nio.ByteBuffer;
37 @Table(keyspace = "dox", name = "vsp_service_artifact")
38 public class ServiceArtifactEntity implements ServiceElementEntity {
39 private static final String ENTITY_TYPE;
42 ENTITY_TYPE = "Vendor Software Product Service artifact";
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;
61 * Instantiates a new Service artifact entity.
63 * @param entity the entity
65 public ServiceArtifactEntity(ServiceArtifact entity) {
66 this.id = entity.getVspId();
67 this.version = entity.getVersion();
68 this.name = entity.getName();
71 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
72 } catch (IOException ioException) {
73 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
74 LoggerTragetServiceName.CREATE_SERVICE_ARTIFACT, ErrorLevel.ERROR.name(),
75 LoggerErrorCode.DATA_ERROR.getErrorCode(),
76 LoggerErrorDescription.CREATE_SERVICE_ARTIFACT);
77 throw new RuntimeException(ioException);
83 public String getEntityType() {
88 public String getFirstClassCitizenId() {
93 public String getId() {
98 public void setId(String id) {
103 public Version getVersion() {
108 public void setVersion(Version version) {
109 this.version = version;
113 public String getName() {
117 public void setName(String name) {
122 public ByteBuffer getContentData() {
126 public void setContentData(ByteBuffer contentData) {
127 this.contentData = contentData;
131 * Gets service artifact.
133 * @return the service artifact
135 public ServiceArtifact getServiceArtifact() {
136 ServiceArtifact serviceArtifact = new ServiceArtifact();
137 serviceArtifact.setName(this.getName());
138 serviceArtifact.setVersion(this.getVersion());
139 serviceArtifact.setContentData(this.getContentData().array());
140 serviceArtifact.setVspId(this.getId());
141 return serviceArtifact;