Fixed health check issue
[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     @NamedQuery(
113         name = "FnApp.retrieveWhereAppName",
114         query = "FROM FnApp WHERE appName = :appName"
115     )
116 })
117
118 //TODO appName as unique index?
119
120 @Table(name = "fn_app")
121 @NoArgsConstructor
122 @AllArgsConstructor
123 @EqualsAndHashCode(callSuper = true)
124 @Getter
125 @Setter
126 @Entity
127 public class FnApp extends DomainVo implements Serializable {
128
129   @Column(name = "app_name", length = 100, nullable = false, columnDefinition = "varchar(100) not null default '?'")
130   @Size(max = 100)
131   @SafeHtml
132   @NotNull
133   private String appName = "?";
134   @Column(name = "app_image_url", length = 256)
135   @Size(max = 256)
136   @SafeHtml
137   private String appImageUrl;
138   @Column(name = "app_description", length = 512)
139   @Size(max = 256)
140   @SafeHtml
141   private String appDescription;
142   @Column(name = "app_notes", length = 4096)
143   @Size(max = 4096)
144   @SafeHtml
145   private String appNotes;
146   @Column(name = "app_url", length = 256)
147   @Size(max = 256)
148   @SafeHtml
149   //TODO URL
150   @URL
151   private String appUrl;
152   @Column(name = "app_alternate_url", length = 256)
153   @Size(max = 256)
154   @SafeHtml
155   private String appAlternateUrl;
156   @Column(name = "app_rest_endpoint", length = 2000)
157   @Size(max = 2000)
158   @SafeHtml
159   private String appRestEndpoint;
160   @Column(name = "ml_app_name", length = 50, nullable = false, columnDefinition = "varchar(50) not null default '?'")
161   @Size(max = 50)
162   @SafeHtml
163   @NotNull
164   private String mlAppName = "?";
165   @Column(name = "ml_app_admin_id", length = 7, nullable = false, columnDefinition = "varchar(7) not null default '?'")
166   @Size(max = 7)
167   @SafeHtml
168   private String mlAppAdminId = "?";
169   @Column(name = "mots_id", length = 11)
170   @Digits(integer = 11, fraction = 0)
171   private Long motsId;
172   @Column(name = "app_password", length = 256, nullable = false, columnDefinition = "varchar(256) not null default '?'")
173   @Size(max = 256)
174   @SafeHtml
175   @NotNull
176   private String appPassword = "?";
177   @Column(name = "open")
178   private Boolean open = false;
179   @Column(name = "enabled")
180   private Boolean enabled = false;
181   @Column(name = "active_yn")
182   @NotNull
183   private Boolean activeYn = true;
184   @Column(name = "_thumbnail", columnDefinition = "mediumblob null default null")
185   private byte[] thumbnail;
186   @Column(name = "app_username", length = 50)
187   @Size(max = 50)
188   @SafeHtml
189   private String appUsername;
190   @Column(name = "ueb_key", length = 256)
191   @Size(max = 256)
192   @SafeHtml
193   private String uebKey;
194   @Column(name = "ueb_secret", length = 256)
195   @Size(max = 256)
196   @SafeHtml
197   private String uebSecret;
198   @Column(name = "ueb_topic_name", length = 256)
199   @Size(max = 256)
200   @SafeHtml
201   private String uebTopicName;
202   @Column(name = "app_type", length = 11, columnDefinition = "int(11) not null default 1")
203   @Digits(integer = 11, fraction = 0)
204   private Long appType = 1L;
205   @Column(name = "auth_central", length = 1, nullable = false)
206   private Boolean authCentral;
207   @Column(name = "auth_namespace", length = 100)
208   @Size(max = 100)
209   @SafeHtml
210   private String authNamespace;
211   @OneToMany(
212       targetEntity = FnMenuFunctionalRoles.class,
213       mappedBy = "appId",
214       cascade = CascadeType.MERGE,
215       fetch = FetchType.LAZY
216   )
217   private Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles;
218   @OneToMany(
219       targetEntity = EpUserRolesRequest.class,
220       mappedBy = "appId",
221       cascade = CascadeType.MERGE,
222       fetch = FetchType.LAZY
223   )
224   private Set<EpUserRolesRequest> epUserRolesRequests;
225   @OneToMany(
226       targetEntity = EpAppFunction.class,
227       mappedBy = "appId",
228       cascade = CascadeType.MERGE,
229       fetch = FetchType.LAZY
230   )
231   private Set<EpAppFunction> epAppFunctions;
232   @OneToMany(
233       targetEntity = EpAppRoleFunction.class,
234       mappedBy = "appId",
235       cascade = CascadeType.MERGE,
236       fetch = FetchType.LAZY
237   )
238   private Set<EpAppRoleFunction> epAppRoleFunctions;
239   @OneToMany(
240       targetEntity = FnUserRole.class,
241       mappedBy = "fnAppId",
242       cascade = CascadeType.MERGE,
243       fetch = FetchType.LAZY
244   )
245   private Set<FnUserRole> fnUserRoles;
246   @OneToMany(
247       targetEntity = EpWebAnalyticsSource.class,
248       mappedBy = "appId",
249       cascade = CascadeType.MERGE,
250       fetch = FetchType.LAZY
251   )
252   private Set<EpWebAnalyticsSource> epWebAnalyticsSources;
253   @OneToMany(
254       targetEntity = EpWidgetCatalogRole.class,
255       mappedBy = "appId",
256       cascade = CascadeType.MERGE,
257       fetch = FetchType.LAZY
258   )
259   private Set<EpWidgetCatalogRole> epWidgetCatalogRoles;
260   @OneToMany(
261       targetEntity = EpMicroservice.class,
262       mappedBy = "appId",
263       cascade = CascadeType.MERGE,
264       fetch = FetchType.LAZY
265   )
266   private Set<EpMicroservice> epMicroservices;
267   @OneToMany(
268       targetEntity = FnPersUserAppSel.class,
269       mappedBy = "appId",
270       cascade = CascadeType.MERGE,
271       fetch = FetchType.LAZY
272   )
273   private Set<FnPersUserAppSel> fnPersUserAppSels;
274
275   public Boolean isRestrictedApp() {
276     return (this.appType == 2);
277   }
278
279   @Builder
280   public FnApp(@Digits(integer = 11, fraction = 0) Long id, LocalDateTime created,
281       LocalDateTime modified, Long rowNum, Serializable auditUserId,
282       DomainVo createdId, DomainVo modifiedId, Set<DomainVo> fnUsersCreatedId,
283       Set<DomainVo> fnUsersModifiedId,
284       @Size(max = 100) @SafeHtml @NotNull String appName,
285       @Size(max = 256) @SafeHtml String appImageUrl,
286       @Size(max = 256) @SafeHtml String appDescription,
287       @Size(max = 4096) @SafeHtml String appNotes,
288       @Size(max = 256) @SafeHtml @URL String appUrl,
289       @Size(max = 256) @SafeHtml String appAlternateUrl,
290       @Size(max = 2000) @SafeHtml String appRestEndpoint,
291       @Size(max = 50) @SafeHtml @NotNull String mlAppName,
292       @Size(max = 7) @SafeHtml @NotNull String mlAppAdminId,
293       @Digits(integer = 11, fraction = 0) Long motsId,
294       @Size(max = 256) @SafeHtml @NotNull String appPassword, Boolean open, Boolean enabled, Boolean activeYn, byte[] thumbnail,
295       @Size(max = 50) @SafeHtml String appUsername,
296       @Size(max = 256) @SafeHtml String uebKey,
297       @Size(max = 256) @SafeHtml String uebSecret,
298       @Size(max = 256) @SafeHtml String uebTopicName,
299       @Digits(integer = 11, fraction = 0) Long appType, Boolean authCentral,
300       @Size(max = 100) @SafeHtml String authNamespace,
301       Set<FnMenuFunctionalRoles> fnMenuFunctionalRoles,
302       Set<EpUserRolesRequest> epUserRolesRequests,
303       Set<EpAppFunction> epAppFunctions, Set<EpAppRoleFunction> epAppRoleFunctions,
304       Set<FnUserRole> fnUserRoles, Set<EpWebAnalyticsSource> epWebAnalyticsSources,
305       Set<EpWidgetCatalogRole> epWidgetCatalogRoles,
306       Set<EpMicroservice> epMicroservices, Set<FnPersUserAppSel> fnPersUserAppSels) {
307     super(id, created, modified, rowNum, auditUserId, createdId, modifiedId, fnUsersCreatedId, fnUsersModifiedId);
308     this.appName = appName;
309     this.appImageUrl = appImageUrl;
310     this.appDescription = appDescription;
311     this.appNotes = appNotes;
312     this.appUrl = appUrl;
313     this.appAlternateUrl = appAlternateUrl;
314     this.appRestEndpoint = appRestEndpoint;
315     this.mlAppName = mlAppName;
316     this.mlAppAdminId = mlAppAdminId;
317     this.motsId = motsId;
318     this.appPassword = appPassword;
319     this.open = open;
320     this.enabled = enabled;
321     this.activeYn = activeYn;
322     this.thumbnail = thumbnail;
323     this.appUsername = appUsername;
324     this.uebKey = uebKey;
325     this.uebSecret = uebSecret;
326     this.uebTopicName = uebTopicName;
327     this.appType = appType;
328     this.authCentral = authCentral;
329     this.authNamespace = authNamespace;
330     this.fnMenuFunctionalRoles = fnMenuFunctionalRoles;
331     this.epUserRolesRequests = epUserRolesRequests;
332     this.epAppFunctions = epAppFunctions;
333     this.epAppRoleFunctions = epAppRoleFunctions;
334     this.fnUserRoles = fnUserRoles;
335     this.epWebAnalyticsSources = epWebAnalyticsSources;
336     this.epWidgetCatalogRoles = epWidgetCatalogRoles;
337     this.epMicroservices = epMicroservices;
338     this.fnPersUserAppSels = fnPersUserAppSels;
339   }
340 }