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