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.common.errors.SdcRuntimeException;
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_enriched_service_artifact")
38 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
40 private static final String ENTITY_TYPE;
43 ENTITY_TYPE = "Vendor Software Product Service artifact";
47 @Column(name = "vsp_id")
50 @PartitionKey(value = 1)
52 public Version version;
55 @Column(name = "name")
58 @Column(name = "content_data")
59 public ByteBuffer contentData;
62 * Every entity class must have a default constructor according to
63 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
64 * Definition of mapped classes</a>.
66 public EnrichedServiceArtifactEntity() {
67 // Don't delete! Default constructor is required by DataStax driver
71 * Instantiates a new Enriched service artifact entity.
73 * @param entity the entity
75 public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
76 this.id = entity.getVspId();
77 this.version = entity.getVersion();
78 this.name = entity.getName();
81 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
82 } catch (IOException ioException) {
83 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
84 LoggerTragetServiceName.CREATE_SERVICE_ENRICH_ARTIFACT, ErrorLevel.ERROR.name(),
85 LoggerErrorCode.DATA_ERROR.getErrorCode(),
86 LoggerErrorDescription.CREATE_ENRICH_SERVICE_ARTIFACT);
87 throw new SdcRuntimeException(ioException);
93 public String getEntityType() {
98 public String getFirstClassCitizenId() {
103 public String getId() {
108 public void setId(String id) {
113 public Version getVersion() {
118 public void setVersion(Version version) {
119 this.version = version;
123 public String getName() {
127 public void setName(String name) {
132 public ByteBuffer getContentData() {
136 public void setContentData(ByteBuffer contentData) {
137 this.contentData = contentData;
140 public ServiceArtifact getServiceArtifact() {
141 ServiceArtifact serviceArtifact = new ServiceArtifact();
142 serviceArtifact.setName(this.getName());
143 serviceArtifact.setVersion(this.getVersion());
144 serviceArtifact.setContentData(this.getContentData().array());
145 serviceArtifact.setVspId(this.getId());
146 return serviceArtifact;