[PORTAL-16 PORTAL-18] Widget ms; staging
[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.security.GeneralSecurityException;
24 import java.util.ArrayList;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.TreeSet;
28
29 import org.openecomp.portalapp.portal.domain.EPApp;
30 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.openecomp.portalsdk.core.service.DataAccessService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.EnableAspectJAutoProxy;
35 import org.springframework.stereotype.Service;
36 import org.springframework.transaction.annotation.Transactional;
37
38 import com.att.nsa.cambria.client.CambriaClientFactory;
39 import com.att.nsa.cambria.client.CambriaTopicManager;
40
41 @Service("epAppService")
42 @Transactional
43 @org.springframework.context.annotation.Configuration
44 @EnableAspectJAutoProxy
45 @EPMetricsLog
46 public class EPAppServiceImpl extends EPAppCommonServiceImpl implements EPAppService {
47
48         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppServiceImpl.class);
49
50         @Autowired
51         private DataAccessService dataAccessService;
52         
53         @Override
54         public List<EPApp> getUserRemoteApps(String id) {
55                 
56                         StringBuilder query = new StringBuilder();
57                 
58                         query.append("SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID = FN_APP.APP_ID where ");
59                         query.append(
60                                                 "FN_USER_ROLE.USER_ID = " + id + " AND FN_USER_ROLE.ROLE_ID != " + SUPER_ADMIN_ROLE_ID);
61                         query.append(" AND FN_APP.ENABLED = 'Y'");
62
63                         TreeSet<EPApp> distinctApps = new TreeSet<EPApp>();
64
65                         @SuppressWarnings("unchecked")
66                         List<EPApp> adminApps = dataAccessService.executeSQLQuery(query.toString(), EPApp.class, null);
67                         for (EPApp app : adminApps) {
68                                 distinctApps.add(app);
69                         }
70
71                         List<EPApp> userApps = new ArrayList<EPApp>();
72                         userApps.addAll(distinctApps);
73                         return userApps;
74         
75         }
76         
77         public CambriaTopicManager getTopicManager(LinkedList<String> urlList, String key, String secret) throws GeneralSecurityException, Exception{
78                 return CambriaClientFactory.createTopicManager( null, urlList, key, secret);
79         }
80
81 }