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