re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-model-lib / openecomp-sdc-model-api / src / main / java / org / openecomp / core / model / types / ServiceArtifactEntity.java
1 /*
2  * Copyright © 2016-2017 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.core.model.types;
18
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;
23
24 import java.io.IOException;
25 import java.nio.ByteBuffer;
26
27 @Table(keyspace = "dox", name = "vsp_service_artifact")
28 public class ServiceArtifactEntity implements ServiceElementEntity {
29     private static final String ENTITY_TYPE;
30
31     static {
32         ENTITY_TYPE = "Vendor Software Product Service artifact";
33     }
34
35     @PartitionKey
36     @Column(name = "vsp_id")
37     public String id;
38
39     @PartitionKey(value = 1)
40     @Frozen
41     public Version version;
42
43     @ClusteringColumn
44     @Column(name = "name")
45     public String name;
46
47     @Column(name = "content_data")
48     public ByteBuffer contentData;
49
50     /**
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>.
54      */
55     public ServiceArtifactEntity() {
56         // Don't delete! Default constructor is required by DataStax driver
57     }
58
59     /**
60      * Instantiates a new Service artifact entity.
61      *
62      * @param entity the entity
63      */
64     public ServiceArtifactEntity(ServiceArtifact entity) {
65         this.id = entity.getVspId();
66         this.version = entity.getVersion();
67         this.name = entity.getName();
68
69         try {
70             this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
71         } catch (IOException ioException) {
72             throw new SdcRuntimeException(ioException);
73         }
74
75     }
76
77     @Override
78     public String getEntityType() {
79         return ENTITY_TYPE;
80     }
81
82     @Override
83     public String getFirstClassCitizenId() {
84         return getId();
85     }
86
87     @Override
88     public String getId() {
89         return id;
90     }
91
92     @Override
93     public void setId(String id) {
94         this.id = id;
95     }
96
97     @Override
98     public Version getVersion() {
99         return version;
100     }
101
102     @Override
103     public void setVersion(Version version) {
104         this.version = version;
105     }
106
107     @Override
108     public String getName() {
109         return name;
110     }
111
112     public void setName(String name) {
113         this.name = name;
114     }
115
116     @Override
117     public ByteBuffer getContentData() {
118         return contentData;
119     }
120
121     public void setContentData(ByteBuffer contentData) {
122         this.contentData = contentData;
123     }
124
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;
132     }
133
134 }