[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 / EnrichedServiceTemplateEntity.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_template")
43 public class EnrichedServiceTemplateEntity implements ServiceElementEntity {
44
45   private static final String ENTITY_TYPE;
46
47   static {
48     ENTITY_TYPE = "Vendor Software Product Service model";
49   }
50
51   @PartitionKey
52   @Column(name = "vsp_id")
53   public String id;
54
55   @PartitionKey(value = 1)
56   @Frozen
57   public Version version;
58
59   @ClusteringColumn
60   @Column(name = "name")
61   public String name;
62
63   @Column(name = "content_data")
64   public ByteBuffer contentData;
65
66   @Column(name = "base_name")
67   private String baseName;
68
69   public EnrichedServiceTemplateEntity() {
70   }
71
72
73   /**
74    * Instantiates a new Enriched service template entity.
75    *
76    * @param entity the entity
77    */
78   public EnrichedServiceTemplateEntity(ServiceTemplate entity) {
79     this.id = entity.getVspId();
80     this.version = entity.getVersion();
81     this.name = entity.getName();
82     this.setBaseName(entity.getBaseName());
83     try {
84       this.contentData = ByteBuffer.wrap(ByteStreams.toByteArray(entity.getContent()));
85     } catch (IOException ioException) {
86       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
87           LoggerTragetServiceName.CREATE_ENRICH_SERVICE_TEMPLATE, ErrorLevel.ERROR.name(),
88           LoggerErrorCode.DATA_ERROR.getErrorCode(),
89           LoggerErrorDescription.CREATE_ENRICH_SERVICE_TEMPLATE);
90       throw new RuntimeException(ioException);
91     }
92
93   }
94
95   public String getBaseName() {
96     return baseName;
97   }
98
99   public void setBaseName(String baseName) {
100     this.baseName = baseName;
101   }
102
103   @Override
104   public String getEntityType() {
105     return ENTITY_TYPE;
106   }
107
108   @Override
109   public String getFirstClassCitizenId() {
110     return getId();
111   }
112
113   public String getId() {
114     return id;
115   }
116
117   public void setId(String id) {
118     this.id = id;
119   }
120
121   @Override
122   public Version getVersion() {
123     return version;
124   }
125
126   @Override
127   public void setVersion(Version version) {
128     this.version = version;
129   }
130
131   public String getName() {
132     return name;
133   }
134
135   public void setName(String name) {
136     this.name = name;
137   }
138
139   public ByteBuffer getContentData() {
140     return contentData;
141   }
142
143   public void setContentData(ByteBuffer contentData) {
144     this.contentData = contentData;
145   }
146
147   /**
148    * Gets service template.
149    *
150    * @return the service template
151    */
152   public ServiceTemplate getServiceTemplate() {
153     ServiceTemplate serviceTemplate = new ServiceTemplate();
154     serviceTemplate.setName(this.getName());
155     serviceTemplate.setVersion(this.getVersion());
156     serviceTemplate.setContentData(this.getContentData().array());
157     serviceTemplate.setVspId(this.getId());
158     serviceTemplate.setBaseName(this.getBaseName());
159     return serviceTemplate;
160
161   }
162 }