2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.db.primary.domain
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
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
45 * Provide BlueprintModel Entity
47 * @author Brinda Santh
51 @EntityListeners(AuditingEntityListener::class)
53 @Table(name = "BLUEPRINT_MODEL", uniqueConstraints = [UniqueConstraint(columnNames = ["artifact_name", "artifact_version"])])
55 class BlueprintModel : Serializable {
58 @Column(name = "blueprint_model_id")
59 var id: String? = null
61 @Column(name = "service_uuid")
62 var serviceUUID: String? = null
64 @Column(name = "distribution_id")
65 var distributionId: String? = null
67 @Column(name = "service_name")
68 var serviceName: String? = null
70 @Column(name = "service_description")
71 var serviceDescription: String? = null
73 @Column(name = "resource_uuid")
74 var resourceUUID: String? = null
76 @Column(name = "resource_instance_name")
77 var resourceInstanceName: String? = null
79 @Column(name = "resource_name")
80 var resourceName: String? = null
82 @Column(name = "resource_version")
83 var resourceVersion: String? = null
85 @Column(name = "resource_type")
86 var resourceType: String? = null
88 @Column(name = "artifact_uuid")
89 var artifactUUId: String? = null
91 @Column(name = "artifact_type")
92 var artifactType: String? = null
94 @Column(name = "artifact_version", nullable = false)
95 @ApiModelProperty(required = true)
96 lateinit var artifactVersion: String
99 @Column(name = "artifact_description")
100 var artifactDescription: String? = null
102 @Column(name = "internal_version")
103 var internalVersion: Int? = null
105 @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
107 @Temporal(TemporalType.TIMESTAMP)
108 @Column(name = "creation_date")
109 var createdDate = Date()
111 @Column(name = "artifact_name", nullable = false)
112 @ApiModelProperty(required = true)
113 lateinit var artifactName: String
115 @Column(name = "published", nullable = false)
116 @ApiModelProperty(required = true)
117 lateinit var published: String
119 @Column(name = "updated_by", nullable = false)
120 @ApiModelProperty(required = true)
121 lateinit var updatedBy: String
124 @Column(name = "tags", nullable = false)
125 @ApiModelProperty(required = true)
126 lateinit var tags: String
128 @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = [CascadeType.ALL])
129 var blueprintModelContent: BlueprintModelContent? = null
131 // will be populated with workflow specs for each workflow (JSON object)
133 @Convert(converter = WorkflowsConverter::class)
134 @Column(name = "workflows", nullable = false)
135 lateinit var workflows: Map<String, Workflow>
139 private const val serialVersionUID = 1L
143 class WorkflowsConverter : AttributeConverter<Map<String, Workflow>, String> {
144 override fun convertToDatabaseColumn(node: Map<String, Workflow>): String {
145 return JacksonUtils.getJson(node, true)
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)