2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portal.service.app;
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.Optional;
46 import javax.persistence.EntityExistsException;
47 import javax.persistence.EntityManager;
49 import org.onap.portal.domain.db.fn.FnApp;
50 import org.onap.portal.domain.dto.transport.OnboardingApp;
51 import org.onap.portal.utils.EPCommonSystemProperties;
52 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
53 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
54 import org.onap.portalsdk.core.util.SystemProperties;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.stereotype.Service;
59 public class FnAppService {
61 private static final String SUPER_ADMIN_ROLE_ID = "1";
63 private final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FnAppService.class);
65 private final FnAppDao fnAppDao;
66 private final EntityManager entityManager;
69 public FnAppService(FnAppDao fnAppDao, EntityManager entityManager) {
70 this.fnAppDao = fnAppDao;
71 this.entityManager = entityManager;
74 public List<FnApp> getAppsFullList() {
75 return fnAppDao.findAll();
78 public FnApp getById(final Long id) {
79 return Optional.of(fnAppDao.getOne(id)).orElseThrow(EntityExistsException::new);
82 public List<FnApp> getByUebKey(final String uebKey){
83 return Optional.of(fnAppDao.getByUebKey(uebKey)).orElse(new ArrayList<>());
86 public List<FnApp> getCentralizedApps(){
87 return Optional.of(fnAppDao.getCentralizedApps()).orElse(new ArrayList<>());
90 public void createOnboardingFromApp(FnApp app, OnboardingApp onboardingApp) {
91 onboardingApp.setId(app.getId());
92 onboardingApp.setName(app.getAppName());
93 onboardingApp.setImageUrl(app.getAppImageUrl());
94 onboardingApp.setDescription(app.getAppDescription());
95 onboardingApp.setNotes(app.getAppNotes());
96 onboardingApp.setUrl(app.getAppUrl());
97 onboardingApp.setAlternateUrl(app.getAppAlternateUrl());
98 onboardingApp.setRestUrl(app.getAppRestEndpoint());
99 onboardingApp.setIsOpen(app.getOpen());
100 onboardingApp.setIsEnabled(app.getEnabled());
101 onboardingApp.setUsername(app.getAppUsername());
102 onboardingApp.setAppPassword((app.getAppPassword().equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD))
103 ? EPCommonSystemProperties.APP_DISPLAY_PASSWORD : decryptedPassword(app.getAppPassword(), app));
104 onboardingApp.setUebTopicName(app.getUebTopicName());
105 onboardingApp.setUebKey(app.getUebKey());
106 onboardingApp.setUebSecret(app.getUebSecret());
107 onboardingApp.setIsCentralAuth(app.getAuthCentral());
108 onboardingApp.setNameSpace(app.getAuthNamespace());
109 onboardingApp.setRestrictedApp(app.isRestrictedApp());
112 private String decryptedPassword(String encryptedAppPwd, FnApp app) {
114 if (encryptedAppPwd != null && !encryptedAppPwd.isEmpty()) {
116 result = CipherUtil.decryptPKC(encryptedAppPwd,
117 SystemProperties.getProperty(SystemProperties.Decryption_Key));
118 } catch (Exception e) {
119 logger.error(EELFLoggerDelegate.errorLogger,
120 "decryptedPassword failed for app " + app.getAppName(), e);
126 public List<FnApp> getUserRemoteApps(String id) {
127 /* StringBuilder sb = new StringBuilder();
128 sb.append("SELECT * FROM FnApp join FN_USER_ROLE ON FN_USER_ROLE.APP_ID = FN_APP.APP_ID where ");
129 sb.append("FN_USER_ROLE.USER_ID = ").append(id).append(" AND FN_USER_ROLE.ROLE_ID != ")
130 .append(SUPER_ADMIN_ROLE_ID);
131 sb.append(" AND FN_APP.ENABLED = 'Y'");
133 Query query = entityManager.createQuery(sb.toString());
134 List<FnApp> adminApps = query.getResultList();*/
135 return new ArrayList<>();
138 public List<FnApp> saveAll(List<FnApp> fnApps) {
139 return fnAppDao.saveAll(fnApps);