1 package org.openecomp.portalapp.portal.service;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.context.annotation.EnableAspectJAutoProxy;
8 import org.springframework.stereotype.Service;
9 import org.springframework.transaction.annotation.Transactional;
11 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
12 import org.openecomp.portalsdk.core.service.DataAccessService;
13 import org.openecomp.portalapp.portal.domain.EPApp;
14 import org.openecomp.portalapp.portal.domain.EPUser;
15 import org.openecomp.portalapp.portal.domain.EPUserApp;
16 import org.openecomp.portalapp.portal.domain.PersUserAppSelection;
17 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
19 @Service("persUserAppService")
21 @org.springframework.context.annotation.Configuration
22 @EnableAspectJAutoProxy
24 public class PersUserAppServiceImpl implements PersUserAppService {
26 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PersUserAppServiceImpl.class);
29 private DataAccessService dataAccessService;
31 private AdminRolesService adminRolesService;
33 private UserRolesService userRolesService;
37 public void setPersUserAppValue(EPUser user, EPApp app, boolean select, boolean pending) {
38 if (user == null || app == null)
39 throw new IllegalArgumentException("setPersUserAppValue: Null values");
41 // Find the record for this user-app combo, if any
42 String filter = " where user_id = " + Long.toString(user.getId()) + " and app_id = "
43 + Long.toString(app.getId());
44 @SuppressWarnings("unchecked")
45 List<PersUserAppSelection> persList = dataAccessService.getList(PersUserAppSelection.class, filter, null, null);
47 // Key constraint limits to 1 row
48 PersUserAppSelection persRow = null;
49 if (persList.size() == 1)
50 persRow = persList.get(0);
52 persRow = new PersUserAppSelection(null, user.getId(), app.getId(), null);
55 // Pending status is not meaningful for open apps.
57 logger.error(EELFLoggerDelegate.errorLogger,
58 "setPersUserAppValue: invalid request, ignoring set-pending for open app");
60 // Open apps have same behavior for regular and admin users
62 // Selection of an open app requires a record
63 persRow.setStatusCode("S"); // show
64 dataAccessService.saveDomainObject(persRow, null);
66 // De-selection of an open app requires no record
67 if (persRow.getId() != null)
68 dataAccessService.deleteDomainObject(persRow, null);
73 // Pending overrides select.
75 persRow.setStatusCode("P");
76 dataAccessService.saveDomainObject(persRow, null);
78 // Behavior depends on Portal (super) admin status, bcos an
79 // admin can force an app onto the dashboard.
80 boolean isPortalAdmin = adminRolesService.isSuperAdmin(user);
81 boolean adminUserHasAppRole = false;
83 List<EPUserApp> roles = userRolesService.getCachedAppRolesForUser(app.getId(), user.getId());
84 adminUserHasAppRole = (roles.size() > 0);
85 logger.debug(EELFLoggerDelegate.debugLogger, "setPersUserAppValue: app {}, admin user {}, role count {}",
86 app.getId(), user.getId(), roles.size());
90 if (isPortalAdmin && !adminUserHasAppRole) {
91 // The special case: portal admin, no role
92 persRow.setStatusCode("S"); // show
93 dataAccessService.saveDomainObject(persRow, null);
95 // User has role-based access to the app.
96 // Showing an accessible app requires no record.
97 if (persRow.getId() != null)
98 dataAccessService.deleteDomainObject(persRow, null);
102 if (isPortalAdmin && !adminUserHasAppRole) {
103 // The special case: portal admin, no role
104 if (persRow.getId() != null)
105 dataAccessService.deleteDomainObject(persRow, null);
107 // User has role-based access to the app.
108 // Hiding an accessible app requires a record
109 persRow.setStatusCode("H"); // hide
110 dataAccessService.saveDomainObject(persRow, null);