push addional 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  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.core.model.types;
22
23 import com.google.common.io.ByteStreams;
24
25 import com.datastax.driver.mapping.annotations.ClusteringColumn;
26 import com.datastax.driver.mapping.annotations.Column;
27 import com.datastax.driver.mapping.annotations.Frozen;
28 import com.datastax.driver.mapping.annotations.PartitionKey;
29 import com.datastax.driver.mapping.annotations.Table;
30 import org.openecomp.sdc.versioning.dao.types.Version;
31
32 import java.io.IOException;
33 import java.nio.ByteBuffer;
34
35 @Table(keyspace = "dox", name = "vsp_enriched_service_artifact")
36 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
37   private static final String ENTITY_TYPE;
38
39   static {
40     ENTITY_TYPE = "Vendor Software Product Service artifact";
41   }
42
43   @PartitionKey
44   @Column(name = "vsp_id")
45   public String id;
46
47   @PartitionKey(value = 1)
48   @Frozen
49   public Version version;
50
51   @ClusteringColumn
52   @Column(name = "name")
53   public String name;
54
55   @Column(name = "content_data")
56   public ByteBuffer contentData;
57
58   public EnrichedServiceArtifactEntity() {
59   }
60
61   /**
62    * Instantiates a new Enriched service artifact entity.
63    *
64    * @param entity the entity
65    */
66   public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
67     this.id = entity.getVspId();
68     this.version = entity.getVersion();
69     this.name = entity.getName();
70
71     try {
72       this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
73     } catch (IOException ioException) {
74       throw new RuntimeException(ioException);
75     }
76
77   }
78
79   @Override
80   public String getEntityType() {
81     return ENTITY_TYPE;
82   }
83
84   @Override
85   public String getFirstClassCitizenId() {
86     return getId();
87   }
88
89   public String getId() {
90     return id;
91   }
92
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   public String getName() {
108     return name;
109   }
110
111   public void setName(String name) {
112     this.name = name;
113   }
114
115   public ByteBuffer getContentData() {
116     return contentData;
117   }
118
119   public void setContentData(ByteBuffer contentData) {
120     this.contentData = contentData;
121   }
122
123   /**
124    * Gets service artifact.
125    *
126    * @return the service artifact
127    */
128   public ServiceArtifact getServiceArtifact() {
129     ServiceArtifact serviceArtifact = new ServiceArtifact();
130     serviceArtifact.setName(this.getName());
131     serviceArtifact.setVersion(this.getVersion());
132     serviceArtifact.setContentData(this.getContentData().array());
133     serviceArtifact.setVspId(this.getId());
134     return serviceArtifact;
135   }
136 }