Coverity Scan issues fix
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnRole.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.fn;
42
43 import java.io.Serializable;
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.JoinTable;
55 import javax.persistence.ManyToMany;
56 import javax.persistence.NamedQueries;
57 import javax.persistence.NamedQuery;
58 import javax.persistence.OneToMany;
59 import javax.persistence.Table;
60 import javax.validation.constraints.Digits;
61 import javax.validation.constraints.NotNull;
62 import javax.validation.constraints.Pattern;
63 import javax.validation.constraints.Size;
64 import lombok.AllArgsConstructor;
65 import lombok.Getter;
66 import lombok.NoArgsConstructor;
67 import lombok.Setter;
68 import org.hibernate.validator.constraints.SafeHtml;
69 import org.onap.portal.domain.db.ep.EpAppRoleFunction;
70 import org.onap.portal.domain.db.ep.EpRoleNotification;
71 import org.onap.portal.domain.db.ep.EpUserRolesRequestDet;
72 import org.onap.portal.domain.db.ep.EpWidgetCatalogRole;
73 import org.onap.portal.domain.dto.DomainVo;
74
75 /*
76 CREATE TABLE `fn_role` (
77         `role_id` int(11) NOT NULL AUTO_INCREMENT,
78         `role_name` varchar(300) NOT NULL,
79         `active_yn` varchar(1) NOT NULL DEFAULT 'y',
80         `priority` decimal(4,0) DEFAULT NULL,
81         `app_id` int(11) DEFAULT NULL,
82         `app_role_id` int(11) DEFAULT NULL,
83         PRIMARY KEY (`role_id`),
84         UNIQUE KEY `fn_role_name_app_id_idx` (`role_name`,`app_id`) USING BTREE
85         )
86 */
87
88 @NamedQueries({
89         @NamedQuery(
90                 name = "FnRole.retrieveAppRolesByRoleNameAndByAppId",
91                 query = "FROM FnRole where role_name =:roleName and app_id =:appId"),
92         @NamedQuery(
93                 name = "FnRole.retrieveAppRolesByAppId",
94                 query = "FROM FnRole where app_id =:appId"),
95         @NamedQuery(
96                 name = "FnRole.retrieveAppRolesWhereAppIdIsNull",
97                 query = "FROM FnRole where app_id is null"),
98         @NamedQuery(
99                 name = "FnRole.retrieveAppRoleByRoleIdWhereAppIdIsNull",
100                 query = "FROM FnRole where role_id =:roleId and app_id is null"),
101         @NamedQuery(
102                 name = "FnRole.retrieveAppRoleByAppRoleIdAndByAppId",
103                 query = "FROM FnRole where app_role_id =:appRoleId and app_id =:appId"),
104         @NamedQuery(
105                 name = "FnRole.retrieveAppRoleByRoleIdAndAppId",
106                 query = "FROM FnRole where role_id =:roleId and app_id =:appId"),
107         @NamedQuery(
108                 name = "FnRole.retrieveAppRolesByRoleNameAndWhereAppIdIsNull",
109                 query = "FROM FnRole where role_name =:roleName and app_id is null"),
110         @NamedQuery(
111                 name = "FnRole.retrieveActiveRolesOfApplication",
112                 query = "from FnRole where active_yn = 'Y' and app_id=:appId"),
113         @NamedQuery(name = "FnRole.retrieveRoleToUpdateInExternalAuthSystem",
114                 query = "FROM FnRole where role_name =:roleName and app_id =:appId")
115 })
116
117 @Table(name = "fn_role", indexes = {
118         @Index(name = "fn_role_name_app_id_idx", columnList = "role_name, app_id", unique = true)
119 })
120 @NoArgsConstructor
121 @AllArgsConstructor
122 @Getter
123 @Setter
124 @Entity
125 public class FnRole extends DomainVo implements Serializable {
126
127        @Id
128        @GeneratedValue(strategy = GenerationType.AUTO)
129        @Column(name = "role_id", length = 11, nullable = false)
130        @Digits(integer = 11, fraction = 0)
131        private Long roleId;
132        @Column(name = "role_name", length = 300, nullable = false)
133        @Size(max = 300)
134        @NotNull
135        @SafeHtml
136        private String roleName;
137        @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false)
138        @NotNull
139        private Boolean activeYn;
140        @Column(name = "priority", length = 4, columnDefinition = "decimal(4,0) DEFAULT NULL")
141        @Digits(integer = 4, fraction = 0)
142        private Long priority;
143        @Column(name = "app_Id", length = 11, columnDefinition = "int(11) default null")
144        @Digits(integer = 11, fraction = 0)
145        private Long appId;
146        @Column(name = "app_role_id", length = 11, columnDefinition = "int(11) default null")
147        @Digits(integer = 11, fraction = 0)
148        private Long appRoleId;
149        @OneToMany(
150                targetEntity = FnRoleFunction.class,
151                mappedBy = "roleId",
152                cascade = CascadeType.ALL,
153                fetch = FetchType.LAZY
154        )
155        private Set<FnRoleFunction> fnRoleFunctions;
156        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
157        @JoinTable(
158                name = "fn_user_pseudo_role",
159                joinColumns = {@JoinColumn(name = "pseudo_role_Id", referencedColumnName = "role_id")},
160                inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "user_id")},
161                indexes = {
162                        @Index(name = "fk_pseudo_role_user_id", columnList = "user_id")
163                }
164        )
165        private Set<FnUser> fnUsers;
166        @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
167        @JoinTable(
168                name = "fn_role_composite",
169                joinColumns = {@JoinColumn(name = "parent_role_id", referencedColumnName = "role_id")},
170                inverseJoinColumns = {@JoinColumn(name = "child_role_id", referencedColumnName = "role_id")},
171                indexes = {
172                        @Index(name = "fk_fn_role_composite_child", columnList = "child_role_id")
173                }
174        )
175        private Set<FnRole> fnRoles;
176        @ManyToMany(cascade = CascadeType.ALL,
177                fetch = FetchType.LAZY)
178        private Set<FnRole> fnRoleList;
179        @OneToMany(
180                targetEntity = EpRoleNotification.class,
181                mappedBy = "notificationID",
182                cascade = CascadeType.ALL,
183                fetch = FetchType.LAZY
184        )
185        private Set<EpRoleNotification> epRoleNotifications;
186        @OneToMany(
187                targetEntity = FnMenuFunctionalRoles.class,
188                mappedBy = "roleId",
189                cascade = CascadeType.ALL,
190                fetch = FetchType.LAZY
191        )
192        private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
193        @OneToMany(
194                targetEntity = EpWidgetCatalogRole.class,
195                mappedBy = "roleId",
196                cascade = CascadeType.ALL,
197                fetch = FetchType.LAZY
198        )
199        private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
200        @OneToMany(
201                targetEntity = EpAppRoleFunction.class,
202                mappedBy = "fnRole",
203                cascade = CascadeType.ALL,
204                fetch = FetchType.LAZY
205        )
206        private Set<EpAppRoleFunction> epAppRoleFunctions;
207        @OneToMany(
208                targetEntity = EpUserRolesRequestDet.class,
209                mappedBy = "requestedRoleId",
210                cascade = CascadeType.ALL,
211                fetch = FetchType.LAZY
212        )
213        private Set<EpUserRolesRequestDet> epUserRolesRequestDets;
214        @OneToMany(
215                targetEntity = FnUserRole.class,
216                mappedBy = "roleId",
217                cascade = CascadeType.ALL,
218                fetch = FetchType.LAZY
219        )
220        private Set<FnUserRole> fnUserRoles;
221 }