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_service_artifact")
28 public class ServiceArtifactEntity implements ServiceElementEntity {
29 private static final String ENTITY_TYPE;
32 ENTITY_TYPE = "Vendor Software Product Service artifact";
36 @Column(name = "vsp_id")
39 @PartitionKey(value = 1)
41 public Version version;
44 @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 ServiceArtifactEntity() {
56 // Don't delete! Default constructor is required by DataStax driver
60 * Instantiates a new Service artifact entity.
62 * @param entity the entity
64 public ServiceArtifactEntity(ServiceArtifact entity) {
65 this.id = entity.getVspId();
66 this.version = entity.getVersion();
67 this.name = entity.getName();
70 this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
71 } catch (IOException ioException) {
72 throw new SdcRuntimeException(ioException);
78 public String getEntityType() {
83 public String getFirstClassCitizenId() {
88 public String getId() {
93 public void setId(String id) {
98 public Version getVersion() {
103 public void setVersion(Version version) {
104 this.version = version;
108 public String getName() {
112 public void setName(String name) {
117 public ByteBuffer getContentData() {
121 public void setContentData(ByteBuffer contentData) {
122 this.contentData = contentData;
125 public ServiceArtifact getServiceArtifact() {
126 ServiceArtifact serviceArtifact = new ServiceArtifact();
127 serviceArtifact.setName(this.getName());
128 serviceArtifact.setVersion(this.getVersion());
129 serviceArtifact.setContentData(this.getContentData().array());
130 serviceArtifact.setVspId(this.getId());
131 return serviceArtifact;