Replace ecomp references
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / ExternalAccessRolesService.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.service;
39
40 import java.io.IOException;
41 import java.util.List;
42 import java.util.Map;
43
44 import org.hibernate.Session;
45 import org.json.JSONArray;
46 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
47 import org.onap.portalapp.portal.domain.CentralizedApp;
48 import org.onap.portalapp.portal.domain.EPApp;
49 import org.onap.portalapp.portal.domain.EPRole;
50 import org.onap.portalapp.portal.domain.EPUser;
51 import org.onap.portalapp.portal.domain.ExternalRoleDetails;
52 import org.onap.portalapp.portal.exceptions.InvalidUserException;
53 import org.onap.portalapp.portal.transport.CentralRole;
54 import org.onap.portalapp.portal.transport.CentralRoleFunction;
55 import org.onap.portalapp.portal.transport.CentralUser;
56 import org.onap.portalapp.portal.transport.CentralV2Role;
57 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
58 import org.onap.portalsdk.core.domain.Role;
59 import org.onap.portalsdk.core.domain.RoleFunction;
60 import org.onap.portalsdk.core.restful.domain.EcompUser;
61 import org.springframework.http.ResponseEntity;
62 import org.springframework.web.client.HttpClientErrorException;
63
64 import com.fasterxml.jackson.core.JsonParseException;
65 import com.fasterxml.jackson.databind.JsonMappingException;
66 import com.fasterxml.jackson.databind.ObjectMapper;
67
68 public interface ExternalAccessRolesService {
69         
70         /**
71          * It gets list of application roles 
72          * 
73          * @param appId
74          * @return List
75          * @throws Exception 
76          */
77         public List<EPRole> getAppRoles(Long appId) throws Exception;
78         
79         /**
80          * It returns single app record
81          * 
82          * @param uebkey
83          * @return List
84          * @throws Exception 
85          */             
86         public List<EPApp> getApp(String uebkey) throws Exception;
87         
88         /**
89          * Adds role in the external access system if fails throws exception
90          * 
91          * @param addRoles
92          * @param uebkey
93          * @return boolean
94          * @throws Exception
95          */
96         public boolean addRole(Role addRoles, String uebkey) throws Exception;
97
98         /**
99          * It returns complete user information
100          * 
101          * @param loginId
102          * @return EPUser object
103          * @throws Exception
104          */
105         List<EPUser> getUser(String loginId) throws InvalidUserException;
106         
107         /**
108          * It returns complete user information including application roles permissions
109          * 
110          * @param loginId
111          * @param uebkey
112          * @return String
113          * @throws Exception
114          */
115         String getV2UserWithRoles(String loginId, String uebkey) throws Exception;
116
117         /**
118          * It returns list of all role functions
119          * @param string 
120          * @return List
121          * @throws Exception 
122          */
123         List<CentralV2RoleFunction> getRoleFuncList(String string) throws Exception;
124         
125         /**
126          * It return list of role provided by the app uebkey and roleId
127          * 
128          * @param roleId
129          * @param uebkey
130          * @return CentralRole
131          * @throws Exception
132          */
133         CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception;
134         
135         /**
136          *  It returns the CentralV2RoleFunction object 
137          *   
138          * @param functionCode
139          * @param uebkey 
140          * @return CentralV2RoleFunction
141          * @throws Exception 
142          */
143         public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception;
144
145         /**
146          *  It saves role function in the DB
147          *  
148          * @param domainCentralRoleFunction
149          * @param requestedApp 
150          * @return true else false
151          * @throws Exception 
152          */
153         public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception;
154         
155         /**
156          * It deletes role function in the DB
157          * 
158          * @param code
159          * @param app 
160          */
161         public boolean deleteCentralRoleFunction(String code, EPApp app);
162
163         /**
164          * It gets all roles the applications
165          * 
166          * @param uebkey
167          * @return List
168          * @throws Exception 
169          */
170         public List<CentralV2Role> getRolesForApp(String uebkey) throws Exception;
171         
172         /**
173          * 
174          * It saves role function in the DB
175          * 
176          * @param saveRole
177          * @param uebkey
178          * @return message and true or false  
179          * @throws Exception
180          */
181         ExternalRequestFieldsValidator saveRoleForApplication(Role saveRole, String uebkey) throws Exception;
182
183         /**
184          *  It deletes role in the DB
185          *  
186          * @param code
187          * @param uebkey
188          * @return true else false
189          * @throws Exception 
190          */
191         boolean deleteRoleForApplication(String code, String uebkey) throws Exception;
192         
193         /**
194          * It gets all active roles for single application 
195          * 
196          * @param uebkey
197          * @return List
198          * @throws Exception
199          */
200         List<CentralV2Role> getActiveRoles(String uebkey) throws Exception;
201         
202         /**
203          * It deletes user related roles for an application in the table
204          * @param roleId
205          * @param uebkey
206          * @param LoginId 
207          * @return true else false
208          * @throws Exception 
209          */
210         public ExternalRequestFieldsValidator deleteDependencyRoleRecord(Long roleId, String uebkey, String LoginId) throws Exception;
211         
212         /**
213          * It sync new functions codes and names from and updates role functions from external access system
214          * 
215          * @param app
216          * @throws Exception
217          */
218         public void syncRoleFunctionFromExternalAccessSystem(EPApp app) throws Exception;
219
220         /**
221          * It uploads portal functions into external auth system
222          * @param uebkey
223          * @return
224          * @throws Exception
225          */
226         public Integer bulkUploadFunctions(String uebkey) throws Exception;
227
228         /**
229          * It uploads portal roles into external auth system
230          * @param uebkey
231          * @return
232          * @throws Exception
233          */
234         public Integer bulkUploadRoles(String uebkey) throws Exception;
235
236         /**
237          * It uploads partner application role functions into external auth system
238          * 
239          * @param uebkey
240          * @param upload
241          * @throws Exception
242          */
243         public void bulkUploadPartnerFunctions(String uebkey, List<RoleFunction> upload) throws Exception;
244
245         /** 
246          * It uploads partner application role functions into external auth system
247          * 
248          * @param uebkey
249          * @param upload
250          * @throws Exception
251          */
252         public void bulkUploadPartnerRoles(String uebkey, List<Role> upload) throws Exception;
253
254         /**
255          * It returns total no. of portal application role functions records added in external auth system 
256          * @param uebkey
257          * @return
258          * @throws Exception
259          */
260         Integer bulkUploadRolesFunctions(String uebkey) throws Exception;
261         
262         /**
263          *  It syncs the roles and rolefunctions to the ONAP DB from AAF
264          * @param app
265          * @throws Exception
266          */
267         void syncApplicationRolesWithEcompDB(EPApp app) throws Exception;
268
269         /**
270          * It uploads list of user roles of the application into external auth system 
271          * 
272          * @param uebkey
273          * @return
274          * @throws Exception
275          */
276         public Integer bulkUploadUserRoles(String uebkey) throws Exception;
277
278         /**
279          * It Uploads partner application role functions into external auth system
280          * 
281          * @param uebkey
282          * @param roleList
283          * @throws Exception
284          */
285         void bulkUploadPartnerRoleFunctions(String uebkey, List<Role> roleList) throws Exception;
286
287         /**
288          * it deletes all dependency role records 
289          * 
290          * @param localSession
291          * @param roleId
292          * @param appId
293          * @param isPortalRequest 
294          * @throws Exception
295          */
296         public void deleteRoleDependencyRecords(Session localSession, Long roleId, Long appId, boolean isPortalRequest) throws Exception;
297
298         /**
299          * It returns list of applications functions along with functions associated with global role
300          * 
301          * @param uebkey
302          * @return
303          * @throws Exception
304          */
305         List<String> getMenuFunctionsList(String uebkey) throws Exception;
306         
307         /**
308          * 
309          * @param uebkey applications UebKey
310          * @return
311          * @throws Exception
312          * Method getAllUsers returns all the active users of application
313          */
314         List<EcompUser> getAllAppUsers(String uebkey) throws Exception;
315         
316         /**
317          * 
318          * @param result
319          * @return returns Role Object
320          * Method ConvertCentralRoleToRole converts the CentralRole String to Role Object
321          */
322         public Role ConvertCentralRoleToRole(String result);
323         
324         /**
325          * It returns the list of centralized applications
326          * 
327          * @param userId
328          * @return List
329          */
330         public List<CentralizedApp> getCentralizedAppsOfUser(String userId);
331         
332         /**
333          * It returns the list of globalRoles of Portal
334          * @return
335          */
336         public  List<EPRole> getGlobalRolesOfPortal();
337         
338         /**
339          * It converts list of CentralV2RoleFunction objects to older version of CentralRoleFunction objects
340          * @param answer contains list of CentralRoleFunction objects
341          * @return List of CentralRoleFunction objects
342          */
343         public List<CentralRoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
344         
345         /**
346          * 
347          * It returns user roles for older version
348          * 
349          * @param loginId
350          * @param uebkey
351          * @return EPUser
352          * @throws Exception 
353          */
354         public CentralUser getUserRoles(String loginId, String uebkey) throws Exception;
355         
356         /**
357          * It converts list of V2 CentralRole objects to old version CentralRole objects
358          * 
359          * @param v2CenRole
360          * @return List of CentralRole objects
361          */
362         public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRole);
363         
364         /**
365          * 
366          * It finds namespace in external auth system if found returns namespace information
367          * 
368          * @param epApp
369          * @return Http response
370          */
371         public ResponseEntity<String> getNameSpaceIfExists(EPApp epApp) throws Exception, HttpClientErrorException;
372         
373         /**
374          * 
375          * It converts V2 CentralRole objects to old version CentralRole objects
376          * 
377          * @param answer
378          * @return
379          */
380         public CentralRole convertV2CentralRoleToOldVerisonCentralRole(CentralV2Role answer);
381
382         /**
383          * 
384          * Returns list of EPRole Objects if exists
385          * 
386          * @param app
387          * @return List of EPRole objects
388          */
389         Map<String, EPRole> getCurrentRolesInDB(EPApp app);
390     
391         
392         /**
393          * 
394          * It uploads list of users for single role when role name is re-named
395          * 
396          * @param header
397          * @param roleId
398          * @param roleName 
399          * @return number of user roles added in External Auth System
400          * @throws Exception 
401          */
402         public Integer bulkUploadUsersSingleRole(String uebkey, Long roleId, String roleName) throws Exception;
403         
404         /**
405          * 
406          * It returns JSON array of external auth roles and its corresponding functions
407          * 
408          * @param app
409          * @return JSON Array
410          * @throws Exception
411          */
412         public JSONArray getAppRolesJSONFromExtAuthSystem(EPApp app) throws Exception;
413         
414         /**
415          * It encodes the function code  based on Hex encoding
416          * @param funCode
417          * 
418          */
419         public String encodeFunctionCode(String funCode);
420         
421         /**
422          * 
423          * It returns list of ExternalRoleDetails which is converted from JSON array of roles
424          * 
425          * @param app 
426          * @param mapper
427          * @param extRole contains external auth application roles JSON array
428          * @return List of ExternalRoleDetails objects
429          * @throws IOException
430          * @throws JsonParseException
431          * @throws JsonMappingException
432          */
433         public List<ExternalRoleDetails> getExternalRoleDetailsList(EPApp app,
434                         ObjectMapper mapper, JSONArray extRole) throws IOException, JsonParseException, JsonMappingException;
435         
436         public JSONArray getAllUsersByRole(String roleName) throws Exception;
437         
438         /**
439          * 
440          * It check function code has any pipes, if found return function type
441          * 
442          * @param roleFuncItem
443          * @param type
444          * @return function type
445          */
446         String getFunctionCodeType(String roleFuncItem);
447         
448         /**
449          * It return function action
450          * 
451          * @param roleFuncItem
452          * @return String action
453          */
454         String getFunctionCodeAction(String roleFuncItem);
455
456 }