Domain model change
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / cr / CrReportFileHistory.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.io.Serializable;
44 import java.time.LocalDateTime;
45 import java.util.Set;
46 import javax.persistence.CascadeType;
47 import javax.persistence.Column;
48 import javax.persistence.Entity;
49 import javax.persistence.FetchType;
50 import javax.persistence.GeneratedValue;
51 import javax.persistence.GenerationType;
52 import javax.persistence.Id;
53 import javax.persistence.Index;
54 import javax.persistence.JoinColumn;
55 import javax.persistence.JoinTable;
56 import javax.persistence.ManyToMany;
57 import javax.persistence.ManyToOne;
58 import javax.persistence.SequenceGenerator;
59 import javax.persistence.Table;
60 import javax.validation.Valid;
61 import javax.validation.constraints.Digits;
62 import javax.validation.constraints.FutureOrPresent;
63 import javax.validation.constraints.NotNull;
64 import javax.validation.constraints.Pattern;
65 import javax.validation.constraints.Positive;
66 import javax.validation.constraints.Size;
67 import lombok.AllArgsConstructor;
68 import lombok.Getter;
69 import lombok.NoArgsConstructor;
70 import lombok.Setter;
71 import org.hibernate.validator.constraints.SafeHtml;
72 import org.hibernate.validator.constraints.URL;
73 import org.onap.portal.domain.db.fn.FnUser;
74
75 /*
76 CREATE TABLE `cr_report_file_history` (
77         `hist_id` int(11) NOT NULL,
78         `sched_user_id` decimal(11,0) NOT NULL,
79         `schedule_id` decimal(11,0) NOT NULL,
80         `user_id` decimal(11,0) NOT NULL,
81         `rep_id` decimal(11,0) DEFAULT NULL,
82         `run_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
83         `recurrence` varchar(50) DEFAULT NULL,
84         `file_type_id` decimal(2,0) DEFAULT NULL,
85         `file_name` varchar(80) DEFAULT NULL,
86         `file_blob` blob DEFAULT NULL,
87         `file_size` decimal(11,0) DEFAULT NULL,
88         `raptor_url` varchar(4000) DEFAULT NULL,
89         `error_yn` char(1) DEFAULT 'n',
90         `error_code` decimal(11,0) DEFAULT NULL,
91         `deleted_yn` char(1) DEFAULT 'n',
92         `deleted_by` decimal(38,0) DEFAULT NULL,
93         PRIMARY KEY (`hist_id`),
94         KEY `sys_c0014614` (`file_type_id`),
95         KEY `sys_c0014615` (`rep_id`),
96         CONSTRAINT `sys_c0014614` FOREIGN KEY (`file_type_id`) REFERENCES `cr_lu_file_type` (`lookup_id`),
97         CONSTRAINT `sys_c0014615` FOREIGN KEY (`rep_id`) REFERENCES `cr_report` (`rep_id`)
98         )
99 */
100
101 @Table(name = "cr_report_file_history", indexes = {
102         @Index(name = "sys_c0014617", columnList = "user_id"),
103         @Index(name = "sys_c0014614", columnList = "file_type_id"),
104         @Index(name = "sys_c0014615", columnList = "rep_id")
105 })
106 @NoArgsConstructor
107 @AllArgsConstructor
108 @Getter
109 @Setter
110 @Entity
111 public class CrReportFileHistory implements Serializable {
112        @Id
113        @Column(name = "hist_id", nullable = false, length = 11)
114        @GeneratedValue(strategy = GenerationType.AUTO)
115        @Digits(integer = 11, fraction = 0)
116        private Long histId;
117        @Column(name = "sched_user_id", nullable = false)
118        @Digits(integer = 11, fraction = 0)
119        @NotNull
120        private Long schedUserId;
121        @Column(name = "schedule_id", nullable = false)
122        @Digits(integer = 11, fraction = 0)
123        @NotNull
124        private Long scheduleId;
125        @Column(name = "user_id", nullable = false)
126        @Digits(integer = 11, fraction = 0)
127        @NotNull
128        private Long userId;
129        @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
130        @JoinColumn(name = "rep_id")
131        @Valid
132        private CrReport repId;
133        @Column(name = "run_date", nullable = false, columnDefinition = "datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()")
134        @FutureOrPresent
135        private LocalDateTime runDate;
136        @Column(name = "recurrence", length = 50, columnDefinition = "varchar(50) DEFAULT NULL")
137        @Size(max = 50)
138        @SafeHtml
139        private String recurrence;
140        @ManyToOne(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
141        @JoinColumn(name = "file_type_id")
142        @Valid
143        private CrLuFileType fileTypeId;
144        @Column(name = "file_name", length = 80, columnDefinition = "varchar(80) DEFAULT NULL")
145        @Size(max = 80)
146        @SafeHtml
147        private String fileName;
148        @Column(name = "file_blob", columnDefinition = "blob DEFAULT NULL")
149        private byte[] fileBlob;
150        @Column(name = "file_size", columnDefinition = "decimal(11,0) DEFAULT NULL")
151        @Digits(integer = 11, fraction = 0)
152        @Positive
153        private Long file_size;
154        //TODO URL @URL
155        @URL
156        @Column(name = "raptor_url", length = 4000)
157        @Size(max = 4000)
158        @SafeHtml
159        private String raptorUrl;
160        @Column(name = "error_yn", length = 1, columnDefinition = "character(1) default 'n'")
161        @Pattern(regexp = "[YNyn]")
162        @Size(max = 1)
163        @SafeHtml
164        private String errorYn;
165        @Column(name = "error_code", columnDefinition = "decimal(11,0) DEFAULT NULL")
166        @Digits(integer = 11, fraction = 0)
167        private Long errorCode;
168        @Column(name = "deleted_yn", length = 1, columnDefinition = "character(1) default 'n'")
169        @Pattern(regexp = "[YNyn]")
170        @Size(max = 1)
171        @SafeHtml
172        private String deletedYn;
173        @Column(name = "deleted_by", columnDefinition = "decimal(38,0) DEFAULT NULL")
174        @Digits(integer = 38, fraction = 0)
175        private Long deletedBy;
176
177        @ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
178        @JoinTable(
179                name = "cr_hist_user_map",
180                joinColumns = {@JoinColumn(name = "hist_id", referencedColumnName = "hist_id")},
181                inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id", columnDefinition = "bigint not null")}
182        )
183        private Set<FnUser> fnUserList;
184 }