Enabling Code Formatter
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / commons / db-lib / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / db / primary / domain / BlueprintModelContent.kt
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.springframework.data.annotation.LastModifiedDate
22 import org.springframework.data.jpa.domain.support.AuditingEntityListener
23 import java.io.Serializable
24 import java.util.Date
25 import java.util.Objects
26 import javax.persistence.Column
27 import javax.persistence.Entity
28 import javax.persistence.EntityListeners
29 import javax.persistence.Id
30 import javax.persistence.JoinColumn
31 import javax.persistence.Lob
32 import javax.persistence.OneToOne
33 import javax.persistence.Table
34 import javax.persistence.Temporal
35 import javax.persistence.TemporalType
36
37 /**
38  * Provide Blueprint Model Content Entity
39  *
40  * @author Brinda Santh
41  * @version 1.0
42  */
43 @EntityListeners(AuditingEntityListener::class)
44 @Entity
45 @Table(name = "BLUEPRINT_MODEL_CONTENT")
46 class BlueprintModelContent : Serializable {
47
48     @Id
49     @Column(name = "blueprint_model_content_id")
50     var id: String? = null
51
52     @Column(name = "name", nullable = false)
53     @ApiModelProperty(required = true)
54     lateinit var name: String
55
56     @Column(name = "content_type", nullable = false)
57     @ApiModelProperty(required = true)
58     lateinit var contentType: String
59
60     @OneToOne
61     @JoinColumn(name = "blueprint_model_id")
62     var blueprintModel: BlueprintModel? = null
63
64     @Lob
65     @Column(name = "description")
66     var description: String? = null
67
68     @Lob
69     @Column(name = "content", nullable = false)
70     @ApiModelProperty(required = true)
71     lateinit var content: ByteArray
72
73     @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
74     @LastModifiedDate
75     @Temporal(TemporalType.TIMESTAMP)
76     @Column(name = "updated_date")
77     var creationDate = Date()
78
79     override fun toString(): String {
80         return "[" + "id = " + id +
81             ", name = " + name +
82             ", contentType = " + contentType +
83             "]"
84     }
85
86     override fun equals(o: Any?): Boolean {
87
88         if (o === this) {
89             return true
90         }
91         if (o !is BlueprintModelContent) {
92             return false
93         }
94         val blueprintModelContent = o as BlueprintModelContent?
95         return (
96             id == blueprintModelContent!!.id && name == blueprintModelContent.name &&
97                 contentType == blueprintModelContent.contentType
98             )
99     }
100
101     override fun hashCode(): Int {
102         return Objects.hash(id, name, contentType)
103     }
104
105     companion object {
106
107         private const val serialVersionUID = 1L
108     }
109 }