2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.portal.service;
22 import java.util.List;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.context.annotation.EnableAspectJAutoProxy;
26 import org.springframework.stereotype.Service;
27 import org.springframework.transaction.annotation.Transactional;
29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.openecomp.portalsdk.core.service.DataAccessService;
31 import org.openecomp.portalapp.portal.domain.EPApp;
32 import org.openecomp.portalapp.portal.domain.EPUser;
33 import org.openecomp.portalapp.portal.domain.EPUserApp;
34 import org.openecomp.portalapp.portal.domain.PersUserAppSelection;
35 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
37 @Service("persUserAppService")
39 @org.springframework.context.annotation.Configuration
40 @EnableAspectJAutoProxy
42 public class PersUserAppServiceImpl implements PersUserAppService {
44 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PersUserAppServiceImpl.class);
47 private DataAccessService dataAccessService;
49 private AdminRolesService adminRolesService;
51 private UserRolesService userRolesService;
56 * @see org.openecomp.portalapp.portal.service.UserAppSelectService#
57 * setAppCatalogSelection(org.openecomp.portalapp.portal.domain.EPUser,
58 * org.openecomp.portalapp.portal.transport.AppCatalogSelection)
61 public void setPersUserAppValue(EPUser user, EPApp app, boolean select, boolean pending) {
62 if (user == null || app == null)
63 throw new IllegalArgumentException("setPersUserAppValue: Null values");
65 // Find the record for this user-app combo, if any
66 String filter = " where user_id = " + Long.toString(user.getId()) + " and app_id = "
67 + Long.toString(app.getId());
68 @SuppressWarnings("unchecked")
69 List<PersUserAppSelection> persList = dataAccessService.getList(PersUserAppSelection.class, filter, null, null);
71 // Key constraint limits to 1 row
72 PersUserAppSelection persRow = null;
73 if (persList.size() == 1)
74 persRow = persList.get(0);
76 persRow = new PersUserAppSelection(null, user.getId(), app.getId(), null);
79 // Pending status is not meaningful for open apps.
81 logger.error(EELFLoggerDelegate.errorLogger,
82 "setPersUserAppValue: invalid request, ignoring set-pending for open app");
84 // Open apps have same behavior for regular and admin users
86 // Selection of an open app requires a record
87 persRow.setStatusCode("S"); // show
88 dataAccessService.saveDomainObject(persRow, null);
90 // De-selection of an open app requires no record
91 if (persRow.getId() != null)
92 dataAccessService.deleteDomainObject(persRow, null);
97 // Pending overrides select.
99 persRow.setStatusCode("P");
100 dataAccessService.saveDomainObject(persRow, null);
102 // Behavior depends on Portal (super) admin status, bcos an
103 // admin can force an app onto the dashboard.
104 boolean isPortalAdmin = adminRolesService.isSuperAdmin(user);
105 boolean adminUserHasAppRole = false;
107 List<EPUserApp> roles = userRolesService.getCachedAppRolesForUser(app.getId(), user.getId());
108 adminUserHasAppRole = (roles.size() > 0);
109 logger.debug(EELFLoggerDelegate.debugLogger, "setPersUserAppValue: app {}, admin user {}, role count {}",
110 app.getId(), user.getId(), roles.size());
115 // The special case: portal admin
116 persRow.setStatusCode("S"); // show
117 dataAccessService.saveDomainObject(persRow, null);
119 // User has role-based access to the app.
120 // Showing an accessible app requires no record.
121 if (persRow.getId() != null)
122 dataAccessService.deleteDomainObject(persRow, null);
126 if (isPortalAdmin && !adminUserHasAppRole) {
127 // The special case: portal admin, no role
128 if (persRow.getId() != null)
129 dataAccessService.deleteDomainObject(persRow, null);
131 // User has role-based access to the app.
132 // Hiding an accessible app requires a record
133 persRow.setStatusCode("H"); // hide
134 dataAccessService.saveDomainObject(persRow, null);