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.versioning.dao.types.Version;
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
31 @Table(keyspace = "dox", name = "vsp_enriched_service_artifact")
32 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
34 private static final String ENTITY_TYPE;
37 ENTITY_TYPE = "Vendor Software Product Service artifact";
41 @Column(name = "vsp_id")
44 @PartitionKey(value = 1)
46 public Version version;
49 @Column(name = "name")
52 @Column(name = "content_data")
53 public ByteBuffer contentData;
56 * Every entity class must have a default constructor according to
57 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
58 * Definition of mapped classes</a>.
60 public EnrichedServiceArtifactEntity() {
61 // Don't delete! Default constructor is required by DataStax driver
65 * Instantiates a new Enriched service artifact entity.
67 * @param entity the entity
69 public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
70 this.id = entity.getVspId();
71 this.version = entity.getVersion();
72 this.name = entity.getName();
75 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
76 } catch (IOException ioException) {
77 throw new SdcRuntimeException(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;
130 public ServiceArtifact getServiceArtifact() {
131 ServiceArtifact serviceArtifact = new ServiceArtifact();
132 serviceArtifact.setName(this.getName());
133 serviceArtifact.setVersion(this.getVersion());
134 serviceArtifact.setContentData(this.getContentData().array());
135 serviceArtifact.setVspId(this.getId());
136 return serviceArtifact;