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;
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 import java.util.UUID;
30 import javax.servlet.http.HttpServletResponse;
32 import org.hibernate.Session;
33 import org.hibernate.Transaction;
34 import org.openecomp.portalapp.portal.domain.EPApp;
35 import org.openecomp.portalapp.portal.domain.EPUser;
36 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
37 import org.openecomp.portalapp.portal.logging.format.EPAppMessagesEnum;
38 import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
39 import org.openecomp.portalapp.portal.transport.FieldsValidator;
40 import org.openecomp.portalapp.portal.transport.OnboardingApp;
41 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
42 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
43 import org.openecomp.portalsdk.core.service.DataAccessService;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.context.annotation.EnableAspectJAutoProxy;
46 import org.springframework.stereotype.Service;
47 import org.springframework.transaction.annotation.Transactional;
49 import com.att.nsa.cambria.client.CambriaClientFactory;
50 import com.att.nsa.cambria.client.CambriaTopicManager;
52 @Service("epAppService")
54 @org.springframework.context.annotation.Configuration
55 @EnableAspectJAutoProxy
57 public class EPAppServiceImpl extends EPAppCommonServiceImpl implements EPAppService {
59 private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(EPAppServiceImpl.class);
61 private static Object syncRests = new Object();
64 private DataAccessService dataAccessService;
67 public List<EPApp> getUserRemoteApps(String id) {
69 StringBuilder query = new StringBuilder();
71 query.append("SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID = FN_APP.APP_ID where ");
73 "FN_USER_ROLE.USER_ID = " + id + " AND FN_USER_ROLE.ROLE_ID != " + SUPER_ADMIN_ROLE_ID);
74 query.append(" AND FN_APP.ENABLED = 'Y'");
76 TreeSet<EPApp> distinctApps = new TreeSet<EPApp>();
78 @SuppressWarnings("unchecked")
79 List<EPApp> adminApps = dataAccessService.executeSQLQuery(query.toString(), EPApp.class, null);
80 for (EPApp app : adminApps) {
81 distinctApps.add(app);
84 List<EPApp> userApps = new ArrayList<EPApp>();
85 userApps.addAll(distinctApps);
90 protected void updateRestrictedApp(Long appId, OnboardingApp onboardingApp, FieldsValidator fieldsValidator,
92 synchronized (syncRests) {
93 boolean result = false;
94 Session localSession = null;
95 Transaction transaction = null;
97 localSession = sessionFactory.openSession();
98 transaction = localSession.beginTransaction();
103 // In the parent class, the UEB code is responsible for generating the keys/secret/mailbox but UEB Messaging
104 // is not actually being used currently; may be used in future at which point we can just remove this method and
105 // depend on parent class's method
106 // So, using UUID generator to generate the unique key instead.
107 String uuidStr = UUID.randomUUID().toString();
108 String appKey = uuidStr;
109 String appSecret = uuidStr;
110 String appMailboxName = "ECOMP-PORTAL-OUTBOX";
111 onboardingApp.setUebTopicName(appMailboxName);
112 onboardingApp.setUebKey(appKey);
113 onboardingApp.setUebSecret(appSecret);
116 app = (EPApp) localSession.get(EPApp.class, appId);
117 if (app == null || app.getId() == null) {
118 // App is already deleted!
119 transaction.commit();
120 localSession.close();
121 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_NOT_FOUND);
125 logger.debug(EELFLoggerDelegate.debugLogger, "LR: about to call createAppFromOnboarding");
126 createAppFromOnboarding(app, onboardingApp, localSession);
127 logger.debug(EELFLoggerDelegate.debugLogger,
128 "LR: updateApp: finished calling createAppFromOnboarding");
129 localSession.saveOrUpdate(app);
130 logger.debug(EELFLoggerDelegate.debugLogger,
131 "LR: updateApp: finished calling localSession.saveOrUpdate");
132 // Enable or disable all menu items associated with this app
133 setFunctionalMenuItemsEnabled(localSession, onboardingApp.isEnabled, appId);
134 logger.debug(EELFLoggerDelegate.debugLogger,
135 "LR: updateApp: finished calling setFunctionalMenuItemsEnabled");
136 transaction.commit();
137 logger.debug(EELFLoggerDelegate.debugLogger, "LR: updateApp: finished calling transaction.commit");
139 } catch (Exception e) {
140 logger.error(EELFLoggerDelegate.errorLogger, "updateApp failed", e);
141 EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeUebRegisterOnboardingAppError, e);
142 EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
143 EcompPortalUtils.rollbackTransaction(transaction,
144 "updateApp rollback, exception = " + EcompPortalUtils.getStackTrace(e));
146 EcompPortalUtils.closeLocalSession(localSession, "updateApp");
149 fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
155 public CambriaTopicManager getTopicManager(LinkedList<String> urlList, String key, String secret) throws GeneralSecurityException, Exception{
156 return CambriaClientFactory.createTopicManager( null, urlList, key, secret);