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_service_artifact")
32 public class ServiceArtifactEntity implements ServiceElementEntity {
33 private static final String ENTITY_TYPE;
36 ENTITY_TYPE = "Vendor Software Product Service artifact";
40 @Column(name = "vsp_id")
43 @PartitionKey(value = 1)
45 public Version version;
48 @Column(name = "name")
51 @Column(name = "content_data")
52 public ByteBuffer contentData;
55 * Every entity class must have a default constructor according to
56 * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
57 * Definition of mapped classes</a>.
59 public ServiceArtifactEntity() {
60 // Don't delete! Default constructor is required by DataStax driver
64 * Instantiates a new Service artifact entity.
66 * @param entity the entity
68 public ServiceArtifactEntity(ServiceArtifact entity) {
69 this.id = entity.getVspId();
70 this.version = entity.getVersion();
71 this.name = entity.getName();
74 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
75 } catch (IOException ioException) {
76 throw new SdcRuntimeException(ioException);
82 public String getEntityType() {
87 public String getFirstClassCitizenId() {
92 public String getId() {
97 public void setId(String id) {
102 public Version getVersion() {
107 public void setVersion(Version version) {
108 this.version = version;
112 public String getName() {
116 public void setName(String name) {
121 public ByteBuffer getContentData() {
125 public void setContentData(ByteBuffer contentData) {
126 this.contentData = contentData;
129 public ServiceArtifact getServiceArtifact() {
130 ServiceArtifact serviceArtifact = new ServiceArtifact();
131 serviceArtifact.setName(this.getName());
132 serviceArtifact.setVersion(this.getVersion());
133 serviceArtifact.setContentData(this.getContentData().array());
134 serviceArtifact.setVspId(this.getId());
135 return serviceArtifact;