Domain model change
[portal.git] / portal-BE / src / main / java / org / onap / portal / domain / db / fn / FnApp.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.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.NamedQueries;
51 import javax.persistence.NamedQuery;
52 import javax.persistence.OneToMany;
53 import javax.persistence.Table;
54 import javax.validation.constraints.Digits;
55 import javax.validation.constraints.NotNull;
56 import javax.validation.constraints.Pattern;
57 import javax.validation.constraints.Size;
58 import lombok.AllArgsConstructor;
59 import lombok.Builder;
60 import lombok.EqualsAndHashCode;
61 import lombok.Getter;
62 import lombok.NoArgsConstructor;
63 import lombok.Setter;
64 import org.hibernate.validator.constraints.SafeHtml;
65 import org.hibernate.validator.constraints.URL;
66 import org.onap.portal.domain.db.ep.EpAppFunction;
67 import org.onap.portal.domain.db.ep.EpAppRoleFunction;
68 import org.onap.portal.domain.db.ep.EpMicroservice;
69 import org.onap.portal.domain.db.ep.EpUserRolesRequest;
70 import org.onap.portal.domain.db.ep.EpWebAnalyticsSource;
71 import org.onap.portal.domain.db.ep.EpWidgetCatalogRole;
72 import org.onap.portal.domain.db.DomainVo;
73
74 /*
75 CREATE TABLE `fn_app` (
76         `app_id` int(11) NOT NULL AUTO_INCREMENT,
77         `app_name` varchar(100) NOT NULL DEFAULT '?',
78         `app_image_url` varchar(256) DEFAULT NULL,
79         `app_description` varchar(512) DEFAULT NULL,
80         `app_notes` varchar(4096) DEFAULT NULL,
81         `app_url` varchar(256) DEFAULT NULL,
82         `app_alternate_url` varchar(256) DEFAULT NULL,
83         `app_rest_endpoint` varchar(2000) DEFAULT NULL,
84         `ml_app_name` varchar(50) NOT NULL DEFAULT '?',
85         `ml_app_admin_id` varchar(7) NOT NULL DEFAULT '?',
86         `mots_id` int(11) DEFAULT NULL,
87         `app_password` varchar(256) NOT NULL DEFAULT '?',
88         `open` char(1) DEFAULT 'N',
89         `enabled` char(1) DEFAULT 'Y',
90         `thumbnail` mediumblob DEFAULT NULL,
91         `app_username` varchar(50) DEFAULT NULL,
92         `ueb_key` varchar(256) DEFAULT NULL,
93         `ueb_secret` varchar(256) DEFAULT NULL,
94         `ueb_topic_name` varchar(256) DEFAULT NULL,
95         `app_type` int(11) NOT NULL DEFAULT 1,
96         `auth_central` char(1) NOT NULL DEFAULT 'N',
97         `auth_namespace` varchar(100) DEFAULT NULL,
98         PRIMARY KEY (`app_id`)
99         )
100 */
101
102 @NamedQueries({
103     @NamedQuery(
104         name = "FnApp.retrieveWhereAuthCentralIsYAndOpenIsNAndAuthNamespaceIsNotNull",
105         query = "from FnApp where authCentral = 'Y' and open = 'N' and authNamespace is not null"),
106     @NamedQuery(
107         name = "FnApp.getByUebKey",
108         query = "from FnApp where uebKey = :uebKey"),
109     @NamedQuery(
110         name = "FnApp.getCentralizedApps",
111         query = "from FnApp where authCentral = 'Y' and open = 'N' and authNamespace is not null"
112     )
113 })
114
115 @Table(name = "fn_app")
116 @NoArgsConstructor
117 @AllArgsConstructor
118 @EqualsAndHashCode(callSuper = true)
119 @Getter
120 @Setter
121 @Entity
122 public class FnApp extends DomainVo implements Serializable {
123
124   @Column(name = "app_name", length = 100, nullable = false, columnDefinition = "varchar(100) not null default '?'")
125   @Size(max = 100)
126   @SafeHtml
127   @NotNull
128   private String appName = "?";
129   @Column(name = "app_image_url", length = 256)
130   @Size(max = 256)
131   @SafeHtml
132   private String appImageUrl;
133   @Column(name = "app_description", length = 512)
134   @Size(max = 256)
135   @SafeHtml
136   private String appDescription;
137   @Column(name = "app_notes", length = 4096)
138   @Size(max = 4096)
139   @SafeHtml
140   private String appNotes;
141   @Column(name = "app_url", length = 256)
142   @Size(max = 256)
143   @SafeHtml
144   //TODO URL
145   @URL
146   private String appUrl;
147   @Column(name = "app_alternate_url", length = 256)
148   @Size(max = 256)
149   @SafeHtml
150   private String appAlternateUrl;
151   @Column(name = "app_rest_endpoint", length = 2000)
152   @Size(max = 2000)
153   @SafeHtml
154   private String appRestEndpoint;
155   @Column(name = "ml_app_name", length = 50, nullable = false, columnDefinition = "varchar(50) not null default '?'")
156   @Size(max = 50)
157   @SafeHtml
158   @NotNull
159   private String mlAppName = "?";
160   @Column(name = "ml_app_admin_id", length = 7, nullable = false, columnDefinition = "varchar(7) not null default '?'")
161   @Size(max = 7)
162   @SafeHtml
163   private String mlAppAdminId = "?";
164   @Column(name = "mots_id", length = 11)
165   @Digits(integer = 11, fraction = 0)
166   private Long motsId;
167   @Column(name = "app_password", length = 256, nullable = false, columnDefinition = "varchar(256) not null default '?'")
168   @Size(max = 256)
169   @SafeHtml
170   @NotNull
171   private String appPassword = "?";
172   @Column(name = "open")
173   private Boolean open = false;
174   @Column(name = "enabled")
175   private Boolean enabled = false;
176   @Column(name = "active_yn")
177   @NotNull
178   private Boolean activeYn = true;
179   @Column(name = "_thumbnail", columnDefinition = "mediumblob null default null")
180   private byte[] thumbnail;
181   @Column(name = "app_username", length = 50)
182   @Size(max = 50)
183   @SafeHtml
184   private String appUsername;
185   @Column(name = "ueb_key", length = 256)
186   @Size(max = 256)
187   @SafeHtml
188   private String uebKey;
189   @Column(name = "ueb_secret", length = 256)
190   @Size(max = 256)
191   @SafeHtml
192   private String uebSecret;
193   @Column(name = "ueb_topic_name", length = 256)
194   @Size(max = 256)
195   @SafeHtml
196   private String uebTopicName;
197   @Column(name = "app_type", length = 11, columnDefinition = "int(11) not null default 1")
198   @Digits(integer = 11, fraction = 0)
199   private Long appType = 1L;
200   @Column(name = "auth_central", length = 1, nullable = false)
201   private Boolean authCentral;
202   @Column(name = "auth_namespace", length = 100)
203   @Size(max = 100)
204   @SafeHtml
205   private String authNamespace;
206   @OneToMany(
207       targetEntity = FnMenuFunctionalRoles.class,
208       mappedBy = "appId",
209       cascade = CascadeType.MERGE,
210       fetch = FetchType.LAZY
211   )
212   private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
213   @OneToMany(
214       targetEntity = EpUserRolesRequest.class,
215       mappedBy = "appId",
216       cascade = CascadeType.MERGE,
217       fetch = FetchType.LAZY
218   )
219   private Set<EpUserRolesRequest> epUserRolesRequests;
220   @OneToMany(
221       targetEntity = EpAppFunction.class,
222       mappedBy = "appId",
223       cascade = CascadeType.MERGE,
224       fetch = FetchType.LAZY
225   )
226   private Set<EpAppFunction> epAppFunctions;
227   @OneToMany(
228       targetEntity = EpAppRoleFunction.class,
229       mappedBy = "appId",
230       cascade = CascadeType.MERGE,
231       fetch = FetchType.LAZY
232   )
233   private Set<EpAppRoleFunction> epAppRoleFunctions;
234   @OneToMany(
235       targetEntity = FnUserRole.class,
236       mappedBy = "fnAppId",
237       cascade = CascadeType.MERGE,
238       fetch = FetchType.LAZY
239   )
240   private Set<FnUserRole> fnUserRoles;
241   @OneToMany(
242       targetEntity = EpWebAnalyticsSource.class,
243       mappedBy = "appId",
244       cascade = CascadeType.MERGE,
245       fetch = FetchType.LAZY
246   )
247   private Set<EpWebAnalyticsSource> epWebAnalyticsSources;
248   @OneToMany(
249       targetEntity = EpWidgetCatalogRole.class,
250       mappedBy = "appId",
251       cascade = CascadeType.MERGE,
252       fetch = FetchType.LAZY
253   )
254   private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
255   @OneToMany(
256       targetEntity = EpMicroservice.class,
257       mappedBy = "appId",
258       cascade = CascadeType.MERGE,
259       fetch = FetchType.LAZY
260   )
261   private Set<EpMicroservice> epMicroservices;
262   @OneToMany(
263       targetEntity = FnPersUserAppSel.class,
264       mappedBy = "appId",
265       cascade = CascadeType.MERGE,
266       fetch = FetchType.LAZY
267   )
268   private Set<FnPersUserAppSel> fnPersUserAppSels;
269
270   public Boolean isRestrictedApp() {
271     return (this.appType == 2);
272   }
273
274   @Builder
275   public FnApp(@Digits(integer = 11, fraction = 0) Long id, LocalDateTime created,
276       LocalDateTime modified, Long rowNum, Serializable auditUserId,
277       DomainVo createdId, DomainVo modifiedId, Set<DomainVo> fnUsersCreatedId,
278       Set<DomainVo> fnUsersModifiedId,
279       @Size(max = 100) @SafeHtml @NotNull String appName,
280       @Size(max = 256) @SafeHtml String appImageUrl,
281       @Size(max = 256) @SafeHtml String appDescription,
282       @Size(max = 4096) @SafeHtml String appNotes,
283       @Size(max = 256) @SafeHtml @URL String appUrl,
284       @Size(max = 256) @SafeHtml String appAlternateUrl,
285       @Size(max = 2000) @SafeHtml String appRestEndpoint,
286       @Size(max = 50) @SafeHtml @NotNull String mlAppName,
287       @Size(max = 7) @SafeHtml @NotNull String mlAppAdminId,
288       @Digits(integer = 11, fraction = 0) Long motsId,
289       @Size(max = 256) @SafeHtml @NotNull String appPassword, Boolean open, Boolean enabled, Boolean activeYn, byte[] thumbnail,
290       @Size(max = 50) @SafeHtml String appUsername,
291       @Size(max = 256) @SafeHtml String uebKey,
292       @Size(max = 256) @SafeHtml String uebSecret,
293       @Size(max = 256) @SafeHtml String uebTopicName,
294       @Digits(integer = 11, fraction = 0) Long appType, Boolean authCentral,
295       @Size(max = 100) @SafeHtml String authNamespace,
296       Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles,
297       Set<EpUserRolesRequest> epUserRolesRequests,
298       Set<EpAppFunction> epAppFunctions, Set<EpAppRoleFunction> epAppRoleFunctions,
299       Set<FnUserRole> fnUserRoles, Set<EpWebAnalyticsSource> epWebAnalyticsSources,
300       Set<EpWidgetCatalogRole> epWidgetCatalogRoles,
301       Set<EpMicroservice> epMicroservices, Set<FnPersUserAppSel> fnPersUserAppSels) {
302     super(id, created, modified, rowNum, auditUserId, createdId, modifiedId, fnUsersCreatedId, fnUsersModifiedId);
303     this.appName = appName;
304     this.appImageUrl = appImageUrl;
305     this.appDescription = appDescription;
306     this.appNotes = appNotes;
307     this.appUrl = appUrl;
308     this.appAlternateUrl = appAlternateUrl;
309     this.appRestEndpoint = appRestEndpoint;
310     this.mlAppName = mlAppName;
311     this.mlAppAdminId = mlAppAdminId;
312     this.motsId = motsId;
313     this.appPassword = appPassword;
314     this.open = open;
315     this.enabled = enabled;
316     this.activeYn = activeYn;
317     this.thumbnail = thumbnail;
318     this.appUsername = appUsername;
319     this.uebKey = uebKey;
320     this.uebSecret = uebSecret;
321     this.uebTopicName = uebTopicName;
322     this.appType = appType;
323     this.authCentral = authCentral;
324     this.authNamespace = authNamespace;
325     this.fnMenuFunctionalRoles = fnMenuFunctionalRoles;
326     this.epUserRolesRequests = epUserRolesRequests;
327     this.epAppFunctions = epAppFunctions;
328     this.epAppRoleFunctions = epAppRoleFunctions;
329     this.fnUserRoles = fnUserRoles;
330     this.epWebAnalyticsSources = epWebAnalyticsSources;
331     this.epWidgetCatalogRoles = epWidgetCatalogRoles;
332     this.epMicroservices = epMicroservices;
333     this.fnPersUserAppSels = fnPersUserAppSels;
334   }
335 }