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.
16 package org.openecomp.core.model.types;
18 import com.datastax.driver.mapping.annotations.ClusteringColumn;
19 import com.datastax.driver.mapping.annotations.Column;
20 import com.datastax.driver.mapping.annotations.Frozen;
21 import com.datastax.driver.mapping.annotations.PartitionKey;
22 import com.datastax.driver.mapping.annotations.Table;
23 import com.google.common.io.ByteStreams;
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
26 import org.openecomp.sdc.common.errors.SdcRuntimeException;
27 import org.openecomp.sdc.versioning.dao.types.Version;
29 @Table(keyspace = "dox", name = "vsp_enriched_service_artifact")
30 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
32 private static final String ENTITY_TYPE;
35 ENTITY_TYPE = "Vendor Software Product Service artifact";
39 @Column(name = "vsp_id")
41 @PartitionKey(value = 1)
43 public Version version;
45 @Column(name = "name")
47 @Column(name = "content_data")
48 public ByteBuffer contentData;
51 * Every entity class must have a default constructor according to
52 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
53 * Definition of mapped classes</a>.
55 public EnrichedServiceArtifactEntity() {
56 // Don't delete! Default constructor is required by DataStax driver
60 * Instantiates a new Enriched service artifact entity.
62 * @param entity the entity
64 public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
65 this.id = entity.getVspId();
66 this.version = entity.getVersion();
67 this.name = entity.getName();
69 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
70 } catch (IOException ioException) {
71 throw new SdcRuntimeException(ioException);
76 public String getEntityType() {
81 public String getFirstClassCitizenId() {
86 public String getId() {
91 public void setId(String id) {
96 public Version getVersion() {
101 public void setVersion(Version version) {
102 this.version = version;
106 public String getName() {
110 public void setName(String name) {
115 public ByteBuffer getContentData() {
119 public void setContentData(ByteBuffer contentData) {
120 this.contentData = contentData;
123 public ServiceArtifact getServiceArtifact() {
124 ServiceArtifact serviceArtifact = new ServiceArtifact();
125 serviceArtifact.setName(this.getName());
126 serviceArtifact.setVersion(this.getVersion());
127 serviceArtifact.setContentData(this.getContentData().array());
128 serviceArtifact.setVspId(this.getId());
129 return serviceArtifact;