Hibernate db fix
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / cr / CrFolder.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ===================================================================
9  *
10  * Unless otherwise specified, all software contained herein is licensed
11  * under the Apache License, Version 2.0 (the "License");
12  * you may not use this software except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Unless otherwise specified, all documentation contained herein is licensed
24  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25  * you may not use this documentation except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
30  * Unless required by applicable law or agreed to in writing, documentation
31  * distributed under the License is distributed on an "AS IS" BASIS,
32  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * ============LICENSE_END============================================
37  *
38  *
39  */
40
41 package org.onap.portal.domain.db.cr;
42
43 import java.time.LocalDateTime;
44 import java.util.Set;
45 import javax.persistence.CascadeType;
46 import javax.persistence.Column;
47 import javax.persistence.Entity;
48 import javax.persistence.FetchType;
49 import javax.persistence.GeneratedValue;
50 import javax.persistence.GenerationType;
51 import javax.persistence.Id;
52 import javax.persistence.Index;
53 import javax.persistence.JoinColumn;
54 import javax.persistence.ManyToOne;
55 import javax.persistence.OneToMany;
56 import javax.persistence.Table;
57 import javax.validation.constraints.Digits;
58 import javax.validation.constraints.NotNull;
59 import javax.validation.constraints.Pattern;
60 import javax.validation.constraints.Positive;
61 import javax.validation.constraints.Size;
62 import lombok.AllArgsConstructor;
63 import lombok.Getter;
64 import lombok.NoArgsConstructor;
65 import lombok.Setter;
66 import org.hibernate.validator.constraints.SafeHtml;
67
68 /*
69
70 CREATE TABLE `cr_folder` (
71         `folder_id` int(11) NOT NULL,
72         `folder_name` varchar(50) NOT NULL,
73         `descr` varchar(500) DEFAULT NULL,
74         `create_id` int(11) NOT NULL,
75         `create_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
76         `parent_folder_id` int(11) DEFAULT NULL,
77         `public_yn` varchar(1) NOT NULL DEFAULT 'n',
78         PRIMARY KEY (`folder_id`),
79         KEY `fk_parent_key_cr_folder` (`parent_folder_id`),
80         CONSTRAINT `fk_parent_key_cr_folder` FOREIGN KEY (`parent_folder_id`) REFERENCES `cr_folder` (`folder_id`)
81         )
82 */
83
84
85 @Table(name = "cr_folder", indexes = {
86         @Index(name = "fk_parent_key_cr_folder", columnList = "parent_folder_id")
87 })
88 @NoArgsConstructor
89 @AllArgsConstructor
90 @Getter
91 @Setter
92 @Entity
93 public class CrFolder {
94        @Id
95        @GeneratedValue(strategy = GenerationType.AUTO)
96        @Column(name = "folder_id", length = 11, nullable = false)
97        @Digits(integer = 11, fraction = 0)
98        @Positive
99        private Long folderId;
100        @Column(name = "folder_name", length = 50, nullable = false)
101        @Size(max = 50)
102        @NotNull
103        @SafeHtml
104        private String folderName;
105        @Column(name = "descr", length = 500, columnDefinition = "varchar(500) DEFAULT NULL")
106        @Size(max = 500)
107        @SafeHtml
108        private String descr;
109        @Column(name = "create_id", length = 50, nullable = false)
110        @Digits(integer = 11, fraction = 0)
111        @Positive
112        private Long createId;
113        @Column(name = "create_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
114        @NotNull
115        private LocalDateTime createDate;
116        @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
117        @JoinColumn(name = "parent_Folder_Id")
118        private CrFolder parentFolderId;
119        @Column(name = "public_Yn", length = 1, nullable = false, columnDefinition = "varchar(1) DEFAULT 'n'")
120        @Pattern(regexp = "[YNyn]")
121        @SafeHtml
122        @NotNull
123        private String publicYn;
124        @OneToMany(
125                targetEntity = CrFolder.class,
126                mappedBy = "parentFolderId",
127                cascade = CascadeType.ALL,
128                fetch = FetchType.LAZY
129        )
130        private Set<CrFolder> crFolders;
131 }