[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-os / src / main / java / org / openecomp / portalapp / portal / service / EPAppServiceImpl.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.portal.service;
21
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.TreeSet;
26
27 import org.openecomp.portalapp.portal.domain.EPApp;
28 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.openecomp.portalsdk.core.service.DataAccessService;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.context.annotation.EnableAspectJAutoProxy;
33 import org.springframework.stereotype.Service;
34 import org.springframework.transaction.annotation.Transactional;
35
36 @Service("epAppService")
37 @Transactional
38 @org.springframework.context.annotation.Configuration
39 @EnableAspectJAutoProxy
40 @EPMetricsLog
41 public class EPAppServiceImpl extends EPAppCommonServiceImpl implements EPAppService {
42
43         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppServiceImpl.class);
44
45         @Autowired
46         private DataAccessService dataAccessService;
47         
48         @Override
49         public List<EPApp> getUserRemoteApps(String id) {
50                 
51                         StringBuilder query = new StringBuilder();
52                 
53                         query.append("SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID = FN_APP.APP_ID where ");
54                         query.append(
55                                                 "FN_USER_ROLE.USER_ID = " + id + " AND FN_USER_ROLE.ROLE_ID != " + SUPER_ADMIN_ROLE_ID);
56                         query.append(" AND FN_APP.ENABLED = 'Y'");
57
58                         TreeSet<EPApp> distinctApps = new TreeSet<EPApp>();
59
60                         @SuppressWarnings("unchecked")
61                         List<EPApp> adminApps = dataAccessService.executeSQLQuery(query.toString(), EPApp.class, null);
62                         for (EPApp app : adminApps) {
63                                 distinctApps.add(app);
64                         }
65
66                         List<EPApp> userApps = new ArrayList<EPApp>();
67                         userApps.addAll(distinctApps);
68                         return userApps;
69         
70         }
71 }