re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-model-lib / openecomp-sdc-model-api / src / main / java / org / openecomp / core / model / types / EnrichedServiceArtifactEntity.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_enriched_service_artifact")
28 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
29
30     private static final String ENTITY_TYPE;
31
32     static {
33         ENTITY_TYPE = "Vendor Software Product Service artifact";
34     }
35
36     @PartitionKey
37     @Column(name = "vsp_id")
38     public String id;
39
40     @PartitionKey(value = 1)
41     @Frozen
42     public Version version;
43
44     @ClusteringColumn
45     @Column(name = "name")
46     public String name;
47
48     @Column(name = "content_data")
49     public ByteBuffer contentData;
50
51     /**
52      * Every entity class must have a default constructor according to
53      * <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/object_mapper/creating/">
54      * Definition of mapped classes</a>.
55      */
56     public EnrichedServiceArtifactEntity() {
57         // Don't delete! Default constructor is required by DataStax driver
58     }
59
60     /**
61      * Instantiates a new Enriched service artifact entity.
62      *
63      * @param entity the entity
64      */
65     public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
66         this.id = entity.getVspId();
67         this.version = entity.getVersion();
68         this.name = entity.getName();
69
70         try {
71             this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
72         } catch (IOException ioException) {
73             throw new SdcRuntimeException(ioException);
74         }
75
76     }
77
78     @Override
79     public String getEntityType() {
80         return ENTITY_TYPE;
81     }
82
83     @Override
84     public String getFirstClassCitizenId() {
85         return getId();
86     }
87
88     @Override
89     public String getId() {
90         return id;
91     }
92
93     @Override
94     public void setId(String id) {
95         this.id = id;
96     }
97
98     @Override
99     public Version getVersion() {
100         return version;
101     }
102
103     @Override
104     public void setVersion(Version version) {
105         this.version = version;
106     }
107
108     @Override
109     public String getName() {
110         return name;
111     }
112
113     public void setName(String name) {
114         this.name = name;
115     }
116
117     @Override
118     public ByteBuffer getContentData() {
119         return contentData;
120     }
121
122     public void setContentData(ByteBuffer contentData) {
123         this.contentData = contentData;
124     }
125
126     public ServiceArtifact getServiceArtifact() {
127         ServiceArtifact serviceArtifact = new ServiceArtifact();
128         serviceArtifact.setName(this.getName());
129         serviceArtifact.setVersion(this.getVersion());
130         serviceArtifact.setContentData(this.getContentData().array());
131         serviceArtifact.setVspId(this.getId());
132         return serviceArtifact;
133     }
134 }