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