Added Junits
[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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
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.CentralUser;
55 import org.onap.portalapp.portal.transport.CentralV2Role;
56 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
57 import org.onap.portalsdk.core.domain.Role;
58 import org.onap.portalsdk.core.domain.RoleFunction;
59 import org.onap.portalsdk.core.restful.domain.EcompUser;
60 import org.springframework.http.ResponseEntity;
61 import org.springframework.web.client.HttpClientErrorException;
62
63 import com.fasterxml.jackson.core.JsonParseException;
64 import com.fasterxml.jackson.databind.JsonMappingException;
65 import com.fasterxml.jackson.databind.ObjectMapper;
66
67 public interface ExternalAccessRolesService {
68         
69         /**
70          * It gets list of application roles 
71          * 
72          * @param appId
73          * @return List
74          * @throws Exception 
75          */
76         public List<EPRole> getAppRoles(Long appId) throws Exception;
77         
78         /**
79          * It returns single app record
80          * 
81          * @param uebkey
82          * @return List
83          * @throws Exception 
84          */             
85         public List<EPApp> getApp(String uebkey) throws Exception;
86         
87         /**
88          * Adds role in the external access system if fails throws exception
89          * 
90          * @param addRoles
91          * @param uebkey
92          * @return boolean
93          * @throws Exception
94          */
95         public boolean addRole(Role addRoles, String uebkey) throws Exception;
96
97         /**
98          * It returns complete user information
99          * 
100          * @param loginId
101          * @return EPUser object
102          * @throws Exception
103          */
104         List<EPUser> getUser(String loginId) throws InvalidUserException;
105         
106         /**
107          * It returns complete user information including application roles permissions
108          * 
109          * @param loginId
110          * @param uebkey
111          * @return String
112          * @throws Exception
113          */
114         String getV2UserWithRoles(String loginId, String uebkey) throws Exception;
115
116         /**
117          * It returns list of all role functions
118          * @param string 
119          * @return List
120          * @throws Exception 
121          */
122         List<CentralV2RoleFunction> getRoleFuncList(String string) throws Exception;
123         
124         /**
125          * It return list of role provided by the app uebkey and roleId
126          * 
127          * @param roleId
128          * @param uebkey
129          * @return CentralRole
130          * @throws Exception
131          */
132         CentralV2Role getRoleInfo(Long roleId, String uebkey) throws Exception;
133         
134         /**
135          *  It returns the CentralRoleFunction object 
136          *   
137          * @param functionCode
138          * @param uebkey 
139          * @return CentralRoleFunction
140          * @throws Exception 
141          */
142         public CentralV2RoleFunction getRoleFunction(String functionCode, String uebkey) throws Exception;
143
144         /**
145          *  It saves role function in the DB
146          *  
147          * @param domainCentralRoleFunction
148          * @param requestedApp 
149          * @return true else false
150          * @throws Exception 
151          */
152         public boolean saveCentralRoleFunction(CentralV2RoleFunction domainCentralRoleFunction, EPApp requestedApp) throws Exception;
153
154         /**
155          * It deletes role function in the DB
156          * 
157          * @param code
158          * @param app 
159          */
160         public boolean deleteCentralRoleFunction(String code, EPApp app);
161
162         /**
163          * It gets all roles the applications
164          * 
165          * @param uebkey
166          * @return List
167          * @throws Exception 
168          */
169         public List<CentralV2Role> getRolesForApp(String uebkey) throws Exception;
170         
171         /**
172          * 
173          * It saves role function in the DB
174          * 
175          * @param saveRole
176          * @param uebkey
177          * @return message and true or false  
178          * @throws Exception
179          */
180         ExternalRequestFieldsValidator saveRoleForApplication(Role saveRole, String uebkey) throws Exception;
181
182         /**
183          *  It deletes role in the DB
184          *  
185          * @param code
186          * @param uebkey
187          * @return true else false
188          * @throws Exception 
189          */
190         boolean deleteRoleForApplication(String code, String uebkey) throws Exception;
191         
192         /**
193          * It gets all active roles for single application 
194          * 
195          * @param uebkey
196          * @return List
197          * @throws Exception
198          */
199         List<CentralV2Role> getActiveRoles(String uebkey) throws Exception;
200         
201         /**
202          * It deletes user related roles for an application in the table
203          * @param roleId
204          * @param uebkey
205          * @param LoginId 
206          * @return true else false
207          * @throws Exception 
208          */
209         public ExternalRequestFieldsValidator deleteDependencyRoleRecord(Long roleId, String uebkey, String LoginId) throws Exception;
210         
211         /**
212          * It sync new functions codes and names from and updates role functions from external access system
213          * 
214          * @param app
215          * @throws Exception
216          */
217         public void syncRoleFunctionFromExternalAccessSystem(EPApp app) throws Exception;
218
219         /**
220          * It uploads portal functions into external auth system
221          * @param uebkey
222          * @return
223          * @throws Exception
224          */
225         public Integer bulkUploadFunctions(String uebkey) throws Exception;
226
227         /**
228          * It uploads portal roles into external auth system
229          * @param uebkey
230          * @return
231          * @throws Exception
232          */
233         public Integer bulkUploadRoles(String uebkey) throws Exception;
234
235         /**
236          * It uploads partner application role functions into external auth system
237          * 
238          * @param uebkey
239          * @param upload
240          * @throws Exception
241          */
242         public void bulkUploadPartnerFunctions(String uebkey, List<RoleFunction> upload) throws Exception;
243
244         /** 
245          * It uploads partner application role functions into external auth system
246          * 
247          * @param uebkey
248          * @param upload
249          * @throws Exception
250          */
251         public void bulkUploadPartnerRoles(String uebkey, List<Role> upload) throws Exception;
252
253         /**
254          * It returns total no. of portal application role functions records added in external auth system 
255          * @param uebkey
256          * @return
257          * @throws Exception
258          */
259         Integer bulkUploadRolesFunctions(String uebkey) throws Exception;
260         
261         /**
262          *  It syncs the roles and rolefunctions to the ecomp DB from AAF
263          * @param app
264          * @throws Exception
265          */
266         void syncApplicationRolesWithEcompDB(EPApp app) throws Exception;
267
268         /**
269          * It uploads list of user roles of the application into external auth system 
270          * 
271          * @param uebkey
272          * @return
273          * @throws Exception
274          */
275         public Integer bulkUploadUserRoles(String uebkey) throws Exception;
276
277         /**
278          * It Uploads partner application role functions into external auth system
279          * 
280          * @param uebkey
281          * @param roleList
282          * @throws Exception
283          */
284         void bulkUploadPartnerRoleFunctions(String uebkey, List<Role> roleList) throws Exception;
285
286         /**
287          * it deletes all dependency role records 
288          * 
289          * @param localSession
290          * @param roleId
291          * @param appId
292          * @param isPortalRequest 
293          * @throws Exception
294          */
295         public void deleteRoleDependencyRecords(Session localSession, Long roleId, Long appId, boolean isPortalRequest) throws Exception;
296
297         /**
298          * It returns list of applications functions along with functions associated with global role
299          * 
300          * @param uebkey
301          * @return
302          * @throws Exception
303          */
304         List<String> getMenuFunctionsList(String uebkey) throws Exception;
305         
306         /**
307          * 
308          * @param uebkey applications UebKey
309          * @return
310          * @throws Exception
311          * Method getAllUsers returns all the active users of application
312          */
313         List<EcompUser> getAllAppUsers(String uebkey) throws Exception;
314         
315         /**
316          * 
317          * @param result
318          * @return returns Role Object
319          * Method ConvertCentralRoleToRole converts the CentralRole String to Role Object
320          */
321         public Role ConvertCentralRoleToRole(String result);
322         
323         /**
324          * It returns the list of centralized applications
325          * 
326          * @param userId
327          * @return List
328          */
329         public List<CentralizedApp> getCentralizedAppsOfUser(String userId);
330         
331         /**
332          * It returns the list of globalRoles of Portal
333          * @return
334          */
335         public  List<EPRole> getGlobalRolesOfPortal();
336         
337         /**
338          * It converts list of CentralRoleFunction objects to RoleFunction objects
339          * @param answer contains list of CentralRoleFunction objects
340          * @return List of RoleFunction objects
341          */
342         public List<RoleFunction> convertCentralRoleFunctionToRoleFunctionObject(List<CentralV2RoleFunction> answer);
343         
344         /**
345          * 
346          * It returns user roles for older version
347          * 
348          * @param loginId
349          * @param uebkey
350          * @return EPUser
351          * @throws Exception 
352          */
353         public CentralUser getUserRoles(String loginId, String uebkey) throws Exception;
354         
355         /**
356          * It converts list of V2 CentralRole objects to old version CentralRole objects
357          * 
358          * @param v2CenRole
359          * @return List of CentralRole objects
360          */
361         public List<CentralRole> convertV2CentralRoleListToOldVerisonCentralRoleList(List<CentralV2Role> v2CenRole);
362         
363         /**
364          * 
365          * It finds namespace in external auth system if found returns namespace information
366          * 
367          * @param epApp
368          * @return Http response
369          */
370         public ResponseEntity<String> getNameSpaceIfExists(EPApp epApp) throws Exception, HttpClientErrorException;
371         
372         /**
373          * 
374          * It converts V2 CentralRole objects to old version CentralRole objects
375          * 
376          * @param answer
377          * @return
378          */
379         public CentralRole convertV2CentralRoleToOldVerisonCentralRole(CentralV2Role answer);
380
381         /**
382          * 
383          * Returns list of EPRole Objects if exists
384          * 
385          * @param app
386          * @return List of EPRole objects
387          */
388         Map<String, EPRole> getCurrentRolesInDB(EPApp app);
389     
390         
391         /**
392          * 
393          * It uploads list of users for single role when role name is re-named
394          * 
395          * @param header
396          * @param roleId
397          * @param roleName 
398          * @return number of user roles added in External Auth System
399          * @throws Exception 
400          */
401         public Integer bulkUploadUsersSingleRole(String uebkey, Long roleId, String roleName) throws Exception;
402         
403         /**
404          * 
405          * It returns JSON array of external auth roles and its corresponding functions
406          * 
407          * @param app
408          * @return JSON Array
409          * @throws Exception
410          */
411         public JSONArray getAppRolesJSONFromExtAuthSystem(EPApp app) throws Exception;
412         
413         /**
414          * It encodes the function code  based on Hex encoding
415          * @param funCode
416          * 
417          */
418         public String encodeFunctionCode(String funCode);
419         
420         /**
421          * 
422          * It returns list of ExternalRoleDetails which is converted from JSON array of roles
423          * 
424          * @param app 
425          * @param mapper
426          * @param extRole contains external auth application roles JSON array
427          * @return List of ExternalRoleDetails objects
428          * @throws IOException
429          * @throws JsonParseException
430          * @throws JsonMappingException
431          */
432         public List<ExternalRoleDetails> getExternalRoleDetailsList(EPApp app,
433                         ObjectMapper mapper, JSONArray extRole) throws IOException, JsonParseException, JsonMappingException;
434         
435         public JSONArray getAllUsersByRole(String roleName) throws Exception;
436
437 }