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.*;
20 import com.google.common.io.ByteStreams;
21 import org.openecomp.sdc.common.errors.SdcRuntimeException;
22 import org.openecomp.sdc.versioning.dao.types.Version;
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
27 @Table(keyspace = "dox", name = "vsp_enriched_service_artifact")
28 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
30 private static final String ENTITY_TYPE;
33 ENTITY_TYPE = "Vendor Software Product Service artifact";
37 @Column(name = "vsp_id")
40 @PartitionKey(value = 1)
42 public Version version;
45 @Column(name = "name")
48 @Column(name = "content_data")
49 public ByteBuffer contentData;
52 * Every entity class must have a default constructor according to
53 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
54 * Definition of mapped classes</a>.
56 public EnrichedServiceArtifactEntity() {
57 // Don't delete! Default constructor is required by DataStax driver
61 * Instantiates a new Enriched service artifact entity.
63 * @param entity the entity
65 public EnrichedServiceArtifactEntity(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 throw new SdcRuntimeException(ioException);
79 public String getEntityType() {
84 public String getFirstClassCitizenId() {
89 public String getId() {
94 public void setId(String id) {
99 public Version getVersion() {
104 public void setVersion(Version version) {
105 this.version = version;
109 public String getName() {
113 public void setName(String name) {
118 public ByteBuffer getContentData() {
122 public void setContentData(ByteBuffer contentData) {
123 this.contentData = contentData;
126 public ServiceArtifact getServiceArtifact() {
127 ServiceArtifact serviceArtifact = new ServiceArtifact();
128 serviceArtifact.setName(this.getName());
129 serviceArtifact.setVersion(this.getVersion());
130 serviceArtifact.setContentData(this.getContentData().array());
131 serviceArtifact.setVspId(this.getId());
132 return serviceArtifact;