[SDC-29] Amdocs OnBoard 1707 initial commit.
[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
31 import org.openecomp.sdc.datatypes.error.ErrorLevel;
32 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
33 import org.openecomp.sdc.logging.types.LoggerConstants;
34 import org.openecomp.sdc.logging.types.LoggerErrorCode;
35 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
36 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
37 import org.openecomp.sdc.versioning.dao.types.Version;
38
39 import java.io.IOException;
40 import java.nio.ByteBuffer;
41
42 @Table(keyspace = "dox", name = "vsp_enriched_service_artifact")
43 public class EnrichedServiceArtifactEntity implements ServiceElementEntity {
44   private static final String ENTITY_TYPE;
45
46   static {
47     ENTITY_TYPE = "Vendor Software Product Service artifact";
48   }
49
50   @PartitionKey
51   @Column(name = "vsp_id")
52   public String id;
53
54   @PartitionKey(value = 1)
55   @Frozen
56   public Version version;
57
58   @ClusteringColumn
59   @Column(name = "name")
60   public String name;
61
62   @Column(name = "content_data")
63   public ByteBuffer contentData;
64
65   public EnrichedServiceArtifactEntity() {
66   }
67
68   /**
69    * Instantiates a new Enriched service artifact entity.
70    *
71    * @param entity the entity
72    */
73   public EnrichedServiceArtifactEntity(ServiceArtifact entity) {
74     this.id = entity.getVspId();
75     this.version = entity.getVersion();
76     this.name = entity.getName();
77
78     try {
79       this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
80     } catch (IOException ioException) { //todo fix typo in Traget
81       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
82           LoggerTragetServiceName.CREATE_SERVICE_ENRICH_ARTIFACT, ErrorLevel.ERROR.name(),
83           LoggerErrorCode.DATA_ERROR.getErrorCode(),
84           LoggerErrorDescription.CREATE_ENRICH_SERVICE_ARTIFACT);
85       throw new RuntimeException(ioException);
86     }
87
88   }
89
90   @Override
91   public String getEntityType() {
92     return ENTITY_TYPE;
93   }
94
95   @Override
96   public String getFirstClassCitizenId() {
97     return getId();
98   }
99
100   public String getId() {
101     return id;
102   }
103
104   public void setId(String id) {
105     this.id = id;
106   }
107
108   @Override
109   public Version getVersion() {
110     return version;
111   }
112
113   @Override
114   public void setVersion(Version version) {
115     this.version = version;
116   }
117
118   public String getName() {
119     return name;
120   }
121
122   public void setName(String name) {
123     this.name = name;
124   }
125
126   public ByteBuffer getContentData() {
127     return contentData;
128   }
129
130   public void setContentData(ByteBuffer contentData) {
131     this.contentData = contentData;
132   }
133
134   /**
135    * Gets service artifact.
136    *
137    * @return the service artifact
138    */
139   public ServiceArtifact getServiceArtifact() {
140     ServiceArtifact serviceArtifact = new ServiceArtifact();
141     serviceArtifact.setName(this.getName());
142     serviceArtifact.setVersion(this.getVersion());
143     serviceArtifact.setContentData(this.getContentData().array());
144     serviceArtifact.setVspId(this.getId());
145     return serviceArtifact;
146   }
147 }