1feac8cd29a979c94b8ea93052aac76f3639681f
[ccsdk/cds.git] /
1 /*
2  *  Copyright © 2019 IBM.
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.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain
18
19 import com.fasterxml.jackson.annotation.JsonFormat
20 import io.swagger.annotations.ApiModelProperty
21 import org.hibernate.annotations.Proxy
22 import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow
23 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
24 import org.springframework.data.annotation.LastModifiedDate
25 import org.springframework.data.jpa.domain.support.AuditingEntityListener
26 import java.io.Serializable
27 import java.util.Date
28 import javax.persistence.AttributeConverter
29 import javax.persistence.CascadeType
30 import javax.persistence.Column
31 import javax.persistence.Convert
32 import javax.persistence.Converter
33 import javax.persistence.Entity
34 import javax.persistence.EntityListeners
35 import javax.persistence.FetchType
36 import javax.persistence.Id
37 import javax.persistence.Lob
38 import javax.persistence.OneToOne
39 import javax.persistence.Table
40 import javax.persistence.Temporal
41 import javax.persistence.TemporalType
42 import javax.persistence.UniqueConstraint
43
44 /**
45  *  Provide BlueprintModel Entity
46  *
47  * @author Brinda Santh
48  * @version 1.0
49  */
50
51 @EntityListeners(AuditingEntityListener::class)
52 @Entity
53 @Table(name = "BLUEPRINT_MODEL", uniqueConstraints = [UniqueConstraint(columnNames = ["artifact_name", "artifact_version"])])
54 @Proxy(lazy = false)
55 class BlueprintModel : Serializable {
56
57     @Id
58     @Column(name = "blueprint_model_id")
59     var id: String? = null
60
61     @Column(name = "service_uuid")
62     var serviceUUID: String? = null
63
64     @Column(name = "distribution_id")
65     var distributionId: String? = null
66
67     @Column(name = "service_name")
68     var serviceName: String? = null
69
70     @Column(name = "service_description")
71     var serviceDescription: String? = null
72
73     @Column(name = "resource_uuid")
74     var resourceUUID: String? = null
75
76     @Column(name = "resource_instance_name")
77     var resourceInstanceName: String? = null
78
79     @Column(name = "resource_name")
80     var resourceName: String? = null
81
82     @Column(name = "resource_version")
83     var resourceVersion: String? = null
84
85     @Column(name = "resource_type")
86     var resourceType: String? = null
87
88     @Column(name = "artifact_uuid")
89     var artifactUUId: String? = null
90
91     @Column(name = "artifact_type")
92     var artifactType: String? = null
93
94     @Column(name = "artifact_version", nullable = false)
95     @ApiModelProperty(required = true)
96     lateinit var artifactVersion: String
97
98     @Lob
99     @Column(name = "artifact_description")
100     var artifactDescription: String? = null
101
102     @Column(name = "internal_version")
103     var internalVersion: Int? = null
104
105     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
106     @LastModifiedDate
107     @Temporal(TemporalType.TIMESTAMP)
108     @Column(name = "creation_date")
109     var createdDate = Date()
110
111     @Column(name = "artifact_name", nullable = false)
112     @ApiModelProperty(required = true)
113     lateinit var artifactName: String
114
115     @Column(name = "published", nullable = false)
116     @ApiModelProperty(required = true)
117     lateinit var published: String
118
119     @Column(name = "updated_by", nullable = false)
120     @ApiModelProperty(required = true)
121     lateinit var updatedBy: String
122
123     @Lob
124     @Column(name = "tags", nullable = false)
125     @ApiModelProperty(required = true)
126     lateinit var tags: String
127
128     @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL])
129     var blueprintModelContent: BlueprintModelContent? = null
130
131     // will be populated with workflow specs for each workflow (JSON object)
132     @Lob
133     @Convert(converter = WorkflowsConverter::class)
134     @Column(name = "workflows", nullable = false)
135     lateinit var workflows: Map<String, Workflow>
136
137     companion object {
138
139         private const val serialVersionUID = 1L
140     }
141
142     @Converter
143     class WorkflowsConverter : AttributeConverter<Map<String, Workflow>, String> {
144         override fun convertToDatabaseColumn(node: Map<String, Workflow>): String {
145             return JacksonUtils.getJson(node, true)
146         }
147
148         override fun convertToEntityAttribute(dbData: String): Map<String, Workflow> {
149             if (dbData == null || "".equals(dbData)) return emptyMap()
150             return JacksonUtils.getMapFromJson(dbData, Workflow::class.java)
151         }
152     }
153 }