2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.service;
40 import java.util.List;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.context.annotation.EnableAspectJAutoProxy;
44 import org.springframework.stereotype.Service;
45 import org.springframework.transaction.annotation.Transactional;
47 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
48 import org.openecomp.portalsdk.core.service.DataAccessService;
49 import org.openecomp.portalapp.portal.domain.EPApp;
50 import org.openecomp.portalapp.portal.domain.EPUser;
51 import org.openecomp.portalapp.portal.domain.EPUserApp;
52 import org.openecomp.portalapp.portal.domain.PersUserAppSelection;
53 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
55 @Service("persUserAppService")
57 @org.springframework.context.annotation.Configuration
58 @EnableAspectJAutoProxy
60 public class PersUserAppServiceImpl implements PersUserAppService {
62 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(PersUserAppServiceImpl.class);
65 private DataAccessService dataAccessService;
67 private AdminRolesService adminRolesService;
69 private UserRolesService userRolesService;
74 * @see org.openecomp.portalapp.portal.service.UserAppSelectService#
75 * setAppCatalogSelection(org.openecomp.portalapp.portal.domain.EPUser,
76 * org.openecomp.portalapp.portal.transport.AppCatalogSelection)
79 public void setPersUserAppValue(EPUser user, EPApp app, boolean select, boolean pending) {
80 if (user == null || app == null)
81 throw new IllegalArgumentException("setPersUserAppValue: Null values");
83 // Find the record for this user-app combo, if any
84 String filter = " where user_id = " + Long.toString(user.getId()) + " and app_id = "
85 + Long.toString(app.getId());
86 @SuppressWarnings("unchecked")
87 List<PersUserAppSelection> persList = dataAccessService.getList(PersUserAppSelection.class, filter, null, null);
89 // Key constraint limits to 1 row
90 PersUserAppSelection persRow = null;
91 if (persList.size() == 1)
92 persRow = persList.get(0);
94 persRow = new PersUserAppSelection(null, user.getId(), app.getId(), null);
97 // Pending status is not meaningful for open apps.
99 logger.error(EELFLoggerDelegate.errorLogger,
100 "setPersUserAppValue: invalid request, ignoring set-pending for open app");
102 // Open apps have same behavior for regular and admin users
104 // Selection of an open app requires a record
105 persRow.setStatusCode("S"); // show
106 dataAccessService.saveDomainObject(persRow, null);
108 // De-selection of an open app requires no record
109 if (persRow.getId() != null)
110 dataAccessService.deleteDomainObject(persRow, null);
115 // Pending overrides select.
117 persRow.setStatusCode("P");
118 dataAccessService.saveDomainObject(persRow, null);
120 // Behavior depends on Portal (super) admin status, bcos an
121 // admin can force an app onto the dashboard.
122 boolean isPortalAdmin = adminRolesService.isSuperAdmin(user);
123 boolean adminUserHasAppRole = false;
125 List<EPUserApp> roles = userRolesService.getCachedAppRolesForUser(app.getId(), user.getId());
126 adminUserHasAppRole = (roles.size() > 0);
127 logger.debug(EELFLoggerDelegate.debugLogger, "setPersUserAppValue: app {}, admin user {}, role count {}",
128 app.getId(), user.getId(), roles.size());
133 // The special case: portal admin
134 persRow.setStatusCode("S"); // show
135 dataAccessService.saveDomainObject(persRow, null);
137 // User has role-based access to the app.
138 // Showing an accessible app requires no record.
139 if (persRow.getId() != null)
140 dataAccessService.deleteDomainObject(persRow, null);
144 if (isPortalAdmin && !adminUserHasAppRole) {
145 // The special case: portal admin, no role
146 if (persRow.getId() != null)
147 dataAccessService.deleteDomainObject(persRow, null);
149 // User has role-based access to the app.
150 // Hiding an accessible app requires a record
151 persRow.setStatusCode("H"); // hide
152 dataAccessService.saveDomainObject(persRow, null);